// #PI-107 BO product page JS refactoring

This commit is contained in:
tDidierjean
2012-04-02 12:46:47 +00:00
parent 2cef59bacc
commit e5ba920187
6 changed files with 169 additions and 136 deletions
@@ -24,12 +24,6 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<script type="text/javascript">
</script>
{if isset($product->id)} {if isset($product->id)}
<h4>{l s='Accounting'}</h4> <h4>{l s='Accounting'}</h4>
@@ -117,43 +117,4 @@
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
<script type="text/javascript">
var formProduct;
var accessories = new Array();
urlToCall = null;
/* function autocomplete */
$(document).ready(function() {
$('#product_autocomplete_input')
.autocomplete('ajax_products_list.php', {
minChars: 1,
autoFill: true,
max:20,
matchContains: true,
mustMatch:true,
scroll:false,
cacheLength:0,
formatItem: function(item) {
return item[1]+' - '+item[0];
}
}).result(addAccessory);
$('#product_autocomplete_input').setOptions({
extraParams: {
excludeIds : getAccessorieIds()
}
});
getManufacturers();
});
function getAccessorieIds()
{
var ids = {$product->id}+',';
ids += $('#inputAccessories').val().replace(/\\-/g,',').replace(/\\,$/,'');
ids = ids.replace(/\,$/,'');
return ids;
}
</script>
@@ -28,7 +28,7 @@
{block name="autoload_tinyMCE"} {block name="autoload_tinyMCE"}
// Execute when tab Informations has finished loading // Execute when tab Informations has finished loading
onTabLoad('Informations', function(){ new ProductTab('Informations').onDisplay(function(){
// change each by click to load only on click // change each by click to load only on click
$(".autoload_rte").each(function(e){ $(".autoload_rte").each(function(e){
tinySetup({ tinySetup({
@@ -98,12 +98,12 @@
product_type = $("input[name=type_product]:checked").val(); product_type = $("input[name=type_product]:checked").val();
$('#product-tab-content-wait').show(); $('#product-tab-content-wait').show();
{if $is_pack} {if $is_pack}
onTabLoad('Informations', function(){ new ProductTab('Informations').onDisplay(function(){
$('#pack_product').attr('checked', 'checked'); $('#pack_product').attr('checked', 'checked');
}); });
$('li.tab-row a[id*="VirtualProduct"]').hide(); $('li.tab-row a[id*="VirtualProduct"]').hide();
{elseif $product->is_virtual} {elseif $product->is_virtual}
onTabLoad('Informations', function(){ new ProductTab('Informations').onDisplay(function(){
$('#virtual_product').attr('checked', 'checked'); $('#virtual_product').attr('checked', 'checked');
$('#condition').attr('disabled', 'disabled'); $('#condition').attr('disabled', 'disabled');
$('#condition option[value=new]').attr('selected', 'selected'); $('#condition option[value=new]').attr('selected', 'selected');
@@ -111,7 +111,7 @@
$('li.tab-row a[id*="Pack"]').hide(); $('li.tab-row a[id*="Pack"]').hide();
$('li.tab-row a[id*="Shipping"]').hide(); $('li.tab-row a[id*="Shipping"]').hide();
{else} {else}
onTabLoad('Informations', function(){ new ProductTab('Informations').onDisplay(function(){
$('#simple_product').attr('checked', 'checked'); $('#simple_product').attr('checked', 'checked');
}); });
$('li.tab-row a[id*="Pack"]').hide(); $('li.tab-row a[id*="Pack"]').hide();
@@ -159,20 +159,20 @@
{ {
$('li.tab-row a[id*="VirtualProduct"]').show().click(); $('li.tab-row a[id*="VirtualProduct"]').show().click();
onTabLoad('VirtualProduct', function(){ new ProductTab('VirtualProduct').onDisplay(function(){
$('#is_virtual_good').attr('checked', true); $('#is_virtual_good').attr('checked', true);
$('#virtual_good').show(); $('#virtual_good').show();
$('#is_virtual').val(1); $('#is_virtual').val(1);
$("#virtual_good_attributes").show(); $("#virtual_good_attributes").show();
}); });
onTabLoad('Quantities', function(){ new ProductTab('Quantities').onDisplay(function(){
$('.stockForVirtualProduct').hide(); $('.stockForVirtualProduct').hide();
}); });
$('li.tab-row a[id*="Shipping"]').hide(); $('li.tab-row a[id*="Shipping"]').hide();
onTabLoad('Informations', function(){ new ProductTab('Informations').onDisplay(function(){
$('#condition').attr('disabled', 'disabled'); $('#condition').attr('disabled', 'disabled');
$('#condition option[value=refurbished]').removeAttr('selected'); $('#condition option[value=refurbished]').removeAttr('selected');
$('#condition option[value=used]').removeAttr('selected'); $('#condition option[value=used]').removeAttr('selected');
@@ -215,7 +215,7 @@
} }
if ($("#product-tab-content-"+id).hasClass('not-loaded') && !$("#product-tab-content-"+id).hasClass('loading')) if ($("#product-tab-content-"+id).hasClass('not-loaded') && !$("#product-tab-content-"+id).hasClass('loading'))
displayTabProductById(id, true, 0, null); ProductTab.display(id, true, 0, null);
else else
{ {
$("#product-tab-content-"+id).show(0, function(){ $("#product-tab-content-"+id).show(0, function(){
@@ -249,8 +249,7 @@
if ($('#product-tab-content-Associations').hasClass('not-loaded')) if ($('#product-tab-content-Associations').hasClass('not-loaded'))
disableSave(); disableSave();
$('#product-tab-content-Associations').bind('loaded', function() new ProductTab('Associations').onDisplay(function(){
{
handleSaveButtons(); handleSaveButtons();
}); });
@@ -276,7 +275,7 @@
{/foreach} {/foreach}
// Recursively load tabs starting with the first element of stack // Recursively load tabs starting with the first element of stack
displayTabProductById(tabs_to_preload[0], false, 0, tabs_to_preload); ProductTab.display(tabs_to_preload[0], false, 0, tabs_to_preload);
$('.productTabs').show(); $('.productTabs').show();
$('#product_form').show(); $('#product_form').show();
@@ -1895,7 +1895,6 @@ class AdminProductsControllerCore extends AdminController
{ {
if ($this->display == 'edit' || $this->display == 'add') if ($this->display == 'edit' || $this->display == 'add')
{ {
$this->addJS(_PS_JS_DIR_.'admin-products.js');
$this->fields_form = array(); $this->fields_form = array();
// Check if Module // Check if Module
@@ -3949,6 +3948,7 @@ class AdminProductsControllerCore extends AdminController
)); ));
$this->addJS(array( $this->addJS(array(
_PS_JS_DIR_.'admin-product-tab.js',
_PS_JS_DIR_.'admin-products.js', _PS_JS_DIR_.'admin-products.js',
_PS_JS_DIR_.'attributesBack.js', _PS_JS_DIR_.'attributesBack.js',
_PS_JS_DIR_.'price.js', _PS_JS_DIR_.'price.js',
+112
View File
@@ -0,0 +1,112 @@
/*
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
var ProductTab = function(name){
this.name = name;
this.id;
this.container;
/**
* 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
*/
this.onDisplay = function (callback_function)
{
if (typeof(this.selector) === 'undefined')
this.container = $('#product-tab-content-' + this.name);
if (this.container.length === 0)
throw 'Could not find container for tab name: ' + this.name;
if (this.container.hasClass('not-loaded'))
this.container.bind('loaded', callback_function);
else
callback_function();
}
}
/**
* Get a single tab or recursively get tabs in stack then display them
*
* @param int id position of the tab in the product page
* @param boolean selected is the tab selected
* @param int index current index in the stack (or 0)
* @param array stack list of tab ids to load (or null)
*/
ProductTab.display = function (id, selected, index, stack)
{
var myurl = $('#link-'+id).attr("href")+"&ajax=1";
var tab_selector = $("#product-tab-content-"+id);
// Used to check if the tab is already in the process of being loaded
tab_selector.addClass('loading');
if (selected)
$('#product-tab-content-wait').show();
$.ajax({
url : myurl,
async : true,
cache: false, // cache needs to be set to false or IE will cache the page with outdated product values
type: 'POST',
success : function(data)
{
tab_selector.html(data);
tab_selector.removeClass('not-loaded');
if (selected)
{
$("#link-"+id).addClass('selected');
tab_selector.show();
}
},
complete : function(data)
{
$("#product-tab-content-"+id).removeClass('loading');
if (selected)
{
$('#product-tab-content-wait').hide();
tab_selector.trigger('displayed');
}
tab_selector.trigger('loaded');
if (stack && stack[index + 1])
ProductTab.display(stack[index + 1], selected, index + 1, stack);
},
beforeSend : function(data)
{
// don't display the loading notification bar
if (typeof(ajax_running_timeout) !== 'undefined')
clearTimeout(ajax_running_timeout);
}
});
}
//ProductTab.tabs =
//
//ProductTab.getByName(name)
//{
//
//}
+45 -78
View File
@@ -205,61 +205,6 @@ function editProductAttribute(url, parent)
} }
/* END Combination */ /* END Combination */
/**
* Get a single tab or recursively get tabs in stack then display them
*
* @param int id position of the tab in the product page
* @param boolean selected is the tab selected
* @param int index current index in the stack (or 0)
* @param array stack list of tab ids to load (or null)
*/
function displayTabProductById(id, selected, index, stack)
{
var myurl = $('#link-'+id).attr("href")+"&ajax=1";
var tab_selector = $("#product-tab-content-"+id);
// Used to check if the tab is already in the process of being loaded
tab_selector.addClass('loading');
if (selected)
$('#product-tab-content-wait').show();
$.ajax({
url : myurl,
async : true,
cache: false, // cache needs to be set to false or IE will cache the page with outdated product values
type: 'POST',
success : function(data)
{
tab_selector.html(data);
tab_selector.removeClass('not-loaded');
if (selected)
{
$("#link-"+id).addClass('selected');
tab_selector.show();
}
},
complete : function(data)
{
$("#product-tab-content-"+id).removeClass('loading');
if (selected)
{
$('#product-tab-content-wait').hide();
tab_selector.trigger('displayed');
}
tab_selector.trigger('loaded');
if (stack && stack[index + 1])
displayTabProductById(stack[index + 1], selected, index + 1, stack);
},
beforeSend : function(data)
{
// don't display the loading notification bar
if (typeof(ajax_running_timeout) !== 'undefined')
clearTimeout(ajax_running_timeout);
}
});
}
/** /**
* Update the manufacturer select element with the list of existing manufacturers * Update the manufacturer select element with the list of existing manufacturers
*/ */
@@ -445,25 +390,42 @@ function deleteSpecificPrice(url, parent)
}); });
} }
/** function initAccessoriesAutocomplete()
* 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); /* function autocomplete */
if (!target_tab) $(document).ready(function() {
return false; $('#product_autocomplete_input')
if (target_tab.hasClass('not-loaded')) .autocomplete('ajax_products_list.php', {
target_tab.bind('loaded', callback_function); minChars: 1,
else autoFill: true,
callback_function(); max:20,
} matchContains: true,
mustMatch:true,
scroll:false,
cacheLength:0,
formatItem: function(item) {
return item[1]+' - '+item[0];
}
}).result(addAccessory);
/* function autocomplete */ $('#product_autocomplete_input').setOptions({
urlToCall = null; extraParams: {
excludeIds : getAccessorieIds()
}
});
function getAccessorieIds()
{
var ids = id_product + ',';
ids += $('#inputAccessories').val().replace(/\\-/g,',').replace(/\\,$/,'');
ids = ids.replace(/\,$/,'');
return ids;
}
});
}
$(document).ready(function() { $(document).ready(function() {
updateCurrentText(); updateCurrentText();
@@ -491,13 +453,13 @@ $(document).ready(function() {
}); });
// Enable writing of the product name when the friendly url field in tab SEO is loaded // Enable writing of the product name when the friendly url field in tab SEO is loaded
onTabLoad('Seo', enableProductName); new ProductTab('Seo').onDisplay(enableProductName);
// Bind to show/hide new specific price form new ProductTab('Prices').onDisplay(function(){
onTabLoad('Prices', toggleSpecificPrice); // Bind to show/hide new specific price form
toggleSpecificPrice();
// Bind to delete specific price link // Bind to delete specific price link
onTabLoad('Prices', function(){
$('#specific_prices_list').delegate('a[name="delete_link"]', 'click', function(e){ $('#specific_prices_list').delegate('a[name="delete_link"]', 'click', function(e){
e.preventDefault(); e.preventDefault();
deleteSpecificPrice(this.href, $(this).parents('tr')); deleteSpecificPrice(this.href, $(this).parents('tr'));
@@ -505,7 +467,7 @@ $(document).ready(function() {
}); });
// Bind attribute list ajax actions (edit, default, delete) // Bind attribute list ajax actions (edit, default, delete)
onTabLoad('Combinations', function(){ new ProductTab('Combinations').onDisplay(function(){
$('table[name=list_table]').delegate('a.edit', 'click', function(e){ $('table[name=list_table]').delegate('a.edit', 'click', function(e){
e.preventDefault(); e.preventDefault();
editProductAttribute(this.href, $(this).closest('tr')); editProductAttribute(this.href, $(this).closest('tr'));
@@ -521,4 +483,9 @@ $(document).ready(function() {
defaultProductAttribute(this.href, $(this).closest('tr')); defaultProductAttribute(this.href, $(this).closest('tr'));
}); });
}); });
new ProductTab('Associations').onDisplay(function(){
initAccessoriesAutocomplete();
getManufacturers();
});
}); });