Remove `SortedMixin`

This commit is contained in:
Robin Ward 2016-12-01 11:33:33 -05:00
parent 0dbcb4ec8a
commit 69ff0e48b4
3 changed files with 11 additions and 21 deletions

View File

@ -6,12 +6,8 @@ export default Ember.Controller.extend({
fieldTypes: null, fieldTypes: null,
createDisabled: Em.computed.gte('model.length', MAX_FIELDS), createDisabled: Em.computed.gte('model.length', MAX_FIELDS),
arrangedContent: function() { fieldSortOrder: ['position'],
return Ember.ArrayProxy.extend(Ember.SortableMixin).create({ sortedFields: Ember.computed.sort('model', 'fieldSortOrder'),
sortProperties: ['position'],
content: this.get('model')
});
}.property('model'),
actions: { actions: {
createField() { createField() {
@ -20,9 +16,9 @@ export default Ember.Controller.extend({
}, },
moveUp(f) { moveUp(f) {
const idx = this.get('arrangedContent').indexOf(f); const idx = this.get('sortedFields').indexOf(f);
if (idx) { if (idx) {
const prev = this.get('arrangedContent').objectAt(idx-1); const prev = this.get('sortedFields').objectAt(idx-1);
const prevPos = prev.get('position'); const prevPos = prev.get('position');
prev.update({ position: f.get('position') }); prev.update({ position: f.get('position') });
@ -31,9 +27,9 @@ export default Ember.Controller.extend({
}, },
moveDown(f) { moveDown(f) {
const idx = this.get('arrangedContent').indexOf(f); const idx = this.get('sortedFields').indexOf(f);
if (idx > -1) { if (idx > -1) {
const next = this.get('arrangedContent').objectAt(idx+1); const next = this.get('sortedFields').objectAt(idx+1);
const nextPos = next.get('position'); const nextPos = next.get('position');
next.update({ position: f.get('position') }); next.update({ position: f.get('position') });

View File

@ -4,11 +4,11 @@
<p class="desc">{{i18n 'admin.user_fields.help'}}</p> <p class="desc">{{i18n 'admin.user_fields.help'}}</p>
{{#if model}} {{#if model}}
{{#each arrangedContent as |uf|}} {{#each sortedFields as |uf|}}
{{admin-user-field-item userField=uf {{admin-user-field-item userField=uf
fieldTypes=fieldTypes fieldTypes=fieldTypes
firstField=arrangedContent.firstObject firstField=sortedFields.firstObject
lastField=arrangedContent.lastObject lastField=sortedFields.lastObject
destroyAction="destroy" destroyAction="destroy"
moveUpAction="moveUp" moveUpAction="moveUp"
moveDownAction="moveDown"}} moveDownAction="moveDown"}}

View File

@ -5,8 +5,6 @@ import { popupAjaxError } from 'discourse/lib/ajax-error';
import { on, default as computed } from "ember-addons/ember-computed-decorators"; import { on, default as computed } from "ember-addons/ember-computed-decorators";
import Ember from 'ember'; import Ember from 'ember';
const SortableArrayProxy = Ember.ArrayProxy.extend(Ember.SortableMixin);
export default Ember.Controller.extend(ModalFunctionality, Ember.Evented, { export default Ember.Controller.extend(ModalFunctionality, Ember.Evented, {
@on('init') @on('init')
@ -20,12 +18,8 @@ export default Ember.Controller.extend(ModalFunctionality, Ember.Evented, {
return categories.map(c => bufProxy.create({ content: c })); return categories.map(c => bufProxy.create({ content: c }));
}, },
categoriesOrdered: function() { categoriesSorting: ['position'],
return SortableArrayProxy.create({ categoriesOrdered: Ember.computed.sort('categoriesBuffered', 'categoriesSorting'),
sortProperties: ['content.position'],
content: this.get('categoriesBuffered')
});
}.property('categoriesBuffered'),
showFixIndices: function() { showFixIndices: function() {
const cats = this.get('categoriesOrdered'); const cats = this.get('categoriesOrdered');