PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/app/assets/javascripts/collections/story_collection.js

https://bitbucket.org/sqctest01/fulcrum
JavaScript | 64 lines | 47 code | 11 blank | 6 comment | 3 complexity | d8b05da4b7ed158f46a5cb64e3ee6e65 MD5 | raw file
  1. if (typeof Fulcrum == 'undefined') {
  2. Fulcrum = {};
  3. }
  4. Fulcrum.StoryCollection = Backbone.Collection.extend({
  5. model: Fulcrum.Story,
  6. initialize: function() {
  7. this.bind('change:position', this.sort);
  8. this.bind('change:state', this.sort);
  9. this.bind('change:estimate', this.sort);
  10. this.bind('change:labels', this.addLabelsFromStory);
  11. this.bind('add', this.addLabelsFromStory);
  12. this.bind('reset', this.resetLabels);
  13. this.labels = [];
  14. },
  15. comparator: function(story) {
  16. return story.position();
  17. },
  18. next: function(story) {
  19. return this.at(this.indexOf(story) + 1);
  20. },
  21. previous: function(story) {
  22. return this.at(this.indexOf(story) - 1);
  23. },
  24. // Returns all the stories in the named column, either #done, #in_progress,
  25. // #backlog or #chilly_bin
  26. column: function(column) {
  27. return this.select(function(story) {
  28. return story.column == column;
  29. });
  30. },
  31. // Returns an array of the stories in a set of columns. Pass an array
  32. // of the column names accepted by column().
  33. columns: function(columns) {
  34. var that = this;
  35. return _.flatten(_.map(columns, function(column) {
  36. return that.column(column);
  37. }));
  38. },
  39. // Takes comma separated string of labels and adds them to the list of
  40. // availableLabels. Any that are already present are ignored.
  41. addLabels: function(labels) {
  42. return (this.labels = _.union(this.labels,labels));
  43. },
  44. addLabelsFromStory: function(story) {
  45. return this.addLabels(story.labels());
  46. },
  47. resetLabels: function() {
  48. var collection = this;
  49. collection.each(function(story) {
  50. collection.addLabelsFromStory(story);
  51. });
  52. }
  53. });