diff --git a/admin-dev/themes/default/template/controllers/products/form.tpl b/admin-dev/themes/default/template/controllers/products/form.tpl index 5bafc06ab..4547206c0 100644 --- a/admin-dev/themes/default/template/controllers/products/form.tpl +++ b/admin-dev/themes/default/template/controllers/products/form.tpl @@ -27,43 +27,41 @@ {extends file="helper/form/form.tpl"} {block name="autoload_tinyMCE"} - // change each by click to load only on click + // Execute when tab Informations has finished loading + onTabLoad('Informations', function(){ + // change each by click to load only on click + $(".autoload_rte").each(function(e){ + tinySetup({ + mode :"exact", + editor_selector :"autoload_rte", + elements : $(this).attr("id"), + theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull|cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,undo,redo", + theme_advanced_buttons2 : "link,unlink,anchor,image,cleanup,code,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,charmap,media,|,ltr,rtl,|,fullscreen", + theme_advanced_buttons3 : "", + theme_advanced_buttons4 : "", + setup : function(ed) { - $("#product-tab-content-Informations").bind('loaded', function(){ + {* Count the total number of the field *} - $(".autoload_rte").each(function(e){ - tinySetup({ - mode :"exact", - editor_selector :"autoload_rte", - elements : $(this).attr("id"), - theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull|cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,undo,redo", - theme_advanced_buttons2 : "link,unlink,anchor,image,cleanup,code,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,charmap,media,|,ltr,rtl,|,fullscreen", - theme_advanced_buttons3 : "", - theme_advanced_buttons4 : "", - setup : function(ed) { - - {* Count the total number of the field *} - - ed.onKeyUp.add(function(ed, e) { - tinyMCE.triggerSave(); - textarea = $('#'+ed.id); - max = textarea.parent('div').find('span.counter').attr('max'); - if (max != 'none') - { - textarea_value = textarea.val(); - count = stripHTML(textarea_value).length; - rest = max - count; - if (rest < 0) - textarea.parent('div').find('span.counter').html('{l s='Maximum'} '+max+' {l s=' characters'} : '+rest+''); - else - textarea.parent('div').find('span.counter').html(' '); - } - }); - } + ed.onKeyUp.add(function(ed, e) { + tinyMCE.triggerSave(); + textarea = $('#'+ed.id); + max = textarea.parent('div').find('span.counter').attr('max'); + if (max != 'none') + { + textarea_value = textarea.val(); + count = stripHTML(textarea_value).length; + rest = max - count; + if (rest < 0) + textarea.parent('div').find('span.counter').html('{l s='Maximum'} '+max+' {l s=' characters'} : '+rest+''); + else + textarea.parent('div').find('span.counter').html(' '); + } + }); + } + }); }); }); -}); -$("#product-tab-content-Informations").trigger('loaded'); {/block} {block name="defaultForm"} diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 226310aae..6a952dfcb 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2082,6 +2082,12 @@ class AdminProductsControllerCore extends AdminController $this->tpl_form_vars['token'] = $this->token; $this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs(); + // autoload rich text editor (tiny mce) + $this->tpl_form_vars['tinymce'] = true; + $iso = $this->context->language->iso_code; + $this->tpl_form_vars['iso'] = file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'; + $this->tpl_form_vars['ad'] = dirname($_SERVER['PHP_SELF']); + if (Validate::isLoadedObject(($this->object))) $id_product = $this->object->id; else @@ -3015,12 +3021,6 @@ class AdminProductsControllerCore extends AdminController { $data = $this->createTemplate($this->tpl_form); - // autoload rich text editor (tiny mce) - $iso = $this->context->language->iso_code; - $this->tpl_form_vars['iso'] = file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'; - $this->tpl_form_vars['ad'] = dirname($_SERVER['PHP_SELF']); - $this->tpl_form_vars['tinymce'] = true; - $currency = $this->context->currency; $data->assign('languages', $this->_languages); $data->assign('currency', $currency); diff --git a/js/admin-products.js b/js/admin-products.js index 0bef27079..347aa3fc9 100644 --- a/js/admin-products.js +++ b/js/admin-products.js @@ -335,6 +335,28 @@ function handleSaveForPack() enableSave(); } +function enableProductName() +{ + $('.copy2friendlyUrl').removeAttr('disabled'); +} + +/** + * Execute a callback function when a specific tab has finished loading or right now if the tab is already loaded + * + * @param tab_name name of the tab that is checked for loading + * @param callback_function function to call + */ +function onTabLoad(tab_name, callback_function) +{ + var target_tab = $('#product-tab-content-' + tab_name); + if (!target_tab) + return false; + if (target_tab.hasClass('not-loaded')) + target_tab.bind('loaded', callback_function); + else + callback_function(); +} + /* function autocomplete */ urlToCall = null; @@ -348,4 +370,7 @@ $(document).ready(function() { code = (e.keyCode ? e.keyCode : e.which); return (code == 13) ? false : true; }); + + // Enable writing of the product name when the friendly url field in tab SEO is loaded + onTabLoad('Seo', enableProductName); });