diff --git a/gulliver/js/grid/core/grid.js b/gulliver/js/grid/core/grid.js index 017996771..4e53d5751 100755 --- a/gulliver/js/grid/core/grid.js +++ b/gulliver/js/grid/core/grid.js @@ -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], ""); diff --git a/gulliver/js/maborak/core/maborak.js b/gulliver/js/maborak/core/maborak.js index d1333ef0f..0f66093dd 100644 --- a/gulliver/js/maborak/core/maborak.js +++ b/gulliver/js/maborak/core/maborak.js @@ -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;iisRegisteredFolder( $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; -} +} diff --git a/gulliver/system/class.publisher.php b/gulliver/system/class.publisher.php index 7ac755b75..586ac487b 100755 --- a/gulliver/system/class.publisher.php +++ b/gulliver/system/class.publisher.php @@ -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" diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index d6afa75e6..b9242d0c2 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -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; iname . '_label]", {' . $sOptions . $storeEntryData . '}); '; + $str .= 'var as_json = new bsn.AutoSuggest(\'form' . $rowId . '[' . $this->name . '_label]\', {' . $sOptions . $storeEntryData . '}); '; $str .= ''; return $str;