Skip to content

Instantly share code, notes, and snippets.

@imjoshdean
Created January 27, 2016 17:12
Show Gist options
  • Save imjoshdean/b4e473ef60f109eafca3 to your computer and use it in GitHub Desktop.
Save imjoshdean/b4e473ef60f109eafca3 to your computer and use it in GitHub Desktop.
steal('can/component',
/* ...*/,
function(Component) {
var timestampComparator = function(ascending) {
return function(modelA, modelB) {
var timeStampA = modelA.attr('call.state.timestamp-connect'),
timeStampB = modelB.attr('call.state.timestamp-connect'),
callModel;
if (modelA.attr('call.info.consult-for-call-id')) {
callModel = Models.Call.model({'call-id': modelA.attr('call.info.consult-for-call-id')});
timeStampA = callModel.attr('state.timestamp-connect');
}
if (modelB.attr('call.info.consult-for-call-id')) {
callModel = Models.Call.model({'call-id': modelB.attr('call.info.consult-for-call-id')});
timeStampB = callModel.attr('state.timestamp-connect');
}
if(ascending) {
return timeStampA === timeStampB ? 0 : timeStampA > timeStampB ? 1 : -1;
}
else {
return timeStampA === timeStampB ? 0 : timeStampA < timeStampB ? 1 : -1;
}
};
};
Component.extend({
/* ... */
someFunction: function() {
if(this.isOperator()) {
callList.attr('comparator', timestampComparator(true));
}
else {
callList.attr('comparator', timestampComparator(false));
}
}
/* ... */
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment