UNPKG

@salla.sa/twilight-components

Version:
5 lines 10.5 kB
var __awaiter=this&&this.__awaiter||function(t,r,e,s){function n(t){return t instanceof e?t:new e((function(r){r(t)}))}return new(e||(e=Promise))((function(e,o){function a(t){try{l(s.next(t))}catch(t){o(t)}}function i(t){try{l(s["throw"](t))}catch(t){o(t)}}function l(t){t.done?e(t.value):n(t.value).then(a,i)}l((s=s.apply(t,r||[])).next())}))};var __generator=this&&this.__generator||function(t,r){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},s,n,o,a;return a={next:i(0),throw:i(1),return:i(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function i(t){return function(r){return l([t,r])}}function l(i){if(s)throw new TypeError("Generator is already executing.");while(a&&(a=0,i[0]&&(e=0)),e)try{if(s=1,n&&(o=i[0]&2?n["return"]:i[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;if(n=0,o)i=[i[0]&2,o.value];switch(i[0]){case 0:case 1:o=i;break;case 4:e.label++;return{value:i[1],done:false};case 5:e.label++;n=i[1];i=[0];continue;case 7:i=e.ops.pop();e.trys.pop();continue;default:if(!(o=e.trys,o=o.length>0&&o[o.length-1])&&(i[0]===6||i[0]===2)){e=0;continue}if(i[0]===3&&(!o||i[1]>o[0]&&i[1]<o[3])){e.label=i[1];break}if(i[0]===6&&e.label<o[1]){e.label=o[1];o=i;break}if(o&&e.label<o[2]){e.label=o[2];e.ops.push(i);break}if(o[2])e.ops.pop();e.trys.pop();continue}i=r.call(t,e)}catch(t){i=[6,t];n=0}finally{s=o=0}if(i[0]&5)throw i[1];return{value:i[0]?i[1]:void 0,done:true}}}; /*! * Crafted with ❤ by Salla */import{r as registerInstance,h,g as getElement}from"./index-BrMYHkA5.js";import{H as Helper}from"./Helper-BrCHOtZG.js";import"./anime.es-CgtvEd63.js";var sallaOrdersCss=":host{display:block}";var SallaOrder=function(){function t(t){var r=this;registerInstance(this,t);this.orderNumberText=salla.lang.get("pages.thank_you.order_id");this.totalOrderText=salla.lang.get("pages.orders.total");this.orderDateText=salla.lang.get("pages.orders.date");this.orderStatusText=salla.lang.get("pages.orders.status");this.noOrderText=salla.lang.get("pages.orders.non_orders");this.load_more_text_trans=salla.lang.get("common.elements.load_more");this.languageCode=salla.lang.locale;this.orders=[];salla.lang.onLoaded((function(){r.languageCode=salla.lang.locale;r.orderNumberText=salla.lang.get("pages.thank_you.order_id");r.totalOrderText=salla.lang.get("pages.orders.total");r.orderDateText=salla.lang.get("pages.orders.date");r.orderStatusText=salla.lang.get("pages.orders.status");r.noOrderText=salla.lang.get("pages.orders.non_orders");r.load_more_text_trans=salla.lang.get("common.elements.load_more")}))}t.prototype.loading=function(t){if(t===void 0){t=true}var r;var e=(r=this.status)===null||r===void 0?void 0:r.querySelector(".s-button-text");if(e){Helper.toggleElementClassIf(e,"s-button-hide","s-button-show",(function(){return t}));this.btnLoader.style.display=t?"inherit":"none"}};t.prototype.initiateInfiniteScroll=function(){var t=this;var r,e,s;if(!this.hasInfiniteScroll){return}if(!this.wrapper){salla.logger.error("Wrapper is undefined. Cannot initiate infinite scroll.");return}this.infiniteScroll=salla.infiniteScroll.initiate(this.wrapper,this.wrapper,{path:function(){return t.nextPage},history:false,nextPage:this.nextPage,scrollThreshold:false},true);(r=this.infiniteScroll)===null||r===void 0?void 0:r.on("request",(function(r){t.loading()}));(e=this.infiniteScroll)===null||e===void 0?void 0:e.on("load",(function(r){var e,s;t.loading(false);t.pagination=r.pagination;t.nextPage=((s=(e=r.pagination)===null||e===void 0?void 0:e.links)===null||s===void 0?void 0:s.next)||null;t.handleResponse(r.data).forEach((function(r){t.wrapper.append(r)}));var n=t.host.querySelectorAll(".s-orders-table-tbody-tr:not(.animated)");Helper.animateItems(n)}));(s=this.infiniteScroll)===null||s===void 0?void 0:s.on("error",(function(t){salla.logger.error("Error loading more comments:",t)}))};t.prototype.loadMore=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.infiniteScroll.loadNextPage();return[2]}))}))};t.prototype.handleResponse=function(t){var r=this;return t.map((function(t){return r.getSingleOrderItem(t)}))};t.prototype.loadInitialData=function(){return __awaiter(this,void 0,void 0,(function(){var t;var r=this;return __generator(this,(function(e){switch(e.label){case 0:t=new URL(window.location.href);return[4,salla.order.api.fetch(Object.assign(Object.assign({},this.params),{types:[""],feedback_status:t.searchParams.get("feedback_status")})).then((function(t){var e,s,n,o;r.orders=t.data;r.hasInfiniteScroll=!!((e=t.pagination)===null||e===void 0?void 0:e.links.next);r.pagination=t.pagination;r.total=(s=t.pagination)===null||s===void 0?void 0:s.total;r.nextPage=((o=(n=t.pagination)===null||n===void 0?void 0:n.links)===null||o===void 0?void 0:o.next)||null;if(!r.orders.length){r.showPlaceholder=true;return r.loading(false)}setTimeout((function(){r.handleResponse(t.data).forEach((function(t){r.wrapper.append(t)}));r.initiateInfiniteScroll();var e=r.wrapper.querySelectorAll(".s-orders-table-tbody-tr:not(.animated)");Helper.animateItems(e)}),100)})).catch((function(t){r.showPlaceholder=true;r.loading(false);salla.logger.error(t)}))];case 1:e.sent();return[2]}}))}))};t.prototype.getSingleOrderItem=function(t){var r=document.createElement("tr");r.classList.add("s-orders-table-tbody-tr","s-orders-table-tbody-tr-shadow");var e=document.createElement("td");e.classList.add("s-orders-table-tbody-tr-td");var s=document.createElement("div");s.classList.add("s-orders-table-tbody-tr-td-content");var n=document.createElement("span");n.classList.add("s-orders-mobile-title");n.textContent=this.orderNumberText+":";var o=document.createElement("span");o.classList.add("s-orders-reference-id");o.textContent="#"+t.reference_id;s.appendChild(n);s.appendChild(o);if(t.source=="buy_as_gift"){var a=document.createElement("i");a.classList.add("sicon-gift-sharing","s-orders-buy-as-gift-icon");s.appendChild(a)}var i=document.createElement("a");i.href=t.url;s.appendChild(i);var l=document.createElement("div");l.classList.add("s-orders-copy-to-clipboard-button");var d=document.createElement("salla-button");d.classList.add("relative");d.setAttribute("color","dark");d.setAttribute("shape","link");d.dataset.content=t.reference_id.toString();d.addEventListener("click",(function(t){Helper.copyToClipboard(t);Helper.toggleElementClassIf(d,"copied","code-to-copy",(function(){return true}));setTimeout((function(){Helper.toggleElementClassIf(d,"code-to-copy","copied",(function(){return true}))}),1e3)}));var u=document.createElement("span");u.textContent="#"+t.reference_id;var c=document.createElement("i");c.classList.add("sicon-swap-stroke","s-orders-copy-to-clipboard-button-icon");var h=salla.config.get("theme.is_rtl",true);if(h){d.appendChild(c);d.appendChild(u)}else{d.appendChild(u);d.appendChild(c)}l.appendChild(d);s.appendChild(l);e.appendChild(s);r.appendChild(e);var f=document.createElement("td");f.classList.add("s-orders-table-tbody-tr-td");var v=document.createElement("div");v.classList.add("s-orders-table-tbody-tr-td-content");var b=document.createElement("span");b.classList.add("s-orders-mobile-title");b.textContent=this.totalOrderText+":";var p=document.createElement("div");p.innerHTML=salla.money(t.total);var m=document.createElement("a");m.href=t.url;v.appendChild(b);v.appendChild(p);v.appendChild(m);f.appendChild(v);r.appendChild(f);var y=document.createElement("td");y.classList.add("s-orders-table-tbody-tr-td");var g=document.createElement("div");g.classList.add("s-orders-table-tbody-tr-td-content");var _=document.createElement("span");_.classList.add("s-orders-mobile-title");_.textContent=this.orderDateText+":";var w=document.createElement("div");w.textContent=Helper.formatDateFromString(t.created_at.date,salla.helpers.number,this.languageCode);var k=document.createElement("a");k.href=t.url;g.appendChild(_);g.appendChild(w);g.appendChild(k);y.appendChild(g);r.appendChild(y);var H=document.createElement("td");H.classList.add("s-orders-table-tbody-tr-td");var x=document.createElement("div");x.classList.add("s-orders-table-tbody-tr-td-content");var O=document.createElement("span");O.classList.add("s-orders-mobile-title");O.textContent=this.orderStatusText+":";var j=document.createElement("span");j.classList.add("s-orders-status-container");j.style.color=t.status.color;var C=document.createElement("i");C.classList.add(t.status.icon);var E=document.createElement("span");E.textContent=t.status.name;j.appendChild(C);j.appendChild(E);x.appendChild(O);x.appendChild(j);var S=document.createElement("i");S.classList.add("sicon-star2","s-orders-status-rated",t.is_rated?"s-orders-rated-text":"s-orders-unrated-text");x.appendChild(S);var T=document.createElement("a");T.href=t.url;x.appendChild(T);H.appendChild(x);r.appendChild(H);return r};t.prototype.render=function(){var t=this;var r;if(this.showPlaceholder){return h("div",{class:"s-orders-no-content"},h("i",{class:"sicon-packed-box icon"}),h("p",null,this.noOrderText))}return h("div",{class:"s-orders-wrapper"},h("table",{class:"s-orders-table"},h("thead",{class:"s-orders-table-head"},h("tr",{class:"s-orders-table-head-tr"},h("th",{class:"s-orders-table-head-tr-th",scope:"col"},this.orderNumberText),h("th",{class:"s-orders-table-head-tr-th",scope:"col"},this.totalOrderText),h("th",{class:"s-orders-table-head-tr-th",scope:"col"},this.orderDateText),h("th",{class:"s-orders-table-head-tr-th",scope:"col"},this.orderStatusText))),h("tbody",{class:"s-orders-table-tbody",ref:function(r){return t.wrapper=r}})),this.nextPage&&h("div",{class:"s-infinite-scroll-wrapper",ref:function(r){return t.status=r}},h("button",{onClick:function(){return t.loadMore()},class:"s-infinite-scroll-btn s-button-btn s-button-primary"},h("span",{class:"s-button-text s-infinite-scroll-btn-text"},(r=this.loadMoreText)!==null&&r!==void 0?r:this.load_more_text_trans),h("span",{class:"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader",ref:function(r){return t.btnLoader=r},style:{display:"none"}}))))};t.prototype.componentWillLoad=function(){var t=this;return salla.onReady().then((function(){return t.loadInitialData()})).then((function(){return t.initiateInfiniteScroll()}))};Object.defineProperty(t.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return t}();SallaOrder.style=sallaOrdersCss;export{SallaOrder as salla_orders}; //# sourceMappingURL=salla-orders.entry.js.map