first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,438 @@
/**
* 2007-2018 PrestaShop
*
* 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:
* https://opensource.org/licenses/OSL-3.0
* 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-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
var $ = window.$;
$(document).ready(function() {
var form = $('form#product_catalog_list');
/*
* Tree behavior: collapse/expand system and radio button change event.
*/
$('div#product_catalog_category_tree_filter').categorytree();
$('div#product_catalog_category_tree_filter div.radio > label > input:radio').change(function() {
if ($(this).is(':checked')) {
$('form#product_catalog_list input[name="filter_category"]').val($(this).val());
$('form#product_catalog_list').submit();
}
});
$('div#product_catalog_category_tree_filter ~ div button, div#product_catalog_category_tree_filter ul').on('click', function() {
categoryFilterButtons();
});
categoryFilterButtons();
/*
* Click on a column header ordering icon to change orderBy / orderWay (location.href redirection)
*/
$('[psorderby][psorderway]', form).click(function() {
var orderBy = $(this).attr('psorderby');
var orderWay = $(this).attr('psorderway');
productOrderTable(orderBy, orderWay);
});
/*
* Checkboxes behavior with bulk actions
*/
$('input:checkbox[name="bulk_action_selected_products[]"]', form).change(function() {
updateBulkMenu();
});
/*
* Filter columns inputs behavior
*/
$('tr.column-filters input:text, tr.column-filters select', form).on('change input', function() {
productCatalogFilterChanged = true;
updateFilterMenu();
});
/*
* Sortable case when ordered by position ASC
*/
$("body").on("mousedown", "tbody.sortable [data-uniturl] td.placeholder", function () {
var trParent = $(this).closest('tr');
trParent.find('input:checkbox[name="bulk_action_selected_products[]"]').attr("checked", true);
});
$('tbody.sortable', form).sortable({
placeholder: 'placeholder',
update: function(event, ui) {
var positionSpan = $('span.position', ui.item)[0];
$(positionSpan).css('color', 'red');
bulkProductEdition(event, 'sort');
}
});
/*
* Form submit pre action
*/
form.submit(function(e) {
e.preventDefault();
$('#filter_column_id_product', form).val($('#filter_column_id_product', form).attr('sql'));
$('#filter_column_price', form).val($('#filter_column_price', form).attr('sql'));
$('#filter_column_sav_quantity', form).val($('#filter_column_sav_quantity', form).attr('sql'));
productCatalogFilterChanged = false;
this.submit();
return false;
});
/*
* Send to SQL manager button on modal
*/
$('#catalog_sql_query_modal button[value="sql_manager"]').on('click', function() {
sendLastSqlQuery(createSqlQueryName());
});
updateBulkMenu();
updateFilterMenu();
/** create keyboard event for save & new */
jwerty.key('ctrl+P', function(e) {
e.preventDefault();
var url = $('form#product_catalog_list').attr('newproducturl');
window.location.href = url;
});
});
function productOrderTable(orderBy, orderWay) {
var form = $('form#product_catalog_list');
var url = form.attr('orderingurl').replace(/name/, orderBy).replace(/asc/, orderWay);
window.location.href = url;
}
function productOrderPrioritiesTable() {
window.location.href = $('form#product_catalog_list').attr('orderingurl');
}
function updateBulkMenu() {
var selectedCount = $('form#product_catalog_list input:checked[name="bulk_action_selected_products[]"][disabled!="disabled"]').length;
$('#product_bulk_menu').prop('disabled', (selectedCount === 0));
}
var productCatalogFilterChanged = false;
function updateFilterMenu() {
var columnFilters = $('#product_catalog_list').find('tr.column-filters');
var count = columnFilters.find('option:selected[value!=""]').length;
columnFilters.find('input[type="text"][sql!=""][sql], input[type="text"]:visible').each(function() {
if ($(this).val() !== '') {
count++;
}
});
var filtersNotUpdatedYet = (count === 0 && productCatalogFilterChanged === false);
$('button[name="products_filter_submit"]').prop('disabled', filtersNotUpdatedYet);
$('button[name="products_filter_reset"]').toggle(!filtersNotUpdatedYet);
}
function productCategoryFilterReset(div) {
$('#product_categories').categorytree('unselect');
$('#product_catalog_list input[name="filter_category"]').val('');
$('#product_catalog_list').submit();
}
function productCategoryFilterExpand(div, btn) {
$('#product_categories').categorytree('unfold');
}
function productCategoryFilterCollapse(div, btn) {
$('#product_categories').categorytree('fold');
}
function categoryFilterButtons() {
var catTree = $('#product_catalog_category_tree_filter');
var catTreeSiblingDivs = $('#product_catalog_category_tree_filter ~ div');
var catTreeList = catTree.find('ul ul');
catTreeSiblingDivs.find('button[name="product_catalog_category_tree_filter_collapse"]').toggle(!catTreeList.filter(':visible').length);
catTreeSiblingDivs.find('button[name="product_catalog_category_tree_filter_expand"]').toggle(!catTreeList.filter(':hidden').length);
catTreeSiblingDivs.find('button[name="product_catalog_category_tree_filter_reset"]').toggle(!catTree.find('ul input:checked').length);
}
function productColumnFilterReset(tr) {
$('input:text', tr).val('');
$('select option:selected', tr).prop('selected', false);
$('#filter_column_price', tr).attr('sql', '');
$('#filter_column_sav_quantity', tr).attr('sql', '');
$('#filter_column_id_product', tr).attr('sql', '');
$('#product_catalog_list').submit();
}
function bulkModalAction(allItems, postUrl, redirectUrl, action) {
var itemsCount = allItems.length;
var currentItemIdx = 0;
if (itemsCount < 1) {
return;
}
var targetModal = $('#catalog_' + action + '_modal');
targetModal.modal('show');
var details = targetModal.find('#catalog_' + action + '_progression .progress-details-text');
var progressBar = targetModal.find('#catalog_' + action + '_progression .progress-bar');
var failure = targetModal.find('#catalog_' + action + '_failure');
// re-init popup
details.html(details.attr('default-value'));
progressBar.css('width', '0%');
progressBar.find('span').html('');
progressBar.removeClass('progress-bar-danger');
progressBar.addClass('progress-bar-success');
failure.hide();
// call in ajax. Recursive with inner function
var bulkCall = function (items, successCallback, errorCallback) {
if (items.length === 0) {
return;
}
var item0 = $(items.shift()).val();
currentItemIdx++;
details.html(details.attr('default-value').replace(/\.\.\./, '') + ' (#' + item0 + ')');
$.ajax({
type: 'POST',
url: postUrl,
data: {bulk_action_selected_products: [item0]},
success: function (data, status) {
progressBar.css('width', (currentItemIdx * 100 / itemsCount) + '%');
progressBar.find('span').html(currentItemIdx + ' / ' + itemsCount);
if (items.length > 0) {
bulkCall(items, successCallback, errorCallback);
} else {
successCallback();
}
},
error: errorCallback,
dataType: 'json'
});
};
bulkCall(allItems.toArray(), function () {
window.location.href = redirectUrl;
}, function () {
progressBar.removeClass('progress-bar-success');
progressBar.addClass('progress-bar-danger');
failure.show();
window.location.href = redirectUrl;
});
}
function bulkProductAction(element, action) {
var form = $('#product_catalog_list');
var postUrl = '';
var redirectUrl = '';
var urlHandler = null;
var items = $('input:checked[name="bulk_action_selected_products[]"]', form);
if (items.length === 0) {
return false;
} else {
urlHandler = $(element).closest('[bulkurl]');
}
switch (action) {
case 'delete_all':
postUrl = urlHandler.attr('bulkurl').replace(/activate_all/, action);
redirectUrl = urlHandler.attr('redirecturl');
// Confirmation popup and callback...
$('#catalog_deletion_modal').modal('show');
$('#catalog_deletion_modal button[value="confirm"]').off('click');
$('#catalog_deletion_modal button[value="confirm"]').on('click', function () {
$('#catalog_deletion_modal').modal('hide');
return bulkModalAction(items, postUrl, redirectUrl, action);
});
return; // No break, but RETURN, to avoid code after switch block :)
case 'activate_all':
postUrl = urlHandler.attr('bulkurl');
redirectUrl = urlHandler.attr('redirecturl');
return bulkModalAction(items, postUrl, redirectUrl, action);
break;
case 'deactivate_all':
postUrl = urlHandler.attr('bulkurl').replace(/activate_all/, action);
redirectUrl = urlHandler.attr('redirecturl');
return bulkModalAction(items, postUrl, redirectUrl, action);
break;
case 'duplicate_all':
postUrl = urlHandler.attr('bulkurl').replace(/activate_all/, action);
redirectUrl = urlHandler.attr('redirecturl');
return bulkModalAction(items, postUrl, redirectUrl, action);
break;
// this case will brings to the next page
case 'edition_next':
redirectUrl = $(element).closest('[massediturl]').attr('redirecturlnextpage');
// no break !
// this case will post inline edition command
case 'edition':
var editionAction;
var bulkEditionSelector = '#bulk_edition_toolbar input:submit';
if ($(bulkEditionSelector).length > 0) {
editionAction = $(bulkEditionSelector).attr('editionaction');
} else {
editionAction = 'sort';
}
urlHandler = $('[massediturl]');
postUrl = urlHandler.attr('massediturl').replace(/sort/, editionAction);
if (redirectUrl === '') {
redirectUrl = urlHandler.attr('redirecturl');
}
break;
// unknown cases...
default:
return false;
}
if (postUrl !== '' && redirectUrl !== '') {
// save action URL for redirection and update to post to bulk action instead
// using form action URL allow to get route attributes and stay on the same page & ordering.
var redirectionInput = $('<input>')
.attr('type', 'hidden')
.attr('name', 'redirect_url').val(redirectUrl);
form.append($(redirectionInput));
form.attr('action', postUrl);
form.submit();
}
return false;
}
function unitProductAction(element, action) {
var form = $('form#product_catalog_list');
// save action URL for redirection and update to post to bulk action instead
// using form action URL allow to get route attributes and stay on the same page & ordering.
var urlHandler = $(element).closest('[data-uniturl]');
var redirectUrlHandler = $(element).closest('[redirecturl]');
var redirectionInput = $('<input>')
.attr('type', 'hidden')
.attr('name', 'redirect_url').val(redirectUrlHandler.attr('redirecturl'));
switch (action) {
case 'delete':
// Confirmation popup and callback...
$('#catalog_deletion_modal').modal('show');
$('#catalog_deletion_modal button[value="confirm"]').off('click');
$('#catalog_deletion_modal button[value="confirm"]').on('click', function () {
form.append($(redirectionInput));
var url = urlHandler.attr('data-uniturl').replace(/duplicate/, action);
form.attr('action', url);
form.submit();
$('#catalog_deletion_modal').modal('hide');
});
return;
// Other cases, nothing to do, continue.
//default:
}
form.append($(redirectionInput));
var url = urlHandler.attr('data-uniturl').replace(/duplicate/, action);
form.attr('action', url);
form.submit();
}
function showBulkProductEdition(show) {
// Paginator does not have a next page link : we are on the last page!
if ($('a#pagination_next_url[href]').length === 0) {
$('#bulk_edition_save_next').prop('disabled', true).removeClass('btn-primary');
$('#bulk_edition_save_keep').attr('type', 'submit').addClass('btn-primary');
}
if (show) {
$('#bulk_edition_toolbar').show();
} else {
$('#bulk_edition_toolbar').hide();
}
}
function bulkProductEdition(element, action) {
var form = $('form#product_catalog_list');
switch (action) {
/*
case 'quantity_edition':
showBulkProductEdition(true);
$('input#bulk_action_select_all, input:checkbox[name="bulk_action_selected_products[]"]', form).prop('disabled', true);
i = 1;
$('td.product-sav-quantity', form).each(function() {
$quantity = $(this).attr('productquantityvalue');
$product_id = $(this).closest('tr[productid]').attr('productid');
$input = $('<input>').attr('type', 'text').attr('name', 'bulk_action_edit_quantity['+$product_id+']')
.attr('tabindex', i++)
.attr('onkeydown', 'if (event.keyCode == 13) return bulkProductAction(this, "edition_next"); if (event.keyCode == 27) return bulkProductEdition(this, "cancel");')
.val($quantity);
$(this).html($input);
});
$('#bulk_edition_toolbar input:submit').attr('tabindex', i++);
$('#bulk_edition_toolbar input:button').attr('tabindex', i++);
$('#bulk_edition_toolbar input:submit').attr('editionaction', action);
$('td.product-sav-quantity input', form).first().focus();
break;
*/
case 'sort':
showBulkProductEdition(true);
$('input#bulk_action_select_all, input:checkbox[name="bulk_action_selected_products[]"]', form).prop('disabled', true);
$('#bulk_edition_toolbar input:submit').attr('editionaction', action);
break;
case 'cancel':
// quantity inputs
$('td.product-sav-quantity', form).each(function() {
$(this).html($(this).attr('productquantityvalue'));
});
$('#bulk_edition_toolbar input:submit').removeAttr('editionaction');
showBulkProductEdition(false);
$('input#bulk_action_select_all, input:checkbox[name="bulk_action_selected_products[]"]', form).prop('disabled', false);
break;
}
}
function showLastSqlQuery() {
$('#catalog_sql_query_modal_content textarea[name="sql"]').val($('tbody[last_sql]').attr('last_sql'));
$('#catalog_sql_query_modal').modal('show');
}
function sendLastSqlQuery(name) {
$('#catalog_sql_query_modal_content textarea[name="sql"]').val($('tbody[last_sql]').attr('last_sql'));
$('#catalog_sql_query_modal_content input[name="name"]').val(name);
$('#catalog_sql_query_modal_content').submit();
}

View File

@@ -0,0 +1,44 @@
/**
* Default category management
*/
var defaultCategory = (function() {
var defaultCategoryForm = $('#form_step1_id_category_default');
return {
'init': function () {
/** Populate category tree with the default category **/
var defaultCategoryId = defaultCategoryForm.find('input:checked').val();
productCategoriesTags.checkDefaultCategory(defaultCategoryId);
/** Hide the default form, if javascript disabled it will be visible and so we
* still can select a default category using the form
*/
defaultCategoryForm.hide();
},
/**
* Check the radio bouton with the selected value
*/
'check': function(value) {
defaultCategoryForm.find('input[value="'+value+'"]').prop('checked', true);
},
'isChecked': function(value) {
return defaultCategoryForm.find('input[value="'+value+'"]').is(':checked');
},
/**
* When the category selected as a default is unselected
* The default category MUST be a selected category
*/
'reset': function() {
var firstInput = defaultCategoryForm.find('input:first-child');
firstInput.prop('checked', true);
var categoryId = firstInput.val();
productCategoriesTags.checkDefaultCategory(categoryId);
}
};
})();
BOEvent.on("Product Default category Management started", function initDefaultCategoryManagement() {
defaultCategory.init();
}, "Back office");

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,205 @@
/**
* Product categories Tags management
*/
var productCategoriesTags = (function () {
var defaultCategoryForm = $('#form_step1_id_category_default');
var categoriesForm = $('#form_step1_categories');
var tagsContainer = $('#ps_categoryTags');
return {
'init': function () {
selectedCategories = this.getTags();
selectedCategories.forEach(this.createTag);
// add tags management
this.manageTagsOnInput();
this.manageTagsOnTags();
// add default category management
this.checkDefaultCategory();
// add search box
this.initSearchBox();
},
'removeTag': function (categoryId) {
$('span[data-id^="' + categoryId + '"]').parent().remove();
return true;
},
'getTags': function () {
var categoriesForm = $('#form_step1_categories');
var inputs = categoriesForm.find('label > input[type=checkbox]:checked').toArray();
var tags = [];
var that = this;
inputs.forEach(function getLabels(input) {
var tree = that.getTree();
var tag = {
'name': input.parentNode.innerText,
'id': input.value,
};
tree.forEach(function getCategories(_category) {
if (_category.id == tag.id) {
tag.breadcrumb = _category.breadcrumb;
}
});
tags.push(tag);
});
return tags;
},
'manageTagsOnInput': function () {
var categoriesForm = $('#form_step1_categories');
var that = this;
categoriesForm.on('change', 'input[type=checkbox]', function (event) {
var input = $(this);
if (input.prop('checked') === false) {
that.removeTag($(this).val());
} else {
var tag = {
'name': input.parent().text(),
'id': input.val(),
'breadcrumb': ''
};
that.createTag(tag);
}
});
return true;
},
'manageTagsOnTags': function () {
var that = this;
tagsContainer.on('click', 'a.pstaggerClosingCross', function (event) {
event.preventDefault();
var id = $(this).data('id');
that.removeTag(id);
categoriesForm.find('input[value="' + id + '"].category').prop('checked', false);
tagsContainer.focus();
});
return true;
},
'checkDefaultCategory': function (categoryId) {
var categoriesForm = $('#form_step1_categories');
var selector = 'input[value="'+categoryId+'"].default-category';
categoriesForm.find(selector).prop('checked', true);
},
'getTree': function () {
var tree = JSON.parse($('#ps_categoryTree').html());
return tree;
},
'createTag': function (category) {
if (category.breadcrumb == '') {
var tree = this.getTree();
tree.forEach(function getCategories(_category) {
if (_category.id == category.id) {
category.breadcrumb = _category.breadcrumb;
}
});
}
var isTagExist = tagsContainer.find('span[data-id='+ category.id +']');
if(0 == isTagExist.length) {
tagsContainer.append('<span class="pstaggerTag">' +
'<span data-id="' + category.id + '" title="' + category.breadcrumb + '">' + category.name + '</span>' +
'<a class="pstaggerClosingCross" href="#" data-id="' + category.id + '">x</a>' +
'</span>')
;
var optionId = '#form_step1_id_category_default_' + category.id;
if (0 == $(optionId).length) {
defaultCategoryForm.append('<div class="radio">' +
'<label class="required">' +
'<input type="radio"' + 'id="form_step1_id_category_default_' + category.id + '" name="form[step1][id_category_default]" required="required" value="' + category.id + '">' +
category.name +'</label>' +
'</div>');
}
}
return true;
},
'getNameFromBreadcrumb': function (name) {
if (name.indexOf('&gt;') !== -1) {
return name.substring(name.lastIndexOf('&gt') + 4); // remove "&gt; "
}
return name;
},
'initSearchBox': function () {
var searchCategorySelector = '#ps-select-product-category';
var searchBox = $(searchCategorySelector);
var tree = this.getTree();
var tags = [];
var that = this;
let searchResultMsg = '';
tree.forEach(function buildTags(tagObject){
tags.push({
label: tagObject.breadcrumb,
value: tagObject.id
});
});
searchBox.autocomplete({
source: tags,
minChars: 2,
autoFill: true,
max:20,
matchContains: true,
mustMatch:false,
scroll:false,
focus: function(event, ui) {
event.preventDefault();
let $this = $(this);
$this.val(that.getNameFromBreadcrumb(ui.item.label));
searchResultMsg = $this.parent().find('[role=status]').text();
},
select: function(event, ui) {
event.preventDefault();
var label = ui.item.label;
var categoryName = that.getNameFromBreadcrumb(label);
var categoryId = ui.item.value;
that.createTag({
'name': categoryName,
'id': categoryId,
'breadcrumb': label
});
var categoriesForm = $('#form_step1_categories');
categoriesForm.find('input[value="' + categoryId + '"].category').prop('checked', true);
$(this).val('');
}
}).data('ui-autocomplete')._renderItem = function(ul, item) {
return $('<li>')
.data('ui-autocomplete-item', item)
.append('<a>'+item.label+'</a>')
.appendTo(ul);
};
searchBox.parent().find('[role=status]').on('DOMSubtreeModified', function () {
let $this = $(this);
if ($.isNumeric($this.text()) && searchResultMsg !== '' && searchBox.val() !== '') {
$this.text(searchResultMsg);
}
});
$('body').on('focusout', searchCategorySelector, function (event) {
var $searchInput = $(event.currentTarget);
if (0 === $searchInput.val().length ) {
$searchInput.parent().find('[role=status]').text('');
searchResultMsg = '';
}
});
}
};
})();
BOEvent.on("Product Categories Management started", function initTagsManagement() {
productCategoriesTags.init();
}, "Back office");

View File

@@ -0,0 +1,294 @@
/**
* Combination management
*/
var combinations = (function() {
var id_product = $('#form_id_product').val();
/**
* Remove a combination
* @param {object} elem - The clicked link
*/
function remove(elem) {
var combinationElem = $('#attribute_' + elem.attr('data'));
modalConfirmation.create(translate_javascripts['Are you sure to delete this?'], null, {
onContinue: function() {
var attributeId = elem.attr('data');
$.ajax({
type: 'DELETE',
data: {'attribute-ids': [attributeId]},
url: elem.attr('href'),
beforeSend: function() {
elem.attr('disabled', 'disabled');
$('#create-combinations, #apply-on-combinations, #submit, .btn-submit').attr('disabled', 'disabled');
},
success: function(response) {
refreshTotalCombinations(-1, 1);
combinationElem.remove();
showSuccessMessage(response.message);
displayFieldsManager.refresh();
},
error: function(response) {
showErrorMessage(jQuery.parseJSON(response.responseText).message);
},
complete: function() {
elem.removeAttr('disabled');
$('#create-combinations, #apply-on-combinations, #submit, .btn-submit').removeAttr('disabled');
supplierCombinations.refresh();
warehouseCombinations.refresh();
if ($('.js-combinations-list .combination').length <= 0) {
$('#combinations_thead').fadeOut();
}
}
});
}
}).show();
}
/**
* Update final price, regarding the impact on price in combinations table
* @param {jQuery} tableRow - Table row that contains the combination
*/
function updateFinalPrice(tableRow) {
if (!tableRow.is('tr')) {
throw new Error('Structure of table has changed, this function needs to be updated.');
}
var priceImpactInput = tableRow.find('.attribute_priceTE').first();
var finalPriceLabel = tableRow.find('.attribute-finalprice span');
var impactOnPrice = Tools.parseFloatFromString(priceImpactInput.val());
var previousImpactOnPrice = Tools.parseFloatFromString(priceImpactInput.attr('value'));
var currentFinalPrice = Tools.parseFloatFromString(finalPriceLabel.data('price'), true);
var finalPrice = currentFinalPrice - previousImpactOnPrice + impactOnPrice;
finalPriceLabel.html(Number(ps_round(finalPrice, 6)).toFixed(6));
}
/**
* Returns a reference to the form for a specific combination
* @param {String} attributeId
* @return {jQuery}
*/
function getCombinationForm(attributeId) {
return $('#combination_form_' + attributeId);
}
/**
* Returns a reference to the row of a specific combination
* @param {String} attributeId
* @return {jQuery}
*/
function getCombinationRow(attributeId) {
return $('#accordion_combinations #attribute_' + attributeId);
}
return {
'init': function() {
var showVariationsSelector = '#show_variations_selector input';
var productTypeSelector = $('#form_step1_type_product');
var combinationsListSelector = '#accordion_combinations .combination';
var combinationsList = $(combinationsListSelector);
if (combinationsList.length > 0) {
productTypeSelector.prop('disabled', true);
}
$(document)
// delete combination
.on('click', '#accordion_combinations .delete', function(e) {
e.preventDefault();
remove($(this));
})
// when typing a new quantity on the form, update it on the row
.on('keyup', 'input[id^="combination"][id$="_attribute_quantity"]', function() {
var attributeId = $(this).closest('.combination-form').attr('data');
var input = getCombinationRow(attributeId).find('.attribute-quantity input');
input.val($(this).val());
})
// when typing a new quantity on the row, update it on the form
.on('keyup', '.attribute-quantity input', function() {
var attributeId = $(this).closest('.combination').attr('data');
var input = getCombinationForm(attributeId).find('input[id^="combination"][id$="_attribute_quantity"]');
input.val($(this).val());
})
.on({
// when typing a new impact on price on the form, update it on the row
'keyup': function () {
var attributeId = $(this).closest('.combination-form').attr('data');
var input = getCombinationRow(attributeId).find('.attribute-price input');
input.val($(this).val());
},
// when impact on price on the form is changed, update final price
'change': function () {
var attributeId = $(this).closest('.combination-form').attr('data');
var input = getCombinationRow(attributeId).find('.attribute-price input');
input.val($(this).val());
updateFinalPrice($(input.parents('tr')[0]));
}
}, 'input[id^="combination"][id$="_attribute_price"]')
// when price impact is changed on the row, update it on the form
.on('change', '.attribute-price input', function() {
var attributeId = $(this).closest('.combination').attr('data');
var input = getCombinationForm(attributeId).find('input[id^="combination"][id$="_attribute_price"]');
input.val($(this).val());
updateFinalPrice($(this).parent().parent().parent());
})
// on change default attribute, update which combination is the new default
.on('click', 'input.attribute-default', function() {
var selectedCombination = $(this);
var combinationRadioButtons = $('input.attribute-default');
var attributeId = $(this).closest('.combination').attr('data');
combinationRadioButtons.each(function unselect(index) {
var combination = $(this);
if (combination.data('id') !== selectedCombination.data('id')) {
combination.prop("checked", false);
}
});
$('.attribute_default_checkbox').removeAttr('checked');
getCombinationForm(attributeId)
.find('input[id^="combination"][id$="_attribute_default"]')
.prop("checked", true);
})
// Combinations fields display management
.on('change', showVariationsSelector, function() {
displayFieldsManager.refresh();
combinationsList = $(combinationsListSelector);
if ($(this).val() === '0') {
//if combination(s) exists, alert user for deleting it
if (combinationsList.length > 0) {
modalConfirmation.create(translate_javascripts['Are you sure to disable variations ? they will all be deleted'], null, {
onCancel: function() {
$('#show_variations_selector input[value="1"]').prop('checked', true);
displayFieldsManager.refresh();
},
onContinue: function() {
$.ajax({
type: 'GET',
url: $('#accordion_combinations').attr('data-action-delete-all').replace(/\/\d+(?=\?.*)/, '/' + $('#form_id_product').val()),
success: function(response) {
combinationsList.remove();
displayFieldsManager.refresh();
},
error: function(response) {
showErrorMessage(jQuery.parseJSON(response.responseText).message);
}
});
// enable the top header selector
// we want to use a "Simple product" without any combinations
productTypeSelector.prop('disabled', false);
}
}).show();
} else {
// enable the top header selector if no combination(s) exists
productTypeSelector.prop('disabled', false);
}
} else {
// this means we have or we want to have combinations
// disable the product type selector
productTypeSelector.prop('disabled', true);
}
})
// open combination form
.on('click', '#accordion_combinations .btn-open', function(e) {
e.preventDefault();
var contentElem = $($(this).attr('href'));
/** create combinations navigation */
var navElem = contentElem.find('.nav');
var id_attribute = contentElem.attr('data');
var prevCombinationId = $('#accordion_combinations tr[data="' + id_attribute + '"]').prev().attr('data');
var nextCombinationId = $('#accordion_combinations tr[data="' + id_attribute + '"]').next().attr('data');
navElem.find('.prev, .next').hide();
if (prevCombinationId) {
navElem.find('.prev').attr('data', prevCombinationId).show();
}
if (nextCombinationId) {
navElem.find('.next').attr('data', nextCombinationId).show();
}
/** init combination tax include price */
priceCalculation.impactTaxInclude(contentElem.find('.attribute_priceTE'));
contentElem.insertBefore('#form-nav').removeClass('hide').show();
contentElem.find('.datepicker input[type="text"]').datetimepicker({
locale: iso_user,
format: 'YYYY-MM-DD'
});
function countSelectedProducts() {
return $('#combination_form_' + contentElem.attr('data') + ' .img-highlight').length;
}
var number = $('#combination_form_' + contentElem.attr('data') + ' .number-of-images'),
allProductCombination = $('#combination_form_' + contentElem.attr('data') + ' .product-combination-image').length;
number.text(countSelectedProducts() + '/' + allProductCombination);
$(document).on('click','.tabs .product-combination-image', function () {
number.text(countSelectedProducts() + '/' + allProductCombination);
});
/** Add title on product's combination image */
$(function() {
$('#combination_form_' + contentElem.attr('data')).find("img").each(function() {
title = $(this).attr('src').split('/').pop();
$(this).attr('title',title);
});
});
$('#form-nav, #form_content').hide();
})
// close combination form
.on('click', '#form .combination-form .btn-back', function(e) {
e.preventDefault();
$(this).closest('.combination-form').hide();
$('#form-nav, #form_content').show();
})
// switch combination form
.on('click', '#form .combination-form .nav a', function(e) {
e.preventDefault();
$('.combination-form').hide();
$('#accordion_combinations .combination[data="' + $(this).attr('data') + '"] .btn-open').click();
})
;
}
};
})();
BOEvent.on("Product Combinations Management started", function initCombinationsManagement() {
combinations.init();
}, "Back office");
/**
* Refresh bulk actions combination number after creating or deleting combinations
*
* @param {number} sign
* @param {number} number
*/
var refreshTotalCombinations = function (sign, number) {
var $bulkCombinationsTotal = $('#js-bulk-combinations-total');
var currentnumber = parseInt($bulkCombinationsTotal.text()) + (sign * number);
$bulkCombinationsTotal.text(currentnumber);
}

View File

@@ -0,0 +1,34 @@
/**
* Manufacturer management
*/
var manufacturer = (function() {
return {
'init': function() {
var addButton = $('#add_brand_button');
var resetButton = $('#reset_brand_product');
var manufacturerContent = $('#manufacturer-content');
var selectManufacturer = $('#form_step1_id_manufacturer');
/** Click event on the add button */
addButton.on('click', function(e) {
e.preventDefault();
manufacturerContent.removeClass('hide');
addButton.hide();
});
resetButton.on('click', function(e) {
e.preventDefault();
modalConfirmation.create(translate_javascripts['Are you sure to delete this?'], null, {
onContinue: function(){
manufacturerContent.addClass('hide');
selectManufacturer.val('').trigger('change');
addButton.show();
}
}).show();
});
}
};
})();
BOEvent.on("Product Manufacturer Management started", function initManufacturerManagement() {
manufacturer.init();
}, "Back office");

View File

@@ -0,0 +1,42 @@
/**
* Related product management
*/
var relatedProduct = (function() {
return {
'init': function() {
var addButton = $('#add-related-product-button');
var resetButton = $('#reset_related_product');
var relatedContent = $('#related-content');
var productItems = $('#form_step1_related_products-data');
var searchProductsBar = $('#form_step1_related_products');
addButton.on('click', function(e) {
e.preventDefault();
relatedContent.removeClass('hide');
addButton.hide();
});
resetButton.on('click', function(e) {
e.preventDefault();
modalConfirmation.create(translate_javascripts['Are you sure to delete this?'], null, {
onContinue: function onContinue(){
var items = productItems.find('li').toArray();
items.forEach(function removeItem(item) {
console.log(item);
item.remove();
});
searchProductsBar.val('');
relatedContent.addClass('hide');
addButton.show();
}
}).show();
});
}
};
})();
BOEvent.on("Product Related Management started", function initRelatedProductManagement() {
relatedProduct.init();
}, "Back office");