mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-03 19:53:19 +03:00
42 lines
7.8 KiB
JavaScript
42 lines
7.8 KiB
JavaScript
/**
|
|
* 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 <mail@simlachat.com>
|
|
* @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<t.orders.length?e.loadOrders(t.orders):e.showMessage("orders-table.empty"),void 0!==t.pagination&&e.loadPagination(t.pagination),void e.setLoading(!1))}).fail(function(t){e.setLoading(!1),e.showMessage("orders-table.error"),console.warn(t)})},t.prototype.loadOrders=function(t){$(this.ordersTableBody).empty(),$(this.ordersTable).removeClass("hidden");let e=this,s=$(this.rowSample).find("td.retail-orders-table__id-crm a").attr("href"),d=$(this.rowSample).find("td.retail-orders-table__id-cms a").attr("href");$.each(t,function(t,r){var i=e.rowSample.clone().get(0);if($(i).find("td.retail-orders-table__date").text(r.last_uploaded),$(i).find("td.retail-orders-table__id-cms a").text(r.id_order).attr("href",d+"&vieworder=&id_order="+r.id_order),null===r.id_order_crm?$(i).find("td.retail-orders-table__id-crm").empty():$(i).find("td.retail-orders-table__id-crm a").text(r.id_order_crm).attr("href",s+r.id_order_crm+"/edit"),null!==r.errors){let e=$(i).find("td.retail-orders-table__status");e.addClass("error");try{var a,o=JSON.parse(r.errors);for(a in e.find(".retail-orders-table__error").append("<ul>"),o)e.find(".retail-orders-table__error").append("<li>"+o[a]+"</li>");e.find(".retail-orders-table__error").append("</ul>")}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<e.totalPageCount&&(a=e.currentPage-Math.floor(5),0<a?t=!0:a=1,o=e.currentPage+Math.floor(5),o<e.totalPageCount?i=!0:o=e.totalPageCount),t&&$(this.pagesMenu).append($("<button/>",{class:"retail-table-pagination__item",text:1}).click(function(t){t.preventDefault(),r.searchOrders(1)})).append($("<span/>",{class:"retail-table-pagination__item retail-table-pagination__item--divider",text:"..."}));for(let e=a;e<=o;e++)$(this.pagesMenu).append($("<button/>",{class:"retail-table-pagination__item "+(e===this.page?" active":""),text:e}).click(function(t){t.preventDefault(),r.searchOrders(e)}));i&&$(this.pagesMenu).append($("<span/>",{class:"retail-table-pagination__item retail-table-pagination__item--divider",text:"..."})).append($("<button/>",{class:"retail-table-pagination__item",text:e.totalPageCount}).click(function(t){t.preventDefault(),r.searchOrders(e.totalPageCount)}))},t.prototype.showMessage=function(t){$(this.ordersTableBody).empty().append('<tr class="alert"><td colspan="5">'+retailcrmTranslates[t]+"</td></tr>"),$(this.ordersTable).removeClass("hidden")},t.prototype.setLoading=function(t){var e="retailcrm-loading-fade",r=$("#"+e);0===r.length&&($("body").append(`
|
|
<div id="${e}">
|
|
<div id="retailcrm-loader"></div>
|
|
</div>
|
|
`.trim()),r=$("#"+e)),r.css("visibility",t?"visible":"hidden")},t.prototype.partitionId=function(t){if(""===t)return[];let e=t.split(",");t=e.filter(t=>-1===t.toString().indexOf("-"));let r=e.filter(t=>-1!==t.toString().indexOf("-")),i=[];return r.forEach(t=>{t=t.split("-");i=[...i,...[...Array(+t[1]+1).keys()].slice(+t[0],+t[1]+1)]}),[...t,...i].map(t=>+t).sort((t,e)=>t-e)},window.RetailcrmOrdersForm=t});
|
|
//# sourceMappingURL=retailcrm-orders.min.js.map
|