keeweb/app/scripts/views/details/details-auto-type-view.js

78 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-04-23 16:50:40 +02:00
'use strict';
var Backbone = require('backbone'),
2016-04-26 21:40:18 +02:00
AutoTypeHintView = require('../auto-type-hint-view'),
2016-04-23 16:50:40 +02:00
Locale = require('../../util/locale'),
FeatureDetector = require('../../util/feature-detector'),
AutoType = require('../../auto-type');
var DetailsAutoTypeView = Backbone.View.extend({
template: require('templates/details/details-auto-type.hbs'),
events: {
2016-04-26 21:40:18 +02:00
'focus #details__auto-type-sequence': 'seqFocus',
2016-04-23 16:50:40 +02:00
'input #details__auto-type-sequence': 'seqInput',
'keypress #details__auto-type-sequence': 'seqKeyPress',
'keydown #details__auto-type-sequence': 'seqKeyDown',
'change #details__auto-type-enabled': 'enabledChange',
'change #details__auto-type-obfuscation': 'obfuscationChange'
},
2016-04-26 21:40:18 +02:00
initialize: function() {
this.views = {};
},
2016-04-23 16:50:40 +02:00
render: function() {
var detAutoTypeShortcutsDesc = Locale.detAutoTypeShortcutsDesc
.replace('{}', FeatureDetector.actionShortcutSymbol() + 'T')
.replace('{}', FeatureDetector.globalShortcutSymbol() + 'T');
this.renderTemplate({
enabled: this.model.getEffectiveEnableAutoType(),
obfuscation: this.model.autoTypeObfuscation,
sequence: this.model.autoTypeSequence,
2016-04-26 21:40:18 +02:00
windows: this.model.autoTypeWindows,
2016-04-23 16:50:40 +02:00
defaultSequence: this.model.group.getEffectiveAutoTypeSeq(),
detAutoTypeShortcutsDesc: detAutoTypeShortcutsDesc
});
return this;
},
seqInput: function(e) {
var that = this;
var el = e.target;
2016-04-26 21:40:18 +02:00
var seq = $.trim(el.value);
2016-04-23 16:50:40 +02:00
AutoType.validate(this.model, seq, function(err) {
$(el).toggleClass('input--error', !!err);
if (!err) {
that.model.setAutoTypeSeq(seq);
}
});
},
seqKeyPress: function(e) {
e.stopPropagation();
},
seqKeyDown: function(e) {
e.stopPropagation();
},
2016-04-26 21:40:18 +02:00
seqFocus: function(e) {
if (!this.views.hint) {
this.views.hint = new AutoTypeHintView({input: e.target}).render();
this.views.hint.on('remove', (function() {delete this.views.hint; }).bind(this));
}
},
2016-04-23 16:50:40 +02:00
enabledChange: function(e) {
this.model.setEnableAutoType(e.target.checked);
},
obfuscationChange: function(e) {
this.model.setAutoTypeObfuscation(e.target.checked);
}
});
module.exports = DetailsAutoTypeView;