Project

General

Profile

Bug #15388 » exclusiveKeys-v2.patch

Administrator Admin, 2006-03-18 15:57

View differences:

class.t3lib_tceforms-exclusive.php 2006-03-18 15:43:55.000000000 +0100
$selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
$size = intval($config['size']);
$size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($itemArray)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
$sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); '.implode('',$PA['fieldChangeFunc']);
if ($config['exclusiveKeys']) {
$sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,\''.$config['exclusiveKeys'].'\'); ';
} else {
$sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ';
}
$sOnChange .= implode('',$PA['fieldChangeFunc']);
$itemsToSelect = '
<select name="'.$PA['itemFormElName'].'_sel"'.
$this->insertDefStyle('select').
......
browserWin = window.open(url,"Typo3WinBrowser","height=350,width="+(mode=="db"?650:600)+",status=0,menubar=0,resizable=1,scrollbars=1");
browserWin.focus();
}
function setFormValueFromBrowseWin(fName,value,label) { //
function setFormValueFromBrowseWin(fName,value,label,exclusiveValues) { //
var formObj = setFormValue_getFObj(fName)
if (formObj && value!="--div--") {
fObj = formObj[fName+"_list"];
var len = fObj.length;
// Clear elements if exclusive values are found
if (exclusiveValues) {
var m = new RegExp("(^|,)"+value+"($|,)");
if (exclusiveValues.match(m)) {
// the new value is exclusive
for (a=len-1;a>=0;a--) fObj[a] = null;
len = 0;
} else if (len == 1) {
m = new RegExp("(^|,)"+fObj.options[0].value+"($|,)");
if (exclusiveValues.match(m)) {
// the old value is exclusive
fObj[0] = null;
len = 0;
}
}
}
// Inserting element
var l=fObj.length;
var setOK=1;
var setOK = 1;
if (!formObj[fName+"_mul"] || formObj[fName+"_mul"].value==0) {
for (a=0;a<l;a++) {
for (a=0;a<len;a++) {
if (fObj.options[a].value==value) {
setOK=0;
setOK = 0;
}
}
}
if (setOK) {
fObj.length++;
fObj.options[l].value=value;
fObj.options[l].text=unescape(label);
fObj.options[len].value = value;
fObj.options[len].text = unescape(label);
// Traversing list and set the hidden-field
setHiddenFromList(fObj,formObj[fName]);
-- class.t3lib_tcemain.php 2006-03-18 15:47:59.000000000 +0100
++ class.t3lib_tcemain-exclusive.php 2006-03-12 15:47:16.000000000 +0100
......
list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
// Detecting if value send is an array and if so, implode it around a comma:
// Detecting if value sent is an array and if so, implode it around a comma:
if (is_array($value)) {
$value = implode(',',$value);
}
......
// Anyways, this should NOT disturb anything else:
$value = $this->convNumEntityToByteValue($value);
// When values are send as group or select they come as comma-separated values which are exploded by this function:
// When values are sent as group or select they come as comma-separated values which are exploded by this function:
$valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
// If not multiple is set, then remove duplicates:
......
$valueArray = array_unique($valueArray);
}
// This could be a good spot for parsing the array through a validation-function which checks if the values are allright (except that database references are not in their final form - but that is the point, isn't it?)
// If an exclusive key is found, discard all others:
if ($tcaFieldConf['type']=='select' && $tcaFieldConf['exclusiveKeys']) {
$exclusiveKeys = t3lib_div::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
foreach($valueArray as $kk => $vv) {
if (in_array($vv, $exclusiveKeys)) { // $vv is the item key!
$valueArray = Array($kk => $vv);
break;
}
}
}
// This could be a good spot for parsing the array through a validation-function which checks if the values are alright (except that database references are not in their final form - but that is the point, isn't it?)
// NOTE!!! Must check max-items of files before the later check because that check would just leave out filenames if there are too many!!
// Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!
(1-1/2)