diff -r a2342f26c9de -r b0b56e0f8c7f server/bo_client/app/models/document.js --- a/server/bo_client/app/models/document.js Fri Jan 15 15:27:56 2016 +0100 +++ b/server/bo_client/app/models/document.js Fri Jan 15 15:35:00 2016 +0100 @@ -8,6 +8,8 @@ title: DS.attr('string'), + language: DS.attr('string'), + publishers: DS.attr({defaultValue: []}), contributors: DS.attr({defaultValue: []}), @@ -29,4 +31,43 @@ } return res; }), + + addContributor: function(contrib_def) { + var contributors = this.get('contributors'); + if(_.findIndex(contributors, function(c) { return _.isEqual(c, contrib_def);}) < 0) { + contributors.pushObject(contrib_def); + } + // must set dirty + this.set('contributors', _.clone(this.get('contributors'))); + }, + removeContributor: function(contrib_def) { + var contributors = this.get('contributors'); + var index = _.findIndex(contributors, function(c) { return _.isEqual(c, contrib_def);}); + if(index >= 0) { + contributors.removeAt(index); + } + //must set dirty + this.set('contributors', _.clone(this.get('contributors'))); + }, + saveContributor: function(contrib_def, index) { + var contributors = this.get('contributors'); + if(index < 0 || index >= contributors.length) { + return; + } + + var contrib_def_map = {name: contrib_def.name||"", url: contrib_def.url||"", role: contrib_def.role||""}; + var existingContribs = _.filter(contributors, function(c, i) { + return (i!==index && _.isEqual({name: c.name||"", url: c.url||"", role: c.role||""}, contrib_def_map)); + }); + if(existingContribs.length > 0) { + // contributor exists, remove contributor @ index + contributors.removeAt(index); + } + else { + contributors[index] = contrib_def; + } + //must set dirty only if needed + this.set('contributors', _.clone(this.get('contributors'))); + } + });