fulcrum /app/assets/javascripts/models/note.js

Language Javascript Lines 41
MD5 Hash 9b86c3ccce9057e91c1b48dd3112cda4
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
if (typeof Fulcrum == 'undefined') {
  Fulcrum = {};
}

Fulcrum.Note = Backbone.Model.extend({

  name: 'note',

  user: function() {
    var userId = this.get('user_id');
    return this.collection.story.collection.project.users.get(userId);
  },

  userName: function() {
    var user = this.user();
    return user ? user.get('name') : 'Author unknown';
  },

  // FIXME - DRY, repeated in Story model
  hasErrors: function() {
    return (typeof this.get('errors') != "undefined");
  },

  // FIXME - DRY, repeated in Story model
  errorsOn: function(field) {
    if (!this.hasErrors()) {
      return false;
    }
    return (typeof this.get('errors')[field] != "undefined");
  },

  // FIXME - DRY, repeated in Story model
  errorMessages: function() {
    return _.map(this.get('errors'), function(errors, field) {
      return _.map(errors, function(error) {
        return field + " " + error;
      }).join(', ');
    }).join(', ');
  }
});
Back to Top