1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-26 07:39:04 +02:00
keeweb/app/scripts/views/menu/menu-view.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-10-17 23:49:24 +02:00
'use strict';
var Backbone = require('backbone'),
Resizable = require('../../mixins/resizable'),
2015-10-17 23:49:24 +02:00
MenuSectionView = require('./menu-section-view'),
DragView = require('../drag-view');
var MenuView = Backbone.View.extend({
template: require('templates/menu/menu.html'),
events: {},
sectionViews: [],
minWidth: 110,
maxWidth: 300,
initialize: function () {
this.listenTo(this.model, 'change:sections', this.menuChanged);
},
remove: function() {
this.sectionViews.forEach(function(sectionView) { sectionView.remove(); });
this.sectionViews = [];
Backbone.View.prototype.remove.apply(this, arguments);
},
render: function () {
this.$el.html(this.template());
var sectionsEl = this.$el.find('.menu');
this.model.get('sections').forEach(function(section) {
var sectionView = new MenuSectionView({ el: sectionsEl, model: section });
sectionView.render();
if (section.get('drag')) {
var dragView = new DragView('y');
var dragEl = $('<div/>').addClass('menu__drag-section').appendTo(sectionsEl);
sectionView.listenDrag(dragView);
dragView.setElement(dragEl).render();
this.sectionViews.push(dragView);
}
this.sectionViews.push(sectionView);
}, this);
return this;
},
menuChanged: function() {
this.render();
2015-10-24 11:15:54 +02:00
},
2015-10-26 22:07:19 +01:00
switchVisibility: function(visible) {
this.$el.toggleClass('menu-visible', visible);
2015-10-17 23:49:24 +02:00
}
});
_.extend(MenuView.prototype, Resizable);
module.exports = MenuView;