Deprecation: replace `itemController` with components
This commit is contained in:
parent
4e5831c43f
commit
b1c4c8a5d0
|
@ -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')
|
||||
});
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -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() {
|
|
@ -1,5 +0,0 @@
|
|||
import { propertyEqual } from 'discourse/lib/computed';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
me: propertyEqual('model.user.id', 'currentUser.id')
|
||||
});
|
|
@ -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')
|
||||
|
||||
});
|
|
@ -13,6 +13,10 @@ export default DiscourseRoute.extend({
|
|||
},
|
||||
|
||||
actions: {
|
||||
removePost(post) {
|
||||
this.modelFor('queued-posts').removeObject(post);
|
||||
},
|
||||
|
||||
refresh() {
|
||||
this.modelFor('queued-posts').refresh();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<td>{{user-info user=item.user}}</td>
|
||||
<td>{{number item.likes_received}}</td>
|
||||
<td>{{number item.likes_given}}</td>
|
||||
<td>{{number item.topic_count}}</td>
|
||||
<td>{{number item.post_count}}</td>
|
||||
<td>{{number item.topics_entered}}</td>
|
||||
<td>{{number item.posts_read}}</td>
|
||||
<td>{{number item.days_visited}}</td>
|
||||
{{#if showTimeRead}}
|
||||
<td><span class='time-read'>{{unbound item.time_read}}</span></td>
|
||||
{{/if}}
|
|
@ -0,0 +1,27 @@
|
|||
{{#if isNotifyUser}}
|
||||
<h3>{{formattedName}}</h3>
|
||||
<div class='controls'>
|
||||
<label class='radio'><input type='radio' id="radio_{{unbound flag.name_key}}" {{action "changePostActionType" flag}} name='post_action_type_index'> <span class='description'>{{{flag.description}}}</span></label>
|
||||
{{#if showMessageInput}}
|
||||
{{textarea name="message" class="flag-message" placeholder=customPlaceholder value=message}}
|
||||
<div {{bind-attr class=":custom-message-length customMessageLengthClasses"}}>{{customMessageLength}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if staffFlagsAvailable}}
|
||||
<hr>
|
||||
<h3>{{i18n 'flagging.notify_staff'}}</h3>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<div class='controls'>
|
||||
<label class='radio'>
|
||||
<input type='radio' id="radio_{{unbound flag.name_key}}" {{action "changePostActionType" flag}} name='post_action_type_index'> <strong>{{formattedName}}</strong>
|
||||
{{#if showDescription}}
|
||||
<div class='description'>{{{flag.description}}}</div>
|
||||
{{/if}}
|
||||
</label>
|
||||
{{#if showMessageInput}}
|
||||
{{textarea name="message" class="flag-message" placeholder=customPlaceholder value=message}}
|
||||
<div {{bind-attr class=":custom-message-length customMessageLengthClasses"}}>{{customMessageLength}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
|
@ -0,0 +1,79 @@
|
|||
<div class='queued-post'>
|
||||
<div class='poster'>
|
||||
{{#user-link user=post.user}}
|
||||
{{avatar post.user imageSize="large"}}
|
||||
{{/user-link}}
|
||||
</div>
|
||||
<div class='cooked'>
|
||||
<div class='names'>
|
||||
<span class="username">
|
||||
{{#user-link user=post.user}}
|
||||
{{post.user.username}}
|
||||
{{/user-link}}
|
||||
{{#if post.user.blocked}}
|
||||
<i class='fa fa-ban' title='{{i18n "user.blocked_tooltip"}}'></i>
|
||||
{{/if}}
|
||||
</span>
|
||||
</div>
|
||||
<div class='post-info'>
|
||||
<span class='post-date'>{{age-with-tooltip post.created_at}}</span>
|
||||
</div>
|
||||
<div class='clearfix'></div>
|
||||
|
||||
<span class='post-title'>
|
||||
{{i18n "queue.topic"}}
|
||||
{{#if post.topic}}
|
||||
{{topic-link post.topic}}
|
||||
{{else}}
|
||||
{{post.post_options.title}}
|
||||
{{/if}}
|
||||
{{category-badge post.category}}
|
||||
</span>
|
||||
|
||||
<div class='body'>
|
||||
{{#if editing}}
|
||||
{{d-editor value=buffered.raw}}
|
||||
{{else}}
|
||||
{{{cook-text post.raw}}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class='queue-controls'>
|
||||
{{#if editing}}
|
||||
{{d-button action="confirmEdit"
|
||||
label="queue.confirm"
|
||||
disabled=post.isSaving
|
||||
class="btn-primary confirm"}}
|
||||
{{d-button action="cancelEdit"
|
||||
label="queue.cancel"
|
||||
icon="times"
|
||||
disabled=post.isSaving
|
||||
class="btn-danger cancel"}}
|
||||
{{else}}
|
||||
{{d-button action="approve"
|
||||
disabled=post.isSaving
|
||||
label="queue.approve"
|
||||
icon="check"
|
||||
class="btn-primary approve"}}
|
||||
{{d-button action="reject"
|
||||
disabled=post.isSaving
|
||||
label="queue.reject"
|
||||
icon="times"
|
||||
class="btn-danger reject"}}
|
||||
{{#if post.can_delete_user}}
|
||||
{{d-button action="deleteUser"
|
||||
disabled=post.isSaving
|
||||
label="queue.delete_user"
|
||||
icon="trash"
|
||||
class="btn-danger delete-user"}}
|
||||
{{/if}}
|
||||
{{d-button action="edit"
|
||||
disabled=post.isSaving
|
||||
label="queue.edit"
|
||||
icon="pencil"
|
||||
class="edit"}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
<div class='clearfix'></div>
|
||||
</div>
|
|
@ -1,34 +1,13 @@
|
|||
<div class="modal-body flag-modal">
|
||||
|
||||
<form>
|
||||
{{#each f in flagsAvailable itemController="flag-action-type"}}
|
||||
{{#if f.isNotifyUser}}
|
||||
<h3>{{f.formattedName}}</h3>
|
||||
<div class='controls'>
|
||||
<label class='radio'><input type='radio' id="radio_{{unbound f.model.name_key}}" {{action "changePostActionType" f}} name='post_action_type_index'> <span class='description'>{{{f.model.description}}}</span></label>
|
||||
{{#if f.showMessageInput}}
|
||||
{{textarea name="message" class="flag-message" placeholder=f.customPlaceholder value=f.message}}
|
||||
<div {{bind-attr class=":custom-message-length f.customMessageLengthClasses"}}>{{f.customMessageLength}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if staffFlagsAvailable}}
|
||||
<hr>
|
||||
<h3>{{i18n 'flagging.notify_staff'}}</h3>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<div class='controls'>
|
||||
<label class='radio'>
|
||||
<input type='radio' id="radio_{{unbound f.model.name_key}}" {{action "changePostActionType" f}} name='post_action_type_index'> <strong>{{f.formattedName}}</strong>
|
||||
{{#if f.showDescription}}
|
||||
<div class='description'>{{{f.model.description}}}</div>
|
||||
{{/if}}
|
||||
</label>
|
||||
{{#if f.showMessageInput}}
|
||||
{{textarea name="message" class="flag-message" placeholder=f.customPlaceholder value=f.message}}
|
||||
<div {{bind-attr class=":custom-message-length f.customMessageLengthClasses"}}>{{f.customMessageLength}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#each flagsAvailable as |f|}}
|
||||
{{flag-action-type flag=f
|
||||
message=message
|
||||
isWarning=isWarning
|
||||
selectedFlag=selected
|
||||
username=model.username
|
||||
changePostActionType="changePostActionType"}}
|
||||
{{else}}
|
||||
{{i18n 'flagging.cant'}}
|
||||
{{/each}}
|
||||
|
|
|
@ -1,85 +1,7 @@
|
|||
<div class='container'>
|
||||
<div class='queued-posts'>
|
||||
{{#each ctrl in model itemController='queued-post'}}
|
||||
<div class='queued-post'>
|
||||
<div class='poster'>
|
||||
{{#user-link user=ctrl.post.user}}
|
||||
{{avatar ctrl.post.user imageSize="large"}}
|
||||
{{/user-link}}
|
||||
</div>
|
||||
<div class='cooked'>
|
||||
<div class='names'>
|
||||
<span class="username">
|
||||
{{#user-link user=ctrl.post.user}}
|
||||
{{ctrl.post.user.username}}
|
||||
{{/user-link}}
|
||||
{{#if ctrl.post.user.blocked}}
|
||||
<i class='fa fa-ban' title='{{i18n "user.blocked_tooltip"}}'></i>
|
||||
{{/if}}
|
||||
</span>
|
||||
</div>
|
||||
<div class='post-info'>
|
||||
<span class='post-date'>{{age-with-tooltip ctrl.post.created_at}}</span>
|
||||
</div>
|
||||
<div class='clearfix'></div>
|
||||
|
||||
<span class='post-title'>
|
||||
{{i18n "queue.topic"}}
|
||||
{{#if ctrl.post.topic}}
|
||||
{{topic-link ctrl.post.topic}}
|
||||
{{else}}
|
||||
{{ctrl.post.post_options.title}}
|
||||
{{/if}}
|
||||
{{category-badge ctrl.post.category}}
|
||||
</span>
|
||||
|
||||
<div class='body'>
|
||||
{{#if ctrl.editing}}
|
||||
{{d-editor value=ctrl.buffered.raw}}
|
||||
{{else}}
|
||||
{{{cook-text ctrl.post.raw}}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class='queue-controls'>
|
||||
{{#if ctrl.editing}}
|
||||
{{d-button action="confirmEdit"
|
||||
label="queue.confirm"
|
||||
disabled=ctrl.post.isSaving
|
||||
class="btn-primary confirm"}}
|
||||
{{d-button action="cancelEdit"
|
||||
label="queue.cancel"
|
||||
icon="times"
|
||||
disabled=ctrl.post.isSaving
|
||||
class="btn-danger cancel"}}
|
||||
{{else}}
|
||||
{{d-button action="approve"
|
||||
disabled=ctrl.post.isSaving
|
||||
label="queue.approve"
|
||||
icon="check"
|
||||
class="btn-primary approve"}}
|
||||
{{d-button action="reject"
|
||||
disabled=ctrl.post.isSaving
|
||||
label="queue.reject"
|
||||
icon="times"
|
||||
class="btn-danger reject"}}
|
||||
{{#if ctrl.post.can_delete_user}}
|
||||
{{d-button action="deleteUser"
|
||||
disabled=ctrl.post.isSaving
|
||||
label="queue.delete_user"
|
||||
icon="trash"
|
||||
class="btn-danger delete-user"}}
|
||||
{{/if}}
|
||||
{{d-button action="edit"
|
||||
disabled=ctrl.post.isSaving
|
||||
label="queue.edit"
|
||||
icon="pencil"
|
||||
class="edit"}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
<div class='clearfix'></div>
|
||||
</div>
|
||||
{{#each model as |post|}}
|
||||
{{queued-post post=post currentlyEditing=editing removePost="removePost"}}
|
||||
{{else}}
|
||||
<p>{{i18n "queue.none"}}</p>
|
||||
{{/each}}
|
||||
|
|
|
@ -26,22 +26,8 @@
|
|||
{{/if}}
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each ic in model itemController="directory-item"}}
|
||||
<tr class="{{if ic.me 'me'}}">
|
||||
{{#with ic.model as |it|}}
|
||||
<td>{{user-info user=it.user}}</td>
|
||||
<td>{{number it.likes_received}}</td>
|
||||
<td>{{number it.likes_given}}</td>
|
||||
<td>{{number it.topic_count}}</td>
|
||||
<td>{{number it.post_count}}</td>
|
||||
<td>{{number it.topics_entered}}</td>
|
||||
<td>{{number it.posts_read}}</td>
|
||||
<td>{{number it.days_visited}}</td>
|
||||
{{#if controller.parentController.showTimeRead}}
|
||||
<td><span class='time-read'>{{unbound it.time_read}}</span></td>
|
||||
{{/if}}
|
||||
{{/with}}
|
||||
</tr>
|
||||
{{#each model as |item|}}
|
||||
{{directory-item item=item showTimeRead=showTimeRead}}
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue