1 define(function(require) {
5 var $ = require('libs/jquery'),
6 Backbone = require('libs/backbone'),
7 template = require('libs/text!./menu.html'),
8 itemTemplate = require('libs/text!./menuitem.html');
11 var Menu = function() {
12 this.dom = $(template);
15 $.extend(Menu.prototype, {
16 addAction: function(action) {
17 var item = new MenuItem(action);
18 item.on('execute', function() {
23 this.actions.push(action);
24 this.dom.find('ul').append(item.dom);
30 this.dom.find('.dropdown-menu').dropdown('toggle');
32 updateContextParam: function(k, v) {
33 this.actions.forEach(function(action) {
34 action.updateContextParam(k, v);
39 var MenuItem = function(action) {
41 this.dom = $(itemTemplate);
43 action.on('paramsChanged', function() {
47 this.dom.on('click', function() {
48 if(this.action.getState().allowed) {
49 this.trigger('execute');
55 $.extend(MenuItem.prototype, Backbone.Events, {
57 var state = this.action.getState();
58 this.dom.find('a').text(state.label || '?');
59 this.dom.toggleClass('disabled', !state.allowed);