1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-07-01 08:20:57 +02:00
keeweb/app/scripts/views/tag-view.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-01-31 07:50:28 +01:00
const Backbone = require('backbone');
const Locale = require('../util/locale');
const Alerts = require('../comp/alerts');
2016-04-17 22:02:39 +02:00
2017-01-31 07:50:28 +01:00
const TagView = Backbone.View.extend({
2016-04-17 22:02:39 +02:00
template: require('templates/tag.hbs'),
events: {
'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'
},
initialize: function() {
this.appModel = this.model;
},
render: function() {
if (this.model) {
2019-08-16 23:05:39 +02:00
this.renderTemplate(
{
title: this.model.get('title')
},
true
);
2016-04-17 22:02:39 +02:00
}
return this;
},
showTag: function(tag) {
this.model = tag;
this.render();
},
renameTag: function() {
2017-01-31 07:50:28 +01:00
const title = $.trim(this.$el.find('#tag__field-title').val());
2016-04-17 22:02:39 +02:00
if (!title || title === this.model.get('title')) {
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;
}
2016-07-17 13:30:38 +02:00
if (this.appModel.tags.some(t => t.toLowerCase() === title.toLowerCase())) {
2016-04-17 22:02:39 +02:00
Alerts.error({ header: Locale.tagExists, body: Locale.tagExistsBody });
return;
}
this.appModel.renameTag(this.model.get('title'), title);
Backbone.trigger('select-all');
},
moveToTrash: function() {
this.title = null;
Alerts.yesno({
header: Locale.tagTrashQuestion,
body: Locale.tagTrashQuestionBody,
2016-07-17 13:30:38 +02:00
success: () => {
this.appModel.renameTag(this.model.get('title'), undefined);
2016-04-17 22:02:39 +02:00
Backbone.trigger('select-all');
}
});
},
returnToApp: function() {
Backbone.trigger('edit-tag');
}
});
module.exports = TagView;