Use progress bar indices in jump control, too

This commit is contained in:
riking 2014-08-14 17:52:21 -07:00
parent 8539c08d35
commit 903c760a9b
2 changed files with 29 additions and 10 deletions

View File

@ -7,7 +7,7 @@ export default Ember.ObjectController.extend({
toggleExpansion: function(opts) { toggleExpansion: function(opts) {
this.toggleProperty('expanded'); this.toggleProperty('expanded');
if (this.get('expanded')) { if (this.get('expanded')) {
this.set('toPostNumber', this.get('progressPosition')); this.set('toPostIndex', this.get('progressPosition'));
if(opts && opts.highlight){ if(opts && opts.highlight){
// TODO: somehow move to view? // TODO: somehow move to view?
Em.run.next(function(){ Em.run.next(function(){
@ -18,17 +18,36 @@ export default Ember.ObjectController.extend({
}, },
jumpPost: function() { jumpPost: function() {
var postNumber = parseInt(this.get('toPostNumber'), 10); var postIndex = parseInt(this.get('toPostIndex'), 10);
// Validate the post number first // Validate the post index first
if (isNaN(postNumber) || postNumber < 1) { if (isNaN(postIndex) || postIndex < 1) {
postNumber = 1; postIndex = 1;
} }
if (postNumber > this.get('highest_post_number')) { if (postIndex > this.get('postStream.filteredPostsCount')) {
postNumber = this.get('highest_post_number'); postIndex = this.get('postStream.filteredPostsCount');
}
this.set('toPostIndex', postIndex);
var stream = this.get('postStream'),
idStream = stream.get('stream'),
postId = idStream[postIndex - 1];
if (!postId) {
Em.Logger.warn("jump-post code broken - requested an index outside the stream array");
return;
}
var post = stream.findLoadedPost(postId);
if (post) {
this.jumpTo(this.get('model').urlForPostNumber(post.get('post_number')));
} else {
var self = this;
// need to load it
stream.findPostsByIds([postId]).then(function(arr) {
post = arr[0];
self.jumpTo(self.get('model').urlForPostNumber(post.get('post_number')));
});
} }
this.set('toPostNumber', postNumber);
this.jumpTo(this.get('model').urlForPostNumber(postNumber));
}, },
jumpTop: function() { jumpTop: function() {

View File

@ -5,7 +5,7 @@
{{i18n topic.progress.go_top}} {{i18n topic.progress.go_top}}
</button> </button>
<div class='jump-form'> <div class='jump-form'>
{{input value=toPostNumber}} <button {{action jumpPost}} class='btn'>{{i18n topic.progress.go}}</button> {{input value=toPostIndex}} <button {{action jumpPost}} class='btn'>{{i18n topic.progress.go}}</button>
</div> </div>
<button {{action jumpBottom}} {{bind-attr disabled=jumpBottomDisabled}} class='btn full no-text jump-bottom'> <button {{action jumpBottom}} {{bind-attr disabled=jumpBottomDisabled}} class='btn full no-text jump-bottom'>
{{i18n topic.progress.go_bottom}} {{i18n topic.progress.go_bottom}}