Skip to content

Instantly share code, notes, and snippets.

@leepfrog
Created March 22, 2012 04:52
Show Gist options
  • Save leepfrog/2156129 to your computer and use it in GitHub Desktop.
Save leepfrog/2156129 to your computer and use it in GitHub Desktop.
Unable to use when loading objects from store
App.actionsController = Em.ArrayController.create({
content: [],
sort: function() {
var array, newArray;
array = this.get('content').toArray();
newArray = array.sort(function(a, b) {
var a_due, a_isdone, a_isstarred, b_due, b_isdone, b_isstarred;
a_isdone = a.get('isDone') ? 1 : 0;
b_isdone = b.get('isDone') ? 1 : 0;
a_isstarred = a.get('isStarred') ? 1 : 0;
b_isstarred = b.get('isStarred') ? 1 : 0;
a_due = a.get('due_at');
b_due = b.get('due_at');
if (a_isdone === b_isdone) {
if (a_isstarred === b_isstarred) {
if (a_due === b_due) {
return 0;
} else {
if (a_due < b_due) {
return -1;
} else {
return 1;
}
}
} else {
return b_isstarred - a_isstarred;
}
} else {
return a_isdone - b_isdone;
}
});
return this.set('content', newArray);
},
loadBlock: function(idNum) {
this.set('content', App.store.find(App.ActionItem, {issue_id: idNum}));
return this.sort();
},
toggleStar: function(action) {
var starredSetting;
starredSetting = !action.get('isStarred');
action.set('isStarred', starredSetting);
return this.sort();
},
toggleDone: function(action) {
var doneSetting;
doneSetting = !action.get('isDone');
action.set('isDone', doneSetting);
return this.sort();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment