diff --git a/app/assets/javascripts/discourse/components/directory-item.js.es6 b/app/assets/javascripts/discourse/components/directory-item.js.es6 new file mode 100644 index 00000000000..df32734571e --- /dev/null +++ b/app/assets/javascripts/discourse/components/directory-item.js.es6 @@ -0,0 +1,7 @@ +import { propertyEqual } from 'discourse/lib/computed'; + +export default Ember.Component.extend({ + tagName: 'tr', + classNameBindings: ['me'], + me: propertyEqual('item.user.id', 'currentUser.id') +}); diff --git a/app/assets/javascripts/discourse/components/flag-action-type.js.es6 b/app/assets/javascripts/discourse/components/flag-action-type.js.es6 new file mode 100644 index 00000000000..031831219c3 --- /dev/null +++ b/app/assets/javascripts/discourse/components/flag-action-type.js.es6 @@ -0,0 +1,54 @@ +import { MAX_MESSAGE_LENGTH } from 'discourse/models/post-action-type'; +import computed from 'ember-addons/ember-computed-decorators'; + +export default Ember.Component.extend({ + + @computed('flag.name_key') + customPlaceholder(nameKey) { + return I18n.t("flagging.custom_placeholder_" + nameKey); + }, + + @computed('flag.name', 'flag.name_key', 'flag.is_custom_flag', 'username') + formattedName(name, nameKey, isCustomFlag, username) { + if (isCustomFlag) { + return name.replace("{{username}}", username); + } else { + return I18n.t("flagging.formatted_name." + nameKey); + } + }, + + @computed('flag', 'selectedFlag') + selected(flag, selectedFlag) { + return flag === selectedFlag; + }, + + showMessageInput: Em.computed.and('flag.is_custom_flag', 'selected'), + showDescription: Em.computed.not('showMessageInput'), + isNotifyUser: Em.computed.equal('flag.name_key', 'notify_user'), + + @computed('message.length') + customMessageLengthClasses(messageLength) { + return (messageLength < Discourse.SiteSettings.min_private_message_post_length) ? "too-short" : "ok"; + }, + + @computed('message.length') + customMessageLength(messageLength) { + const len = messageLength || 0; + const minLen = Discourse.SiteSettings.min_private_message_post_length; + if (len === 0) { + return I18n.t("flagging.custom_message.at_least", { n: minLen }); + } else if (len < minLen) { + return I18n.t("flagging.custom_message.more", { n: minLen - len }); + } else { + return I18n.t("flagging.custom_message.left", { + n: MAX_MESSAGE_LENGTH - len + }); + } + }, + + actions: { + changePostActionType(at) { + this.sendAction('changePostActionType', at); + } + } +}); diff --git a/app/assets/javascripts/discourse/controllers/queued-post.js.es6 b/app/assets/javascripts/discourse/components/queued-post.js.es6 similarity index 71% rename from app/assets/javascripts/discourse/controllers/queued-post.js.es6 rename to app/assets/javascripts/discourse/components/queued-post.js.es6 index a285537491e..28f5a90fdd0 100644 --- a/app/assets/javascripts/discourse/controllers/queued-post.js.es6 +++ b/app/assets/javascripts/discourse/components/queued-post.js.es6 @@ -1,5 +1,5 @@ import { propertyEqual } from 'discourse/lib/computed'; -import BufferedContent from 'discourse/mixins/buffered-content'; +import { bufferedProperty } from 'discourse/mixins/buffered-content'; import { popupAjaxError } from 'discourse/lib/ajax-error'; function updateState(state, opts) { @@ -12,18 +12,14 @@ function updateState(state, opts) { if (opts.deleteUser) { args.delete_user = true; } post.update(args).then(() => { - this.get('controllers.queued-posts.model').removeObject(post); + this.sendAction('removePost', post); + // this.get('controllers.queued-posts.model').removeObject(post); }).catch(popupAjaxError); }; } -export default Ember.Controller.extend(BufferedContent, { - needs: ['queued-posts'], - post: Ember.computed.alias('model'), - currentlyEditing: Ember.computed.alias('controllers.queued-posts.editing'), - - editing: propertyEqual('model', 'currentlyEditing'), - +export default Ember.Component.extend(bufferedProperty('post'), { + editing: propertyEqual('post', 'currentlyEditing'), _confirmDelete: updateState('rejected', {deleteUser: true}), actions: { @@ -31,7 +27,7 @@ export default Ember.Controller.extend(BufferedContent, { reject: updateState('rejected'), deleteUser() { - bootbox.confirm(I18n.t('queue.delete_prompt', {username: this.get('model.user.username')}), (confirmed) => { + bootbox.confirm(I18n.t('queue.delete_prompt', {username: this.get('post.user.username')}), (confirmed) => { if (confirmed) { this._confirmDelete(); } }); }, @@ -39,7 +35,7 @@ export default Ember.Controller.extend(BufferedContent, { edit() { // This is stupid but pagedown cannot be on the screen twice or it will break this.set('currentlyEditing', null); - Ember.run.scheduleOnce('afterRender', () => this.set('currentlyEditing', this.get('model'))); + Ember.run.scheduleOnce('afterRender', () => this.set('currentlyEditing', this.get('post'))); }, confirmEdit() { diff --git a/app/assets/javascripts/discourse/controllers/directory-item.js.es6 b/app/assets/javascripts/discourse/controllers/directory-item.js.es6 deleted file mode 100644 index 2d09b3824f3..00000000000 --- a/app/assets/javascripts/discourse/controllers/directory-item.js.es6 +++ /dev/null @@ -1,5 +0,0 @@ -import { propertyEqual } from 'discourse/lib/computed'; - -export default Ember.Controller.extend({ - me: propertyEqual('model.user.id', 'currentUser.id') -}); diff --git a/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 b/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 deleted file mode 100644 index d706a88e1c1..00000000000 --- a/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 +++ /dev/null @@ -1,48 +0,0 @@ -import { MAX_MESSAGE_LENGTH } from 'discourse/models/post-action-type'; - -// Supports logic for flags in the modal -export default Ember.Controller.extend({ - needs: ['flag'], - - message: Em.computed.alias('controllers.flag.message'), - isWarning: Em.computed.alias('controllers.flag.isWarning'), - - customPlaceholder: function(){ - return I18n.t("flagging.custom_placeholder_" + this.get('model.name_key')); - }.property('model.name_key'), - - formattedName: function(){ - if (this.get("model.is_custom_flag")) { - return this.get('model.name').replace("{{username}}", this.get('controllers.flag.model.username')); - } else { - return I18n.t("flagging.formatted_name." + this.get('model.name_key')); - } - }.property('model.name', 'model.name_key', 'model.is_custom_flag'), - - selected: function() { - return this.get('model') === this.get('controllers.flag.selected'); - }.property('controllers.flag.selected'), - - showMessageInput: Em.computed.and('model.is_custom_flag', 'selected'), - showDescription: Em.computed.not('showMessageInput'), - isNotifyUser: Em.computed.equal('model.name_key', 'notify_user'), - - customMessageLengthClasses: function() { - return (this.get('message.length') < Discourse.SiteSettings.min_private_message_post_length) ? "too-short" : "ok"; - }.property('message.length'), - - customMessageLength: function() { - var len = this.get('message.length') || 0; - var minLen = Discourse.SiteSettings.min_private_message_post_length; - if (len === 0) { - return I18n.t("flagging.custom_message.at_least", { n: minLen }); - } else if (len < minLen) { - return I18n.t("flagging.custom_message.more", { n: minLen - len }); - } else { - return I18n.t("flagging.custom_message.left", { - n: MAX_MESSAGE_LENGTH - len - }); - } - }.property('message.length') - -}); diff --git a/app/assets/javascripts/discourse/routes/queued-posts.js.es6 b/app/assets/javascripts/discourse/routes/queued-posts.js.es6 index 32706c9a6c3..cf5c204d943 100644 --- a/app/assets/javascripts/discourse/routes/queued-posts.js.es6 +++ b/app/assets/javascripts/discourse/routes/queued-posts.js.es6 @@ -13,6 +13,10 @@ export default DiscourseRoute.extend({ }, actions: { + removePost(post) { + this.modelFor('queued-posts').removeObject(post); + }, + refresh() { this.modelFor('queued-posts').refresh(); } diff --git a/app/assets/javascripts/discourse/templates/components/directory-item.hbs b/app/assets/javascripts/discourse/templates/components/directory-item.hbs new file mode 100644 index 00000000000..4b1d9a940e1 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/directory-item.hbs @@ -0,0 +1,11 @@ +