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

Language Javascript Lines 65
MD5 Hash d8b05da4b7ed158f46a5cb64e3ee6e65
Repository https://bitbucket.org/sqctest01/fulcrum.git View Raw File View Project SPDX
| Open JSFiddle
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
if (typeof Fulcrum == 'undefined') {
  Fulcrum = {};
}

Fulcrum.StoryCollection = Backbone.Collection.extend({
  model: Fulcrum.Story,

  initialize: function() {
    this.bind('change:position', this.sort);
    this.bind('change:state', this.sort);
    this.bind('change:estimate', this.sort);
    this.bind('change:labels', this.addLabelsFromStory);
    this.bind('add', this.addLabelsFromStory);
    this.bind('reset', this.resetLabels);

    this.labels = [];
  },

  comparator: function(story) {
    return story.position();
  },

  next: function(story) {
    return this.at(this.indexOf(story) + 1);
  },

  previous: function(story) {
    return this.at(this.indexOf(story) - 1);
  },

  // Returns all the stories in the named column, either #done, #in_progress,
  // #backlog or #chilly_bin
  column: function(column) {
    return this.select(function(story) {
      return story.column == column;
    });
  },

  // Returns an array of the stories in a set of columns.  Pass an array
  // of the column names accepted by column().
  columns: function(columns) {
    var that = this;
    return _.flatten(_.map(columns, function(column) {
      return that.column(column);
    }));
  },

  // Takes comma separated string of labels and adds them to the list of
  // availableLabels.  Any that are already present are ignored.
  addLabels: function(labels) {
    return (this.labels = _.union(this.labels,labels));
  },

  addLabelsFromStory: function(story) {
    return this.addLabels(story.labels());
  },

  resetLabels: function() {
    var collection = this;
    collection.each(function(story) {
      collection.addLabelsFromStory(story);
    });
  }
});
Back to Top