1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-28 07:50:55 +02:00
keeweb/app/scripts/views/tag-view.js

69 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-09-16 22:57:56 +02:00
import { Events } from 'framework/events';
2019-09-16 20:42:33 +02:00
import { View } from 'framework/views/view';
2019-09-15 14:16:32 +02:00
import { Alerts } from 'comp/ui/alerts';
import { Locale } from 'util/locale';
2019-09-15 18:33:45 +02:00
import template from 'templates/tag.hbs';
2016-04-17 22:02:39 +02:00
2019-09-15 18:33:45 +02:00
class TagView extends View {
parent = '.app__panel';
2016-04-17 22:02:39 +02:00
2019-09-15 18:33:45 +02:00
template = template;
events = {
2016-04-17 22:02:39 +02:00
'click .tag__buttons-trash': 'moveToTrash',
2016-08-13 21:13:16 +02:00
'click .back-button': 'returnToApp',
2016-04-17 22:02:39 +02:00
'click .tag__btn-rename': 'renameTag'
2019-09-15 18:33:45 +02:00
};
2016-04-17 22:02:39 +02:00
2019-08-18 10:17:09 +02:00
render() {
2019-09-15 18:33:45 +02:00
if (this.tag) {
super.render({
2019-09-18 23:37:57 +02:00
title: this.tag.title
2019-09-15 18:33:45 +02:00
});
2016-04-17 22:02:39 +02:00
}
2019-09-15 18:33:45 +02:00
}
2016-04-17 22:02:39 +02:00
2019-08-18 10:17:09 +02:00
showTag(tag) {
2019-09-15 18:33:45 +02:00
this.tag = tag;
2016-04-17 22:02:39 +02:00
this.render();
2019-09-15 18:33:45 +02:00
}
2016-04-17 22:02:39 +02:00
2019-08-18 10:17:09 +02:00
renameTag() {
2017-01-31 07:50:28 +01:00
const title = $.trim(this.$el.find('#tag__field-title').val());
2019-09-18 23:37:57 +02:00
if (!title || title === this.tag.title) {
2016-04-17 22:02:39 +02:00
return;
}
if (/[;,:]/.test(title)) {
2019-08-18 08:05:38 +02:00
Alerts.error({
header: Locale.tagBadName,
body: Locale.tagBadNameBody.replace('{}', '`,`, `;`, `:`')
});
2016-04-17 22:02:39 +02:00
return;
}
2020-06-01 16:53:51 +02:00
if (this.model.tags.some((t) => t.toLowerCase() === title.toLowerCase())) {
2016-04-17 22:02:39 +02:00
Alerts.error({ header: Locale.tagExists, body: Locale.tagExistsBody });
return;
}
2019-09-18 23:37:57 +02:00
this.model.renameTag(this.tag.title, title);
2019-09-16 22:57:56 +02:00
Events.emit('select-all');
2019-09-15 18:33:45 +02:00
}
2016-04-17 22:02:39 +02:00
2019-08-18 10:17:09 +02:00
moveToTrash() {
2016-04-17 22:02:39 +02:00
this.title = null;
Alerts.yesno({
header: Locale.tagTrashQuestion,
body: Locale.tagTrashQuestionBody,
2016-07-17 13:30:38 +02:00
success: () => {
2019-09-18 23:37:57 +02:00
this.model.renameTag(this.tag.title, undefined);
2019-09-16 22:57:56 +02:00
Events.emit('select-all');
2016-04-17 22:02:39 +02:00
}
});
2019-09-15 18:33:45 +02:00
}
2016-04-17 22:02:39 +02:00
2019-08-18 10:17:09 +02:00
returnToApp() {
2019-09-16 22:57:56 +02:00
Events.emit('edit-tag');
2016-04-17 22:02:39 +02:00
}
2019-09-15 18:33:45 +02:00
}
2016-04-17 22:02:39 +02:00
2019-09-15 14:16:32 +02:00
export { TagView };