Feature #17542 » ConditionalRequiredFields_v5_(trunk).patch
t3lib/class.t3lib_tceforms.php (working copy) | ||
---|---|---|
var $palettesRendered=array(); // During rendering of forms this will keep track of which palettes has already been rendered (so they are not rendered twice by mistake)
|
||
var $hiddenFieldListArr = array(); // This array of fields will be set as hidden-fields instead of rendered normally! For instance palette fields edited in the top frame are set as hidden fields since the main form has to submit the values. The top frame actually just sets the value in the main form!
|
||
var $requiredFields=array(); // Used to register input-field names, which are required. (Done during rendering of the fields). This information is then used later when the JavaScript is made.
|
||
var $requiredAdditional=array(); // Used to register input-field names, which are required an have additional requirements (e.g. like a date/time must be positive integer). The information of this array is merged with $this->requiredFields later.
|
||
var $requiredElements=array(); // Used to register the min and max number of elements for selectorboxes where that apply (in the "group" type for instance)
|
||
var $requiredTrigger=array(); // Used to register trigger-fields, which checks a required field on a change
|
||
var $renderDepth=0; // Keeps track of the rendering depth of nested records.
|
||
var $savedSchemes=array(); // Color scheme buffer.
|
||
var $dynNestedStack = array(); // holds the path an element is nested in (e.g. required for RTEhtmlarea)
|
||
... | ... | |
$itemFormElValue = $PA['itemFormElValue'];
|
||
if (in_array('date',$evalList)) {
|
||
$config['format'] = 'date';
|
||
} elseif (in_array('date',$evalList)) {
|
||
$config['format'] = 'date';
|
||
} elseif (in_array('datetime',$evalList)) {
|
||
$config['format'] = 'datetime';
|
||
} elseif (in_array('time',$evalList)) {
|
||
... | ... | |
}
|
||
return $this->getSingleField_typeNone_render($config, $itemFormElValue);
|
||
}
|
||
|
||
$required = false; // is required?
|
||
|
||
foreach ($evalList as $func) {
|
||
switch ($func) {
|
||
case 'date':
|
||
case 'datetime':
|
||
case 'time':
|
||
continue;
|
||
break;
|
||
case 'required':
|
||
$this->requiredFields[$table.'_'.$row['uid'].'_'.$field]=$PA['itemFormElName'];
|
||
// Mark this field for date/time disposal:
|
||
if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
|
||
$this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = true;
|
||
}
|
||
$required = true;
|
||
break;
|
||
default:
|
||
if (substr($func, 0, 3) == 'tx_') {
|
||
... | ... | |
}
|
||
}
|
||
// requiredCondition
|
||
$condition = array();
|
||
if ($required) {
|
||
$condition[] = '!'.$field;
|
||
}
|
||
if ($config['requiredCond'] && $required) {
|
||
$condition[] = $config['requiredCond'];
|
||
$config['requiredCond'] = '['.implode(']&[',$condition).']';
|
||
$this->registerRequiredProperty($PA['itemFormElName'], $config['requiredCond'], $table, $row['uid'], $field);
|
||
}
|
||
// Register field for check
|
||
$PA['requiredParameter']['isDatatime'] = array_intersect($evalList, array('date', 'datetime', 'time'));
|
||
$this->registerPossibleTrigger($PA['itemFormElName'], 'input',$PA['requiredParameter']);
|
||
|
||
$paramsList = "'".$PA['itemFormElName']."','".implode(',',$evalList)."','".trim($config['is_in'])."',".(isset($config['checkbox'])?1:0).",'".$config['checkbox']."'";
|
||
if (isset($config['checkbox'])) {
|
||
// Setting default "click-checkbox" values for eval types "date" and "datetime":
|
||
... | ... | |
$item.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($thisValue).'" />';
|
||
}
|
||
// Register field for check
|
||
$PA['requiredParameter']['itemKeys'] = array_keys($selItems);
|
||
$this->registerPossibleTrigger($PA['itemFormElName'], 'check', $PA['requiredParameter']);
|
||
return $item;
|
||
}
|
||
... | ... | |
if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
|
||
// Traverse the items, making the form elements:
|
||
for ($c=0;$c<count($selItems);$c++) {
|
||
$p = $selItems[$c];
|
||
$rID = $PA['itemFormElID'].'_'.$c;
|
||
$rOnClick = implode('',$PA['fieldChangeFunc']);
|
||
$rChecked = (!strcmp($p[1],$PA['itemFormElValue'])?' checked="checked"':'');
|
||
$item.= '<input type="radio"'.$this->insertDefStyle('radio').' name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($p[1]).'" onclick="'.htmlspecialchars($rOnClick).'"'.$rChecked.$PA['onFocus'].$disabled.' id="'.$rID.'" />
|
||
<label for="'.$rID.'">'.htmlspecialchars($p[0]).'</label>
|
||
<br />';
|
||
foreach ($selItems AS $subfieldName => $selItem) {
|
||
$rID = $PA['itemFormElID'].'_'.$subfieldName;
|
||
$rOnClick = implode('',$PA['fieldChangeFunc']);
|
||
$rChecked = (!strcmp($selItem[1],$PA['itemFormElValue'])?' checked="checked"':'');
|
||
$item.= '<input type="radio"'.$this->insertDefStyle('radio').' name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($selItem[1]).'" onclick="'.htmlspecialchars($rOnClick).'"'.$rChecked.$PA['onFocus'].$disabled.' id="'.$rID.'" />
|
||
<label for="'.$rID.'">'.htmlspecialchars($selItem[0]).'</label>
|
||
<br />';
|
||
}
|
||
// Register field for check
|
||
$PA['requiredParameter']['itemKeys'] = array_keys($selItems);
|
||
$this->registerPossibleTrigger($PA['itemFormElName'], 'radio', $PA['requiredParameter']);
|
||
return $item;
|
||
}
|
||
... | ... | |
$minitems = t3lib_div::intInRange($config['minitems'],0);
|
||
// Register the required number of elements:
|
||
$this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
|
||
$config['requiredCond'] = '!'.$field.';'.$minitems.'-'.$maxitems.($config['requiredCond'] ? '&['.$config['requiredCond'].']' : '' );
|
||
$this->registerRequiredProperty($PA['itemFormElName'], $config['requiredCond'], $table, $row['uid'], $field);
|
||
|
||
// Register field for check
|
||
$this->registerPossibleTrigger($PA['itemFormElName'], 'range');
|
||
|
||
// Get "removeItems":
|
||
$removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
|
||
... | ... | |
$disabled = ' disabled="disabled"';
|
||
}
|
||
// Register the required number of elements:
|
||
$config['requiredCond'] = '!'.$field.';'.$minitems.'-'.$maxitems.($config['requiredCond'] ? '&['.$config['requiredCond'].']' : '' );
|
||
$this->registerRequiredProperty($PA['itemFormElName'], $config['requiredCond'], $table, $row['uid'], $field);
|
||
// Register field for check
|
||
$this->registerPossibleTrigger($PA['itemFormElName'], 'range');
|
||
|
||
$item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'"'.$disabled.' />';
|
||
$this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
|
||
$info='';
|
||
// "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
|
||
... | ... | |
$jsFile = array();
|
||
$elements = array();
|
||
// required:
|
||
foreach ($this->requiredFields as $itemImgName => $itemName) {
|
||
$match = array();
|
||
$this->transformRequiredProperties();
|
||
// required
|
||
foreach ($this->requiredFields as $itemName => $data) {
|
||
if (preg_match('/^(.+)\[((\w|\d|_)+)\]$/', $itemName, $match)) {
|
||
$record = $match[1];
|
||
$field = $match[2];
|
||
$elements[$record][$field]['required'] = 1;
|
||
$elements[$record][$field]['requiredImg'] = $itemImgName;
|
||
if (isset($this->requiredAdditional[$itemName]) && is_array($this->requiredAdditional[$itemName])) {
|
||
$elements[$record][$field]['additional'] = $this->requiredAdditional[$itemName];
|
||
$record = $match[1];
|
||
$field = $match[2];
|
||
$elements[$record][$field]['required'] = 1;
|
||
$elements[$record][$field]['requiredCondition'] = $data['condition'];
|
||
$elements[$record][$field]['requiredParameter'] = $data['parameter'];
|
||
}
|
||
}
|
||
// triggers
|
||
foreach ($this->requiredTriggers AS $itemName => $data) {
|
||
if (count($data['fields']) > 0) {
|
||
if (preg_match('/^(.+)\[((\w|\d|_)+)\]$/', $itemName, $match)) {
|
||
$record = $match[1];
|
||
$field = $match[2];
|
||
$elements[$record][$field]['trigger'] = $data['fields'];
|
||
$elements[$record][$field]['triggerType'] = $data['type'];
|
||
$elements[$record][$field]['triggerParameter'] = $data['parameter'];
|
||
}
|
||
}
|
||
}
|
||
// range:
|
||
foreach ($this->requiredElements as $itemName => $range) {
|
||
if (preg_match('/^(.+)\[((\w|\d|_)+)\]$/', $itemName, $match)) {
|
||
$record = $match[1];
|
||
$field = $match[2];
|
||
$elements[$record][$field]['range'] = array($range[0], $range[1]);
|
||
$elements[$record][$field]['rangeImg'] = $range['imgName'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$this->TBE_EDITOR_fieldChanged_func='TBE_EDITOR.fieldChanged_fName(fName,formObj[fName+"_list"]);';
|
||
if (!$update) {
|
||
... | ... | |
}
|
||
return ($json ? t3lib_div::array2json($result) : $result);
|
||
}
|
||
/************************************************************
|
||
*
|
||
* Required-Functions
|
||
*
|
||
************************************************************/
|
||
|
||
|
||
/**
|
||
* Takes care of registering properties in requiredFields.
|
||
* The current hierarchy of IRRE and/or Tabs is stored. Thus, it is possible to determine,
|
||
* which required field/element was filled incorrectly and show it.
|
||
* For further implementations see the already implemented getSingleField_...
|
||
*
|
||
* @param String $elementName: Elementname
|
||
* @param String $condition: Condition of the Element
|
||
* @param String $table: Tablename
|
||
* @param Integer $uid: UID
|
||
* @param String $field: Fieldname
|
||
* @param String $subfield: Subfieldname for Multiplecheckboxes (not in use yet)
|
||
* @param Array $parameter: Some special information for a type
|
||
* @return void
|
||
*/
|
||
function registerRequiredProperty($elementName, $condition, $table, $uid, $field, $subfield = null, $parameter=array()) {
|
||
$this->requiredFields[$elementName] = array(
|
||
'table' => $table,
|
||
'uid' => $uid,
|
||
'field' => $field,
|
||
'subfield' => $subfield,
|
||
'condition' => $condition,
|
||
'parameter' => $parameter,
|
||
);
|
||
}
|
||
|
||
function issetRequiredProperty($elementName) {
|
||
return isset($this->requiredFields[$elementName]);
|
||
}
|
||
|
||
/**
|
||
* Registers a possible Trigger.
|
||
* The Registration is needed for a simple required-field or requiredConf-field.
|
||
*
|
||
* @param String $elementName: Elementname
|
||
* @param String $type: Type must be implement (see getCondition)
|
||
* @param Array $parameter: Some special information for a type
|
||
* @return void
|
||
*/
|
||
function registerPossibleTrigger($elementName, $type, $parameter=array()) {
|
||
$this->requiredTriggers[$elementName] = array(
|
||
'type' => $type,
|
||
'fields' => array(),
|
||
'parameter' => $parameter,
|
||
);
|
||
}
|
||
/**
|
||
* This function adds the imagename and gets the validate condition for each required-field.
|
||
* Required-Fields must also be supported as Triggertype (see getCondition).
|
||
*
|
||
* Supported Required-Fields: input, range
|
||
*
|
||
* @return void
|
||
*/
|
||
function transformRequiredProperties() {
|
||
foreach ($this->requiredFields AS $elementName => $data) {
|
||
// Imagename
|
||
if (!isset($this->requiredFields[$elementName]['parameter']['img'])) {
|
||
$this->requiredFields[$elementName]['parameter']['img'] = $data['table'].'_'.$data['uid'].'_'.$data['field'];
|
||
}
|
||
$this->requiredFields[$elementName]['condition'] = $this->getCondition($elementName, $data['table'], $data['uid'], $data['field'], $data['subfield'], $data['condition']);
|
||
}
|
||
}
|
||
/**
|
||
* Validates the Condition and return the condition as an array, so it can used as JSON
|
||
* The Conditions must also be implemented in the typo3/jsfunc.tbe_editor.ts
|
||
*
|
||
* Supported Triggertypes: input, radio, check, range
|
||
*
|
||
* @param Stirng $elementName: Elementname of the Condition-Field
|
||
* @param String $table: Tablename of the Condition-Field
|
||
* @param Integer $uid: UID of the Condition-Field
|
||
* @param String $field: Fieldname of the Condition-Field
|
||
* @param String $subfield: Not used yet, but for adding Condition for Multiple-Checkboxes etc.
|
||
* @param String $condition: Condition
|
||
* @return Array
|
||
*/
|
||
function getCondition($elementName, $table, $uid, $field, $subfield, $condition) {
|
||
$i = 0;
|
||
$condition = '['.$condition.']';
|
||
|
||
$condParts = array();
|
||
//Getting all Trigger-Fields
|
||
$replace = "([a-z\_\-\!]+[0-9a-zA-Z\_\-\;]*)";
|
||
while(preg_match($replace, $condition,$res)) {
|
||
// replacing this field
|
||
$condition = preg_replace($replace , "~$i~", $condition,1);
|
||
|
||
// trigger element with value
|
||
list($trigger_name,$item_value) = explode(";",$res[0]);
|
||
|
||
// storing this field
|
||
$condParts[$i]['part'] = $trigger_name;
|
||
$condParts[$i]['cond'] = false;
|
||
|
||
// should condition be negated?
|
||
if (substr($trigger_name,0,1) == '!') {
|
||
$trigger_name = substr($trigger_name,1);
|
||
$item_bool = 0;
|
||
}else {
|
||
$item_bool = 1;
|
||
}
|
||
|
||
// does trigger exists/is allowed
|
||
$triggerElementName = $this->prependFormFieldNames.'['.$table.']['.$uid.']['.$trigger_name.']';
|
||
if (!isset($this->requiredTriggers[$triggerElementName])) {
|
||
continue;
|
||
}
|
||
switch ($this->requiredTriggers[$triggerElementName]['type']) {
|
||
case 'radio':
|
||
if (!in_array($item_value,$this->requiredTriggers[$triggerElementName]['parameter']['itemKeys'])) {
|
||
$item_value = 0;
|
||
}
|
||
settype($item_value,'integer'); // Needed for JavaScript
|
||
break;
|
||
case 'check':
|
||
if (!in_array($item_value,$this->requiredTriggers[$triggerElementName]['parameter']['itemKeys'])) {
|
||
$item_value = 0;
|
||
}
|
||
settype($item_value,'integer'); // Needed for JavaScript
|
||
break;
|
||
case 'input':
|
||
if (empty($item_value)) {
|
||
$item_value = null;
|
||
}
|
||
break;
|
||
case 'range':
|
||
list($minrange,$maxrange) = t3lib_div::trimExplode("-",$item_value);
|
||
$minrange = t3lib_div::intInRange($minrange,0);
|
||
$maxrange = t3lib_div::intInRange($maxrange,0);
|
||
if (!$maxrange) $maxrange=100000;
|
||
$item_value = array($minrange,$maxrange);
|
||
break;
|
||
}
|
||
if (!in_array($field,$this->requiredTriggers[$triggerElementName]['fields'])) {
|
||
$this->requiredTriggers[$triggerElementName]['fields'][] = $field;
|
||
}
|
||
$condParts[$i]['cond'] = array(
|
||
'type' => 'field',
|
||
'parameter' => array(
|
||
'name' => $trigger_name,
|
||
'type' => $this->requiredTriggers[$triggerElementName]['type'],
|
||
'bool' => $item_bool,
|
||
'value' => $item_value,
|
||
)
|
||
);
|
||
$i++;
|
||
}
|
||
// if ($field == 'field2') {
|
||
//echo 'te';
|
||
// print_r($condition);
|
||
//echo 'te';
|
||
//}
|
||
// Getting Subpattern with ORs and ANDs
|
||
$replace = "|\[([0-9\~\&\|\;]+)\]|";
|
||
while(preg_match($replace, $condition,$res)) {
|
||
$res = str_replace('[','',str_replace(']','',$res[0]));
|
||
$condParts[$i]['part'] = $res; //check output
|
||
$ors = explode("|",$res);
|
||
$condParts[$i]['cond'] = array('type' => 'or', 'parameter' => array());
|
||
foreach ($ors AS $or) {
|
||
$ands = explode("&",$or);
|
||
$or = array('type' => 'and', 'parameter' => array());
|
||
foreach($ands AS $and) {
|
||
$and = $condParts[str_replace('~','',$and)]['cond'];
|
||
if ($and !== false) {
|
||
$or['parameter'][] = $and;
|
||
}
|
||
}
|
||
if (count($or['parameter']) == 1) {
|
||
$or = $or['parameter'][0];
|
||
}
|
||
if (count($or['parameter']) > 0) {
|
||
$condParts[$i]['cond']['parameter'][] = $or;
|
||
}
|
||
}
|
||
if (count($condParts[$i]['cond']['parameter']) == 1) {
|
||
$condParts[$i]['cond'] = $condParts[$i]['cond']['parameter'][0];
|
||
}
|
||
if (count($condParts[$i]['cond']['parameter']) == 0) {
|
||
$condParts[$i]['cond'] = false;
|
||
}
|
||
$condition = preg_replace($replace , "~$i~", $condition,1);
|
||
$i++;
|
||
}
|
||
$condition = $condParts[str_replace('~','',$condition)]['cond'];
|
||
if ($condition === false) {
|
||
$condition = array('type' => 'ignore');
|
||
}
|
||
// if ($field == 'field2') {
|
||
//echo 'te';
|
||
// print_r($condition);
|
||
//echo 'te';
|
||
//}
|
||
unset($condParts);
|
||
return $condition;
|
||
}
|
||
}
|
||
t3lib/class.t3lib_tceforms_inline.php (working copy) | ||
---|---|---|
if (!$maxitems) $maxitems=100000;
|
||
// Register the required number of elements:
|
||
$this->fObj->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
|
||
$config['requiredCond'] = '!'.$field.';'.$minitems.'-'.$maxitems.($config['requiredCond'] ? '&['.$config['requiredCond'].']' : '' );
|
||
$this->fObj->registerRequiredProperty($PA['itemFormElName'], $config['requiredCond'], $table, $row['uid'], $field);
|
||
// Register field for check
|
||
$this->fObj->registerPossibleTrigger($PA['itemFormElName'], 'range');
|
||
// remember the page id (pid of record) where inline editing started first
|
||
// we need that pid for ajax calls, so that they would know where the action takes place on the page structure
|
t3lib/class.t3lib_tcemain.php (working copy) | ||
---|---|---|
case 'lower':
|
||
$value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toLower');
|
||
break;
|
||
case 'required':
|
||
if (!$value) {$set=0;}
|
||
break;
|
||
case 'is_in':
|
||
$c=strlen($value);
|
||
if ($c) {
|
typo3/jsfunc.tbe_editor.js (working copy) | ||
---|---|---|
elements: {
|
||
'data[table][uid]': {
|
||
'field': {
|
||
'range': [0, 100],
|
||
'rangeImg': '',
|
||
'required': true,
|
||
'requiredImg': ''
|
||
}
|
||
... | ... | |
return result;
|
||
},
|
||
checkElements: function(type, recentUpdated, record, field) {
|
||
/**
|
||
* Get the Recordname of a elementName
|
||
* Return something like 'data[table][uid]'
|
||
*
|
||
* @param String elementName: Should look like 'data[table][uid][field]'
|
||
* @return String
|
||
*
|
||
* @author Malte Jansen
|
||
*/
|
||
getTheRecord: function(elementName) {
|
||
var idx = 2+TBE_EDITOR.prependFormFieldNamesCnt;
|
||
var table = TBE_EDITOR.split(elementName, "[", idx);
|
||
var uid = TBE_EDITOR.split(elementName, "[", idx+1);
|
||
|
||
table = table.substr(0,table.length-1);
|
||
uid = uid.substr(0,uid.length-1);
|
||
|
||
return TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']';
|
||
},
|
||
/**
|
||
* Checks all Elements (for Init and Submitting)
|
||
* Returns false if one or more checks are false.
|
||
*
|
||
* @param Boolean recentUpdate:
|
||
* @return Boolean
|
||
*/
|
||
checkAllElements: function(recentUpdated) {
|
||
var result = 1;
|
||
var elementName, elementData, elementRecord, elementField;
|
||
var source = recentUpdated ? TBE_EDITOR.recentUpdatedElements : TBE_EDITOR.elements;
|
||
if (type) {
|
||
if (record && field) {
|
||
elementName = record+'['+field+']';
|
||
elementData = TBE_EDITOR.getElement(record, field, type);
|
||
if (elementData) {
|
||
if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;
|
||
var source = (recentUpdated ? TBE_EDITOR.recentUpdatedElements : TBE_EDITOR.elements);
|
||
var elementRecord, elementField;
|
||
var elementFieldList, elRecIndex, elRecCnt, elFldIndex, elFldCnt;
|
||
var elementRecordList = $H(source).keys();
|
||
for (elRecIndex=0, elRecCnt=elementRecordList.length; elRecIndex<elRecCnt; elRecIndex++) {
|
||
elementRecord = elementRecordList[elRecIndex];
|
||
elementFieldList = $H(source[elementRecord]).keys();
|
||
for (elFldIndex=0, elFldCnt=elementFieldList.length; elFldIndex<elFldCnt; elFldIndex++) {
|
||
if (!TBE_EDITOR.checkElement(elementRecord,elementFieldList[elFldIndex])) {
|
||
result = 0;
|
||
}
|
||
} else {
|
||
var elementFieldList, elRecIndex, elRecCnt, elFldIndex, elFldCnt;
|
||
var elementRecordList = $H(source).keys();
|
||
for (elRecIndex=0, elRecCnt=elementRecordList.length; elRecIndex<elRecCnt; elRecIndex++) {
|
||
elementRecord = elementRecordList[elRecIndex];
|
||
elementFieldList = $H(source[elementRecord]).keys();
|
||
for (elFldIndex=0, elFldCnt=elementFieldList.length; elFldIndex<elFldCnt; elFldIndex++) {
|
||
elementField = elementFieldList[elFldIndex];
|
||
elementData = TBE_EDITOR.getElement(elementRecord, elementField, type);
|
||
if (elementData) {
|
||
elementName = elementRecord+'['+elementField+']';
|
||
if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
},
|
||
checkElementByType: function(type, elementName, elementData) {
|
||
var result = 1;
|
||
/**
|
||
* Checks one Element and sets if needed the required/clear-image
|
||
*
|
||
* @param String elementRecord: Should look like 'data[table][uid]'
|
||
* @param String elementField: Should look like 'field'
|
||
* @return Boolean
|
||
*/
|
||
checkElement: function(elementRecord, elementField) {
|
||
var elementName = elementRecord+'['+elementField+']';
|
||
var elementData = TBE_EDITOR.getElement(elementRecord, elementField, 'required');
|
||
if (type) {
|
||
if (type == 'required') {
|
||
var value = document[TBE_EDITOR.formname][elementName].value;
|
||
if (!value || elementData.additional && elementData.additional.isPositiveNumber && (isNaN(value) || Number(value) <= 0)) {
|
||
result = 0;
|
||
TBE_EDITOR.setImage('req_'+elementData.requiredImg, TBE_EDITOR.images.req);
|
||
if (elementData) {
|
||
var requiredImage = 'req_'+elementData.requiredParameter['img'];
|
||
if (TBE_EDITOR.checkCondition(elementRecord,elementData.requiredCondition)) {
|
||
TBE_EDITOR.setImage(requiredImage, TBE_EDITOR.images.req);
|
||
return false;
|
||
}else {
|
||
TBE_EDITOR.setImage(requiredImage,TBE_EDITOR.images.clear);
|
||
}
|
||
}
|
||
return true;
|
||
},
|
||
/**
|
||
* Switch for the condition type: field,and,or
|
||
*
|
||
* @param String elementRecord: Should look like 'data[table][uid]'
|
||
* @param Array condition: The Array must contain following keys: type,parameter
|
||
* @return Boolean
|
||
*
|
||
* @author Malte Jansen
|
||
*/
|
||
checkCondition: function(elementRecord,condition) {
|
||
switch (condition['type']) {
|
||
// Checking a single Field
|
||
case 'field':
|
||
return TBE_EDITOR.checkFieldCondition(elementRecord,condition['parameter']);
|
||
// Checking a and-Array
|
||
case 'and':
|
||
return TBE_EDITOR.checkAndCondition(elementRecord,condition['parameter']);
|
||
// Checking a or-Array
|
||
case 'or':
|
||
return TBE_EDITOR.checkOrCondition(elementRecord,condition['parameter']);
|
||
default:
|
||
return false;
|
||
}
|
||
},
|
||
/**
|
||
* Checks the Field-Conditions
|
||
* Supported Field-Types: input,radio,check,range
|
||
* Also see: t3lib_tceforms.php
|
||
*
|
||
* @param String elementRecord: Should look like 'data[table][uid]'
|
||
* @param Array parameter: The Array must/can contain following keys: bool,value,...
|
||
* @return Boolean
|
||
*
|
||
* @author Malte Jansen
|
||
*/
|
||
checkFieldCondition: function(theRecord,parameter) {
|
||
var checkBool = parameter['bool'];
|
||
|
||
var triggerInformation = TBE_EDITOR.getElement(theRecord,parameter['name'],'trigger');
|
||
var triggerType = triggerInformation['triggerType'];
|
||
var triggerParameter = triggerInformation['triggerParameter'];
|
||
|
||
var elementName = theRecord+'['+parameter['name']+']';
|
||
if (triggerType == 'check') {
|
||
// spliting the hidden field is slower
|
||
elementName+= '_'+parameter['value'];
|
||
}
|
||
var element = document[TBE_EDITOR.formname][elementName];
|
||
|
||
switch (triggerType) {
|
||
// input
|
||
case 'input':
|
||
if (parameter['value']) {
|
||
return TBE_EDITOR.compareCheck(checkBool,(element.value == parameter['value']));
|
||
}
|
||
if (!element.value || triggerParameter['isDatetime'] && (isNaN(element.value) || Number(element.value) <= 0)) {
|
||
return TBE_EDITOR.compareCheck(checkBool,false);
|
||
}else {
|
||
return TBE_EDITOR.compareCheck(checkBool,true);
|
||
}
|
||
// radio
|
||
case 'radio':
|
||
if (element.length > 1) {
|
||
element = element[parameter['value']];
|
||
}
|
||
} else if (type == 'range' && elementData.range) {
|
||
var formObj = document[TBE_EDITOR.formname][elementName+'_list'];
|
||
if (!formObj) {
|
||
// special treatment for IRRE fields:
|
||
var tempObj = document[TBE_EDITOR.formname][elementName];
|
||
if (tempObj && Element.hasClassName(tempObj, 'inlineRecord')) {
|
||
formObj = tempObj.value ? tempObj.value.split(',') : [];
|
||
}
|
||
}
|
||
if (!TBE_EDITOR.checkRange(formObj, elementData.range[0], elementData.range[1])) {
|
||
result = 0;
|
||
TBE_EDITOR.setImage('req_'+elementData.rangeImg, TBE_EDITOR.images.req);
|
||
}
|
||
return TBE_EDITOR.compareCheck(checkBool,element.checked);
|
||
// check
|
||
case 'check':
|
||
return TBE_EDITOR.compareCheck(checkBool,element.checked);
|
||
//range
|
||
case 'range':
|
||
element = document[TBE_EDITOR.formname][elementName+'_list'];
|
||
if (!element) {
|
||
// special treatment for IRRE fields:
|
||
var tempObj = document[TBE_EDITOR.formname][elementName];
|
||
if (tempObj && Element.hasClassName(tempObj, 'inlineRecord')) {
|
||
element = tempObj.value ? tempObj.value.split(',') : [];
|
||
}
|
||
}
|
||
var elementTRUE = (TBE_EDITOR.checkRange(element, parameter['value'][0], parameter['value'][1]));
|
||
return (TBE_EDITOR.compareCheck(checkBool,elementTRUE));
|
||
default:
|
||
return false;
|
||
}
|
||
},
|
||
/**
|
||
* Checks, if the check should be negative (Helper for CheckField)
|
||
*
|
||
* @param Boolean checkBool: Field-requirement shall be negative
|
||
* @param Boolean check:
|
||
* @return Boolean
|
||
*
|
||
* @author Malte Jansen
|
||
*/
|
||
compareCheck: function(checkBool,check) {
|
||
return ((checkBool && check) || (!checkBool && !check));
|
||
},
|
||
/**
|
||
* Checks, the range of an element
|
||
*
|
||
* @param Object element:
|
||
* @param int lowerRange:
|
||
* @param int upperRange:
|
||
* @return Boolean
|
||
*/
|
||
checkRange: function(element,lowerRange,upperRange) {
|
||
return (element && element.length>=lowerRange && element.length<=upperRange);
|
||
},
|
||
/**
|
||
* Checks the Or-Condition
|
||
*
|
||
* @param String elementRecord: Should look like 'data[table][uid]'
|
||
* @param Array conditions: Subconditions
|
||
* @return Boolean
|
||
*/
|
||
checkOrCondition: function(theRecord,conditions) {
|
||
for (var i = 0; i < conditions.size(); i++) {
|
||
if (TBE_EDITOR.checkCondition(theRecord,conditions[i])) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
},
|
||
/**
|
||
* Checks the And-Condition
|
||
*
|
||
* @param String elementRecord: Should look like 'data[table][uid]'
|
||
* @param Array conditions: Subconditions
|
||
* @return Boolean
|
||
*/
|
||
checkAndCondition: function(theRecord,conditions) {
|
||
for (var i = 0; i < conditions.size(); i++) {
|
||
if (!TBE_EDITOR.checkCondition(theRecord,conditions[i])) {
|
||
return false;
|
||
}
|
||
}
|
||
return result;
|
||
return true;
|
||
},
|
||
addActionChecks: function(type, checks) {
|
||
TBE_EDITOR.actionChecks[type].push(checks);
|
||
... | ... | |
table = table.substr(0,table.length-1);
|
||
uid = uid.substr(0,uid.length-1);
|
||
field = field.substr(0,field.length-1);
|
||
TBE_EDITOR.fieldChanged(table,uid,field,el);
|
||
TBE_EDITOR.fieldPerformAction(table,uid,field,el,true);
|
||
},
|
||
/**
|
||
* Calls the fieldPerformAction-function
|
||
*
|
||
* @param String table
|
||
* @param String uid
|
||
* @param String field
|
||
* @param String el: Element
|
||
* @return void
|
||
*/
|
||
fieldChanged: function(table,uid,field,el) {
|
||
var theField = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']['+field+']';
|
||
TBE_EDITOR.fieldPerformAction(table,uid,field,el,true);
|
||
},
|
||
/**
|
||
* Sets the change image if changed = true.
|
||
*
|
||
* @param String table:
|
||
* @param String uid:
|
||
* @param String field:
|
||
* @param String el: Element
|
||
* @param Boolean changed: is this function called by a fieldChanged-function
|
||
* @return void
|
||
*/
|
||
fieldPerformAction: function(table,uid,field,el,changed) {
|
||
var theRecord = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']';
|
||
TBE_EDITOR.isChanged = 1;
|
||
var theField = theRecord+'['+field+']';
|
||
// Set change image:
|
||
var imgObjName = "cm_"+table+"_"+uid+"_"+field;
|
||
TBE_EDITOR.setImage(imgObjName,TBE_EDITOR.images.cm);
|
||
// Set change image
|
||
if (document[TBE_EDITOR.formname][theField] && document[TBE_EDITOR.formname][theField].type=="select-one" && document[TBE_EDITOR.formname][theField+"_selIconVal"]) {
|
||
var imgObjName = "selIcon_"+table+"_"+uid+"_"+field+"_";
|
||
TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.clear);
|
||
document[TBE_EDITOR.formname][theField+"_selIconVal"].value = document[TBE_EDITOR.formname][theField].selectedIndex;
|
||
TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.sel);
|
||
// Change action
|
||
if (changed) {
|
||
TBE_EDITOR.isChanged = true;
|
||
// Set change image:
|
||
var imgObjName = "cm_"+table+"_"+uid+"_"+field;
|
||
TBE_EDITOR.setImage(imgObjName,TBE_EDITOR.images.cm);
|
||
|
||
// Set change image
|
||
if (document[TBE_EDITOR.formname][theField] && document[TBE_EDITOR.formname][theField].type=="select-one" && document[TBE_EDITOR.formname][theField+"_selIconVal"]) {
|
||
var imgObjName = "selIcon_"+table+"_"+uid+"_"+field+"_";
|
||
TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.clear);
|
||
document[TBE_EDITOR.formname][theField+"_selIconVal"].value = document[TBE_EDITOR.formname][theField].selectedIndex;
|
||
TBE_EDITOR.setImage(imgObjName+document[TBE_EDITOR.formname][theField+"_selIconVal"].value,TBE_EDITOR.images.sel);
|
||
}
|
||
}
|
||
// Set required flag:
|
||
var imgReqObjName = "req_"+table+"_"+uid+"_"+field;
|
||
if (TBE_EDITOR.getElement(theRecord,field,'required') && document[TBE_EDITOR.formname][theField]) {
|
||
if (TBE_EDITOR.checkElements('required', false, theRecord, field)) {
|
||
TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);
|
||
} else {
|
||
TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
|
||
}
|
||
if (TBE_EDITOR.getElement(theRecord,field,'required')
|
||
&& document[TBE_EDITOR.formname][theField]) {
|
||
TBE_EDITOR.checkElement(theRecord, field);
|
||
}
|
||
if (TBE_EDITOR.getElement(theRecord,field,'range') && document[TBE_EDITOR.formname][theField]) {
|
||
if (TBE_EDITOR.checkElements('range', false, theRecord, field)) {
|
||
TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);
|
||
} else {
|
||
TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
|
||
// Activate trigger
|
||
if (changed
|
||
&& TBE_EDITOR.getElement(theRecord,field,'trigger')
|
||
&& document[TBE_EDITOR.formname][theField]) {
|
||
var condElement = TBE_EDITOR.getElement(theRecord,field,'trigger');
|
||
for (var i = 0; i < condElement['trigger'].size(); i++) {
|
||
// Check against looping
|
||
if (field != condElement['trigger'][i]) {
|
||
TBE_EDITOR.fieldPerformAction(table,uid,condElement['trigger'][i],el,0);
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
},
|
||
isFormChanged: function(noAlert) {
|
||
if (TBE_EDITOR.isChanged && !noAlert && confirm(TBE_EDITOR.labels.fieldsChanged)) {
|
||
return 0;
|
||
return false;
|
||
}
|
||
return TBE_EDITOR.isChanged;
|
||
},
|
||
... | ... | |
}
|
||
}
|
||
// $reqLinesCheck
|
||
if (!TBE_EDITOR.checkElements('required', false)) { OK = 0; }
|
||
// $reqRangeCheck
|
||
if (!TBE_EDITOR.checkElements('range', false)) { OK = 0; }
|
||
if (!TBE_EDITOR.checkAllElements(false)) { OK = 0; }
|
||
if (OK || sendAlert==-1) {
|
||
return true;
|
||
... | ... | |
return false;
|
||
}
|
||
},
|
||
checkRange: function(el,lower,upper) {
|
||
if (el && el.length>=lower && el.length<=upper) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
},
|
||
initRequired: function() {
|
||
// $reqLinesCheck
|
||
TBE_EDITOR.checkElements('required', true);
|
||
// $reqRangeCheck
|
||
TBE_EDITOR.checkElements('range', true);
|
||
TBE_EDITOR.checkAllElements(true);
|
||
},
|
||
setImage: function(name,image) {
|
||
if (document[name]) {
|