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

76 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-01-31 07:50:28 +01:00
const Backbone = require('backbone');
const AutoTypeHintView = require('../auto-type-hint-view');
const Locale = require('../../util/locale');
const FeatureDetector = require('../../util/feature-detector');
const AutoType = require('../../auto-type');
2016-04-23 16:50:40 +02:00
2017-01-31 07:50:28 +01:00
const DetailsAutoTypeView = Backbone.View.extend({
2016-04-23 16:50:40 +02:00
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() {
2017-01-31 07:50:28 +01:00
const detAutoTypeShortcutsDesc = Locale.detAutoTypeShortcutsDesc
2016-04-23 16:50:40 +02:00
.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) {
2017-01-31 07:50:28 +01:00
const el = e.target;
const seq = $.trim(el.value);
2016-07-17 13:30:38 +02:00
AutoType.validate(this.model, seq, err => {
2016-04-23 16:50:40 +02:00
$(el).toggleClass('input--error', !!err);
if (!err) {
2016-07-17 13:30:38 +02:00
this.model.setAutoTypeSeq(seq);
2016-04-23 16:50:40 +02:00
}
});
},
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) {
2019-08-16 23:05:39 +02:00
this.views.hint = new AutoTypeHintView({ input: e.target }).render();
this.views.hint.on('remove', () => {
delete this.views.hint;
});
2016-04-26 21:40:18 +02:00
}
},
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;