server/bo_client/app/models/document.js
changeset 137 1baa7c6bd370
parent 130 fac22d8c2df8
child 158 366509ae2f37
--- a/server/bo_client/app/models/document.js	Wed Mar 02 13:47:07 2016 +0100
+++ b/server/bo_client/app/models/document.js	Thu Mar 03 17:34:12 2016 +0100
@@ -1,6 +1,7 @@
 import DS from 'ember-data';
 import Ember from 'ember';
 import _ from 'lodash/lodash';
+import * as utils from 'corpus-common-addon/utils/utils';
 
 export default DS.Model.extend({
   //id: attr('string'),
@@ -70,6 +71,23 @@
     }
     //must set dirty only if needed
     this.set('contributors', _.clone(this.get('contributors')));
-  }
+  },
+  removeSubject: function(subject_def) {
+    var subjects = this.get('subjects');
+    var index = _.findIndex(subjects, function(s) { return _.isEqual(s, subject_def);});
+    if(index >= 0) {
+      subjects.removeAt(index);
+    }
+    //must set dirty
+    this.set('subjects', _.clone(subjects));
+  },
+  addSubject: function(subject_def) {
+    var subjects = this.get('subjects');
+    if(_.findIndex(subjects, function(s) { return _.isEqual(s, subject_def) || _.isEqual(s, utils.switchArkBnfLink(subject_def));}) < 0) {
+      subjects.pushObject(subject_def);
+    }
+    // must set dirty
+    this.set('subjects', _.clone(subjects));
+  },
 
 });