1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-20 06:56:40 +02:00
keeweb/app/scripts/mixins/copyable.js
2019-08-18 10:17:09 +02:00

54 lines
1.5 KiB
JavaScript

const AppSettingsModel = require('../models/app-settings-model');
const Backbone = require('backbone');
const Locale = require('../util/locale');
const Tip = require('../util/tip');
const Timeouts = require('../const/timeouts');
const Copyable = {
hideFieldCopyTip() {
if (this.fieldCopyTip) {
this.fieldCopyTip.hide();
this.fieldCopyTip = null;
}
},
fieldCopied(e) {
this.hideFieldCopyTip();
const fieldLabel = e.source.labelEl;
const clipboardTime = e.copyRes.seconds;
const msg = clipboardTime
? Locale.detFieldCopiedTime.replace('{}', clipboardTime)
: Locale.detFieldCopied;
let tip;
if (!this.isHidden()) {
tip = Tip.createTip(fieldLabel[0], {
title: msg,
placement: 'right',
fast: true,
force: true,
noInit: true
});
this.fieldCopyTip = tip;
tip.show();
}
setTimeout(() => {
if (tip) {
tip.hide();
}
this.fieldCopyTip = null;
if (
e.source.model.name === '$Password' &&
AppSettingsModel.instance.get('lockOnCopy')
) {
setTimeout(() => {
Backbone.trigger('lock-workspace');
}, Timeouts.BeforeAutoLock);
}
}, Timeouts.CopyTip);
}
};
module.exports = Copyable;