Handle multiple buttons in a single custom field

This commit is contained in:
Nathan Gray 2014-07-08 20:13:51 +00:00
parent 210ebb5706
commit a5b9173fc9

View File

@ -222,7 +222,9 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput
row.attr('data-field', field_name); row.attr('data-field', field_name);
row.attr('data-help', field.help); row.attr('data-help', field.help);
this.detachedNodes.push(row[0]); this.detachedNodes.push(row[0]);
} else { }
else
{
// Label in first column, widget in 2nd // Label in first column, widget in 2nd
cf.text(field.label + ""); cf.text(field.label + "");
cf = jQuery(document.createElement("td")) cf = jQuery(document.createElement("td"))
@ -238,7 +240,9 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput
if(!this.options.fields || jQuery.isEmptyObject(this.options.fields) || this.options.fields[field_name] == true) if(!this.options.fields || jQuery.isEmptyObject(this.options.fields) || this.options.fields[field_name] == true)
{ {
jQuery(this.rows[field_name]).show(); jQuery(this.rows[field_name]).show();
} else { }
else
{
jQuery(this.rows[field_name]).hide(); jQuery(this.rows[field_name]).hide();
} }
@ -482,12 +486,48 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput
delete(attrs.label); delete(attrs.label);
attrs.label = field.label; attrs.label = field.label;
// Simple case, one widget for a custom field
if(Object.keys(field.values).length == 1)
{
for(var key in field.values) for(var key in field.values)
{ {
attrs.label = key; attrs.label = key;
attrs.onclick = field.values[key]; attrs.onclick = field.values[key];
} }
return !attrs.readonly; return !attrs.readonly;
}
else if (this._type == 'customfields-list')
{
// No buttons in a list, it causes problems with detached nodes
return false;
}
else
{
// Complicated case, a single custom field you get multiple widgets
// Handle it all here, since this is the exception
var row = $j('tr',this.tbody).last();
var cf = $j('td',row);
// Label in first column, widget in 2nd
cf.text(field.label + "");
cf = jQuery(document.createElement("td"))
.appendTo(row);
for(var key in field.values)
{
var button_attrs = jQuery.extend({},attrs);
button_attrs.label = key;
button_attrs.onclick = field.values[key];
button_attrs.id = attrs.id + '_' + key;
// This controls where the button is placed in the DOM
this.rows[button_attrs.id] = cf[0];
// Do not store in the widgets list, one name for multiple widgets would cause problems
/*this.widgets[field_name] = */ et2_createWidget(attrs.type ? attrs.type : field.type, button_attrs, this);
}
return false;
}
}, },
_setup_link_entry: function(field_name, field, attrs) { _setup_link_entry: function(field_name, field, attrs) {
// No label on the widget itself // No label on the widget itself