Fix for Json message makes Trigger dropdown list fail.

This commit is contained in:
ralph
2012-11-26 18:03:59 -04:00
parent 8eaacc678a
commit c0ec55ee2b
4 changed files with 230 additions and 222 deletions

View File

@@ -284,7 +284,7 @@ function G_Field ( form, element, name )
return me.element.value; return me.element.value;
}; };
this.toJSONString=function() { this.toJSONString=function() {
return '{'+me.name+':'+me.element.value.toJSONString()+'}'; return '{"'+me.name+'":'+me.element.value.toJSONString()+'}';
}; };
this.highLight=function(){ this.highLight=function(){
try{ try{

View File

@@ -960,7 +960,7 @@ var callServer;callServer=new leimnud.module.rpc.xmlhttp({url:me.form.ajaxServer
else{for(var i=0;i<newcont.length;i++){var oAux=me.form.getElementByName(grid);if(oAux){var oAux2=oAux.getElementByName(row,newcont[i].name);if(oAux2){oAux2.setValue(newcont[i].value);oAux2.setContent(newcont[i].content);oAux2.updateDepententFields();}}}}}else{alert('Invalid response: '+response);} else{for(var i=0;i<newcont.length;i++){var oAux=me.form.getElementByName(grid);if(oAux){var oAux2=oAux.getElementByName(row,newcont[i].name);if(oAux2){oAux2.setValue(newcont[i].value);oAux2.setContent(newcont[i].content);oAux2.updateDepententFields();}}}}}else{alert('Invalid response: '+response);}
return true;};this.setValue=function(newValue){me.element.value=newValue;};this.setContent=function(newContent){};this.setAttributes=function(attributes){for(var a in attributes){if(a=='formula'&&attributes[a]){sumaformu(this.element,attributes[a],attributes['mask']);} return true;};this.setValue=function(newValue){me.element.value=newValue;};this.setContent=function(newContent){};this.setAttributes=function(attributes){for(var a in attributes){if(a=='formula'&&attributes[a]){sumaformu(this.element,attributes[a],attributes['mask']);}
switch(typeof(attributes[a])){case'string':case'int':case'boolean':if(a!='strTo'){switch(true){case typeof(me[a])==='undefined':case typeof(me[a])==='object':case typeof(me[a])==='function':case a==='isObject':case a==='isArray':break;default:me[a]=attributes[a];}} switch(typeof(attributes[a])){case'string':case'int':case'boolean':if(a!='strTo'){switch(true){case typeof(me[a])==='undefined':case typeof(me[a])==='object':case typeof(me[a])==='function':case a==='isObject':case a==='isArray':break;default:me[a]=attributes[a];}}
else{me[a]=attributes[a];}}}};this.value=function(){return me.element.value;};this.toJSONString=function(){return'{'+me.name+':'+me.element.value.toJSONString()+'}';};this.highLight=function(){try{G.highLight(me.element);if(G.autoFirstField){me.element.focus();G.autoFirstField=false;setTimeout("G.autoFirstField=true;",1000);}}catch(e){}};} else{me[a]=attributes[a];}}}};this.value=function(){return me.element.value;};this.toJSONString=function(){return'{"'+me.name+'":'+me.element.value.toJSONString()+'}';};this.highLight=function(){try{G.highLight(me.element);if(G.autoFirstField){me.element.focus();G.autoFirstField=false;setTimeout("G.autoFirstField=true;",1000);}}catch(e){}};}
function G_DropDown(form,element,name) function G_DropDown(form,element,name)
{var me=this;this.parent=G_Field;this.parent(form,element,name);this.setContent=function(content){var dd=me.element;var browser=getBrowserClient();if((browser.name=='msie')||((browser.name=='firefox')&&(browser.version<12))){while(dd.options.length>1)dd.remove(0);}else{for(var key in dd.options){dd.options[key]=null;}} {var me=this;this.parent=G_Field;this.parent(form,element,name);this.setContent=function(content){var dd=me.element;var browser=getBrowserClient();if((browser.name=='msie')||((browser.name=='firefox')&&(browser.version<12))){while(dd.options.length>1)dd.remove(0);}else{for(var key in dd.options){dd.options[key]=null;}}
for(var o=0;o<content.options.length;o++){var optn=$dce("OPTION");optn.text=content.options[o].value;optn.value=content.options[o].key;dd.options[o]=optn;}};if(!element)return;leimnud.event.add(this.element,'change',this.updateDepententFields);} for(var o=0;o<content.options.length;o++){var optn=$dce("OPTION");optn.text=content.options[o].value;optn.value=content.options[o].key;dd.options[o]=optn;}};if(!element)return;leimnud.event.add(this.element,'change',this.updateDepententFields);}

View File

@@ -1,219 +1,227 @@
<?php <?php
/** /**
* defaultAjax.php * defaultAjax.php
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.23 * Copyright (C) 2004 - 2008 Colosa Inc.23
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* */
*/
/*NEXT LINE: Runs any configuration defined to be executed before dependent fields recalc*/
/*NEXT LINE: Runs any configuration defined to be executed before dependent fields recalc*/ if (isset( $_SESSION['CURRENT_PAGE_INITILIZATION'] ))
if ( isset($_SESSION['CURRENT_PAGE_INITILIZATION']) ) eval( $_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'); if (! defined( 'XMLFORM_AJAX_PATH' ))
//$json=new Services_JSON(); define( 'XMLFORM_AJAX_PATH', PATH_XMLFORM );
if (!defined('XMLFORM_AJAX_PATH')) define('XMLFORM_AJAX_PATH',PATH_XMLFORM);
$_DBArray = array ();
$_DBArray = array(); if (isset( $_SESSION['_DBArray'] )) {
if (isset($_SESSION['_DBArray'])) { $_DBArray = $_SESSION['_DBArray'];
$_DBArray = $_SESSION['_DBArray']; }
}
$xmlFile = G::getUIDName( urlDecode( $_POST['form'] ) );
$xmlFile = G::getUIDName(urlDecode($_POST['form'])); $sPath = XMLFORM_AJAX_PATH;
$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 )) {
if ( !is_file ( XMLFORM_AJAX_PATH . $xmlFile ) ) { $aux = explode( PATH_SEP, $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' )) {
if ( count($aux) == 2 && defined ( 'G_PLUGIN_CLASS' ) ) { $oPluginRegistry = & PMPluginRegistry::getSingleton();
$oPluginRegistry =& PMPluginRegistry::getSingleton(); if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) {
if ( $oPluginRegistry->isRegisteredFolder($aux[0]) ) { $sPath = PATH_PLUGINS;
$sPath = PATH_PLUGINS; }
} }
} }
} $G_FORM = new form( $xmlFile, $sPath );
$G_FORM=new form( $xmlFile , $sPath ); $G_FORM->id = urlDecode( $_POST['form'] );
$G_FORM->id=urlDecode($_POST['form']); $G_FORM->values = isset( $_SESSION[$G_FORM->id] ) ? $_SESSION[$G_FORM->id] : array ();
$G_FORM->values=isset($_SESSION[$G_FORM->id]) ? $_SESSION[$G_FORM->id] : array(); $newValues = (Bootstrap::json_decode( urlDecode( stripslashes( $_POST['fields'] ) ) ));
$newValues=(Bootstrap::json_decode(urlDecode(stripslashes($_POST['fields'])))); if (isset( $_POST['grid'] )) {
if (isset($_POST['grid'])) { $_POST['row'] = (int) $_POST['row'];
$_POST['row'] = (int)$_POST['row']; $aAux = array ();
$aAux = array(); foreach ($newValues as $sKey => $newValue) {
foreach ($newValues as $sKey => $newValue) { $newValue = (array) $newValue;
$newValue = (array)$newValue; $aKeys = array_keys( $newValue );
$aKeys = array_keys($newValue); $aValues = array ();
$aValues = array(); for ($i = 1; $i <= ($_POST['row'] - 1); $i ++) {
for ($i = 1; $i <= ($_POST['row'] - 1); $i++) { $aValues[$i] = array ($aKeys[0] => ''
$aValues[$i] = array($aKeys[0] => ''); );
} }
$aValues[$_POST['row']] = array($aKeys[0] => $newValue[$aKeys[0]]); $aValues[$_POST['row']] = array ($aKeys[0] => $newValue[$aKeys[0]]
$newValues[$sKey]->$_POST['grid'] = $aValues; );
unset($newValues[$sKey]->$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.
if (sizeof($newValues)>1 && isset($_POST['grid'])){ //Next Lines re-build newValues array to send multiple dependent fields merged by row into a grid.
$fieldBase = array(); if (sizeof( $newValues ) > 1 && isset( $_POST['grid'] )) {
foreach ($newValues as $key => $values){ $fieldBase = array ();
for ($r2=1; $r2 <= $_POST['row']; $r2++){ foreach ($newValues as $key => $values) {
foreach ($values as $class => $value){ for ($r2 = 1; $r2 <= $_POST['row']; $r2 ++) {
if ($class == $_POST['grid']){ foreach ($values as $class => $value) {
$value = (array) $value; if ($class == $_POST['grid']) {
$arrayK = $value[$r2]; $value = (array) $value;
foreach ($arrayK as $key2 => $val) { $arrayK = $value[$r2];
$fieldBase[$r2][$key2] = is_array($val)? $val[$key2] : $val; foreach ($arrayK as $key2 => $val) {
} $fieldBase[$r2][$key2] = is_array( $val ) ? $val[$key2] : $val;
} }
} }
} }
} }
$newValues = array(); }
$newValues = array ();
//$fieldBase = (array) $fieldBase; //$fieldBase = (array) $fieldBase;
$newValues[0]->$_POST['grid'] = $fieldBase; $newValues[0]->$_POST['grid'] = $fieldBase;
} }
//Resolve dependencies //Resolve dependencies
//Returns an array ($dependentFields) with the names of the fields //Returns an array ($dependentFields) with the names of the fields
//that depends of fields passed through AJAX ($_GET/$_POST) //that depends of fields passed through AJAX ($_GET/$_POST)
$dependentFields=array(); $aux=array(); $dependentFields = array ();
for($r=0;$r<sizeof($newValues);$r++) { $aux = array ();
$newValues[$r]=(array)$newValues[$r]; for ($r = 0; $r < sizeof( $newValues ); $r ++) {
$G_FORM->setValues($newValues[$r]); $newValues[$r] = (array) $newValues[$r];
//Search dependent fields $G_FORM->setValues( $newValues[$r] );
foreach($newValues[$r] as $k => $v) { //Search dependent fields
if (!is_array($v)) { foreach ($newValues[$r] as $k => $v) {
$myDependentFields = subDependencies( $k , $G_FORM , $aux ); if (! is_array( $v )) {
$_SESSION[$G_FORM->id][$k] = $v; $myDependentFields = subDependencies( $k, $G_FORM, $aux );
} $_SESSION[$G_FORM->id][$k] = $v;
else { } else {
foreach($v[$_POST['row']] as $k1 => $v1) { foreach ($v[$_POST['row']] as $k1 => $v1) {
$myDependentFields = subDependencies( $k1 , $G_FORM , $aux, $_POST['grid'] ); $myDependentFields = subDependencies( $k1, $G_FORM, $aux, $_POST['grid'] );
$_SESSION[$G_FORM->id][$_POST['grid']][$_POST['row']][$k1] = $v1; $_SESSION[$G_FORM->id][$_POST['grid']][$_POST['row']][$k1] = $v1;
} }
} }
$dependentFields=array_merge($dependentFields, $myDependentFields); $dependentFields = array_merge( $dependentFields, $myDependentFields );
} }
} }
if (isset($_POST['grid'])) $G_FORM->values=isset($_SESSION[$G_FORM->id]) ? $_SESSION[$G_FORM->id] : array(); if (isset( $_POST['grid'] ))
$G_FORM->values = isset( $_SESSION[$G_FORM->id] ) ? $_SESSION[$G_FORM->id] : array ();
$dependentFields=array_unique($dependentFields);
$dependentFields = array_unique( $dependentFields );
//Parse and update the new content
$template = PATH_CORE . 'templates/xmlform.html'; //Parse and update the new content
$newContent=$G_FORM->getFields($template, (isset($_POST['row']) ? $_POST['row'] : -1)); $template = PATH_CORE . 'templates/xmlform.html';
//Returns the dependentFields's content $newContent = $G_FORM->getFields( $template, (isset( $_POST['row'] ) ? $_POST['row'] : - 1) );
$sendContent=array(); //Returns the dependentFields's content
$r=0; $sendContent = array ();
$r = 0;
foreach($dependentFields as $d) {
$sendContent[$r]->name=$d; foreach ($dependentFields as $d) {
$sendContent[$r]->content=NULL; $sendContent[$r]->name = $d;
if (!isset($_POST['grid'])) { $sendContent[$r]->content = NULL;
if (isset($G_FORM->fields[$d])) { if (! isset( $_POST['grid'] )) {
foreach($G_FORM->fields[$d] as $attribute => $value) { if (isset( $G_FORM->fields[$d] )) {
switch($attribute) { foreach ($G_FORM->fields[$d] as $attribute => $value) {
case 'type': switch ($attribute) {
$sendContent[$r]->content->{$attribute}=$value;break; case 'type':
case 'options': $sendContent[$r]->content->{$attribute} = $value;
$sendContent[$r]->content->{$attribute}=toJSArray($value, $sendContent[$r]->content->type); break; break;
} case 'options':
} $sendContent[$r]->content->{$attribute} = toJSArray( $value, $sendContent[$r]->content->type );
$sendContent[$r]->value=isset($G_FORM->values[$d]) ? $G_FORM->values[$d] : ''; break;
} }
} }
else { $sendContent[$r]->value = isset( $G_FORM->values[$d] ) ? $G_FORM->values[$d] : '';
foreach($G_FORM->fields[$_POST['grid']]->fields[$d] as $attribute => $value) { }
switch($attribute) { } else {
case 'type': foreach ($G_FORM->fields[$_POST['grid']]->fields[$d] as $attribute => $value) {
$sendContent[$r]->content->{$attribute}=$value; break; switch ($attribute) {
case 'options': case 'type':
if ($sendContent[$r]->content->type != 'text') { $sendContent[$r]->content->{$attribute} = $value;
$sendContent[$r]->content->{$attribute}=toJSArray($value); break;
} case 'options':
else { if ($sendContent[$r]->content->type != 'text') {
$sendContent[$r]->content->{$attribute}=toJSArray((isset($value[$_POST['row']]) ? array($value[$_POST['row']]) : array())); $sendContent[$r]->content->{$attribute} = toJSArray( $value );
} } else {
break; $sendContent[$r]->content->{$attribute} = toJSArray( (isset( $value[$_POST['row']] ) ? array ($value[$_POST['row']]
} ) : array ()) );
} }
$sendContent[$r]->value=isset($G_FORM->values[$_POST['grid']][$_POST['row']][$d]) ? $G_FORM->values[$_POST['grid']][$_POST['row']][$d] : ''; break;
} }
$r++; }
} $sendContent[$r]->value = isset( $G_FORM->values[$_POST['grid']][$_POST['row']][$d] ) ? $G_FORM->values[$_POST['grid']][$_POST['row']][$d] : '';
echo(Bootstrap::json_encode($sendContent)); }
$r ++;
function toJSArray($array, $type= '') }
{ echo (Bootstrap::json_encode( $sendContent ));
$result=array();
foreach($array as $k => $v){ function toJSArray ($array, $type = '')
$o=NULL; {
$o->key=$k; $result = array ();
// TODO: review the condition to make the differentiation to dependent dropdowns in a grid function. foreach ($array as $k => $v) {
// this way of validation is if you have a dependent field in text fields $o = NULL;
$o->value= ($type =='text' || $type =='textarea')? $k:$v; $o->key = $k;
$result[]=$o; // 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
return $result; $o->value = ($type == 'text' || $type == 'textarea') ? $k : $v;
} $result[] = $o;
}
function subDependencies( $k , &$G_FORM , &$aux, $grid = '') { return $result;
if (array_search( $k, $aux )!==FALSE) return array(); }
if ($grid == '') {
if (!array_key_exists( $k , $G_FORM->fields )) return array(); function subDependencies ($k, &$G_FORM, &$aux, $grid = '')
if (!isset($G_FORM->fields[$k]->dependentFields)) return array(); {
$aux[] = $k; if (array_search( $k, $aux ) !== FALSE)
if (strpos($G_FORM->fields[$k]->dependentFields, ',') !== false) { return array ();
$myDependentFields = explode( ',', $G_FORM->fields[$k]->dependentFields); if ($grid == '') {
} if (! array_key_exists( $k, $G_FORM->fields ))
else { return array ();
$myDependentFields = explode( '|', $G_FORM->fields[$k]->dependentFields); if (! isset( $G_FORM->fields[$k]->dependentFields ))
} return array ();
for( $r=0 ; $r < sizeof($myDependentFields) ; $r++ ) { $aux[] = $k;
if ($myDependentFields[$r]=="") unset($myDependentFields[$r]); if (strpos( $G_FORM->fields[$k]->dependentFields, ',' ) !== false) {
} $myDependentFields = explode( ',', $G_FORM->fields[$k]->dependentFields );
// $mD = $myDependentFields; } else {
// foreach( $mD as $ki) { $myDependentFields = explode( '|', $G_FORM->fields[$k]->dependentFields );
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux ) ); }
// } for ($r = 0; $r < sizeof( $myDependentFields ); $r ++) {
} if ($myDependentFields[$r] == "")
else { unset( $myDependentFields[$r] );
if (!array_key_exists( $k , $G_FORM->fields[$grid]->fields )) return array(); }
if (!isset($G_FORM->fields[$grid]->fields[$k]->dependentFields)) return array(); // $mD = $myDependentFields;
$aux[] = $k; // foreach( $mD as $ki) {
if (strpos($G_FORM->fields[$grid]->fields[$k]->dependentFields, ',') !== false) { // $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux ) );
$myDependentFields = explode( ',', $G_FORM->fields[$grid]->fields[$k]->dependentFields); // }
} } else {
else { if (! array_key_exists( $k, $G_FORM->fields[$grid]->fields ))
$myDependentFields = explode( '|', $G_FORM->fields[$grid]->fields[$k]->dependentFields); return array ();
} if (! isset( $G_FORM->fields[$grid]->fields[$k]->dependentFields ))
for( $r=0 ; $r < sizeof($myDependentFields) ; $r++ ) { return array ();
if ($myDependentFields[$r]=="") unset($myDependentFields[$r]); $aux[] = $k;
} if (strpos( $G_FORM->fields[$grid]->fields[$k]->dependentFields, ',' ) !== false) {
// $mD = $myDependentFields; $myDependentFields = explode( ',', $G_FORM->fields[$grid]->fields[$k]->dependentFields );
// foreach( $mD as $ki) { } else {
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux, $grid) ); $myDependentFields = explode( '|', $G_FORM->fields[$grid]->fields[$k]->dependentFields );
// } }
} for ($r = 0; $r < sizeof( $myDependentFields ); $r ++) {
return $myDependentFields; if ($myDependentFields[$r] == "")
} unset( $myDependentFields[$r] );
?> }
// $mD = $myDependentFields;
// foreach( $mD as $ki) {
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux, $grid) );
// }
}
return $myDependentFields;
}

View File

@@ -109,7 +109,7 @@ class WebResource
} }
/* end class WebResource */ /* end class WebResource */
if (! function_exists( 'json_encode' )) { /*if (! function_exists( 'json_encode' )) {
G::LoadThirdParty( 'pear/json', 'class.json' ); G::LoadThirdParty( 'pear/json', 'class.json' );
function json_encode (&$value) function json_encode (&$value)
@@ -127,5 +127,5 @@ if (! function_exists( 'json_decode' )) {
$json = new Services_JSON(); $json = new Services_JSON();
return $json->decode( $value ); return $json->decode( $value );
} }
} }*/