Form fields: added callbacks ('equals' and 'get_field_value') to allow the implementation of enhanced form fields

SVN:trunk[3356]
This commit is contained in:
Romain Quetiez
2014-10-01 12:17:15 +00:00
parent 68dd0513c6
commit 110aace270
2 changed files with 40 additions and 9 deletions

View File

@@ -234,9 +234,11 @@ class DesignerForm
}
$sNotifyParentSelectorJS = is_null($sNotifyParentSelector) ? 'null' : "'".addslashes($sNotifyParentSelector)."'";
$sAutoApply = $oField->IsAutoApply() ? 'true' : 'false';
$sHandlerEquals = $oField->GetHandlerEquals();
$sHandlerGetValue = $oField->GetHandlerGetValue();
$this->AddReadyScript(
<<<EOF
$('#row_$sFieldId').property_field({parent_selector: $sNotifyParentSelectorJS, field_id: '$sFieldId', auto_apply: $sAutoApply, value: '', submit_to: '$sActionUrl', submit_parameters: $sJSSubmitParams });
$('#row_$sFieldId').property_field({parent_selector: $sNotifyParentSelectorJS, field_id: '$sFieldId', equals: $sHandlerEquals, get_field_value: $sHandlerGetValue, auto_apply: $sAutoApply, value: '', submit_to: '$sActionUrl', submit_parameters: $sJSSubmitParams });
EOF
);
}
@@ -670,6 +672,16 @@ class DesignerFormField
{
$this->aCSSClasses[] = $sCSSClass;
}
public function GetHandlerEquals()
{
return 'null';
}
public function GetHandlerGetValue()
{
return 'null';
}
}
class DesignerLabelField extends DesignerFormField

View File

@@ -10,12 +10,13 @@ $(function()
{
parent_selector: null,
field_id: '',
get_field_value: null,
equals: null,
submit_to: 'index.php',
submit_parameters: {operation: 'async_action'},
do_apply: null,
do_cancel: null,
auto_apply: false
},
// the constructor
@@ -83,7 +84,11 @@ $(function()
_on_change: function()
{
var new_value = this._get_field_value();
if (new_value != this.value)
if (this._equals(new_value, this.value))
{
this.bModified = false;
}
else
{
this.bModified = true;
if (this.options.auto_apply)
@@ -91,22 +96,36 @@ $(function()
this._do_apply();
}
}
this._refresh();
},
_equals: function( value1, value2 )
{
if (this.options.equals === null)
{
return value1 == value2;
}
else
{
this.bModified = false;
return this.options.equals(value1, value2);
}
this._refresh();
},
_get_field_value: function()
{
var oField = $('#'+this.options.field_id);
if (oField.attr('type') == 'checkbox')
if (this.options.get_field_value === null)
{
return (oField.attr('checked') == 'checked');
var oField = $('#'+this.options.field_id);
if (oField.attr('type') == 'checkbox')
{
return (oField.attr('checked') == 'checked');
}
else
{
return oField.val();
}
}
else
{
return oField.val();
return this.options.get_field_value();
}
},
_get_committed_value: function()