From 3e2c2d451e81639dcab156bbc28f110a5b0987ab Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 16 Jun 2012 10:08:37 +0000 Subject: [PATCH] ButtonGroup: add enableButton/disableButton methods --- source/Ox.UI/js/Form/ButtonGroup.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/Form/ButtonGroup.js b/source/Ox.UI/js/Form/ButtonGroup.js index e8212e8e..d4fcb58b 100644 --- a/source/Ox.UI/js/Form/ButtonGroup.js +++ b/source/Ox.UI/js/Form/ButtonGroup.js @@ -71,26 +71,35 @@ Ox.ButtonGroup = function(options, self) { self.$buttons = []; self.options.buttons.forEach(function(button, pos) { - var id = self.options.id + Ox.toTitleCase(button.id); self.$buttons[pos] = Ox.Button({ - disabled: button.disabled, + disabled: button.disabled || false, // FIXME: getset should handle undefined group: true, - id: id, + id: button.id, selectable: self.options.selectable, size: self.options.size, style: self.options.style, title: button.title, tooltip: button.tooltip, type: self.options.type, - value: button.selected, + value: button.selected || false, // FIXME: getset should handle undefined width: button.width }) - .bindEvent('change', function() { - self.options.selectable && toggleButton(pos); + .bindEvent(self.options.selectable ? { + change: function() { + toggleButton(pos); + } + } : { + click: function() { + that.triggerEvent('click', {id: button.id}); + } }) .appendTo(that); }); + function getButtonById(id) { + return self.$buttons[Ox.getIndexById(self.options.buttons, id)]; + } + function toggleButton(pos) { var toggled = self.optionGroup.toggle(pos); if (!toggled.length) { @@ -113,6 +122,14 @@ Ox.ButtonGroup = function(options, self) { } } + that.disableButton = function(id) { + getButtonById(id).options({disabled: true}); + }; + + that.enableButton = function(id) { + getButtonById(id).options({disabled: false}); + }; + return that; };