|
|
|
|
@ -36,6 +36,11 @@ define([
|
|
|
|
|
this.$droplist = $('<ul />')
|
|
|
|
|
.addClass('dropdown-menu')
|
|
|
|
|
.appendTo(this.$buttongroup);
|
|
|
|
|
|
|
|
|
|
this.model.on('change:button_style', function(model, value) {
|
|
|
|
|
this.update_button_style();
|
|
|
|
|
}, this);
|
|
|
|
|
this.update_button_style('');
|
|
|
|
|
|
|
|
|
|
// Set defaults.
|
|
|
|
|
this.update();
|
|
|
|
|
@ -96,6 +101,18 @@ define([
|
|
|
|
|
return DropdownView.__super__.update.apply(this);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update_button_style: function(previous_trait_value) {
|
|
|
|
|
var class_map = {
|
|
|
|
|
primary: ['btn-primary'],
|
|
|
|
|
success: ['btn-success'],
|
|
|
|
|
info: ['btn-info'],
|
|
|
|
|
warning: ['btn-warning'],
|
|
|
|
|
danger: ['btn-danger']
|
|
|
|
|
};
|
|
|
|
|
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$droplabel);
|
|
|
|
|
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$dropbutton);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update_attr: function(name, value) {
|
|
|
|
|
// Set a css attr of the widget view.
|
|
|
|
|
if (name.substring(0, 6) == 'border' || name == 'background' || name == 'color') {
|
|
|
|
|
@ -103,9 +120,13 @@ define([
|
|
|
|
|
this.$dropbutton.css(name, value);
|
|
|
|
|
this.$droplist.css(name, value);
|
|
|
|
|
} else if (name == 'width') {
|
|
|
|
|
var width = value - this.$dropbutton.width();
|
|
|
|
|
this.$droplist.css(name, width);
|
|
|
|
|
this.$droplabel.css(name, width);
|
|
|
|
|
this.$droplist.css(name, value);
|
|
|
|
|
this.$droplabel.css(name, value);
|
|
|
|
|
} else if (name == 'padding') {
|
|
|
|
|
this.$droplist.css(name, value);
|
|
|
|
|
this.$buttongroup.css(name, value);
|
|
|
|
|
} else if (name == 'margin') {
|
|
|
|
|
this.$buttongroup.css(name, value);
|
|
|
|
|
} else if (name == 'height') {
|
|
|
|
|
this.$droplabel.css(name, value);
|
|
|
|
|
this.$dropbutton.css(name, value);
|
|
|
|
|
@ -239,6 +260,11 @@ define([
|
|
|
|
|
.addClass('btn-group')
|
|
|
|
|
.attr('data-toggle', 'buttons-radio')
|
|
|
|
|
.appendTo(this.$el);
|
|
|
|
|
|
|
|
|
|
this.model.on('change:button_style', function(model, value) {
|
|
|
|
|
this.update_button_style();
|
|
|
|
|
}, this);
|
|
|
|
|
this.update_button_style('');
|
|
|
|
|
this.update();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -269,7 +295,7 @@ define([
|
|
|
|
|
.appendTo(that.$buttongroup)
|
|
|
|
|
.attr('data-value', item)
|
|
|
|
|
.on('click', $.proxy(that.handle_click, that));
|
|
|
|
|
that._update_button_style($item_element);
|
|
|
|
|
that.update_style_traits($item_element);
|
|
|
|
|
}
|
|
|
|
|
if (that.model.get('value_name') == item) {
|
|
|
|
|
$item_element.addClass('active');
|
|
|
|
|
@ -310,23 +336,36 @@ define([
|
|
|
|
|
update_attr: function(name, value) {
|
|
|
|
|
// Set a css attr of the widget view.
|
|
|
|
|
this._css_state[name] = value;
|
|
|
|
|
this._update_button_style();
|
|
|
|
|
this.update_style_traits();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_update_button_style: function(button) {
|
|
|
|
|
update_style_traits: function(button) {
|
|
|
|
|
for (var name in this._css_state) {
|
|
|
|
|
if (this._css_state.hasOwnProperty(name) && name != 'width') {
|
|
|
|
|
if (button) {
|
|
|
|
|
button.css(name, this._css_state[name]);
|
|
|
|
|
} else {
|
|
|
|
|
this.$buttongroup.find('button').each(function(i, obj) {
|
|
|
|
|
$(obj).css(name, this._css_state[name]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (this._css_state.hasOwnProperty(name)) {
|
|
|
|
|
if (name == 'margin') {
|
|
|
|
|
this.$buttongroup.css(name, this._css_state[name]);
|
|
|
|
|
} else if (name != 'width') {
|
|
|
|
|
if (button) {
|
|
|
|
|
button.css(name, this._css_state[name]);
|
|
|
|
|
} else {
|
|
|
|
|
this.$buttongroup.find('button').css(name, this._css_state[name]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update_button_style: function(previous_trait_value) {
|
|
|
|
|
var class_map = {
|
|
|
|
|
primary: ['btn-primary'],
|
|
|
|
|
success: ['btn-success'],
|
|
|
|
|
info: ['btn-info'],
|
|
|
|
|
warning: ['btn-warning'],
|
|
|
|
|
danger: ['btn-danger']
|
|
|
|
|
};
|
|
|
|
|
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$buttongroup.find('button'));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handle_click: function (e) {
|
|
|
|
|
// Handle when a value is clicked.
|
|
|
|
|
|
|
|
|
|
|