|
|
|
@ -13,6 +13,8 @@ define(['backbone', 'text!./../template/classTag.html'], |
|
|
|
this.config = o.config || {}; |
|
|
|
this.coll = o.coll || null; |
|
|
|
this.pfx = this.config.stylePrefix || ''; |
|
|
|
this.ppfx = this.config.pStylePrefix || ''; |
|
|
|
this.inputProp = 'readonly'; |
|
|
|
this.target = this.config.target; |
|
|
|
this.className = this.pfx + 'tag'; |
|
|
|
this.closeId = this.pfx + 'close'; |
|
|
|
@ -20,13 +22,33 @@ define(['backbone', 'text!./../template/classTag.html'], |
|
|
|
this.labelId = this.pfx + 'tag-label'; |
|
|
|
this.events['click #' + this.closeId ] = 'removeTag'; |
|
|
|
this.events['click #' + this.chkId ] = 'changeStatus'; |
|
|
|
this.events['click #' + this.labelId ] = 'changeStatus'; |
|
|
|
this.events['dblclick #' + this.labelId ] = 'startEditTag'; |
|
|
|
this.events['keypress #' + this.labelId + ' input'] = 'updateInputLabel'; |
|
|
|
this.events['blur #' + this.labelId + ' input'] = 'endEditTag'; |
|
|
|
|
|
|
|
this.listenTo( this.model, 'change:active', this.updateStatus); |
|
|
|
//this.listenTo( this.model, 'change:label', this.updateStatus);
|
|
|
|
|
|
|
|
this.delegateEvents(); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Start editing tag |
|
|
|
*/ |
|
|
|
startEditTag: function(){ |
|
|
|
this.$labelInput.prop(this.inputProp, false); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* End editing tag |
|
|
|
*/ |
|
|
|
endEditTag: function(){ |
|
|
|
this.$labelInput.prop(this.inputProp, true); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Update status of the tag |
|
|
|
*/ |
|
|
|
changeStatus: function(){ |
|
|
|
this.model.set('active', !this.model.get('active')); |
|
|
|
this.target.trigger('targetClassUpdated'); |
|
|
|
@ -66,14 +88,28 @@ define(['backbone', 'text!./../template/classTag.html'], |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Update label's input |
|
|
|
*/ |
|
|
|
updateInputLabel: function(){ |
|
|
|
if(!this.$labelInput) |
|
|
|
this.$labelInput = this.$el.find('input'); |
|
|
|
var size = this.$labelInput.val().length - 2; |
|
|
|
size = size < 1 ? 1 : size; |
|
|
|
this.$labelInput.attr('size', size); |
|
|
|
}, |
|
|
|
|
|
|
|
/** @inheritdoc */ |
|
|
|
render : function(){ |
|
|
|
this.$el.html( this.template({ |
|
|
|
label: this.model.get('label'), |
|
|
|
pfx: this.pfx, |
|
|
|
ppfx: this.ppfx, |
|
|
|
inputProp: this.inputProp, |
|
|
|
})); |
|
|
|
this.updateStatus(); |
|
|
|
this.$el.attr('class', this.className); |
|
|
|
this.updateInputLabel(); |
|
|
|
return this; |
|
|
|
}, |
|
|
|
|
|
|
|
|