/** * 2007-2018 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 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/afl-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 * @copyright 2007-2018 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ $(document).ready(function() { /*** STAY IN THE SELECTED TAB ***/ $("ul.nav-tabs > li > a").on("shown.bs.tab", function(e) { localStorage.setItem('activeTab', $(e.target).attr('href')); }); var activeTab = localStorage.getItem('activeTab'); if (activeTab) { $('#manage_tab a[href="' + activeTab + '"]').tab('show'); } /** Select all checkbox **/ $(".checkAll").change(function () { var status = this.checked; id_element = $(this).attr('value'); type = $(this).attr('name'); var getDataTable = ''; if(type != undefined) { switch(type) { case 'category_box' : getDataTable = $('#id_sitemap').DataTable(); break; case 'product_box' : getDataTable = $('#id_sitemap_product').DataTable(); break; case 'cms_box' : getDataTable = $('#id_sitemap_cms').DataTable(); break; case 'other_page_box' : getDataTable = $('#other_pages').DataTable(); break; } } var all_pages = getDataTable.cells().nodes(); if ($(this).hasClass('.ajaxupdate.'+type)) { $(all_pages).find('input[type="checkbox"]').prop('checked', false); } else { $(all_pages).find('input[type="checkbox"]').prop('checked', true); } $(this).toggleClass('allChecked'); var rowcollection = getDataTable.$('.ajaxupdate.'+type+':checked', {'page':'all'}); rowcollection.each(function(index,elem){ var checkbox_value = $(elem).val(); this.checked = status; status = (status == true) ? 1 : false; $.ajax({ type: 'POST', url: admin_module_ajax_url, dataType: 'html', data: { controller : admin_module_controller, action : 'UpdateExportElement', ajax : true, id_element: checkbox_value, type: type, active: status, }, // success: function(res){ // if (res == true) // $.growl.notice({ message: "Element updated" }) // else // $.growl.error({message: "Element not updated"}); // } }); }); $.growl.notice({ message: "Element updated" }); }); $(document).on('click', '.switch', function (e) { var toggleOption = $(this).children(':first').attr('name'); var isChecked = $("input[name='"+toggleOption+"']:checked").val(); if (isChecked == 1) { $('.'+ toggleOption).removeClass('hide'); switch (toggleOption) { case 'categoty_sitemap' : $('.'+ 'category_conf').addClass('hide'); break; case 'product_sitemap' : $('.'+ 'product_conf').addClass('hide'); break; case 'cms_sitemap' : $('.'+ 'cms_conf').addClass('hide'); break; case 'other_sitemap' : $('.'+ 'other_conf').addClass('hide'); break; case 'html_sitemap' : $('.'+ 'html_conf').addClass('hide'); } } else { $('.'+ toggleOption).addClass('hide'); switch (toggleOption) { case 'categoty_sitemap' : $('.'+ 'category_conf').removeClass('hide'); break; case 'product_sitemap' : $('.'+ 'product_conf').removeClass('hide'); break; case 'cms_sitemap' : $('.'+ 'cms_conf').removeClass('hide'); break; case 'other_sitemap' : $('.'+ 'other_conf').removeClass('hide'); break; case 'html_sitemap' : $('.'+ 'html_conf').removeClass('hide'); } } }); /** Update one element **/ $('.ajaxupdate').live('click', function(){ id_element = $(this).attr('value'); type = $(this).attr('name'); active = $(this).is(':checked'); active = (active == true) ? 1 : false; $.ajax({ type: 'POST', url: admin_module_ajax_url, dataType: 'html', data: { controller : admin_module_controller, action : 'UpdateExportElement', ajax : true, id_element: id_element, type: type, active: active, }, success: function(res){ if (res == true) $.growl.notice({ message: "Element updated" }) else $.growl.error({message: "Element not updated"});; } }); }); $('#id_sitemap').DataTable({ "oLanguage": { "sSearch": psSearch, "sInfo": psInfo, "sInfoFiltered": psInfoFiltered, "sEmptyTable": psEmptyTable, "sLoadingRecords": psLoadingRecords, "sProcessing": psProcessing, "sLengthMenu": psLengthMenu, "oPaginate": { "sNext": psNext, "sPrevious": psPrevious } } }); $('#id_sitemap_product').DataTable({ "oLanguage": { "sSearch": psSearch, "sInfo": psInfo, "sInfoFiltered": psInfoFiltered, "sEmptyTable": psEmptyTable, "sLoadingRecords": psLoadingRecords, "sProcessing": psProcessing, "sLengthMenu": psLengthMenu, "oPaginate": { "sNext": psNext, "sPrevious": psPrevious } } }); $('#id_sitemap_cms').DataTable({ "oLanguage": { "sSearch": psSearch, "sInfo": psInfo, "sInfoFiltered": psInfoFiltered, "sEmptyTable": psEmptyTable, "sLoadingRecords": psLoadingRecords, "sProcessing": psProcessing, "sLengthMenu": psLengthMenu, "oPaginate": { "sNext": psNext, "sPrevious": psPrevious } } }); $('#other_pages').DataTable({ "oLanguage": { "sSearch": psSearch, "sInfo": psInfo, "sInfoFiltered": psInfoFiltered, "sEmptyTable": psEmptyTable, "sLoadingRecords": psLoadingRecords, "sProcessing": psProcessing, "sLengthMenu": psLengthMenu, "oPaginate": { "sNext": psNext, "sPrevious": psPrevious } } }); });