2019-09-15 14:16:32 +02:00
|
|
|
import Backbone from 'backbone';
|
|
|
|
import { MenuItemCollection } from 'collections/menu/menu-item-collection';
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
const MenuSectionModel = Backbone.Model.extend({
|
2015-10-17 23:49:24 +02:00
|
|
|
defaults: {
|
|
|
|
items: null,
|
|
|
|
scrollable: false,
|
|
|
|
grow: false,
|
|
|
|
drag: false
|
|
|
|
},
|
|
|
|
|
|
|
|
defaultItems: undefined,
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
initialize(items) {
|
2015-10-17 23:49:24 +02:00
|
|
|
this.set('items', new MenuItemCollection(items || this.defaultItems));
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
addItem(item) {
|
2015-10-17 23:49:24 +02:00
|
|
|
this.get('items').add(item);
|
|
|
|
this.trigger('change-items');
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
removeAllItems() {
|
2015-10-17 23:49:24 +02:00
|
|
|
this.get('items').reset(this.defaultItems);
|
|
|
|
this.trigger('change-items');
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
removeByFile(file) {
|
2017-01-31 07:50:28 +01:00
|
|
|
const items = this.get('items');
|
2016-07-17 13:30:38 +02:00
|
|
|
items.find(item => {
|
2015-11-07 21:37:54 +01:00
|
|
|
if (item.file === file || item.get('file') === file) {
|
2016-06-05 16:49:00 +02:00
|
|
|
items.remove(item);
|
|
|
|
return true;
|
2015-11-07 21:37:54 +01:00
|
|
|
}
|
2019-08-18 10:17:09 +02:00
|
|
|
return false;
|
2015-11-07 21:37:54 +01:00
|
|
|
});
|
2016-06-05 16:49:00 +02:00
|
|
|
this.trigger('change-items');
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
replaceByFile(file, newItem) {
|
2017-01-31 07:50:28 +01:00
|
|
|
const items = this.get('items');
|
2016-07-17 13:30:38 +02:00
|
|
|
items.find((item, ix) => {
|
2016-06-05 16:49:00 +02:00
|
|
|
if (item.file === file || item.get('file') === file) {
|
|
|
|
items.remove(item);
|
|
|
|
items.add(newItem, { at: ix });
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-18 10:17:09 +02:00
|
|
|
return false;
|
2016-06-05 16:49:00 +02:00
|
|
|
});
|
|
|
|
this.trigger('change-items');
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
setItems(items) {
|
2015-10-17 23:49:24 +02:00
|
|
|
this.get('items').reset(items);
|
|
|
|
this.trigger('change-items');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
export { MenuSectionModel };
|