create entry templates

This commit is contained in:
antelle 2017-05-03 20:44:16 +02:00
parent a4cdb37594
commit 6930b23ad9
6 changed files with 45 additions and 3 deletions

View File

@ -123,6 +123,9 @@
"listNoWebsite": "no website",
"listNoUser": "no user",
"listNoAttachments": "no attachments",
"listAddTemplateHeader": "Templates",
"listAddTemplateBody1": "Templates allow you to create entries with one click. Add something to template entry and then click {} again to use this template.",
"listAddTemplateBody2": "You can always find your templates in {} group.",
"searchAddNew": "Add New",
"searchSort": "Sort",

View File

@ -344,6 +344,12 @@ const AppModel = Backbone.Model.extend({
return GroupModel.newGroup(sel.group, sel.file);
},
createNewTemplateEntry: function() {
const file = this.getFirstSelectedGroup().file;
const group = file.getEntryTemplatesGroup() || file.createEntryTemplatesGroup();
return EntryModel.newEntry(group, file);
},
createDemoFile: function() {
if (!this.files.getByName('Demo')) {
const demoFile = new FileModel({ id: IdGenerator.uuid() });

View File

@ -22,6 +22,7 @@ const AppSettingsModel = Backbone.Model.extend({
lockOnCopy: false,
lockOnAutoType: false,
helpTipCopyShown: false,
templateHelpShown: false,
skipOpenLocalWarn: false,
hideEmptyFields: false,
skipHttpsWarning: false,

View File

@ -344,6 +344,19 @@ const FileModel = Backbone.Model.extend({
return this.db.meta.recycleBinEnabled ? this.getGroup(this.subId(this.db.meta.recycleBinUuid.id)) : null;
},
getEntryTemplatesGroup: function() {
return this.db.meta.entryTemplatesGroup ? this.getGroup(this.subId(this.db.meta.entryTemplatesGroup.id)) : null;
},
createEntryTemplatesGroup: function() {
const rootGroup = this.get('groups').first();
const templatesGroup = GroupModel.newGroup(rootGroup, this);
templatesGroup.setName('Templates');
this.db.meta.entryTemplatesGroup = templatesGroup.group.uuid;
this.reload();
return templatesGroup;
},
setModified: function() {
if (!this.get('demo')) {
this.set({ modified: true, dirty: true });

View File

@ -252,13 +252,14 @@ const ListSearchView = Backbone.View.extend({
},
toggleSortOptions: function() {
if (this.views.searchDropdown && this.views.searchDropdown.options === this.sortOptions) {
if (this.views.searchDropdown && this.views.searchDropdown.isSort) {
this.hideSearchOptions();
return;
}
this.hideSearchOptions();
this.$el.find('.list__search-btn-sort').addClass('sel--active');
const view = new DropdownView();
view.isSort = true;
this.listenTo(view, 'cancel', this.hideSearchOptions);
this.listenTo(view, 'select', this.sortDropdownSelect);
this.sortOptions.forEach(function(opt) {
@ -275,7 +276,7 @@ const ListSearchView = Backbone.View.extend({
},
toggleCreateOptions: function() {
if (this.views.searchDropdown && this.views.searchDropdown.options === this.createOptions) {
if (this.views.searchDropdown && this.views.searchDropdown.isCreate) {
this.hideSearchOptions();
return;
}
@ -283,6 +284,7 @@ const ListSearchView = Backbone.View.extend({
this.hideSearchOptions();
this.$el.find('.list__search-btn-new').addClass('sel--active');
const view = new DropdownView();
view.isCreate = true;
this.listenTo(view, 'cancel', this.hideSearchOptions);
this.listenTo(view, 'select', this.createDropdownSelect);
view.render({

View File

@ -162,7 +162,24 @@ const ListView = Backbone.View.extend({
},
createTemplate: function() {
Alerts.notImplemented();
if (!this.model.settings.get('templateHelpShown')) {
Alerts.yesno({
icon: 'sticky-note-o',
header: Locale.listAddTemplateHeader,
body: Locale.listAddTemplateBody1.replace('{}', '<i class="fa fa-plus"></i>') + '<br/>' +
Locale.listAddTemplateBody2.replace('{}', 'Templates'),
buttons: [Alerts.buttons.ok, Alerts.buttons.cancel],
success: () => {
this.model.settings.set('templateHelpShown', true);
this.createTemplate();
}
});
return;
}
const templateEntry = this.model.createNewTemplateEntry();
this.items.unshift(templateEntry);
this.render();
this.selectItem(templateEntry);
},
selectItem: function(item) {