mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-29 08:00:53 +02:00
71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
import Backbone from 'backbone';
|
|
import { MenuOptionCollection } from 'collections/menu/menu-option-collection';
|
|
let ItemCollection;
|
|
|
|
const MenuItemModel = Backbone.Model.extend({
|
|
defaults: {
|
|
title: '',
|
|
icon: '',
|
|
customIcon: null,
|
|
active: false,
|
|
expanded: true,
|
|
items: null,
|
|
shortcut: null,
|
|
options: null,
|
|
cls: null,
|
|
disabled: false,
|
|
visible: true,
|
|
drag: false,
|
|
drop: false,
|
|
filterKey: null,
|
|
filterValue: null,
|
|
collapsible: false
|
|
},
|
|
|
|
initialize(model) {
|
|
if (model && model.file) {
|
|
this.listenTo(model.file, 'change:name', this.changeTitle, this);
|
|
}
|
|
},
|
|
|
|
_loadItemCollectionType() {
|
|
return require('collections/menu/menu-item-collection').MenuItemCollection;
|
|
},
|
|
|
|
addItem(item) {
|
|
if (!ItemCollection) {
|
|
ItemCollection = this._loadItemCollectionType();
|
|
}
|
|
let items = this.get('items');
|
|
if (!items) {
|
|
items = new ItemCollection();
|
|
this.set('items', items);
|
|
}
|
|
items.add(item);
|
|
},
|
|
|
|
addOption(option) {
|
|
let options = this.get('options');
|
|
if (!options) {
|
|
options = new MenuOptionCollection();
|
|
this.set('options', options);
|
|
}
|
|
options.add(option);
|
|
},
|
|
|
|
toggleExpanded() {
|
|
const items = this.get('items');
|
|
let expanded = !this.get('expanded');
|
|
if (!items || !items.length) {
|
|
expanded = true;
|
|
}
|
|
this.set('expanded', expanded);
|
|
},
|
|
|
|
changeTitle(model, newTitle) {
|
|
this.set('title', newTitle);
|
|
}
|
|
});
|
|
|
|
export { MenuItemModel };
|