From d9eb4cbeb9c10c9edc345ad75de47dc60a214421 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 31 Oct 2011 16:57:10 +0100 Subject: [PATCH] New: add edit in place with ckeditor Fix: remove unused jQuery plugin ckeip --- htdocs/compta/deplacement/fiche.php | 5 +- htdocs/core/class/html.form.class.php | 36 ++++++--- htdocs/core/js/editinplace.js | 30 ++++++++ .../includes/jquery/plugins/ckeip/ckeip.jgz | Bin 746 -> 0 bytes htdocs/includes/jquery/plugins/ckeip/ckeip.js | 70 ------------------ .../jeditable/jquery.jeditable.ckeditor.js | 70 ++++++++++++++++++ htdocs/main.inc.php | 36 ++++----- htdocs/theme/eldy/style.css.php | 2 +- 8 files changed, 148 insertions(+), 101 deletions(-) delete mode 100755 htdocs/includes/jquery/plugins/ckeip/ckeip.jgz delete mode 100644 htdocs/includes/jquery/plugins/ckeip/ckeip.js create mode 100644 htdocs/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index cf5647ae055..c21931f8b25 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -346,7 +346,6 @@ else if ($id) // Type print ''.$langs->trans("Type").''; print $form->editInPlace($langs->trans($object->type), 'type', $user->rights->deplacement->creer, 'select', 'types_fees'); - //print $langs->trans($object->type); print ''; // Who @@ -407,7 +406,7 @@ else if ($id) // Public note print ''.$langs->trans("NotePublic").''; print ''; - print $form->editInPlace($object->note_public, 'note_public', $user->rights->deplacement->creer, 'textarea'); + print $form->editInPlace($object->note_public, 'note_public', $user->rights->deplacement->creer, 'ckeditor', 'dolibarr_notes'); print ""; // Private note @@ -415,7 +414,7 @@ else if ($id) { print ''.$langs->trans("NotePrivate").''; print ''; - print $form->editInPlace($object->note_private, 'note', $user->rights->deplacement->creer, 'textarea'); + print $form->editInPlace($object->note_private, 'note', $user->rights->deplacement->creer, 'ckeditor', 'dolibarr_notes'); print ""; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 6372ede364b..1d644f6d6e0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -149,28 +149,44 @@ class Form * @param string $value Value to show/edit * @param string $htmlname DIV ID (field name) * @param int $condition Condition to edit - * @param string $area Type of edit - * @param string $loadmethod Name of load method + * @param string $inputType Type of input + * @param string $inputOption Input option * @return string HTML edit in place */ - function editInPlace($value, $htmlname, $condition, $type='textarea', $loadmethod='') + function editInPlace($value, $htmlname, $condition, $inputType='textarea', $inputOption='') { global $conf; $out=''; // Check parameters - if ($type == 'textarea') $value = dol_nl2br($value); - else if ($type == 'numeric') $value = price($value); - else if ($type == 'datepicker') $value = dol_print_date($value, 'day'); + if ($inputType == 'textarea') $value = dol_nl2br($value); + else if ($inputType == 'numeric') $value = price($value); + else if ($inputType == 'datepicker') $value = dol_print_date($value, 'day'); if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && $condition) { - // Use for timestamp format - if ($type == 'datepicker') $out.= ''; - else if ($type == 'select' && ! empty($loadmethod)) $out.= ''; + if ($inputType == 'datepicker') + { + $out.= ''; // Use for timestamp format + } + else if ($inputType == 'select' && ! empty($inputOption)) + { + $out.= ''; + } + else if ($inputType == 'ckeditor' && ! empty($inputOption)) + { + if (! empty($conf->fckeditor->enabled)) + { + $out.= ''; + } + else + { + $inputType = 'textarea'; + } + } - $out.= '
'; + $out.= '
'; $out.= $value; $out.= '
'; } diff --git a/htdocs/core/js/editinplace.js b/htdocs/core/js/editinplace.js index b36e0aa6b48..5ff7ca6cd25 100644 --- a/htdocs/core/js/editinplace.js +++ b/htdocs/core/js/editinplace.js @@ -44,6 +44,36 @@ $(document).ready(function() { } } }); + $('.edit_ckeditor').editable(urlSaveInPlace, { + type : 'ckeditor', + id : 'field', + onblur : 'ignore', + tooltip : tooltipInPlace, + placeholder : placeholderInPlace, + cancel : cancelInPlace, + submit : submitInPlace, + indicator : indicatorInPlace, + ckeditor : { + customConfig: ckeditorConfig, + toolbar: $('#toolbar').val() + }, + submitdata : { + type: 'ckeditor', + element: element, + table_element: table_element, + fk_element: fk_element + }, + callback : function(result, settings) { + var obj = $.parseJSON(result); + + if (obj.error) { + $(this).html(this.revert); + $.jnotify(obj.error, "error", true); + } else { + $(this).html(obj.value); + } + } + }); $('.edit_text').editable(urlSaveInPlace, { type : 'text', id : 'field', diff --git a/htdocs/includes/jquery/plugins/ckeip/ckeip.jgz b/htdocs/includes/jquery/plugins/ckeip/ckeip.jgz deleted file mode 100755 index d8ef3b259bb9c3487e9f052d49a26a19a6dca1cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 746 zcmVcxTa{#4POK;jh5WXYvA4Vq9nuM72&_l!H&?JYb zs`|X6#UA5rHoIuOhN6i7-dR7eu>rN}UhvM$H_vZ}@pZp9fQL^{kIz59e21q<*xP3X zUnLI_etpZ(?C6rMgbH#)gWO^SA9wJ`HwaJMNZjSB?RFbD*=;Ec^=rR(J?{7Vy{jNr zLHL4V4Ks){6B+Y(-=flD@xVg?QgcHbrZNTDfGe0{m@JMZU|WDq;j>LtKRg%%IJT0#|l` zJWTw$dBbMK&OLRv)u_N-{i)ug~+F1=`Y#3A=^AEMPSl9Mc4n+{1yl5#y zDZ&?T1TCu6h$bo#5gsw*IJs78X`;9Oarph|Z1R_Mj;&3@FiriI${n{2Rz_zkdMI9F zbI|oGJqGTZh3q>W_@D5MT?*BGDBj>KH#~~!Ms&G5XC`oFUPqg97{olnXVtMQw@J)p zirw^^$)9-&f0MdfF$MCljLuSh!)3RaV69W@H|9;7den~M4!s82p|s`eaHFnOvGWh^ z+_g2zCQ%HgYudorDa#!ZgKu|h)bZgT3uZI$D!4a1$ZJQF_R~8#v3yh4b+nsOVE%;@ cC!;iY(V_EYuAF2`{<)w00h_dJHA4sh0Qtvn8vp
"); - - $('#ckeip_e_' + u_id + '').ckeditor(settings.ckeditor_config); - - $(this).bind("dblclick", function () { - - $(this).hide(); - $('#ckeip_' + u_id + '').show(); - - }); - - $(this).hover(function () { - $(this).css({ - backgroundColor: settings.e_hover_color - }); - }, function () { - $(this).css({ - backgroundColor: '' - }); - }); - - - $("#cancel_ckeip_" + u_id + "").click(function () { - $('#ckeip_' + u_id + '').hide(); - $(original_html).fadeIn(); - return false; - }); - - $("#save_ckeip_" + u_id + "").click(function () { - var ckeip_html = $('#ckeip_e_' + u_id + '').val(); - $.post(settings.e_url, { - content: ckeip_html, - data: settings.data - }, function (response) { - if (typeof callback == "function") callback(response); - - $(original_html).html(ckeip_html); - $('#ckeip_' + u_id + '').hide(); - $(original_html).fadeIn(); - - });; - return false; - - }); - - }); -}; \ No newline at end of file diff --git a/htdocs/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js b/htdocs/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js new file mode 100644 index 00000000000..3682d4fe14e --- /dev/null +++ b/htdocs/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js @@ -0,0 +1,70 @@ +/* + * CKEditor input for Jeditable + * + * Adapted from Wysiwyg input for Jeditable by Mike Tuupola + * http://www.appelsiini.net/2008/9/wysiwyg-for-jeditable + * + * Copyright (c) 2009 Jeremy Bell + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + * + * Depends on CKEditor: + * http://ckeditor/ + * + */ + +(function($) { + $.generateId = function() { + return arguments.callee.prefix + arguments.callee.count++; + }; + $.generateId.prefix = 'jq$'; + $.generateId.count = 0; + + $.fn.generateId = function() { + return this.each(function() { + this.id = $.generateId(); + }); + }; +})(jQuery); + +(function($) { +$.editable.addInputType('ckeditor', { + /* Use default textarea instead of writing code here again. */ + //element : $.editable.types.textarea.element, + element : function(settings, original) { + /* Hide textarea to avoid flicker. */ + var textarea = $('