/** * MIT License * * Copyright (c) 2021 DIGITAL RETAIL TECHNOLOGIES SL * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * 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 DIGITAL RETAIL TECHNOLOGIES SL * @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ $(function(){function t(){if(this.form=$("#retail-search-orders-form").get(0),void 0===this.form)return!1;this.isInitiated=!1,this.initButton=$("#retail-uploaded-orders-tab .retail-row__title").get(0),this.initAction=this.initAction.bind(this),this.submitButton=$(this.form).find('button[id="search-orders-submit"]').get(0),this.submitAction=this.submitAction.bind(this),this.ordersTable=$("#retail-orders-table").get(0),this.ordersTableBody=$(this.ordersTable).find("tbody").get(0),this.rowSample=$(this.ordersTableBody).find("tr").clone(),this.loadOrders=this.loadOrders.bind(this),this.searchOrders=this.searchOrders.bind(this),this.pagesMenu=$(".retail-table-pagination").get(0),this.loadPagination=this.loadPagination.bind(this),this.uploadLink=$("#retail-controller-orders-upload").attr("href"),$("#retail-controller-orders-upload").remove(),this.uploadOrder=this.uploadOrder.bind(this),this.partitionId=this.partitionId.bind(this),this.setLoading=this.setLoading.bind(this),this.showMessage=this.showMessage.bind(this),this.orders=[],this.filter=null,this.page=null,$(this.submitButton).click(this.submitAction),$(this.initButton).click(this.initAction)}t.prototype.initAction=function(t){t.preventDefault(),this.isInitiated||($(this.ordersTableBody).empty(),$(this.pagesMenu).empty(),$(".retail-table-filter-btn").click(function(t){$(".retail-table-filter-btn").removeClass("active"),$(this).addClass("active")}),this.searchOrders(),this.isInitiated=!0)},t.prototype.submitAction=function(t){t.preventDefault();t=$(this.form).serializeArray().reduce(function(t,e){return t[e.name]=e.value,t},{});let e=t["search-orders-value"];this.orders=this.partitionId(e.toString().replace(/\s+/g,"")),this.filter=t["search-orders-filter"],this.searchOrders()},t.prototype.searchOrders=function(t=1){this.setLoading(!0);let e=this;t={orders:this.orders,filter:this.filter,page:t};$.ajax({url:this.form.action,method:this.form.method,dataType:"json",timeout:0,data:t}).done(function(t){return void 0!==t.success&&!1===t.success?(e.setLoading(!1),e.showMessage("orders-table.error"),void console.warn(t)):(void 0!==t.orders&&0"),o)e.find(".retail-orders-table__error").append("
  • "+o[a]+"
  • ");e.find(".retail-orders-table__error").append("")}catch(t){console.log(t),e.find(".retail-orders-table__error").append(r.errors)}e.find(".retail-collapsible__input").attr("id","errors_"+r.id_order),e.find(".retail-collapsible__title").attr("for","errors_"+r.id_order)}$(i).find("td.retail-orders-table__upload").click(function(t){t.preventDefault(),e.uploadOrder(r.id_order)}),$(e.ordersTableBody).append(i)})},t.prototype.uploadOrder=function(t){this.setLoading(!0);let r=this;$.ajax({url:this.uploadLink,method:"POST",dataType:"json",timeout:0,data:{orders:[t]}}).done(function(t){let e="";if(void 0!==t.success&&t.success)e="Order successfully uploaded";else{if(e="Error uploading order: ",void 0!==t.errorMsg&&(e+=t.errorMsg),void 0!==t.errors)for(orderErrors in t.errors)for(error in t.errors[orderErrors])e+=" "+t.errors[orderErrors][error]+" ";if(void 0!==t.skippedOrders)for(skippedOrder in t.skippedOrders)e+="Order "+skippedOrder+" already exists"}r.setLoading(!1),alert(e)}).fail(function(t){console.warn(t),r.setLoading(!1),alert(retailcrmTranslates["orders-table.error"])})},t.prototype.loadPagination=function(e){$(this.pagesMenu).empty();let r=this;this.page=e.currentPage;let t=!1,i=!1;let a=1,o=e.totalPageCount;10",{class:"retail-table-pagination__item",text:1}).click(function(t){t.preventDefault(),r.searchOrders(1)})).append($("",{class:"retail-table-pagination__item retail-table-pagination__item--divider",text:"..."}));for(let e=a;e<=o;e++)$(this.pagesMenu).append($("