mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FEATURE: 'b' as a keyboard shortcut for bookmarking a topic
This commit is contained in:
parent
8b7afd644f
commit
1b1ea8e718
3 changed files with 71 additions and 21 deletions
|
@ -8,7 +8,6 @@ var PATH_BINDINGS = {
|
|||
},
|
||||
|
||||
SELECTED_POST_BINDINGS = {
|
||||
'b': 'toggleBookmark',
|
||||
'd': 'deletePost',
|
||||
'e': 'editPost',
|
||||
'l': 'toggleLike',
|
||||
|
@ -50,7 +49,8 @@ var PATH_BINDINGS = {
|
|||
'ctrl+f': 'showBuiltinSearch',
|
||||
'command+f': 'showBuiltinSearch',
|
||||
'?': 'showHelpModal', // open keyboard shortcut help
|
||||
'q': 'quoteReply'
|
||||
'q': 'quoteReply',
|
||||
'b': 'toggleBookmark'
|
||||
};
|
||||
|
||||
|
||||
|
@ -65,6 +65,11 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
_.each(FUNCTION_BINDINGS, this._bindToFunction, this);
|
||||
},
|
||||
|
||||
toggleBookmark: function(){
|
||||
this.sendToSelectedPost('toggleBookmark');
|
||||
this.sendToTopicListItemView('toggleBookmark');
|
||||
},
|
||||
|
||||
quoteReply: function(){
|
||||
$('.topic-post.selected button.create').click();
|
||||
// lazy but should work for now
|
||||
|
@ -157,19 +162,32 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
Discourse.__container__.lookup('controller:application').send('showKeyboardShortcutsHelp');
|
||||
},
|
||||
|
||||
_bindToSelectedPost: function(action, binding) {
|
||||
sendToTopicListItemView: function(action){
|
||||
var elem = $('tr.selected.topic-list-item.ember-view')[0];
|
||||
if(elem){
|
||||
var view = Ember.View.views[elem.id];
|
||||
view.send(action);
|
||||
}
|
||||
},
|
||||
|
||||
sendToSelectedPost: function(action){
|
||||
var container = this.container;
|
||||
// TODO: We should keep track of the post without a CSS class
|
||||
var selectedPostId = parseInt($('.topic-post.selected article.boxed').data('post-id'), 10);
|
||||
if (selectedPostId) {
|
||||
var topicController = container.lookup('controller:topic'),
|
||||
post = topicController.get('postStream.posts').findBy('id', selectedPostId);
|
||||
if (post) {
|
||||
topicController.send(action, post);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_bindToSelectedPost: function(action, binding) {
|
||||
var self = this;
|
||||
|
||||
this.keyTrapper.bind(binding, function() {
|
||||
// TODO: We should keep track of the post without a CSS class
|
||||
var selectedPostId = parseInt($('.topic-post.selected article.boxed').data('post-id'), 10);
|
||||
if (selectedPostId) {
|
||||
var topicController = container.lookup('controller:topic'),
|
||||
post = topicController.get('postStream.posts').findBy('id', selectedPostId);
|
||||
if (post) {
|
||||
topicController.send(action, post);
|
||||
}
|
||||
}
|
||||
self.sendToSelectedPost(action);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -244,9 +262,14 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
var $article = $articles.eq(index + direction);
|
||||
|
||||
if ($article.size() > 0) {
|
||||
|
||||
$articles.removeClass('selected');
|
||||
$article.addClass('selected');
|
||||
|
||||
if($article.is('.topic-list-item')){
|
||||
this.sendToTopicListItemView('select');
|
||||
}
|
||||
|
||||
if ($article.is('.topic-post')) {
|
||||
var tabLoc = $article.find('a.tabLoc');
|
||||
if (tabLoc.length === 0) {
|
||||
|
|
|
@ -188,15 +188,23 @@ Discourse.Topic = Discourse.Model.extend({
|
|||
|
||||
return Discourse.ajax('/t/' + this.get('id') + '/bookmark', {
|
||||
type: 'PUT',
|
||||
data: { bookmarked: self.get('bookmarked') }
|
||||
}).then(null, function (error) {
|
||||
self.toggleProperty('bookmarked');
|
||||
if (self.get("postStream.firstPostPresent")) { firstPost.toggleProperty('bookmarked'); }
|
||||
data: { bookmarked: self.get('bookmarked') },
|
||||
error: function(error){
|
||||
self.toggleProperty('bookmarked');
|
||||
if (self.get("postStream.firstPostPresent")) { firstPost.toggleProperty('bookmarked'); }
|
||||
|
||||
if (error && error.responseText) {
|
||||
bootbox.alert($.parseJSON(error.responseText).errors);
|
||||
} else {
|
||||
bootbox.alert(I18n.t('generic_error'));
|
||||
var showGenericError = true;
|
||||
|
||||
if (error && error.responseText) {
|
||||
try {
|
||||
bootbox.alert($.parseJSON(error.responseText).errors);
|
||||
showGenericError = false;
|
||||
} catch(e){}
|
||||
}
|
||||
|
||||
if(showGenericError){
|
||||
bootbox.alert(I18n.t('generic_error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
@ -6,13 +6,32 @@ export default Discourse.View.extend(StringBuffer, {
|
|||
rawTemplate: 'list/topic_list_item.raw',
|
||||
classNameBindings: ['controller.checked',
|
||||
':topic-list-item',
|
||||
'unboundClassNames'
|
||||
'unboundClassNames',
|
||||
'selected'
|
||||
],
|
||||
actions: {
|
||||
select: function(){
|
||||
this.set('controller.selected', this);
|
||||
},
|
||||
|
||||
toggleBookmark: function(){
|
||||
var self = this;
|
||||
this.get('topic').toggleBookmark().catch(function(){
|
||||
self.rerender();
|
||||
});
|
||||
self.rerender();
|
||||
}
|
||||
},
|
||||
|
||||
selected: function(){
|
||||
return this.get('controller.selected')===this;
|
||||
}.property('controller.selected'),
|
||||
|
||||
unboundClassNames: function(){
|
||||
var classes = [];
|
||||
var topic = this.get('topic');
|
||||
|
||||
|
||||
if (topic.get('category')) {
|
||||
classes.push("category-" + topic.get('category.slug'));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue