3 var Backbone
= require('backbone');
4 var context
= require('gitter-web-client-context');
5 var validateTag
= require('gitter-web-shared/validation/validate-tag').validateTag
;
7 var TagModel
= Backbone
.Model
.extend({
12 //we get an array of tag strings from the server
13 //rather than { value: '' }
14 //we need to parse them here
15 initialize: function(tag
) {
16 this.set('value', tag
);
19 validate: function(attrs
) {
20 var isStaff
= context
.isStaff();
21 var result
= validateTag(attrs
.value
, isStaff
);
23 if (result
.messages
.length
> 0) {
24 return result
.messages
.join(' ');
29 var TagCollection
= Backbone
.Collection
.extend({
32 addModel: function(model
) {
33 var val
= model
.get('value');
35 //if there is a duplicate fire error
36 if (this.where({ value
: val
}).length
) {
37 this.trigger('tag:error:duplicate', val
);
40 this.trigger('tag:added', val
);
45 return this.reduce(function(memo
, model
) {
46 memo
.push(model
.get('value'));
53 TagCollection
: TagCollection
,