From f382a68dd7bd1e3d4527934e6a71853630b75f86 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 14 May 2011 11:34:15 +0000 Subject: [PATCH] Test: not reload page with dialog confirm Fix: form tag is not used in view mode Fix: debug error --- htdocs/core/class/html.form.class.php | 12 +++-- htdocs/lib/functions.lib.php | 49 +++++++++++++++---- .../canvas/actions_card_common.class.php | 11 ++--- .../default/actions_card_default.class.php | 7 ++- .../canvas/default/tpl/card_view.tpl.php | 15 +++--- .../actions_card_individual.class.php | 7 ++- .../canvas/individual/tpl/card_view.tpl.php | 15 +++--- htdocs/societe/soc.php | 30 +++++------- 8 files changed, 81 insertions(+), 65 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index fa6783fb114..53b13e367a6 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2057,8 +2057,10 @@ class Form $(function() { var choice=\'ko\'; var $inputarray='.json_encode($inputarray).'; + var button=\''.$button.'\'; + var dialogconfirm=\''.$dialogconfirm.'\'; - $("#'.$dialogconfirm.'").dialog({ + $( "#" + dialogconfirm ).dialog({ autoOpen: '.($autoOpen?'true':'false').', resizable: false, height:'.$height.', @@ -2092,9 +2094,11 @@ class Form } }); - $( "#'.$button.'" ).click(function() { - $( "#'.$dialogconfirm.'" ).dialog( \'open\' ); - }); + if (button.length > 0) { + $( "#" + button ).click(function() { + $( "#" + dialogconfirm ).dialog( \'open\' ); + }); + } }); '; diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 0a269e231c4..305d5d9365b 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -3573,7 +3573,7 @@ function monthArrayOrSelected($selected=0) /** - * Print formated messages to output (Used to show messages on html output) + * Get formated messages to output (Used to show messages on html output) * @param mesgstring Message * @param mesgarray Messages array * @param style Style of message output @@ -3582,7 +3582,7 @@ function monthArrayOrSelected($selected=0) * @see dol_print_error * @see dol_htmloutput_errors */ -function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0) +function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0) { global $conf, $langs; @@ -3620,20 +3620,50 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb if ($out) { - if (! empty($conf->global->MAIN_USE_JQUERY_JNOTIFY) && ! $keepembedded) + if (! empty($conf->global->MAIN_USE_JQUERY_JNOTIFY) && empty($keepembedded)) { - print ''; } else { - print $out; + $return = $out; } } - return $ret; + + return $return; +} + +/** + * Get formated error messages to output (Used to show messages on html output) + * @param mesgstring Error message + * @param mesgarray Error messages array + * @return keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) + * @return html Return html output + * @see dol_print_error + * @see dol_htmloutput_mesg + */ +function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) +{ + return get_htmloutput_mesg($mesgstring, $mesgarray,'error',$keepembedded); +} + +/** + * print formated messages to output (Used to show messages on html output) + * @param mesgstring Message + * @param mesgarray Messages array + * @param style Style of message output + * @return string Return html output + * @return $keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) + * @see dol_print_error + * @see dol_htmloutput_errors + */ +function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0) +{ + print get_htmloutput_mesg($mesgstring,$mesgarray,$style,$keepembedded); } /** @@ -3647,10 +3677,9 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb */ function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) { - return dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded); + print get_htmloutput_errors($mesgstring, $mesgarray,$keepembedded); } - /** * Advanced sort array by second index function, which produces * ascending (default) or descending output and uses optionally diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 4a9159404cb..e887494d8ed 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -385,8 +385,8 @@ class ActionsCardCommon } $this->tpl['title'] = $this->getTitle($action); - $this->tpl['error'] = $this->error; - $this->tpl['errors']= $this->errors; + + $this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors); if ($action == 'create') { @@ -410,7 +410,7 @@ class ActionsCardCommon '."\n"; } } - + if ($action == 'create' || $action == 'edit') { if ($conf->use_javascript_ajax) @@ -538,10 +538,9 @@ class ActionsCardCommon } } - - if ($action == 'view') + else { - $this->tpl['showhead']=$this->showHead($action); + $this->tpl['showhead']=$this->showHead('view'); $this->tpl['showrefnav'] = $form->showrefnav($this->object,'socid','',($user->societe_id?0:1),'rowid','nom'); diff --git a/htdocs/societe/canvas/default/actions_card_default.class.php b/htdocs/societe/canvas/default/actions_card_default.class.php index ccf676efb5d..8a7e86ae3a6 100644 --- a/htdocs/societe/canvas/default/actions_card_default.class.php +++ b/htdocs/societe/canvas/default/actions_card_default.class.php @@ -146,13 +146,12 @@ class ActionsCardDefault extends ActionsCardCommon $this->tpl['tva_intra'] = $s; } } - - if ($action == 'view') + else { // Confirm delete third party - if ($_GET["action"] == 'delete') + if ($_GET["action"] == 'delete' || ($conf->use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX)) { - $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,2); + $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,"1,action-delete"); } for ($i=1; $i<=4; $i++) diff --git a/htdocs/societe/canvas/default/tpl/card_view.tpl.php b/htdocs/societe/canvas/default/tpl/card_view.tpl.php index 3de5fd46b96..d2c9493ddf9 100644 --- a/htdocs/societe/canvas/default/tpl/card_view.tpl.php +++ b/htdocs/societe/canvas/default/tpl/card_view.tpl.php @@ -21,16 +21,10 @@ -control->tpl['error'],$this->control->tpl['errors']); -?> - +control->tpl['error']) echo $this->control->tpl['error']; ?> control->tpl['action_delete']) echo $this->control->tpl['action_delete']; ?> control->tpl['js_checkVatPopup']) echo $this->control->tpl['js_checkVatPopup']; ?> -
- - @@ -231,7 +225,6 @@ for ($i=1; $i<=4; $i++) {
-
@@ -245,7 +238,11 @@ for ($i=1; $i<=4; $i++) { rights->societe->supprimer) { ?> -">trans('Delete'); ?> + use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { ?> + trans('Delete'); ?> + + ">trans('Delete'); ?> + diff --git a/htdocs/societe/canvas/individual/actions_card_individual.class.php b/htdocs/societe/canvas/individual/actions_card_individual.class.php index f3db23ed2b1..aa9245c58aa 100644 --- a/htdocs/societe/canvas/individual/actions_card_individual.class.php +++ b/htdocs/societe/canvas/individual/actions_card_individual.class.php @@ -96,13 +96,12 @@ class ActionsCardIndividual extends ActionsCardCommon { $this->tpl['select_civility'] = $formcompany->select_civility($contact->civilite_id); } - - if ($action == 'view') + else { // Confirm delete third party - if ($_GET["action"] == 'delete') + if ($_GET["action"] == 'delete' || ($conf->use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX)) { - $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteAnIndividual"),$langs->trans("ConfirmDeleteIndividual"),"confirm_delete",'',0,2); + $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteAnIndividual"),$langs->trans("ConfirmDeleteIndividual"),"confirm_delete",'',0,"1,action-delete"); } } } diff --git a/htdocs/societe/canvas/individual/tpl/card_view.tpl.php b/htdocs/societe/canvas/individual/tpl/card_view.tpl.php index e3a6832164c..9ac90a19b4b 100644 --- a/htdocs/societe/canvas/individual/tpl/card_view.tpl.php +++ b/htdocs/societe/canvas/individual/tpl/card_view.tpl.php @@ -21,15 +21,9 @@ -control->tpl['error'],$this->control->tpl['errors']); -?> - +control->tpl['error']) echo $this->control->tpl['error']; ?> control->tpl['action_delete']) echo $this->control->tpl['action_delete']; ?> -
- - @@ -172,7 +166,6 @@ dol_htmloutput_errors($this->control->tpl['error'],$this->control->tpl['errors']
-
@@ -186,7 +179,11 @@ dol_htmloutput_errors($this->control->tpl['error'],$this->control->tpl['errors'] rights->societe->supprimer) { ?> -">trans('Delete'); ?> + use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { ?> + trans('Delete'); ?> + + ">trans('Delete'); ?> + diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 2fcf9d82761..570c0872864 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -250,7 +250,7 @@ else } else { - $mesg=$soc->error; + $error=$soc->error; } if ($result >= 0) @@ -268,7 +268,7 @@ else $db->rollback(); $langs->load("errors"); - $mesg=$langs->trans($soc->error); + $error=$langs->trans($soc->error); $action='create'; } } @@ -299,7 +299,7 @@ else { $soc->id = $socid; - $mesg = $soc->error; + $error = $soc->error; $action= "edit"; } } @@ -320,7 +320,7 @@ else else { $langs->load("errors"); - $mesg=$langs->trans($soc->error); + $error=$langs->trans($soc->error); $action=''; } } @@ -333,7 +333,7 @@ else { if (is_numeric(GETPOST('model'))) { - $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model")); + $error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model")); } else { @@ -400,16 +400,16 @@ if (! empty($objcanvas->template_dir)) { $objcanvas->fetch($socid); // Reload object if (! empty($_POST)) { - $objcanvas->assign_post(); // Assign POST data + $objcanvas->assign_post(); // Assign POST data } $objcanvas->assign_values($action); // Set value for templates $objcanvas->display_canvas($action); // Show template } else { - $result=$objcanvas->fetch($socid); // Relaod object - $objcanvas->assign_values('view'); // Assign values - $objcanvas->display_canvas('view'); // Show template + $result=$objcanvas->fetch($socid); // Relaod object + $objcanvas->assign_values(); // Assign values + $objcanvas->display_canvas(); // Show template // TODO Move this also into template print '
'; @@ -1335,16 +1335,8 @@ else if ($ret == 'html') print '
'; } - // Template - if ($mesg) - { - print '
'; - print $mesg; - print '
'; - } + dol_htmloutput_errors($error,$errors); - print '
'; - print ''; print ''; // Name @@ -1683,7 +1675,7 @@ else } print '
'; - print '
'; + print "\n";