Allow slide toggles for checkboxes in toolbar if they specify toggle_on or toggle_off

This commit is contained in:
Nathan Gray 2016-01-09 00:54:02 +00:00
parent 000376c69d
commit 863e64f0fd
2 changed files with 59 additions and 9 deletions

View File

@ -310,7 +310,7 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput],
var dropdown = et2_createWidget("dropdown_button", { var dropdown = et2_createWidget("dropdown_button", {
id: action.id id: action.id
},this); },this);
dropdown.set_select_options(children); dropdown.set_select_options(children);
dropdown.set_label (action.caption); dropdown.set_label (action.caption);
//Set default selected action //Set default selected action
@ -358,14 +358,14 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput],
} }
// ************** Drag and Drop feature for toolbar ***** // ************** Drag and Drop feature for toolbar *****
this.actionlist.find('span').sort( function (lg,g){ this.actionlist.find('span[data-group]').sort( function (lg,g){
return +lg.getAttribute('data-group') - +g.getAttribute('data-group'); return +lg.getAttribute('data-group') - +g.getAttribute('data-group');
}).appendTo(this.actionlist); }).appendTo(this.actionlist);
this.actionlist.appendTo(this.div); this.actionlist.appendTo(this.div);
this.actionbox.appendTo(this.div); this.actionbox.appendTo(this.div);
var toolbar = this.actionlist.find('span').children(), var toolbar = this.actionlist.find('span[data-group]').children(),
toolbox = this.actionbox, toolbox = this.actionbox,
menulist = jQuery(this.actionbox.children()[1]); menulist = jQuery(this.actionbox.children()[1]);
@ -476,15 +476,41 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput],
if (action && action.checkbox) if (action && action.checkbox)
{ {
if (this.checkbox(action.id)) button.addClass('toolbar_toggled'+ (typeof action.toggledClass != 'undefined'?" "+action.toggledClass:'')); if (action.data.toggle_on || action.data.toggle_off)
} {
var toggle = et2_createWidget('checkbox', {
id: this.id+'-'+action.id,
toggle_on: action.data.toggle_on,
toggle_off: action.data.toggle_off
}, this);
toggle.doLoadingFinished();
toggle.set_value(action.checked);
action.data.widget = toggle;
toggle =toggle.toggle;
toggle.appendTo(button.parent())
.attr('id', this.id+'-'+action.id);
button.remove();
button = toggle;
}
else
{
if (this.checkbox(action.id)) button.addClass('toolbar_toggled'+ (typeof action.toggledClass != 'undefined'?" "+action.toggledClass:''));
}
}
if ( action.iconUrl) if ( action.iconUrl)
{ {
button.attr('style','background-image:url(' + action.iconUrl + ')'); button.attr('style','background-image:url(' + action.iconUrl + ')');
} }
if (action.caption) if (action.caption)
{ {
if ((this.countActions <= parseInt(this.options.view_range) || // Set label for checkboxes inside the dropdown
if(this.preference[action.id] &&
action.data && action.data.widget && action.data.widget.instanceOf(et2_checkbox))
{
button.prepend(action.caption);
}
else if ((this.countActions <= parseInt(this.options.view_range) ||
this.preference[action.id]) && this.preference[action.id]) &&
typeof button[0] !== 'undefined') typeof button[0] !== 'undefined')
{ {
@ -543,13 +569,17 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput],
{ {
if (!_action || typeof this._actionManager == 'undefined') return undefined; if (!_action || typeof this._actionManager == 'undefined') return undefined;
var action_event = this._actionManager.getActionById(_action); var action_event = this._actionManager.getActionById(_action);
if (action_event && typeof _value !='undefined') if (action_event && typeof _value !='undefined')
{ {
action_event.set_checked(_value);
var btn = jQuery('#'+this.id+'-'+_action); var btn = jQuery('#'+this.id+'-'+_action);
if (btn.length > 0) if(action_event.data && action_event.data.widget)
{
action_event.data.widget.set_value(_value);
}
else if (btn.length > 0)
{ {
action_event.set_checked(_value);
btn.toggleClass('toolbar_toggled'+ (typeof action_event.data.toggledClass != 'undefined'?" "+action_event.data.toggledClass:'')); btn.toggleClass('toolbar_toggled'+ (typeof action_event.data.toggledClass != 'undefined'?" "+action_event.data.toggledClass:''));
} }
} }

View File

@ -1738,6 +1738,26 @@ span.et2_checkbox_slideSwitch > input {
span.et2_checkbox_slideSwitch.switchOn > span.slideSwitch_container a { span.et2_checkbox_slideSwitch.switchOn > span.slideSwitch_container a {
right:50%; right:50%;
} }
/* Slide switch in a toolbar */
.et2_toolbar_actionlist span.et2_checkbox_slideSwitch {
padding-right: 12px;
padding-bottom: 2px;
vertical-align: bottom;
}
.et2_toolbar_activeList span.et2_checkbox_slideSwitch {
text-align: left;
color: black;
font-size: 11px;
font-weight: normal;
width: 100%;
}
.et2_toolbar_activeList span.et2_checkbox_slideSwitch > span.slideSwitch_container {
width: 40px;
float: left;
}
.et2_toolbar_activeList span.et2_checkbox_slideSwitch > input {
display: none;
}
.et2_radiobox { .et2_radiobox {
margin-right: 5px; margin-right: 5px;