Skip to content

Instantly share code, notes, and snippets.

@nathansobo
Created March 18, 2010 03:47
Show Gist options
  • Save nathansobo/336024 to your computer and use it in GitHub Desktop.
Save nathansobo/336024 to your computer and use it in GitHub Desktop.
constructor("Views.Rankings", View.Template, {
content: function() { with(this.builder) {
div({id: "ranking", 'class': "widget itemList"}, function() {
div({'class': "widgetContent"}, function() {
ol().ref("rankingOl");
}).ref('widgetContent');
});
}},
viewProperties: {
attrAccessors: ["election"],
initialize: function() {
var self = this;
this.registerResizeCallbacks();
_.defer(function() {
self.rankingOl.sortable({
connectWith: "#candidates ol",
update: function(event, ui) {
self.handleUpdate(ui.item);
}
});
});
},
handleUpdate: function(item) {
if (item.parents("#ranking").length == 0) return this.handleRemoval(item);
var candidateId = item.attr('candidateId');
var predecessorId = item.prev().attr('candidateId');
var successorId = item.next().attr('candidateId');
var candidate = candidateId ? Candidate.find(candidateId) : null;
var predecessor = predecessorId ? Candidate.find(predecessorId) : null;
var successor = successorId ? Candidate.find(successorId) : null;
Ranking.createOrUpdate(Application.currentUser(), this.election(), candidate, predecessor, successor);
},
handleRemoval: function(item) {
console.debug("REMOVAL", item.attr('candidateId'));
},
registerResizeCallbacks: function() {
var self = this;
$(window).resize(function() {
self.fillHeight();
});
_.defer(function() {
self.fillHeight();
});
},
fillHeight: function() {
var height = $(window).height() - this.widgetContent.offset().top - 10;
this.rankingOl.height(height);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment