get-translation
Version:
Effective translation workflow
148 lines (121 loc) • 2.64 kB
JavaScript
if(typeof define !== 'function') {
var define = require('amdefine')(module);
}
define(function(require) {
var View = inServer ? require('../../libraries/View') : require('View')
, template = inServer ? content_appTemplates : require('contentTemplates')
, _ = require('underscore');
return View.extend({
/**
* Initializer
*
* @return {void}
* @api public
*/
initialize : function(model) {
this.model = model;
if(inClient) {
this._bindMethods();
this._bindModel();
}
},
/**
* Bind DOM
*
* @return {void}
* @api public
*/
bindDOM : function() {
this._addMouseInteractions();
},
/**
* Bind methods
*
* @return {void}
* @api public
*/
_bindMethods : function() {
_.bindAll(this,
'render',
'_setValue',
'_addSelectAllTextHandler',
'_selectAllText',
'_updateRow'
);
},
/**
* Bind model
*
* @return {void}
* @api private
*/
_bindModel : function() {
this.model.on('change:row', this._updateRow);
},
/**
* Add desktop listeners
*
* @return {void}
* @api private
*/
_addMouseInteractions : function() {
this._addSelectAllTextHandler();
this.$el.on('blur', this._addSelectAllTextHandler);
this.$el.on('keyup', this._setValue);
},
/**
* Adds select all text handler. The select all text handler is always
* removed after one have clicked the input. On blur we want add
* `_selectAllText` handler again.
*
* @delegate
*/
_addSelectAllTextHandler : function() {
this.$el.on('mouseup', this._selectAllText);
},
/**
* Select all text
*
* @delegate
*/
_selectAllText : function(event) {
var _this = this;
this.$el.select();
event.preventDefault();
_.defer(function() {
_this.$el.off('mouseup', _this._selectAllText);
});
},
/**
* On operator change
*
* @delegate
*/
_updateRow : function() {
this.el.dataset.row = this.model.get('row');
},
/**
* Set value on model
*
* @delegate
*/
_setValue : function() {
this.model.set('value', this.$el.val());
},
/**
* Render view
*
* @return {void}
* @api public
*/
render : function() {
return this.template(this.model.toJSON());
},
/**
* Template
*
* @type {String}
*/
template : template['Input']
});
});