From dd8f447c6261babb3068db232d73c237ad0d6e08 Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Fri, 16 Nov 2012 13:21:53 +0000 Subject: [PATCH] [-] BO : fixed bug #PSCFV-5141 - Product Url being rewritten when a product is edited --- .../controllers/products/input_text_lang.tpl | 1 - js/admin-products.js | 5 ----- js/admin.js | 17 ++++++++++------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/input_text_lang.tpl b/admin-dev/themes/default/template/controllers/products/input_text_lang.tpl index a2a96ef8d..ae9cc3d43 100644 --- a/admin-dev/themes/default/template/controllers/products/input_text_lang.tpl +++ b/admin-dev/themes/default/template/controllers/products/input_text_lang.tpl @@ -30,7 +30,6 @@ {/foreach} diff --git a/js/admin-products.js b/js/admin-products.js index 03c07f0a5..0efcb4a01 100644 --- a/js/admin-products.js +++ b/js/admin-products.js @@ -482,7 +482,6 @@ product_tabs['Seo'] = new function(){ var self = this; this.onReady = function() { - copy2friendlyURL(); // Enable writing of the product name when the friendly url field in tab SEO is loaded $('.copy2friendlyUrl').removeAttr('disabled'); @@ -1578,9 +1577,7 @@ tabs_manager.setTabs(product_tabs); $(document).ready(function() { // The manager schedules the onReady() methods of each tab to be called when the tab is loaded tabs_manager.init(); - updateCurrentText(); - $("#name_" + id_lang_default + ",#link_rewrite_" + id_lang_default) .live("change", function(e) { @@ -1592,7 +1589,6 @@ $(document).ready(function() { { handleSaveButtons() }); - updateFriendlyURL(); // Pressing enter in an input field should not submit the form $('#product_form').delegate('input', 'keypress', function(e){ @@ -1601,4 +1597,3 @@ $(document).ready(function() { return (code == 13) ? false : true; }); }); - diff --git a/js/admin.js b/js/admin.js index 9a6dd22e5..f016104e5 100644 --- a/js/admin.js +++ b/js/admin.js @@ -53,11 +53,14 @@ function str2url(str,encoding,ucfirst) function copy2friendlyURL() { - $('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8').replace('%', '')); - if ($('#friendly-url')) - $('#friendly-url').html($('#link_rewrite_' + id_language).val()); - // trigger onchange event to use anything binded there - $('#link_rewrite_' + id_language).change(); + if (!$('#link_rewrite_' + id_language).val().length)//check if user didn't type anything in rewrite field, to prevent overwriting + { + $('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8').replace('%', '')); + if ($('#friendly-url')) + $('#friendly-url').html($('#link_rewrite_' + id_language).val()); + // trigger onchange event to use anything binded there + $('#link_rewrite_' + id_language).change(); + } return; } @@ -121,7 +124,7 @@ function changeFormLanguage(id_language_new, iso_code, employee_cookie) if (employee_cookie) $.post("ajax.php", { form_language_id: id_language_new }); id_language = id_language_new; - updateFriendlyURL(); + updateCurrentText(); } @@ -691,7 +694,7 @@ $(document).ready(function() if(isArrowKey(e)) return; - updateCurrentText() + updateCurrentText(); }); $(".copyMeta2friendlyURL").live('keyup change',function(e){