From 3ab8b6f7d10be433a36aeab685ebe9f3677df4f4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 26 Sep 2014 09:44:21 +0200 Subject: [PATCH] New: add possibility to define a custom error message --- htdocs/core/class/html.form.class.php | 25 ++++++++++++++++++------- htdocs/core/js/editinplace.js | 17 ++++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0233706928c..8bbf5ad8337 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2013 Regis Houssin + * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Marc Barilley/Ocebo * Copyright (C) 2007 Franky Van Liedekerke @@ -124,11 +124,11 @@ class Form * @param string $typeofdata Type of data ('string' by default, 'amount', 'email', 'numeric:99', 'text' or 'textarea:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols', 'select:xxx'...) * @param string $editvalue When in edit mode, use this value as $value instead of value (for example, you can provide here a formated price instead of value). Use '' to use same than $value * @param object $extObject External object - * @param string $success Success message + * @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage') * @param string $moreparam More param to add on a href URL * @return string HTML edit field */ - function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $success=null, $moreparam='') + function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='') { global $conf,$langs,$db; @@ -140,7 +140,7 @@ class Form // When option to edit inline is activated if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;|datehourpicker/',$typeofdata)) // TODO add jquery timepicker { - $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $success); + $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg); } else { @@ -244,10 +244,10 @@ class Form * @param string $inputType Type of input ('numeric', 'datepicker', 'textarea:rows:cols', 'ckeditor:dolibarr_zzz:width:height:?:1:rows:cols', 'select:xxx') * @param string $editvalue When in edit mode, use this value as $value instead of value * @param object $extObject External object - * @param string $success Success message + * @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage') * @return string HTML edit in place */ - private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $editvalue=null, $extObject=null, $success=null) + private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $editvalue=null, $extObject=null, $custommsg=null) { global $conf; @@ -334,7 +334,18 @@ class Form $out.= ''."\n"; if (! empty($savemethod)) $out.= ''."\n"; if (! empty($ext_element)) $out.= ''."\n"; - if (! empty($success)) $out.= ''."\n"; + if (! empty($custommsg)) + { + if (is_array($custommsg)) + { + if (!empty($custommsg['success'])) + $out.= ''."\n"; + if (!empty($custommsg['error'])) + $out.= ''."\n"; + } + else + $out.= ''."\n"; + } if ($inputType == 'textarea') { $out.= ''."\n"; $out.= ''."\n"; diff --git a/htdocs/core/js/editinplace.js b/htdocs/core/js/editinplace.js index 4fe29e4b4fb..17d70220b31 100644 --- a/htdocs/core/js/editinplace.js +++ b/htdocs/core/js/editinplace.js @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2012 Regis Houssin +// Copyright (C) 2011-2014 Regis Houssin // Copyright (C) 2011 Laurent Destailleur // // This program is free software; you can redistribute it and/or modify @@ -358,12 +358,19 @@ $(document).ready(function() { var res = $.parseJSON(result); if (res.error) { $(obj).html(obj.revert); - $.jnotify(res.error, "error", true); + var htmlname = $(obj).attr('id').substr(8); + var errormsg = $( '#errormsg_' + htmlname ).val(); + if (errormsg != undefined) { + $.jnotify(errormsg, "error", true); + } else { + $.jnotify(res.error, "error", true); + } + } else { var htmlname = $(obj).attr('id').substr(8); - var success = $( '#success_' + htmlname ).val(); - if (success != undefined) { - $.jnotify(success, "ok"); + var successmsg = $( '#successmsg_' + htmlname ).val(); + if (successmsg != undefined) { + $.jnotify(successmsg, "ok"); } $(obj).html(res.value); $(obj).hide();