Harmonize readonlys processing, fixes some fields in grids not validating if other rows were read-only.

- Change server-side get_array() to return null if not found, matches client side getEntry() and allows us to tell the difference between false and not found
- Change server-side is_readonly() to properly consider expansion & sub-arrays
- Fix client side et2_readonlysArrayMgr to properly consider expansion & sub-arrays
This commit is contained in:
Nathan Gray 2014-02-10 21:59:50 +00:00
parent 74b52fb1da
commit e314011e88
3 changed files with 36 additions and 7 deletions

View File

@ -703,7 +703,7 @@ class etemplate_widget
* @param string $idx the index, may contain sub-indices like a[b], see example below
* @param boolean $reference_into default False, if True none-existing sub-arrays/-indices get created to be returned as referenz, else False is returned
* @param bool $skip_empty returns false if $idx is not present in $arr
* @return mixed reference to $arr[$idx] or false if $idx is not set and not $reference_into
* @return mixed reference to $arr[$idx] or null if $idx is not set and not $reference_into
*/
static function &get_array(&$arr,$idx,$reference_into=False,$skip_empty=False)
{
@ -732,9 +732,9 @@ class etemplate_widget
if (!is_array($pos) && (!$reference_into || $reference_into && isset($pos)))
{
//if ($reference_into) error_log(__METHOD__."(".(strlen($s=array2string($arr))>512?substr($s,0,512).'...':$s).", '$idx', ".array2string($reference_into).", ".array2string($skip_empty).") ".function_backtrace());
return False;
return null;
}
if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return false;
if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null;
$pos = &$pos[$idx];
}
return $pos;
@ -760,9 +760,14 @@ class etemplate_widget
$form_name = self::form_name($cname, $this->id, $expand);
}
$readonly = $this->attrs['readonly'] || self::$request->readonlys[$form_name] ||
isset(self::$request->readonlys['__ALL__']) && self::$request->readonlys[$form_name] !== false;
self::get_array(self::$request->readonlys,$form_name) === true ||
isset(self::$request->readonlys['__ALL__']) && (
// Exceptions to all
self::$request->readonlys[$form_name] !== false &&
self::get_array(self::$request->readonlys,$form_name) !== false
);
//error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly));
error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys[$form_name]=".array2string(self::get_array(self::$request->readonlys,$form_name)).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly));
return $readonly;
}
/**

View File

@ -135,6 +135,10 @@ class etemplate_widget_menupopup extends etemplate_widget
$valid = $value;
//error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed));
}
else
{
//error_log($this . "($form_name) is read-only, skipping validate");
}
}
/**

View File

@ -207,6 +207,9 @@ var et2_arrayMgr = Class.extend(
*
* Expands variables inside the given identifier to their values inside the
* content array.
*
* @parm {string} _ident Key used to reference into managed array
* @return {*}
*/
expandName : function(_ident) {
// Check whether the identifier refers to an index in the content array
@ -366,7 +369,6 @@ var et2_arrayMgr = Class.extend(
*/
var et2_readonlysArrayMgr = et2_arrayMgr.extend(
{
splitIds: false,
/**
* @memberOf et2_readonlysArrayMgr
@ -380,7 +382,12 @@ var et2_readonlysArrayMgr = et2_arrayMgr.extend(
if (_id != null)
{
if(_id.indexOf('$') >= 0 || _id.indexOf('@') >= 0)
{
_id = this.expandName(_id);
}
entry = this.getEntry(_id);
}
// Let the array entry override the read only attribute entry
@ -404,8 +411,21 @@ var et2_readonlysArrayMgr = et2_arrayMgr.extend(
// Otherwise return the default value
entry = this.getEntry("__ALL__");
return entry !== null && (typeof entry != "undefined");
}
},
/**
* Override parent to handle cont and row_cont.
*
* Normally these should refer to the readonlys data, but that's not
* useful, so we use the owner inside perspective data to expand using content.
*
* @param {string} ident Key for searching into the array.
* @returns {*}
*/
expandName: function(ident)
{
return this.perspectiveData.owner.getArrayMgr('content').expandName(ident)
}
});
/**