2015-10-17 23:49:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Backbone = require('backbone'),
|
|
|
|
MenuSectionCollection = require('../../collections/menu/menu-section-collection'),
|
|
|
|
MenuSectionModel = require('./menu-section-model'),
|
|
|
|
GroupsMenuModel = require('./groups-menu-model'),
|
2015-12-17 19:25:25 +01:00
|
|
|
Locale = require('../../util/locale'),
|
2015-10-17 23:49:24 +02:00
|
|
|
Keys = require('../../const/keys'),
|
|
|
|
Colors = require('../../const/colors');
|
|
|
|
|
|
|
|
var MenuModel = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
|
|
sections: null
|
|
|
|
},
|
|
|
|
|
|
|
|
menus: null,
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.menus = {};
|
2015-12-17 19:25:25 +01:00
|
|
|
this.allItemsSection = new MenuSectionModel([{ title: Locale.menuAllItems, icon: 'th-large', active: true,
|
|
|
|
shortcut: Keys.DOM_VK_A, filterKey: '*' }]);
|
2015-10-17 23:49:24 +02:00
|
|
|
this.groupsSection = new GroupsMenuModel();
|
2015-12-17 19:25:25 +01:00
|
|
|
this.colorsSection = new MenuSectionModel([{ title: Locale.menuColors, icon: 'bookmark', shortcut: Keys.DOM_VK_C,
|
|
|
|
cls: 'menu__item-colors', filterKey: 'color', filterValue: true }]);
|
2015-10-17 23:49:24 +02:00
|
|
|
this.colorsItem = this.colorsSection.get('items').models[0];
|
2015-12-17 19:25:25 +01:00
|
|
|
var defTags = [{ title: Locale.menuTags, icon: 'tags', defaultItem: true,
|
|
|
|
disabled: { header: Locale.menuAlertNoTags, body: Locale.menuAlertNoTagsBody, icon: 'tags' } }];
|
2015-10-17 23:49:24 +02:00
|
|
|
this.tagsSection = new MenuSectionModel(defTags);
|
|
|
|
this.tagsSection.set({ scrollable: true, drag: true });
|
|
|
|
this.tagsSection.defaultItems = defTags;
|
2015-12-17 19:25:25 +01:00
|
|
|
this.trashSection = new MenuSectionModel([{ title: Locale.menuTrash, icon: 'trash', shortcut: Keys.DOM_VK_D,
|
2015-11-15 21:26:37 +01:00
|
|
|
filterKey: 'trash', filterValue: true, drop: true }]);
|
2015-10-17 23:49:24 +02:00
|
|
|
Colors.AllColors.forEach(function(color) { this.colorsSection.get('items').models[0]
|
|
|
|
.addOption({ cls: 'fa ' + color + '-color', value: color, filterValue: color }); }, this);
|
|
|
|
this.menus.app = new MenuSectionCollection([
|
|
|
|
this.allItemsSection,
|
|
|
|
this.colorsSection,
|
|
|
|
this.tagsSection,
|
|
|
|
this.groupsSection,
|
|
|
|
this.trashSection
|
|
|
|
]);
|
|
|
|
|
2015-12-17 19:25:25 +01:00
|
|
|
this.generalSection = new MenuSectionModel([{ title: Locale.menuSetGeneral, icon: 'cog', page: 'general', active: true }]);
|
|
|
|
this.shortcutsSection = new MenuSectionModel([{ title: Locale.menuSetShortcuts, icon: 'keyboard-o', page: 'shortcuts' }]);
|
|
|
|
this.aboutSection = new MenuSectionModel([{ title: Locale.menuSetAbout, icon: 'info', page: 'about' }]);
|
|
|
|
this.helpSection = new MenuSectionModel([{ title: Locale.menuSetHelp, icon: 'question', page: 'help' }]);
|
2015-10-17 23:49:24 +02:00
|
|
|
this.filesSection = new MenuSectionModel();
|
|
|
|
this.filesSection.set({ scrollable: true, grow: true });
|
|
|
|
this.menus.settings = new MenuSectionCollection([
|
|
|
|
this.generalSection,
|
|
|
|
this.shortcutsSection,
|
|
|
|
this.aboutSection,
|
2015-10-22 20:03:44 +02:00
|
|
|
this.helpSection,
|
2015-10-17 23:49:24 +02:00
|
|
|
this.filesSection
|
|
|
|
]);
|
|
|
|
this.set('sections', this.menus.app);
|
|
|
|
},
|
|
|
|
|
|
|
|
select: function(sel) {
|
|
|
|
var sections = this.get('sections');
|
|
|
|
sections.forEach(function(section) { this._select(section, sel.item); }, this);
|
|
|
|
if (sections === this.menus.app) {
|
|
|
|
this.colorsItem.get('options').forEach(function (opt) {
|
|
|
|
opt.set('active', opt === sel.option);
|
|
|
|
});
|
|
|
|
var selColor = sel.item === this.colorsItem && sel.option ? sel.option.get('value') + '-color' : '';
|
|
|
|
this.colorsItem.set('cls', 'menu__item-colors ' + selColor);
|
|
|
|
var filterKey = sel.item.get('filterKey'),
|
|
|
|
filterValue = (sel.option || sel.item).get('filterValue');
|
|
|
|
var filter = {};
|
|
|
|
filter[filterKey] = filterValue;
|
|
|
|
Backbone.trigger('set-filter', filter);
|
|
|
|
} else if (sections === this.menus.settings) {
|
|
|
|
Backbone.trigger('set-page', { page: sel.item.get('page'), file: sel.item.get('file') });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_select: function(item, selectedItem) {
|
|
|
|
var items = item.get('items');
|
|
|
|
if (items) {
|
|
|
|
items.forEach(function(it) {
|
|
|
|
it.set('active', it === selectedItem);
|
|
|
|
this._select(it, selectedItem);
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setMenu: function(type) {
|
|
|
|
this.set('sections', this.menus[type]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = MenuModel;
|