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

76 lines
2.3 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');
2019-09-15 08:47:57 +02:00
const Shortcuts = require('../../comp/app/shortcuts');
2017-01-31 07:50:28 +01:00
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'
},
2019-08-18 10:17:09 +02:00
initialize() {
2016-04-26 21:40:18 +02:00
this.views = {};
},
2019-08-18 10:17:09 +02:00
render() {
2017-01-31 07:50:28 +01:00
const detAutoTypeShortcutsDesc = Locale.detAutoTypeShortcutsDesc
.replace('{}', Shortcuts.actionShortcutSymbol() + 'T')
.replace('{}', Shortcuts.globalShortcutText('autoType'));
2016-04-23 16:50:40 +02:00
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(),
2019-08-18 10:17:09 +02:00
detAutoTypeShortcutsDesc
2016-04-23 16:50:40 +02:00
});
return this;
},
2019-08-18 10:17:09 +02:00
seqInput(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
}
});
},
2019-08-18 10:17:09 +02:00
seqKeyPress(e) {
2016-04-23 16:50:40 +02:00
e.stopPropagation();
},
2019-08-18 10:17:09 +02:00
seqKeyDown(e) {
2016-04-23 16:50:40 +02:00
e.stopPropagation();
},
2019-08-18 10:17:09 +02:00
seqFocus(e) {
2016-04-26 21:40:18 +02:00
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
}
},
2019-08-18 10:17:09 +02:00
enabledChange(e) {
2016-04-23 16:50:40 +02:00
this.model.setEnableAutoType(e.target.checked);
},
2019-08-18 10:17:09 +02:00
obfuscationChange(e) {
2016-04-23 16:50:40 +02:00
this.model.setAutoTypeObfuscation(e.target.checked);
}
});
module.exports = DetailsAutoTypeView;