From 4332c341bf67d17c930caa04841104b77f8ff0e7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 28 Aug 2012 12:36:35 +0200 Subject: [PATCH] Fix: check if textarea is not empty for free lines --- htdocs/core/js/lib_head.js | 2 +- htdocs/core/lib/ajax.lib.php | 2 +- htdocs/core/tpl/objectline_add.tpl.php | 78 ++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/htdocs/core/js/lib_head.js b/htdocs/core/js/lib_head.js index 11e78f419b1..aee93a8f0dc 100644 --- a/htdocs/core/js/lib_head.js +++ b/htdocs/core/js/lib_head.js @@ -739,7 +739,7 @@ function hideMessage(fieldId,message) { $.widget("ui.onDelayedKeyup", { _init : function() { var self = this; - $(this.element).bind('keyup', function() { + $(this.element).bind('keyup input', function() { if(typeof(window['inputTimeout']) != "undefined"){ window.clearTimeout(inputTimeout); } diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 4aac7871fbc..b47db30d670 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -136,7 +136,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt } if (ui.item.textarea) { $.each(ui.item.textarea, function(key, value) { - if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && CKEDITOR.instances["product_desc"] != "undefined") { + if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && CKEDITOR.instances[key] != "undefined") { CKEDITOR.instances[key].setData(value); CKEDITOR.instances[key].focus(); } else { diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php index 4080fa0766c..1a4ffb08ace 100644 --- a/htdocs/core/tpl/objectline_add.tpl.php +++ b/htdocs/core/tpl/objectline_add.tpl.php @@ -238,14 +238,14 @@ $(document).ready(function() { }, function(data) { if (typeof data != 'undefined') { - $('#select_type').val(data.type).attr('disabled','disabled').trigger('change'); $('#product_ref').val(data.ref); $('#product_label').val(data.label).attr('disabled','disabled'); $('#origin_label_cache').val(data.label); $('#origin_desc_cache').val(data.desc); $('#price_base_type').val(data.pricebasetype); - $('#price_ht').val(data.price_ht); + $('#price_ht').val(data.price_ht).trigger('change'); $('#origin_price_ht_cache').val(data.price_ht); + $('#select_type').val(data.type).attr('disabled','disabled').trigger('change'); $('#update_label_area').show().trigger('show'); $('#update_desc_area').show().trigger('show'); $('#update_price_area').show().trigger('show'); @@ -293,7 +293,22 @@ $(document).ready(function() { $('#service_duration_area').show(); } //$('#add_product_area').show(); // TODO for add product card + var addline=false; if ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0) { + if ($('#idprod').val() == 0) { + if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { + var content = CKEDITOR.instances['product_desc'].getData(); + } else { + var content = $('#product_desc').val(); + } + if (content.length > 0) { + addline=true; + } + } else { + addline=true; + } + } + if (addline) { $('#addlinebutton').removeAttr('disabled'); } else { $('#addlinebutton').attr('disabled','disabled'); @@ -461,21 +476,74 @@ $(document).ready(function() { 'tva_tx': $('#tva_tx').val() }, function(data) { + var addline=false; if (typeof data[output] != 'undefined') { $('#' + output).val(data[output]); - if ($('#select_type').val() >= 0) { - $('#addlinebutton').removeAttr('disabled'); + if ($('#idprod').val() == 0 && $('#select_type').val() >= 0) { + if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { + var content = CKEDITOR.instances['product_desc'].getData(); + } else { + var content = $('#product_desc').val(); + } + if (content.length > 0) { + addline=true; + } } else { - $('#addlinebutton').attr('disabled','disabled'); + addline=true; } } else { $('#' + input).val(''); $('#' + output).val(''); + } + if (addline) { + $('#addlinebutton').removeAttr('disabled'); + } else { $('#addlinebutton').attr('disabled','disabled'); } }, 'json'); } + // Check if decription is not empty for free line + fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?> + CKEDITOR.on('instanceReady', function() { + CKEDITOR.instances['product_desc'].on('key', function() { + var addline=false; + if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + var content = CKEDITOR.instances['product_desc'].getData(); + if (content.length > 0) { + addline=true; + } + } else if ($('#idprod').val() > 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + addline=true; + } + if (addline) { + $('#addlinebutton').removeAttr('disabled'); + } else { + $('#addlinebutton').attr('disabled','disabled'); + } + }); + }); + + $('#product_desc').onDelayedKeyup({ + 'handler': function() { + var addline=false; + if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + var content = $('#product_desc').val(); + if (content.length > 0) { + addline=true; + } + } else if ($('#idprod').val() > 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + addline=true; + } + if (addline) { + $('#addlinebutton').removeAttr('disabled'); + } else { + $('#addlinebutton').attr('disabled','disabled'); + } + } + }); + + });