BUG 10054 Feature request: grid to support a suggest field SOLVED
- Add the possibility to insert Suggest fields in a grid. - Adjustment element Suggest for dependent fields in grids.
This commit is contained in:
@@ -340,18 +340,24 @@ var G_Grid = function(oForm, sGridName){
|
||||
|
||||
return newElem;
|
||||
};
|
||||
function replaceHtml(el, html) {
|
||||
|
||||
this.replaceHtml = function (el, html) {
|
||||
var oldEl = typeof el === "string" ? document.getElementById(el) : el;
|
||||
/*Pure innerHTML is slightly faster in IE
|
||||
oldEl.innerHTML = html;
|
||||
return oldEl;
|
||||
*/
|
||||
var newEl = oldEl.cloneNode(false);
|
||||
newEl.innerHTML = html;
|
||||
oldEl.parentNode.replaceChild(newEl, oldEl);
|
||||
/* Since we just removed the old element from the DOM, return a reference
|
||||
to the new element, which can be used to restore variable references. */
|
||||
return newEl;
|
||||
if ( this.determineBrowser() == "MSIE" ) {
|
||||
oldEl.innerHTML = html;
|
||||
return oldEl;
|
||||
} else {
|
||||
var newEl = oldEl.cloneNode(false);
|
||||
newEl.innerHTML = html;
|
||||
oldEl.parentNode.replaceChild(newEl, oldEl);
|
||||
/* Since we just removed the old element from the DOM, return a reference
|
||||
to the new element, which can be used to restore variable references. */
|
||||
return newEl;
|
||||
}
|
||||
};
|
||||
|
||||
this.addGridRow = function() {
|
||||
@@ -458,14 +464,40 @@ var G_Grid = function(oForm, sGridName){
|
||||
}
|
||||
}
|
||||
}
|
||||
aObjectsScript = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('script');
|
||||
sObjectType = this.aFields[i-1].sType;
|
||||
|
||||
var aObjectsScript = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('script');
|
||||
|
||||
var sObjectType = this.aFields[i-1].sType;
|
||||
if (aObjectsScript[0] != 'undefined' && sObjectType == 'suggest') {
|
||||
sObjScript = aObjectsScript[0].innerHTML;
|
||||
sNewObjScript = sObjScript.replace(/\[1\]/g, '\[' + currentRow + '\]');
|
||||
replaceHtml(aObjectsScript[0], sNewObjScript);
|
||||
eval(aObjectsScript[0].innerHTML);
|
||||
if ( this.determineBrowser() == "MSIE" ) {
|
||||
|
||||
var firstNode = aCells[i];
|
||||
|
||||
var firstScriptSuggest = firstNode.childNodes[2].innerHTML ;
|
||||
var sScriptAdjustRow = firstScriptSuggest.replace(/\[1\]/g, '\[' + currentRow + '\]');
|
||||
|
||||
var elementTD = oNewRow.getElementsByTagName('td')[i];
|
||||
|
||||
var elementLabel = elementTD.childNodes[0];
|
||||
var sNewLabelRow = elementLabel.getAttribute("id").replace(/\[1\]/g, '\[' + currentRow + '\]');
|
||||
|
||||
var elementHidden = elementTD.childNodes[1];
|
||||
|
||||
var elementScript = elementTD.childNodes[2];
|
||||
var parentScript = elementScript.parentNode;
|
||||
var scriptElement = document.createElement("script");
|
||||
scriptElement.text = sScriptAdjustRow;
|
||||
parentScript.removeChild(elementScript);
|
||||
parentScript.appendChild(scriptElement);
|
||||
|
||||
} else {
|
||||
var sObjScript = aObjectsScript[0].innerHTML;
|
||||
var sNewObjScript = sObjScript.replace(/\[1\]/g, '\[' + currentRow + '\]');
|
||||
aObjectsScript[0].innerHTML = sNewObjScript;
|
||||
eval(aObjectsScript[0].innerHTML);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'checkbox': //CHECKBOX
|
||||
var attributeCheckBox = elementAttributesNS(aObjects[n], "");
|
||||
|
||||
@@ -1333,12 +1333,12 @@ switch(tag.toLowerCase()){case"input":case"textarea":newElem.value=elem.value;br
|
||||
newElem.options[i]=new Option(elem.options[i].text,elem.options[i].value,elem.options[i].defaultSelected);}
|
||||
newElem.options[pos].selected=true;}
|
||||
break;}
|
||||
return newElem;};function replaceHtml(el,html){var oldEl=typeof el==="string"?document.getElementById(el):el;var newEl=oldEl.cloneNode(false);newEl.innerHTML=html;oldEl.parentNode.replaceChild(newEl,oldEl);return newEl;};this.addGridRow=function(){this.oGrid=document.getElementById(this.sGridName);var i,aObjects;var defaultValue='';var n,a,x;var oRow=document.getElementById('firstRow_'+this.sGridName);var aCells=oRow.getElementsByTagName('td');var oNewRow=this.oGrid.insertRow(this.oGrid.rows.length-1);var currentRow=this.oGrid.rows.length-2;var newID,attributes,img2,gridType;oNewRow.onmouseover=function(){highlightRow(this,'#D9E8FF');};oNewRow.onmouseout=function(){highlightRow(this,'#fff');};for(i=0;i<aCells.length;i++){oNewRow.appendChild(aCells[i].cloneNode(true));switch(i){case 0:oNewRow.getElementsByTagName('td')[i].innerHTML=currentRow;break;case aCells.length-1:oNewRow.getElementsByTagName('td')[i].innerHTML=oNewRow.getElementsByTagName('td')[i].innerHTML.replace(/\[1\]/g,'\['+currentRow+'\]');break;default:var eNodeName=aCells[i].innerHTML.substring(aCells[i].innerHTML.indexOf('<')+1,aCells[i].innerHTML.indexOf(' '));eNodeName=eNodeName.toLowerCase();switch(eNodeName){case'input':aObjects=oNewRow.getElementsByTagName('td')[i].getElementsByTagName('input');if(aObjects){newID=aObjects[0].id.replace(/\[1\]/g,'\['+currentRow+'\]');aObjects[0].id=newID;aObjects[0].name=newID;attributes=elementAttributesNS(aObjects[0],'pm');if(typeof attributes.defaultvalue!="undefined"&&attributes.defaultvalue!=""){defaultValue=attributes.defaultvalue;}else{defaultValue="";}
|
||||
return newElem;};this.replaceHtml=function(el,html){var oldEl=typeof el==="string"?document.getElementById(el):el;if(this.determineBrowser()=="MSIE"){oldEl.innerHTML=html;return oldEl;}else{var newEl=oldEl.cloneNode(false);newEl.innerHTML=html;oldEl.parentNode.replaceChild(newEl,oldEl);return newEl;}};this.addGridRow=function(){this.oGrid=document.getElementById(this.sGridName);var i,aObjects;var defaultValue='';var n,a,x;var oRow=document.getElementById('firstRow_'+this.sGridName);var aCells=oRow.getElementsByTagName('td');var oNewRow=this.oGrid.insertRow(this.oGrid.rows.length-1);var currentRow=this.oGrid.rows.length-2;var newID,attributes,img2,gridType;oNewRow.onmouseover=function(){highlightRow(this,'#D9E8FF');};oNewRow.onmouseout=function(){highlightRow(this,'#fff');};for(i=0;i<aCells.length;i++){oNewRow.appendChild(aCells[i].cloneNode(true));switch(i){case 0:oNewRow.getElementsByTagName('td')[i].innerHTML=currentRow;break;case aCells.length-1:oNewRow.getElementsByTagName('td')[i].innerHTML=oNewRow.getElementsByTagName('td')[i].innerHTML.replace(/\[1\]/g,'\['+currentRow+'\]');break;default:var eNodeName=aCells[i].innerHTML.substring(aCells[i].innerHTML.indexOf('<')+1,aCells[i].innerHTML.indexOf(' '));eNodeName=eNodeName.toLowerCase();switch(eNodeName){case'input':aObjects=oNewRow.getElementsByTagName('td')[i].getElementsByTagName('input');if(aObjects){newID=aObjects[0].id.replace(/\[1\]/g,'\['+currentRow+'\]');aObjects[0].id=newID;aObjects[0].name=newID;attributes=elementAttributesNS(aObjects[0],'pm');if(typeof attributes.defaultvalue!="undefined"&&attributes.defaultvalue!=""){defaultValue=attributes.defaultvalue;}else{defaultValue="";}
|
||||
for(n=0;n<aObjects.length;n++){switch(aObjects[n].type){case'text':aObjects[n].className="module_app_input___gray";tags=oNewRow.getElementsByTagName('td')[i].getElementsByTagName('a');if(tags.length==2){img2=tags[1].innerHTML;var datePickerTriggerId=tags[1].id.replace(/\[1\]/g,'\['+currentRow+'\]');oNewRow.getElementsByTagName('td')[i].removeChild(tags[1]);var scriptTags=oNewRow.getElementsByTagName('td')[i].getElementsByTagName('script');oNewRow.getElementsByTagName('td')[i].removeChild(scriptTags[0]);if(tags[0].onclick){var onclickevn=new String(tags[0].onclick);eval('tags[0].onclick = '+onclickevn.replace(/\[1\]/g,'\['+currentRow+'\]')+';');}
|
||||
var a2=document.createElement('a');if(a2.style.setAttribute){var styleText="position:relative;top:0px;left:-19px;";a2.style.setAttribute("cssText",styleText);}
|
||||
else{var styleText="position:relative;top:0px;left:-22px;";a2.setAttribute("style",styleText);}
|
||||
a2.id=datePickerTriggerId;a2.innerHTML=img2;oNewRow.getElementsByTagName('td')[i].appendChild(a2);datePicker4("",newID,attributes.mask,attributes.start,attributes.end,attributes.time);aObjects[n].value=defaultValue;}else{if(_BROWSER.name=='msie'&&aObjects.length==1){var oNewOBJ=this.cloneElement(aObjects[n]);oNewOBJ.value=defaultValue;var parentGG=aObjects[n].parentNode;parentGG.removeChild(aObjects[n]);parentGG.appendChild(oNewOBJ);}else{if((attributes.gridtype)&&attributes.gridtype=="currency"){var attributesCurrency=elementAttributesNS(aObjects[n],"");aObjects[n].value=attributesCurrency.value.replace(/[.,0-9\s]/g,"");}else{aObjects[n].value=defaultValue;}}}
|
||||
aObjectsScript=oNewRow.getElementsByTagName('td')[i].getElementsByTagName('script');sObjectType=this.aFields[i-1].sType;if(aObjectsScript[0]!='undefined'&&sObjectType=='suggest'){sObjScript=aObjectsScript[0].innerHTML;sNewObjScript=sObjScript.replace(/\[1\]/g,'\['+currentRow+'\]');replaceHtml(aObjectsScript[0],sNewObjScript);eval(aObjectsScript[0].innerHTML);}
|
||||
var aObjectsScript=oNewRow.getElementsByTagName('td')[i].getElementsByTagName('script');var sObjectType=this.aFields[i-1].sType;if(aObjectsScript[0]!='undefined'&&sObjectType=='suggest'){if(this.determineBrowser()=="MSIE"){var firstNode=aCells[i];var firstScriptSuggest=firstNode.childNodes[2].innerHTML;var sScriptAdjustRow=firstScriptSuggest.replace(/\[1\]/g,'\['+currentRow+'\]');var elementTD=oNewRow.getElementsByTagName('td')[i];var elementLabel=elementTD.childNodes[0];var sNewLabelRow=elementLabel.getAttribute("id").replace(/\[1\]/g,'\['+currentRow+'\]');var elementHidden=elementTD.childNodes[1];var elementScript=elementTD.childNodes[2];var parentScript=elementScript.parentNode;var scriptElement=document.createElement("script");scriptElement.text=sScriptAdjustRow;parentScript.removeChild(elementScript);parentScript.appendChild(scriptElement);}else{var sObjScript=aObjectsScript[0].innerHTML;var sNewObjScript=sObjScript.replace(/\[1\]/g,'\['+currentRow+'\]');aObjectsScript[0].innerHTML=sNewObjScript;eval(aObjectsScript[0].innerHTML);}}
|
||||
break;case'checkbox':var attributeCheckBox=elementAttributesNS(aObjects[n],"");if(defaultValue==""||(typeof attributeCheckBox.falseValue!="undefined"&&defaultValue==attributeCheckBox.falseValue)||(typeof attributeCheckBox.falsevalue!="undefined"&&defaultValue==attributeCheckBox.falsevalue)){aObjects[n].checked=false;}else{aObjects[n].checked=true;}
|
||||
break;case'hidden':if((attributes.gridtype!='yesno'&&attributes.gridtype!='dropdown')||typeof attributes.gridtype=='undefined'){aObjects[n].value=defaultValue;newID=aObjects[n].id.replace(/\[1\]/g,'\['+currentRow+'\]');aObjects[n].id=newID;aObjects[n].name=newID;}
|
||||
break;case'button':if(aObjects[n].onclick){var onclickevn=new String(aObjects[n].onclick);eval('aObjects[n].onclick = '+onclickevn.replace(/\[1\]/g,'\['+currentRow+'\]')+';');}
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
/*NEXT LINE: Runs any configuration defined to be executed before dependent fields recalc*/
|
||||
if (isset( $_SESSION['CURRENT_PAGE_INITILIZATION'] ))
|
||||
eval( $_SESSION['CURRENT_PAGE_INITILIZATION'] );
|
||||
|
||||
// G::LoadThirdParty('pear/json','class.json');
|
||||
// $json=new Services_JSON();
|
||||
|
||||
// G::LoadThirdParty('pear/json','class.json');
|
||||
// $json=new Services_JSON();
|
||||
if (! defined( 'XMLFORM_AJAX_PATH' ))
|
||||
define( 'XMLFORM_AJAX_PATH', PATH_XMLFORM );
|
||||
|
||||
@@ -39,10 +39,10 @@ if (isset( $_SESSION['_DBArray'] )) {
|
||||
$xmlFile = G::getUIDName( urlDecode( $_POST['form'] ) );
|
||||
$sPath = XMLFORM_AJAX_PATH;
|
||||
|
||||
//if the xmlform file doesn't exist, then try with the plugins folders
|
||||
//if the xmlform file doesn't exist, then try with the plugins folders
|
||||
if (! is_file( XMLFORM_AJAX_PATH . $xmlFile )) {
|
||||
$aux = explode( PATH_SEP, $xmlFile );
|
||||
//check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment
|
||||
//check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment
|
||||
if (count( $aux ) == 2 && defined( 'G_PLUGIN_CLASS' )) {
|
||||
$oPluginRegistry = & PMPluginRegistry::getSingleton();
|
||||
if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) {
|
||||
@@ -57,22 +57,23 @@ $newValues = (Bootstrap::json_decode( urlDecode( stripslashes( $_POST['fields']
|
||||
if (isset( $_POST['grid'] )) {
|
||||
$_POST['row'] = (int) $_POST['row'];
|
||||
$aAux = array ();
|
||||
|
||||
foreach ($newValues as $sKey => $newValue) {
|
||||
$newValue = (array) $newValue;
|
||||
$aKeys = array_keys( $newValue );
|
||||
$aValues = array ();
|
||||
for ($i = 1; $i <= ($_POST['row'] - 1); $i ++) {
|
||||
$aValues[$i] = array ($aKeys[0] => ''
|
||||
);
|
||||
if (count($aKeys)>0) {
|
||||
$aValues = array ();
|
||||
for ($i = 1; $i <= ($_POST['row'] - 1); $i ++) {
|
||||
$aValues[$i] = array ($aKeys[0] => '' );
|
||||
}
|
||||
$aValues[$_POST['row']] = array ($aKeys[0] => $newValue[$aKeys[0]] );
|
||||
$newValues[$sKey]->$_POST['grid'] = $aValues;
|
||||
unset( $newValues[$sKey]->$aKeys[0] );
|
||||
}
|
||||
$aValues[$_POST['row']] = array ($aKeys[0] => $newValue[$aKeys[0]]
|
||||
);
|
||||
$newValues[$sKey]->$_POST['grid'] = $aValues;
|
||||
unset( $newValues[$sKey]->$aKeys[0] );
|
||||
}
|
||||
}
|
||||
|
||||
//Next Lines re-build newValues array to send multiple dependent fields merged by row into a grid.
|
||||
//Next Lines re-build newValues array to send multiple dependent fields merged by row into a grid.
|
||||
if (sizeof( $newValues ) > 1 && isset( $_POST['grid'] )) {
|
||||
$fieldBase = array ();
|
||||
foreach ($newValues as $key => $values) {
|
||||
@@ -89,19 +90,19 @@ if (sizeof( $newValues ) > 1 && isset( $_POST['grid'] )) {
|
||||
}
|
||||
}
|
||||
$newValues = array ();
|
||||
//$fieldBase = (array) $fieldBase;
|
||||
//$fieldBase = (array) $fieldBase;
|
||||
$newValues[0]->$_POST['grid'] = $fieldBase;
|
||||
}
|
||||
|
||||
//Resolve dependencies
|
||||
//Returns an array ($dependentFields) with the names of the fields
|
||||
//that depends of fields passed through AJAX ($_GET/$_POST)
|
||||
//Resolve dependencies
|
||||
//Returns an array ($dependentFields) with the names of the fields
|
||||
//that depends of fields passed through AJAX ($_GET/$_POST)
|
||||
$dependentFields = array ();
|
||||
$aux = array ();
|
||||
for ($r = 0; $r < sizeof( $newValues ); $r ++) {
|
||||
$newValues[$r] = (array) $newValues[$r];
|
||||
$G_FORM->setValues( $newValues[$r] );
|
||||
//Search dependent fields
|
||||
//Search dependent fields
|
||||
foreach ($newValues[$r] as $k => $v) {
|
||||
if (! is_array( $v )) {
|
||||
$myDependentFields = subDependencies( $k, $G_FORM, $aux );
|
||||
@@ -120,10 +121,10 @@ if (isset( $_POST['grid'] ))
|
||||
|
||||
$dependentFields = array_unique( $dependentFields );
|
||||
|
||||
//Parse and update the new content
|
||||
//Parse and update the new content
|
||||
$template = PATH_CORE . 'templates/xmlform.html';
|
||||
$newContent = $G_FORM->getFields( $template, (isset( $_POST['row'] ) ? $_POST['row'] : - 1) );
|
||||
//Returns the dependentFields's content
|
||||
//Returns the dependentFields's content
|
||||
$sendContent = array ();
|
||||
$r = 0;
|
||||
|
||||
@@ -154,7 +155,7 @@ foreach ($dependentFields as $d) {
|
||||
if ($sendContent[$r]->content->type != 'text') {
|
||||
$sendContent[$r]->content->{$attribute} = toJSArray( $value );
|
||||
} else {
|
||||
$sendContent[$r]->content->{$attribute} = toJSArray( (isset( $value[$_POST['row']] ) ? array ($value[$_POST['row']]
|
||||
$sendContent[$r]->content->{$attribute} = toJSArray( (isset( $value[$_POST['row']] ) ? array ($value[$_POST['row']]
|
||||
) : array ()) );
|
||||
}
|
||||
break;
|
||||
@@ -172,8 +173,8 @@ function toJSArray ($array, $type = '')
|
||||
foreach ($array as $k => $v) {
|
||||
$o = NULL;
|
||||
$o->key = $k;
|
||||
// TODO: review the condition to make the differentiation to dependent dropdowns in a grid function.
|
||||
// this way of validation is if you have a dependent field in text fields
|
||||
// TODO: review the condition to make the differentiation to dependent dropdowns in a grid function.
|
||||
// this way of validation is if you have a dependent field in text fields
|
||||
$o->value = ($type == 'text' || $type == 'textarea') ? $k : $v;
|
||||
$result[] = $o;
|
||||
}
|
||||
@@ -199,11 +200,14 @@ function subDependencies ($k, &$G_FORM, &$aux, $grid = '')
|
||||
if ($myDependentFields[$r] == "")
|
||||
unset( $myDependentFields[$r] );
|
||||
}
|
||||
// $mD = $myDependentFields;
|
||||
// foreach( $mD as $ki) {
|
||||
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux ) );
|
||||
// }
|
||||
// $mD = $myDependentFields;
|
||||
// foreach( $mD as $ki) {
|
||||
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux ) );
|
||||
// }
|
||||
} else {
|
||||
if (! isset($G_FORM->fields[$grid])) {
|
||||
return array ();
|
||||
}
|
||||
if (! array_key_exists( $k, $G_FORM->fields[$grid]->fields ))
|
||||
return array ();
|
||||
if (! isset( $G_FORM->fields[$grid]->fields[$k]->dependentFields ))
|
||||
@@ -218,10 +222,10 @@ function subDependencies ($k, &$G_FORM, &$aux, $grid = '')
|
||||
if ($myDependentFields[$r] == "")
|
||||
unset( $myDependentFields[$r] );
|
||||
}
|
||||
// $mD = $myDependentFields;
|
||||
// foreach( $mD as $ki) {
|
||||
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux, $grid) );
|
||||
// }
|
||||
// $mD = $myDependentFields;
|
||||
// foreach( $mD as $ki) {
|
||||
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux, $grid) );
|
||||
// }
|
||||
}
|
||||
return $myDependentFields;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,8 +219,6 @@ class Publisher
|
||||
$G_FORM->setValues( $Part['Data'] );
|
||||
|
||||
$G_FORM->setValues( array ('G_FORM_ID' => $G_FORM->id ) );
|
||||
//G::LoadSystem('CVarDumper');
|
||||
//CVarDumper::dump($Part,10, true);
|
||||
|
||||
//Asegurese de que no entre cuando $Part['Template']=="grid"
|
||||
//de hecho soo deberia usarse cuando $Part['Template']=="xmlform"
|
||||
|
||||
@@ -1409,11 +1409,11 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
|
||||
if ($count > 0) {
|
||||
for ($cnt = 0; $cnt < $count; $cnt ++) {
|
||||
$sOptions .= 'if ( "' . $this->name . '" == "' . $aDepFields[$cnt] . '" ) {';
|
||||
$sOptions .= ' jField[\'' . $aDepFields[$cnt] . '\'] = obj.id;';
|
||||
$sOptions .= '} else { ';
|
||||
$sOptions .= ' jField[\'' . $aDepFields[$cnt] . '\'] = getField(\'' . $aDepFields[$cnt] . '\').value; ';
|
||||
$sOptions .= '}';
|
||||
if ( $this->name == $aDepFields[$cnt] ) {
|
||||
$sOptions .= ' jField[\'' . $aDepFields[$cnt] . '\'] = obj.id;';
|
||||
} else {
|
||||
$sOptions .= ' jField[\'' . $aDepFields[$cnt] . '\'] = getField(\'' . $aDepFields[$cnt] . '\').value; ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1470,13 +1470,13 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
* @param type $value
|
||||
* @param type $owner
|
||||
* @param type $rowId
|
||||
* @param type $ownerName
|
||||
* @param type $index
|
||||
* @param type $ownerName Grid Name
|
||||
* @param type $index Index on the grid
|
||||
* @return string
|
||||
*/
|
||||
public function renderFieldGrid($value = null, $owner = null, $rowId = '', $ownerName = '', $index = 0)
|
||||
{
|
||||
|
||||
$rowIdField = substr($rowId, 1);
|
||||
if (! $this->sqlConnection) {
|
||||
$this->sqlConnection = 'workflow';
|
||||
}
|
||||
@@ -1558,7 +1558,8 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
$sResultKeys = str_rot13( base64_encode( implode( '|', $aResultKeys ) ) );
|
||||
|
||||
foreach ($aResult as $key => $field) {
|
||||
$depValues .= 'getField("' . $field . '").value';
|
||||
$depValues .= 'getField(\''. $rowIdField . '[' . $field . '\').value';
|
||||
|
||||
if ($i ++ < count( $aResult )) {
|
||||
$depValues .= '+"|"+';
|
||||
}
|
||||
@@ -1575,7 +1576,7 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
$count = 0;
|
||||
if ($this->dependentFields !== '') {
|
||||
$dependentFields = explode( ",", $this->dependentFields );
|
||||
foreach ($dependentFields as $keyDependent => $valueDependent) {
|
||||
foreach ($dependentFields as $valueDependent) {
|
||||
$sqlDepField = $owner->fields[$valueDependent]->sql;
|
||||
$count = preg_match_all( '/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $sqlDepField, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
|
||||
for ($cnt = 0; $cnt < $count; $cnt ++) {
|
||||
@@ -1586,9 +1587,7 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
|
||||
$sOptions = 'script: function (input) { ';
|
||||
|
||||
$rowIdField = substr($rowId, 1);
|
||||
|
||||
$sOptions .= ' var inputValue = base64_encode(getField("' . $rowIdField . '[' . $this->name . '_label").value); ';
|
||||
$sOptions .= ' var inputValue = base64_encode(getField(\'' . $rowIdField . '[' . $this->name . '_label\').value); ';
|
||||
|
||||
$sOptions .= ' return "' . $this->ajaxServer . '?request=suggest&json=true&limit=' . $this->maxresults;
|
||||
$sOptions .= '&hash=' . $hash . '&dependentFieldsKeys=' . $sResultKeys . '&dependentFieldsValue="';
|
||||
@@ -1609,11 +1608,11 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
|
||||
if ($count > 0) {
|
||||
for ($cnt = 0; $cnt < $count; $cnt ++) {
|
||||
$sOptions .= 'if ( "' . $this->name . '" == "' . $aDepFields[$cnt] . '" ) {';
|
||||
$sOptions .= ' jField["' . $aDepFields[$cnt] . '"] = obj.id;';
|
||||
$sOptions .= '} else { ';
|
||||
$sOptions .= ' jField["' . $aDepFields[$cnt] . '\'] = getField("' . $aDepFields[$cnt] . '").value; ';
|
||||
$sOptions .= '}';
|
||||
if ( $this->name == $aDepFields[$cnt] ) {
|
||||
$sOptions .= ' jField[\'' . $aDepFields[$cnt] . '\'] = obj.id;';
|
||||
// } else {
|
||||
// $sOptions .= ' jField[\'' . $aDepFields[$cnt] . '\'] = getField(\'' . $rowIdField . '[' . $aDepFields[$cnt] . '\').value; ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1621,41 +1620,50 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
|
||||
$sOptions .= $sCallBack . '; getField("' . $rowIdField . '[' . $this->name . '").value = obj.id;';
|
||||
|
||||
$sOwnerId = (isset($owner->owner->id))? $owner->owner->id : $owner->id;
|
||||
$sOptions .= 'var indexField = "' . $rowIdField . '[' . $this->name . '";';
|
||||
$sOptions .= 'indexField = indexField.match(/\[[0-9]+\]/g); ';
|
||||
$sOptions .= 'indexFieldVal = indexField[0].replace(/\[|\]/g,""); ';
|
||||
|
||||
$sOptions .= 'var response = ajax_function("../gulliver/defaultAjaxDynaform", "reloadField", ';
|
||||
$sOptions .= ' "form=' . $sOwnerId . '&fields=" + sField, "POST"); ';
|
||||
$sOptions .= ' "form=' . $sOwnerId . '&fields=" + sField + "&grid=' . $ownerName . '&row=" + indexFieldVal, "POST" ); ';
|
||||
|
||||
$sOptions .= 'if (response.substr(0,1) === "[") { ';
|
||||
$sOptions .= 'if (response.substr(0,1) === \'[\') { ';
|
||||
$sOptions .= ' var newcont; ';
|
||||
$sOptions .= ' eval("newcont=" + response + ";"); ';
|
||||
$sOptions .= ' for(var i = 0; i<newcont.length; i++) { ';
|
||||
$sOptions .= ' var j = getField(newcont[i].name); ';
|
||||
$sOptions .= ' getField(newcont[i].name).value = newcont[i].value; ';
|
||||
$sOptions .= ' if (newcont[i].content.type == "dropdown") { ';
|
||||
$sOptions .= ' eval(\'newcont=\' + response + \';\'); ';
|
||||
|
||||
$sOptions .= ' for(var i = 0; i<newcont.length; i++) { ';
|
||||
// $sOptions .= ' var depField = getField(\'' . $rowIdField . '[\' + ' . 'newcont[i].name); ';
|
||||
$sOptions .= ' var depField = \'' . $rowIdField . '[\' + ' . 'newcont[i].name; ';
|
||||
|
||||
$sOptions .= ' getField(depField).value = newcont[i].value; ';
|
||||
$sOptions .= ' if (newcont[i].content.type == \'dropdown\') { ';
|
||||
|
||||
$sOptions .= ' fieldLength = getField(depField).options.length; ';
|
||||
|
||||
$sOptions .= ' fieldLength = getField(newcont[i].name).options.length; ';
|
||||
$sOptions .= ' for (ni = 0; ni < fieldLength; ni++ ){ ';
|
||||
$sOptions .= ' getField(newcont[i].name).options.remove(ni); ';
|
||||
$sOptions .= ' getField(depField).options.remove(ni); ';
|
||||
$sOptions .= ' } ';
|
||||
$sOptions .= ' getField(newcont[i].name).length = 0; ';
|
||||
$sOptions .= ' getField(depField).length = 0; ';
|
||||
|
||||
$sOptions .= ' for (ni = 0; ni < newcont[i].content.options.length; ni++ ){ ';
|
||||
$sOptions .= ' var opt = document.createElement("OPTION"); ';
|
||||
$sOptions .= ' opt.value = newcont[i].content.options[ni].key; ';
|
||||
$sOptions .= ' opt.text = newcont[i].content.options[ni].value; ';
|
||||
$sOptions .= ' getField(newcont[i].name).options.add(opt); ';
|
||||
$sOptions .= ' getField(depField).options.add(opt); ';
|
||||
|
||||
$sOptions .= ' } ';
|
||||
$sOptions .= ' } ';
|
||||
|
||||
$sOptions .= ' } ';
|
||||
$sOptions .= '} else { ';
|
||||
$sOptions .= ' alert("Invalid response: " + response); ';
|
||||
$sOptions .= ' alert(\'Invalid response: \' + response); ';
|
||||
$sOptions .= '} ';
|
||||
$sOptions .= '} ';
|
||||
$sOptions .= 'return false; ';
|
||||
$sOptions .= '}';
|
||||
|
||||
$str .= '<script type="text/javascript">';
|
||||
$str .= 'var as_json = new bsn.AutoSuggest("form' . $rowId . '[' . $this->name . '_label]", {' . $sOptions . $storeEntryData . '}); ';
|
||||
$str .= 'var as_json = new bsn.AutoSuggest(\'form' . $rowId . '[' . $this->name . '_label]\', {' . $sOptions . $storeEntryData . '}); ';
|
||||
$str .= '</script>';
|
||||
|
||||
return $str;
|
||||
|
||||
Reference in New Issue
Block a user