1 /*globals View render_template scriptletCenter*/
2 var ButtonToolbarView = View.extend({
3 _className: 'ButtonToolbarView',
7 init: function(element, model, parent, template) {
8 this._super(element, model, null);
10 this.template = 'button-toolbar-view-template';
12 this.model.addObserver(this, 'buttons', this.modelButtonsChanged.bind(this));
13 this.buttons = this.model.get('buttons');
18 modelButtonsChanged: function(property, value) {
19 this.set('buttons', value);
24 $('.buttontoolbarview-tab', this.element).unbind('click.buttontoolbarview');
25 $('.buttontoolbarview-button', this.element).unbind('click.buttontoolbarview');
28 this.element.html(render_template(this.template, this));
30 $('.buttontoolbarview-tab', this.element).bind('click.buttontoolbarview', function() {
31 var groupIndex = $(this).attr('ui:groupindex');
32 $('.buttontoolbarview-group', self.element).each(function() {
33 if ($(this).attr('ui:groupindex') == groupIndex) {
39 $(self.element).trigger('resize');
42 $('.buttontoolbarview-button', this.element).
43 bind('click.buttontoolbarview', this.buttonPressed.bind(this) );
45 $(this.element).trigger('resize');
48 buttonPressed: function(event)
50 var target = event.target;
52 var groupIndex = parseInt($(target).attr('ui:groupindex'), 10);
53 var buttonIndex = parseInt($(target).attr('ui:buttonindex'), 10);
54 var button = this.get('buttons')[groupIndex].buttons[buttonIndex];
55 var scriptletId = button.scriptlet_id;
56 var params = eval('(' + button.params + ')'); // To nie powinno być potrzebne
58 console.log('Executing', scriptletId, 'with params', params);
60 scriptletCenter.scriptlets[scriptletId](this.parent, params);
62 console.log("Scriptlet", scriptletId, "failed.");
68 $('.buttontoolbarview-tab', this.element).unbind('click.buttontoolbarview');
69 $('.buttontoolbarview-button', this.element).unbind('click.buttontoolbarview');