Skip to content

Commit

Permalink
Merge pull request PrestaShop#5479 from mickaelandrieu/boom-371-2-imp…
Browse files Browse the repository at this point in the history
…rovements

[-] BO : added missing delete confirmation poppin on product page form
  • Loading branch information
Maxime Biloé committed Apr 26, 2016
2 parents 3f8644a + 52e4d32 commit 6bad532
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 56 deletions.
61 changes: 61 additions & 0 deletions admin-dev/themes/default/js/bundle/modal-confirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* modal confirmation management
*/
var modalConfirmation = (function() {
var modal = $('#confirmation_modal');

if(!modal) {
throw new Error('Modal confirmation is not available');
}

var actionsCallbacks = {
onCancel: function() {
console.log('modal canceled');
return;
},
onContinue: function() {
console.log('modal continued');
return;
}
};

modal.find('button.cancel').click(function() {
if (typeof actionsCallbacks.onCancel === 'function') {
actionsCallbacks.onCancel();
}
modalConfirmation.hide();
});

modal.find('button.continue').click(function() {
if (typeof actionsCallbacks.onContinue === 'function') {
actionsCallbacks.onContinue();
}
modalConfirmation.hide();
});
return {
'init': function init() {
console.log('modal initialised');
},
'create': function create(content, title, callbacks) {
if(title != null){
modal.find('.modal-title').html(title);
}
if(content != null){
modal.find('.modal-body').html(content);
}

actionsCallbacks = callbacks;
return this;
},
'show': function show() {
modal.modal('show');
},
'hide': function hide() {
modal.modal('hide');
}
};
})();

BOEvent.on("Modal confirmation started", function initModalConfirmationSystem() {
modalConfirmation.init();
}, "Back office");
51 changes: 1 addition & 50 deletions admin-dev/themes/default/js/bundle/product/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $(document).ready(function() {
BOEvent.emitEvent("Product Default category Management started", "CustomEvent");
BOEvent.emitEvent("Product Manufacturer Management started", "CustomEvent");
BOEvent.emitEvent("Product Related Management started", "CustomEvent");
BOEvent.emitEvent("Modal confirmation started", "CustomEvent");

/** Type product fields display management */
$('#form_step1_type_product').change(function(){
Expand Down Expand Up @@ -1866,56 +1867,6 @@ var priceCalculation = (function() {
};
})();


/**
* modal confirmation management
*/
var modalConfirmation = (function() {
var modal = $('#confirmation_modal');
var actionsCallbacks = {
onCancel: function(){
return;
},
onContinue: function(){
return;
}
};

modal.find('button.cancel').click(function(){
if (typeof actionsCallbacks.onCancel === 'function') {
actionsCallbacks.onCancel();
}
modalConfirmation.hide();
});

modal.find('button.continue').click(function(){
if (typeof actionsCallbacks.onContinue === 'function') {
actionsCallbacks.onContinue();
}
modalConfirmation.hide();
});

return {
'create': function(content, title, callbacks) {
if(title != null){
modal.find('.modal-title').html(title);
}
if(content != null){
modal.find('.modal-body').html(content);
}

actionsCallbacks = callbacks;
return this;
},
'show': function() {
modal.modal('show');
},
'hide': function() {
modal.modal('hide');
}
};
})();

/**
* Manage seo
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ var manufacturer = (function() {
});
resetButton.on('click', function(e) {
e.preventDefault();
manufacturerContent.addClass('hide');
selectManufacturer.val('').trigger('change');
addButton.show();
modalConfirmation.create(translate_javascripts['Are you sure to delete this?'], null, {
onContinue: function(){
manufacturerContent.addClass('hide');
selectManufacturer.val('').trigger('change');
addButton.show();
}
}).show();
});
}
};
Expand Down
19 changes: 16 additions & 3 deletions admin-dev/themes/default/js/bundle/product/product-related.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@ var relatedProduct = (function() {
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();
productItems.remove();
relatedContent.addClass('hide');
addButton.show();
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();
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,12 +1086,14 @@
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('themes/default/js/bundle/product/form.js') }}"></script>

<script src="{{ asset('themes/default/js/bundle/product/product-manufacturer.js') }}"></script>
<script src="{{ asset('themes/default/js/bundle/product/product-related.js') }}"></script>
<script src="{{ asset('themes/default/js/bundle/product/product-category-tags.js') }}"></script>
<script src="{{ asset('themes/default/js/bundle/product/default-category.js') }}"></script>
<script src="{{ asset('themes/default/js/bundle/category-tree.js') }}"></script>
<script src="{{ asset('themes/default/js/bundle/module/module_card.js') }}"></script>
<script src="{{ asset('themes/default/js/bundle/modal-confirmation.js') }}"></script>
<script src="{{ asset('../js/tiny_mce/tiny_mce.js') }}"></script>
<script src="{{ asset('../js/admin/tinymce.inc.js') }}"></script>
<script src="{{ asset('../js/admin/tinymce_loader.js') }}"></script>
Expand Down

0 comments on commit 6bad532

Please sign in to comment.