var SharedModelMethods = require('mixins/shared_model_methods');

var Activity = module.exports = Backbone.Model.extend({
  name: 'activity',

  i18nScope: 'activerecord.attributes.',

  timestampFormat: 'd mmm yyyy',

  initialize: function(args) {
    var attributes = this.attributes;
    var data = args.activity;

    this.i18nScope += data.subject_type.toLowerCase();
    attributes.date = new Date(data.updated_at).format(this.timestampFormat);
    attributes.action = this.humanActionName(data.action);
    attributes.subject_changes = this.parseChanges(data.subject_changes);
  },

  humanActionName: function(action) {
    return I18n.t(action, {scope: 'activity.actions'});
  },

  parseChanges: function(changes) {
    return _.map(changes, function(value, key) {
      if (key == 'documents_attributes') key = 'documents';
      return {
        attribute: this.humanAttributeName(key),
        oldValue: value[0],
        newValue: value[1]
      }
    }, this);
  }
});

_.defaults(Activity.prototype, SharedModelMethods);

@@ -247,46 +247,8 @@
 ) %7B%0A
-    var attributes = this.attributes;%0A
     
@@ -337,25 +337,30 @@
     
-attributes.
+this.set(%7B%0A      
 date
- =
+:
  new
@@ -414,33 +414,23 @@
 mat)
-;%0A
+,%0A  
     
-attributes.
 action
- =
+:
  thi
@@ -463,25 +463,16 @@
 ion)
-;
+,
 %0A    
-attributes.
+  
 subj
@@ -482,18 +482,17 @@
 _changes
- =
+:
  this.pa
@@ -523,16 +523,23 @@
 changes)
+%0A    %7D)
 ;%0A  %7D,%0A%0A

Fix 'Do not access attributes directly.' error on Activity