@salla.sa/twilight-components 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Helper-8c75b6ac.js +20 -0
- package/dist/cjs/index-23da2c6b.js +1601 -0
- package/dist/cjs/index.cjs.js +12 -0
- package/dist/cjs/loader.cjs.js +21 -0
- package/dist/cjs/multi-warehouse_3.cjs.entry.js +155 -0
- package/dist/cjs/order-rating.cjs.entry.js +227 -0
- package/dist/cjs/salla-button.cjs.entry.js +56 -0
- package/dist/cjs/salla-localization.cjs.entry.js +49 -0
- package/dist/cjs/salla-login-476fb312.js +14 -0
- package/dist/{twilight-components/search-modal-c1babeb6.js → cjs/salla-search-b9403062.js} +13 -11
- package/dist/cjs/salla-search.cjs.entry.js +10 -0
- package/dist/cjs/twilight-components.cjs.js +19 -0
- package/dist/collection/Helpers/Helper.js +16 -0
- package/dist/collection/collection-manifest.json +18 -0
- package/dist/collection/components/generate-summary.js +35 -0
- package/dist/collection/components/multi-warehouse/multi-warehouse.js +239 -0
- package/dist/collection/components/order-rating/order-rating.css +3 -0
- package/dist/collection/components/order-rating/order-rating.js +288 -0
- package/dist/collection/components/salla-button/salla-button.css +3 -0
- package/dist/collection/components/salla-button/salla-button.js +167 -0
- package/dist/collection/components/salla-localization/salla-localization.js +106 -0
- package/dist/collection/components/salla-login/salla-login.js +31 -0
- package/dist/collection/components/salla-modal/salla-modal.js +281 -0
- package/dist/collection/components/salla-search/salla-search.js +154 -0
- package/dist/collection/index.js +2 -0
- package/dist/{types/components/salla-modal/test/salla-modal.e2e.d.ts → collection/interfaces/colors.js} +0 -0
- package/dist/collection/interfaces/index.js +2 -0
- package/dist/{types/components/salla-modal/test/salla-modal.spec.d.ts → collection/interfaces/ratio.js} +0 -0
- package/dist/collection/plugins/tailwind-theme/generator.js +53 -0
- package/dist/collection/plugins/tailwind-theme/index.js +26 -0
- package/dist/esm/Helper-23b2de40.js +18 -0
- package/dist/esm/index-643344dc.js +1573 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/loader.js +17 -0
- package/dist/esm/multi-warehouse_3.entry.js +149 -0
- package/dist/esm/order-rating.entry.js +223 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/esm/salla-button.entry.js +52 -0
- package/dist/esm/salla-localization.entry.js +45 -0
- package/dist/{twilight-components/salla-login-0e725af9.js → esm/salla-login-0e85b2d8.js} +1 -1
- package/dist/{twilight-components/search-modal-ee69bd04.js → esm/salla-search-5d4a6f1a.js} +9 -9
- package/dist/esm/salla-search.entry.js +2 -0
- package/dist/esm/twilight-components.js +17 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/twilight-components/index.esm.js +1 -3
- package/dist/twilight-components/p-36c87e2e.js +1 -0
- package/dist/twilight-components/p-4b137380.js +1 -0
- package/dist/twilight-components/p-4cc11ee2.entry.js +1 -0
- package/dist/twilight-components/p-520446eb.js +1 -0
- package/dist/twilight-components/p-60f0446f.entry.js +1 -0
- package/dist/twilight-components/p-b490f9e0.entry.js +1 -0
- package/dist/twilight-components/p-b72e6cfa.entry.js +1 -0
- package/dist/twilight-components/p-baeca520.entry.js +1 -0
- package/dist/twilight-components/p-d1ef2268.js +1 -0
- package/dist/twilight-components/twilight-components.esm.js +1 -125
- package/dist/types/Helpers/Helper.d.ts +8 -0
- package/dist/types/components/multi-warehouse/multi-warehouse.d.ts +23 -0
- package/dist/types/components/order-rating/order-rating.d.ts +16 -0
- package/dist/types/components/salla-button/salla-button.d.ts +15 -0
- package/dist/types/components/salla-localization/salla-localization.d.ts +10 -0
- package/dist/types/components/salla-modal/salla-modal.d.ts +12 -1
- package/dist/types/components/{search-modal/search-modal.d.ts → salla-search/salla-search.d.ts} +1 -1
- package/dist/types/components.d.ts +95 -11
- package/dist/types/index.d.ts +1 -1
- package/package.json +10 -6
- package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
- package/dist/twilight-components/css-shim-a64b8820.js +0 -4
- package/dist/twilight-components/dom-d08ba8aa.js +0 -73
- package/dist/twilight-components/index-0aa9ca9b.js +0 -3010
- package/dist/twilight-components/index-d2312a61.js +0 -3010
- package/dist/twilight-components/index-d6ed984a.js +0 -3010
- package/dist/twilight-components/salla-login-2a48c6c7.js +0 -29
- package/dist/twilight-components/salla-login-2bfbce21.js +0 -16
- package/dist/twilight-components/salla-login-45a3f61c.js +0 -16
- package/dist/twilight-components/salla-login-5fe80dd7.js +0 -29
- package/dist/twilight-components/salla-login-69a00ca2.js +0 -12
- package/dist/twilight-components/salla-login-7bf31d85.js +0 -29
- package/dist/twilight-components/salla-login-cb872dc2.js +0 -16
- package/dist/twilight-components/salla-login.entry.js +0 -2
- package/dist/twilight-components/salla-modal.entry.js +0 -24
- package/dist/twilight-components/salla-search-modal.entry.js +0 -2
- package/dist/twilight-components/search-modal-5dc35a08.js +0 -94
- package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
- package/dist/types/utils/utils.d.ts +0 -6
- package/dist/types/utils/utils.spec.d.ts +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Helper extends salla.AppHelpers {
|
|
2
|
+
setHost(host) {
|
|
3
|
+
this.host = host;
|
|
4
|
+
}
|
|
5
|
+
getElement(selector) {
|
|
6
|
+
return this.host.querySelector(selector);
|
|
7
|
+
}
|
|
8
|
+
getAttribute(selector, attribute) {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = this.getElement(selector)) === null || _a === void 0 ? void 0 : _a.getAttribute(attribute);
|
|
11
|
+
}
|
|
12
|
+
val(selector) {
|
|
13
|
+
return this.getAttribute(selector, 'value');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default new Helper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"entries": [
|
|
3
|
+
"./components/salla-login/salla-login.js",
|
|
4
|
+
"./components/salla-search/salla-search.js",
|
|
5
|
+
"./components/multi-warehouse/multi-warehouse.js",
|
|
6
|
+
"./components/order-rating/order-rating.js",
|
|
7
|
+
"./components/salla-button/salla-button.js",
|
|
8
|
+
"./components/salla-localization/salla-localization.js",
|
|
9
|
+
"./components/salla-modal/salla-modal.js"
|
|
10
|
+
],
|
|
11
|
+
"compiler": {
|
|
12
|
+
"name": "@stencil/core",
|
|
13
|
+
"version": "2.8.1",
|
|
14
|
+
"typescriptVersion": "4.2.3"
|
|
15
|
+
},
|
|
16
|
+
"collections": [],
|
|
17
|
+
"bundles": []
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var fs = require('fs'), path = require('path'), util = require('util');
|
|
2
|
+
|
|
3
|
+
var dirToJSON = function (dir, done) {
|
|
4
|
+
var results = [];
|
|
5
|
+
|
|
6
|
+
function recWalk(d, res) {
|
|
7
|
+
var list = fs.readdirSync(d);
|
|
8
|
+
list.forEach((name) => {
|
|
9
|
+
var file = path.resolve(d, name);
|
|
10
|
+
var stat = fs.statSync(file);
|
|
11
|
+
if (stat && stat.isDirectory()) {
|
|
12
|
+
var title;
|
|
13
|
+
if (name) {
|
|
14
|
+
title = 'salla-' + name
|
|
15
|
+
}
|
|
16
|
+
res.push({ title: title, file: name + '/readme.md' });
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
recWalk(dir, results);
|
|
23
|
+
done(null, results);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
done(err);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
dirToJSON("src/components", function (err, results) {
|
|
30
|
+
if (err) console.log(err);
|
|
31
|
+
else fs.writeFile('src/components/summary.json', JSON.stringify(results), 'utf8', function (err) {
|
|
32
|
+
if (err) throw err;
|
|
33
|
+
console.log('Saved!');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { Component, h, Prop, Method, State, Element } from "@stencil/core";
|
|
2
|
+
// import Helper from "../../Helpers/Helper";
|
|
3
|
+
let engine = require('store/src/store-engine');
|
|
4
|
+
let storages = require('store/storages/sessionStorage');
|
|
5
|
+
let sessionStore = engine.createStore(storages);
|
|
6
|
+
export class MultiWarehouse {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.open = false;
|
|
9
|
+
this.isOpenedBefore = sessionStore.get("multi-warehouse-opened-before");
|
|
10
|
+
this.displayAs = 'default';
|
|
11
|
+
this.browseProductsFrom = 'all';
|
|
12
|
+
this.branches = [
|
|
13
|
+
{ id: 1, name: 'فرع الرياض', open: true, available: true, limited: false, tag: 'متوفر' },
|
|
14
|
+
{ id: 2, name: 'فرع جدة', open: false, available: false, limited: false, tag: 'غير متوفر' },
|
|
15
|
+
{ id: 3, name: 'فرع مكة', open: true, available: true, limited: false, tag: 'متوفر' },
|
|
16
|
+
{ id: 4, name: 'فرع المدينة', open: true, available: true, limited: false, tag: 'متوفر' },
|
|
17
|
+
{ id: 5, name: 'فرع جازان', open: true, available: true, limited: true, tag: 'الكمية محدودة' }
|
|
18
|
+
];
|
|
19
|
+
this.current = 1;
|
|
20
|
+
this.currentBranch = (prop) => {
|
|
21
|
+
return this.branches.filter((el) => el.id == this.current)[0][prop];
|
|
22
|
+
};
|
|
23
|
+
this.statusColor = (branch = null) => {
|
|
24
|
+
return branch ?
|
|
25
|
+
branch.limited ? 'text-red-400' : branch.available ? 'text-green-500' : 'text-gray-400'
|
|
26
|
+
:
|
|
27
|
+
this.currentBranch('limited') ? 'text-red-400' : this.currentBranch('available') ? 'text-green-500' : 'text-gray-400';
|
|
28
|
+
};
|
|
29
|
+
this.isChoiceable = () => {
|
|
30
|
+
return (this.browseProductsFrom !== 'all' && this.position == 'single') || this.position == 'header';
|
|
31
|
+
};
|
|
32
|
+
this.formTitle = () => {
|
|
33
|
+
return this.isChoiceable() ?
|
|
34
|
+
'توفر المنتج في الفروع الآخرى'
|
|
35
|
+
: 'التسوق من فرع آخر';
|
|
36
|
+
};
|
|
37
|
+
salla.event.on('branches::show', () => this.show());
|
|
38
|
+
}
|
|
39
|
+
async show() {
|
|
40
|
+
return this.modal.show();
|
|
41
|
+
}
|
|
42
|
+
async hide() {
|
|
43
|
+
return this.modal.hide();
|
|
44
|
+
}
|
|
45
|
+
handelChange(event) {
|
|
46
|
+
this.selected = event.target.value;
|
|
47
|
+
}
|
|
48
|
+
handleSubmit() {
|
|
49
|
+
sessionStore.set("multi-warehouse-opened-before", true);
|
|
50
|
+
this.show();
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
this.current = this.selected;
|
|
53
|
+
}, 300);
|
|
54
|
+
}
|
|
55
|
+
render() {
|
|
56
|
+
return (h("salla-modal", { "is-closable": !this.isOpenedBefore && this.displayAs == 'popup' ? 'false' : 'true', ref: modal => this.modal = modal, "modal-width": "w-116", id: "multi-warehouse-modal", class: "hidden" },
|
|
57
|
+
h("slot", { name: "header" },
|
|
58
|
+
h("div", { slot: "header" })),
|
|
59
|
+
h("div", null,
|
|
60
|
+
h("div", { class: "text-right" },
|
|
61
|
+
h("div", { class: "flex items-center mb-8" },
|
|
62
|
+
h("div", { class: "flex-shrink-0 sm:mb-0 me-4" },
|
|
63
|
+
h("div", { class: "h-16 w-16 border border-gray-200 bg-white text-primary rounded-full flex justify-center items-center" },
|
|
64
|
+
h("span", { class: "sicon-store-alt" }))),
|
|
65
|
+
h("div", null,
|
|
66
|
+
h("p", { class: "mt-1 text-xs text-gray-400" }, "\u0623\u0646\u062A \u0627\u0644\u0622\u0646 \u062A\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u062A\u062C\u0631 \u0645\u0646"),
|
|
67
|
+
h("h4", { class: "text-base" }, "\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636"))),
|
|
68
|
+
h("fieldset", { class: "mt-4" },
|
|
69
|
+
h("h4", { class: "text-sm text-gray-600 mb-6" }, this.formTitle()),
|
|
70
|
+
h("legend", { class: "sr-only" }, this.formTitle()),
|
|
71
|
+
this.branches.length <= 5 ?
|
|
72
|
+
h("div", { class: "space-y-5" }, this.branches.map((branch) => h("div", { class: "flex items-center" },
|
|
73
|
+
h("input", { id: this.position + '_branch_' + branch.id, disabled: !branch.open && this.isChoiceable(), name: "lang", type: "radio", value: branch.id, onChange: (event) => this.handelChange(event), class: {
|
|
74
|
+
'me-3 focus:ring-primary h-4 w-4 text-primary border-gray-300': true,
|
|
75
|
+
'opacity-50': !branch.open,
|
|
76
|
+
'hidden': !this.isChoiceable()
|
|
77
|
+
}, checked: this.current == branch.id }),
|
|
78
|
+
h("label", { htmlFor: this.position + '_branch_' + branch.id, class: {
|
|
79
|
+
'flex items-center justify-between text-sm font-medium text-gray-700 flex-grow': true,
|
|
80
|
+
'cursor-pointer': this.isChoiceable()
|
|
81
|
+
} },
|
|
82
|
+
h("span", { class: { 'opacity-50': !branch.open } }, branch.name),
|
|
83
|
+
this.isChoiceable() ?
|
|
84
|
+
h("small", { class: "text-red-400" }, branch.open ? '' : 'مُغلق')
|
|
85
|
+
:
|
|
86
|
+
h("span", { class: this.statusColor(branch) }, branch.tag)))))
|
|
87
|
+
:
|
|
88
|
+
h("select", { class: "w-full h-10 transition-colors duration-300 focus:ring-transparent focus:border-primary sm:text-sm border-gray-200 rounded-md appearance-none visibility_condition px-4", onInput: (event) => this.handelChange(event) }, this.branches.map(branch => (h("option", { value: branch.id, disabled: !branch.open, selected: this.selected == branch.id },
|
|
89
|
+
branch.name,
|
|
90
|
+
" ",
|
|
91
|
+
branch.open ? '' : '- مُغلق'))))))),
|
|
92
|
+
this.isChoiceable() ?
|
|
93
|
+
h("p", { slot: "footer" },
|
|
94
|
+
h("slot", { name: "footer" },
|
|
95
|
+
h("button", { type: "button", class: "mt-8 w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-primary text-base font-medium text-white transition-colors hover:bg-primary-d focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary sm:col-start-2 sm:text-sm", onClick: () => this.handleSubmit() }, salla.lang.get('common.elements.ok'))))
|
|
96
|
+
: ''));
|
|
97
|
+
}
|
|
98
|
+
componentDidRender() {
|
|
99
|
+
if (!this.isOpenedBefore && this.displayAs == 'popup') {
|
|
100
|
+
//this.show()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
static get is() { return "multi-warehouse"; }
|
|
104
|
+
static get properties() { return {
|
|
105
|
+
"position": {
|
|
106
|
+
"type": "string",
|
|
107
|
+
"mutable": false,
|
|
108
|
+
"complexType": {
|
|
109
|
+
"original": "string",
|
|
110
|
+
"resolved": "string",
|
|
111
|
+
"references": {}
|
|
112
|
+
},
|
|
113
|
+
"required": false,
|
|
114
|
+
"optional": false,
|
|
115
|
+
"docs": {
|
|
116
|
+
"tags": [],
|
|
117
|
+
"text": ""
|
|
118
|
+
},
|
|
119
|
+
"attribute": "position",
|
|
120
|
+
"reflect": false
|
|
121
|
+
},
|
|
122
|
+
"displayAs": {
|
|
123
|
+
"type": "string",
|
|
124
|
+
"mutable": false,
|
|
125
|
+
"complexType": {
|
|
126
|
+
"original": "string",
|
|
127
|
+
"resolved": "string",
|
|
128
|
+
"references": {}
|
|
129
|
+
},
|
|
130
|
+
"required": false,
|
|
131
|
+
"optional": false,
|
|
132
|
+
"docs": {
|
|
133
|
+
"tags": [],
|
|
134
|
+
"text": ""
|
|
135
|
+
},
|
|
136
|
+
"attribute": "display-as",
|
|
137
|
+
"reflect": false,
|
|
138
|
+
"defaultValue": "'default'"
|
|
139
|
+
},
|
|
140
|
+
"browseProductsFrom": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"mutable": false,
|
|
143
|
+
"complexType": {
|
|
144
|
+
"original": "string",
|
|
145
|
+
"resolved": "string",
|
|
146
|
+
"references": {}
|
|
147
|
+
},
|
|
148
|
+
"required": false,
|
|
149
|
+
"optional": false,
|
|
150
|
+
"docs": {
|
|
151
|
+
"tags": [],
|
|
152
|
+
"text": ""
|
|
153
|
+
},
|
|
154
|
+
"attribute": "browse-products-from",
|
|
155
|
+
"reflect": false,
|
|
156
|
+
"defaultValue": "'all'"
|
|
157
|
+
},
|
|
158
|
+
"branches": {
|
|
159
|
+
"type": "unknown",
|
|
160
|
+
"mutable": false,
|
|
161
|
+
"complexType": {
|
|
162
|
+
"original": "any[]",
|
|
163
|
+
"resolved": "any[]",
|
|
164
|
+
"references": {}
|
|
165
|
+
},
|
|
166
|
+
"required": false,
|
|
167
|
+
"optional": false,
|
|
168
|
+
"docs": {
|
|
169
|
+
"tags": [],
|
|
170
|
+
"text": ""
|
|
171
|
+
},
|
|
172
|
+
"defaultValue": "[\n {id: 1, name: '\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 2, name: '\u0641\u0631\u0639 \u062C\u062F\u0629', open: false, available: false, limited: false, tag: '\u063A\u064A\u0631 \u0645\u062A\u0648\u0641\u0631'},\n {id: 3, name: '\u0641\u0631\u0639 \u0645\u0643\u0629', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 4, name: '\u0641\u0631\u0639 \u0627\u0644\u0645\u062F\u064A\u0646\u0629', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 5, name: '\u0641\u0631\u0639 \u062C\u0627\u0632\u0627\u0646', open: true, available: true, limited: true, tag: '\u0627\u0644\u0643\u0645\u064A\u0629 \u0645\u062D\u062F\u0648\u062F\u0629'}\n ]"
|
|
173
|
+
},
|
|
174
|
+
"current": {
|
|
175
|
+
"type": "number",
|
|
176
|
+
"mutable": true,
|
|
177
|
+
"complexType": {
|
|
178
|
+
"original": "number",
|
|
179
|
+
"resolved": "number",
|
|
180
|
+
"references": {}
|
|
181
|
+
},
|
|
182
|
+
"required": false,
|
|
183
|
+
"optional": false,
|
|
184
|
+
"docs": {
|
|
185
|
+
"tags": [],
|
|
186
|
+
"text": ""
|
|
187
|
+
},
|
|
188
|
+
"attribute": "current",
|
|
189
|
+
"reflect": false,
|
|
190
|
+
"defaultValue": "1"
|
|
191
|
+
}
|
|
192
|
+
}; }
|
|
193
|
+
static get states() { return {
|
|
194
|
+
"open": {},
|
|
195
|
+
"selected": {},
|
|
196
|
+
"isOpenedBefore": {}
|
|
197
|
+
}; }
|
|
198
|
+
static get methods() { return {
|
|
199
|
+
"show": {
|
|
200
|
+
"complexType": {
|
|
201
|
+
"signature": "() => Promise<HTMLElement>",
|
|
202
|
+
"parameters": [],
|
|
203
|
+
"references": {
|
|
204
|
+
"Promise": {
|
|
205
|
+
"location": "global"
|
|
206
|
+
},
|
|
207
|
+
"HTMLElement": {
|
|
208
|
+
"location": "global"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"return": "Promise<HTMLElement>"
|
|
212
|
+
},
|
|
213
|
+
"docs": {
|
|
214
|
+
"text": "",
|
|
215
|
+
"tags": []
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"hide": {
|
|
219
|
+
"complexType": {
|
|
220
|
+
"signature": "() => Promise<HTMLElement>",
|
|
221
|
+
"parameters": [],
|
|
222
|
+
"references": {
|
|
223
|
+
"Promise": {
|
|
224
|
+
"location": "global"
|
|
225
|
+
},
|
|
226
|
+
"HTMLElement": {
|
|
227
|
+
"location": "global"
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
"return": "Promise<HTMLElement>"
|
|
231
|
+
},
|
|
232
|
+
"docs": {
|
|
233
|
+
"text": "",
|
|
234
|
+
"tags": []
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}; }
|
|
238
|
+
static get elementRef() { return "host"; }
|
|
239
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { Component, Host, h, Prop } from '@stencil/core';
|
|
2
|
+
import Helper from "../../Helpers/Helper";
|
|
3
|
+
export class OrderRating {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.stars = [1, 2, 3, 4, 5];
|
|
6
|
+
this.order = {
|
|
7
|
+
shipping: { id: 5622 },
|
|
8
|
+
order_id: "179794",
|
|
9
|
+
products: [
|
|
10
|
+
{
|
|
11
|
+
"title": "ميكروفون عالى الجودة",
|
|
12
|
+
"image": "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/pMdEEyMVpZFj4L1Hrdm2g48AuiSx0TrKULBiOnPo.jpg",
|
|
13
|
+
"price": "10,978.00 ر.س",
|
|
14
|
+
"qty": "2",
|
|
15
|
+
"totalBefore": "1120 ر.س",
|
|
16
|
+
"discount": "-5%",
|
|
17
|
+
"total": "1064 ر.س",
|
|
18
|
+
"id": "2314513454",
|
|
19
|
+
"getOptimusRouteKey": "7351233357"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"title": "وحدة تحكم لمشغل العاب",
|
|
23
|
+
"image": "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/NOa4kHvOkd1hBWHk3JIgAo1602oVACfuWGFz3vXv.jpg",
|
|
24
|
+
"price": "10,978.00 ر.س",
|
|
25
|
+
"qty": "2",
|
|
26
|
+
"totalBefore": "1120 ر.س",
|
|
27
|
+
"discount": "-5%",
|
|
28
|
+
"total": "1064 ر.س",
|
|
29
|
+
"id": "9842833",
|
|
30
|
+
"getOptimusRouteKey": "735152357"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"title": "ساعة ذكية بنظام اندرويد",
|
|
34
|
+
"image": "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/T4kTqYNuPAZmPMLw1bx92RnjVMZyFszVXOUZQsFJ.jpg",
|
|
35
|
+
"price": "10,978.00 ر.س",
|
|
36
|
+
"qty": "2",
|
|
37
|
+
"totalBefore": "1120 ر.س",
|
|
38
|
+
"discount": "-5%",
|
|
39
|
+
"total": "1064 ر.س",
|
|
40
|
+
"id": "679822376",
|
|
41
|
+
"getOptimusRouteKey": "73233357"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
ratingMessage: {
|
|
45
|
+
1: "غير راضي <span class='emoji mx-1'>😒</span>",
|
|
46
|
+
2: "لم يعجبني <span class='emoji mx-1'>😌</span>",
|
|
47
|
+
3: "معقول <span class='emoji mx-1'>🙄</span>",
|
|
48
|
+
4: "أعجبني <span class='emoji mx-1'>👍</span>",
|
|
49
|
+
5: "أعجبني جداً <span class='emoji mx-1'>🤩</span>"
|
|
50
|
+
},
|
|
51
|
+
settings: {
|
|
52
|
+
isProductsRating: true,
|
|
53
|
+
isStoreRating: true,
|
|
54
|
+
isShippingRating: true,
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
return (h(Host, null,
|
|
60
|
+
this.order.settings.isProductsRating && this.renderProductsRating(),
|
|
61
|
+
this.order.settings.isStoreRating && this.renderStoreRating(),
|
|
62
|
+
this.order.settings.isShippingRating && this.renderShippingRating()));
|
|
63
|
+
}
|
|
64
|
+
renderProductsRating() {
|
|
65
|
+
return (h("section", { class: "rating-section products-section", "data-type": "product" },
|
|
66
|
+
h("div", { class: "bg-white mb-5 p-5 rounded-md overflow-hidden mb-10" }, this.order.products.map((item, index) => {
|
|
67
|
+
var _a;
|
|
68
|
+
return h("div", { class: "rating-outer-form", "data-stars-error": `يرجى تقييم (${item.title}) بواسطة النجمات` },
|
|
69
|
+
h("div", { class: "product-item mb-4" },
|
|
70
|
+
h("div", { class: "mb-5" },
|
|
71
|
+
h("div", { class: "flex space-s-5 mb-8" },
|
|
72
|
+
h("img", { src: item.image, alt: item.title, class: "w-18 h-14 object-cover rounded-md" }),
|
|
73
|
+
h("div", { class: "flex-1" },
|
|
74
|
+
h("h3", { class: "section-title leading-5 mb-1.5 md:text-base" },
|
|
75
|
+
" ",
|
|
76
|
+
item.title),
|
|
77
|
+
h("div", { class: "rw-product-entry__rate" },
|
|
78
|
+
h("div", { class: "rating-wrap flex items-center space-s-4" },
|
|
79
|
+
h("form", { class: "rate-element rate-element--has-label" }, this.getStarsRating()),
|
|
80
|
+
h("p", { class: "rate-label fix-align font-xsm my-0" })),
|
|
81
|
+
h("input", { type: "hidden", name: "order_id", value: (_a = this.order) === null || _a === void 0 ? void 0 : _a.order_id }),
|
|
82
|
+
h("input", { type: "hidden", name: `products[${index}][product_id]`, value: item.getOptimusRouteKey }),
|
|
83
|
+
h("input", { type: "hidden", name: "type", value: "products" }),
|
|
84
|
+
h("textarea", { "data-product-id": item.id, name: `products[${index}][comment]`, id: `productReview_${item.id}`, class: "comment form-input h-20 product-review", placeholder: `اضف رأيك عن المنتج (${item.title})` }),
|
|
85
|
+
h("small", { class: "text-red-400 validation-message" })))))));
|
|
86
|
+
}))));
|
|
87
|
+
}
|
|
88
|
+
renderStoreRating() {
|
|
89
|
+
return (h("section", { class: "rating-section bg-white my-10 p-5 rounded-md mb-5", "data-type": "store" },
|
|
90
|
+
h("div", { class: "rating-outer-form", "data-stars-error": "\u064A\u0631\u062C\u0649 \u062A\u0642\u064A\u064A\u0645 \u0627\u0644\u0645\u062A\u062C\u0631 \u0628\u0648\u0627\u0633\u0637\u0629 \u0627\u0644\u0646\u062C\u0645\u0627\u062A" },
|
|
91
|
+
h("input", { type: "hidden", name: "order_id", value: this.order.order_id }),
|
|
92
|
+
h("input", { type: "hidden", name: "type", value: "store" }),
|
|
93
|
+
h("h2", { class: "section-title text-lg font-bold mb-5" }, "\u0643\u064A\u0641 \u0643\u0627\u0646\u062A \u062A\u062C\u0631\u0628\u062A\u0643 \u0645\u0639 \u0627\u0644\u0645\u062A\u062C\u0631 \u0647\u0630\u0647 \u0627\u0644\u0645\u0631\u0629"),
|
|
94
|
+
h("div", { class: "mb-2" },
|
|
95
|
+
h("textarea", { id: "storeReview", name: "comment", class: "form-input comment h-20", placeholder: "\u0627\u0636\u0641 \u0631\u0623\u064A\u0643 \u0639\u0646 \u0627\u0644\u0645\u062A\u062C\u0631.." })),
|
|
96
|
+
h("div", { class: "rating-wrap flex items-center space-s-4" },
|
|
97
|
+
h("form", { class: "rate-element rate-element--has-label" }, this.getStarsRating()),
|
|
98
|
+
h("p", { class: "rate-label fix-align font-sm center mb-0" })),
|
|
99
|
+
h("small", { class: "text-red-400 validation-message" }))));
|
|
100
|
+
}
|
|
101
|
+
renderShippingRating() {
|
|
102
|
+
return (h("section", { class: "rating-section bg-white my-10 p-5 rounded-md mb-5", "data-type": "shipping" },
|
|
103
|
+
h("div", { class: "rating-outer-form", "data-stars-error": "\u064A\u0631\u062C\u0649 \u062A\u0642\u064A\u064A\u0645 \u0634\u0631\u0643\u0629 \u0627\u0644\u0634\u062D\u0646 \u0628\u0648\u0627\u0633\u0637\u0629 \u0627\u0644\u0646\u062C\u0645\u0627\u062A" },
|
|
104
|
+
h("input", { type: "hidden", name: "order_id", value: this.order.order_id }),
|
|
105
|
+
h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.id }),
|
|
106
|
+
h("input", { type: "hidden", name: "type", value: "shipping" }),
|
|
107
|
+
h("h2", { class: "section-title text-lg font-bold mb-5" }, "\u062E\u0628\u0631\u0646\u0627 \u0639\u0646 \u062A\u062C\u0631\u0628\u062A\u0643 \u0645\u0639 \u0634\u0631\u0643\u0629 \u0627\u0644\u0634\u062D\u0646"),
|
|
108
|
+
h("div", { class: "mb-2" },
|
|
109
|
+
h("textarea", { id: "shippingReview", name: "comment", class: "form-input comment h-20 mb-2", placeholder: "\u0627\u0636\u0641 \u0631\u0623\u064A\u0643 \u0639\u0646 \u0634\u0631\u0643\u0629 \u0627\u0644\u0634\u062D\u0646" })),
|
|
110
|
+
h("div", { class: "rating-wrap flex items-center space-s-4" },
|
|
111
|
+
h("form", { class: "rate-element ratFeedbackPresentere-element--has-label" }, this.getStarsRating()),
|
|
112
|
+
h("p", { class: "rate-label fix-align font-sm center mb-0" })),
|
|
113
|
+
h("small", { class: "text-red-400 validation-message" }))));
|
|
114
|
+
}
|
|
115
|
+
getStarsRating() {
|
|
116
|
+
return (h("div", { class: "mb-1" },
|
|
117
|
+
h("input", { type: "hidden", class: "rating_hidden_input", name: "rating", value: "" }),
|
|
118
|
+
this.stars.map((star) => h("button", { type: "submit", class: "btn btn--transparent px-1 text-lg text-gray-400 btn--star", "data-star": star, "data-text": this.order.ratingMessage[`${star}`] },
|
|
119
|
+
h("i", { class: "sicon-star2" })))));
|
|
120
|
+
}
|
|
121
|
+
//========================= Start Rating Logic =========================//
|
|
122
|
+
initiateRating() {
|
|
123
|
+
this.highlightSelectedStars();
|
|
124
|
+
this.starsRating();
|
|
125
|
+
//show submitRating Button Only When there is a comment field
|
|
126
|
+
Helper.app.toggle('#submitRating', 'btn', 'hidden', () => Helper.app.element('#shippingReview,#storeReview,.product-review'));
|
|
127
|
+
this.ratingChain = Promise.resolve();
|
|
128
|
+
Helper.app.onClick('#submitRating', () => this.sendRating().then(() => window.location.reload()));
|
|
129
|
+
}
|
|
130
|
+
sendRating() {
|
|
131
|
+
this.ratingValidation();
|
|
132
|
+
Helper.app.all('.rating-section', ratingSection => {
|
|
133
|
+
let type = ratingSection.dataset.type;
|
|
134
|
+
let formsData = [];
|
|
135
|
+
ratingSection.querySelectorAll('.rating-outer-form')
|
|
136
|
+
.forEach((form) => {
|
|
137
|
+
let formData = {};
|
|
138
|
+
form.querySelectorAll('[name]')
|
|
139
|
+
.forEach(function (input) {
|
|
140
|
+
let inputData = salla.helpers.inputData(input.name, input.value, formData);
|
|
141
|
+
formData[inputData.name] = inputData.value;
|
|
142
|
+
});
|
|
143
|
+
formsData = [];
|
|
144
|
+
formsData.push(formData);
|
|
145
|
+
this.sendFeedback(type, formsData);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
return this.ratingChain;
|
|
149
|
+
}
|
|
150
|
+
sendFeedback(type, formsData) {
|
|
151
|
+
if (!formsData || formsData.length == 0) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
salla.config.canLeave = false;
|
|
155
|
+
this.ratingChain = salla.feedback.api[type](formsData[0])
|
|
156
|
+
.then(function () {
|
|
157
|
+
salla.config.canLeave = true;
|
|
158
|
+
}).catch(() => salla.config.canLeave = true);
|
|
159
|
+
}
|
|
160
|
+
ratingValidation() {
|
|
161
|
+
let errorMsg = '';
|
|
162
|
+
document.querySelectorAll('.rating-section')
|
|
163
|
+
.forEach((ratingSection) => {
|
|
164
|
+
ratingSection.querySelectorAll('.rating-outer-form')
|
|
165
|
+
.forEach((rating) => {
|
|
166
|
+
let ratingInput = rating.querySelector('.rating_hidden_input');
|
|
167
|
+
let commentInput = rating.querySelector('.comment');
|
|
168
|
+
let sectionTitle = rating.querySelector('.section-title');
|
|
169
|
+
let validationMessage = rating.querySelector('.validation-message');
|
|
170
|
+
if (ratingInput.value && commentInput.value && commentInput.value.length > 3) {
|
|
171
|
+
commentInput.classList.remove('has-error');
|
|
172
|
+
sectionTitle === null || sectionTitle === void 0 ? void 0 : sectionTitle.classList.remove('has-error', 'text-red-400');
|
|
173
|
+
validationMessage.innerHTML = '';
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
else if (commentInput.value && commentInput.value.length > 3) {
|
|
177
|
+
commentInput.classList.remove('has-error');
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
commentInput.classList.add('has-error');
|
|
181
|
+
}
|
|
182
|
+
sectionTitle === null || sectionTitle === void 0 ? void 0 : sectionTitle.classList.add('has-error', 'text-red-400');
|
|
183
|
+
errorMsg = ratingInput.value
|
|
184
|
+
? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + commentInput.getAttribute('placeholder'))
|
|
185
|
+
: (rating.dataset.starsError || salla.lang.get('pages.rating.rate_store_stars'));
|
|
186
|
+
validationMessage.innerHTML = errorMsg;
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
//Fire error to prevent sending rating
|
|
190
|
+
if (errorMsg) {
|
|
191
|
+
// scroll to first error
|
|
192
|
+
let ratingErrors = document.querySelectorAll('.has-error');
|
|
193
|
+
if (ratingErrors.length) {
|
|
194
|
+
let firstError = ratingErrors[0].offsetTop;
|
|
195
|
+
window.scrollTo({ top: firstError - 80 }); // 80 = fixed nav height
|
|
196
|
+
}
|
|
197
|
+
throw new Error(errorMsg);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// for hovered star ---
|
|
201
|
+
highlightSelectedStars() {
|
|
202
|
+
let hover = ['hovered', 'text-theme-yellow'];
|
|
203
|
+
Helper.app.all('.rate-element', el => {
|
|
204
|
+
let starElements = el.querySelectorAll('.btn--star');
|
|
205
|
+
// remove hovered state from stars ---
|
|
206
|
+
el.addEventListener('mouseout', () => el.querySelectorAll('.btn--star').forEach(star => star.classList.remove(...hover)));
|
|
207
|
+
starElements.forEach((starElement, index) => {
|
|
208
|
+
starElement.addEventListener('mouseover', () => {
|
|
209
|
+
starElement.classList.add(...hover);
|
|
210
|
+
if (index <= 1) {
|
|
211
|
+
starElement.previousElementSibling.tagName === 'BUTTON' ? starElement.previousElementSibling.classList.add(...hover) : null;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
for (let i = 0; i < index; i++) {
|
|
215
|
+
starElements[i].classList.add(...hover);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
starElement.addEventListener('mouseout', () => {
|
|
220
|
+
starElement.classList.contains(...hover) ? starElement.classList.remove(...hover) : null;
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
starsRating() {
|
|
226
|
+
let selectedClasses = ['selected', 'text-theme-yellow'];
|
|
227
|
+
// Listen for form submissions
|
|
228
|
+
salla.document.event.onSubmit('.rate-element', function (event) {
|
|
229
|
+
// Prevent form from submitting
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
// Get the selected star - activeElement is not supported in safari
|
|
232
|
+
var activeStars = event.target.querySelectorAll('.btn--star.hovered');
|
|
233
|
+
var selected = activeStars[activeStars.length - 1];
|
|
234
|
+
if (!selected)
|
|
235
|
+
return;
|
|
236
|
+
var selectedIndex = parseInt(selected.dataset.star, 10), selectedText = selected.dataset.text;
|
|
237
|
+
event.target.nextElementSibling.innerHTML = selectedText;
|
|
238
|
+
event.target.querySelector('.rating_hidden_input').value = selectedIndex;
|
|
239
|
+
// Get all stars in this form (only search in the form, not the whole document)
|
|
240
|
+
// Loop through each star, and add or remove the `.selected` class to toggle highlighting
|
|
241
|
+
event.target
|
|
242
|
+
.querySelectorAll('.btn--star')
|
|
243
|
+
.forEach(function (star, index) {
|
|
244
|
+
if (index < selectedIndex) {
|
|
245
|
+
// Selected star or before it, Add highlighting
|
|
246
|
+
star.classList.add(...selectedClasses);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
// After selected star, Remove highlight
|
|
250
|
+
star.classList.remove(...selectedClasses);
|
|
251
|
+
});
|
|
252
|
+
// Remove aria-pressed from any previously selected star
|
|
253
|
+
var previousRating = event.target.querySelector('.star[aria-pressed="true"]');
|
|
254
|
+
if (previousRating) {
|
|
255
|
+
previousRating.removeAttribute('aria-pressed');
|
|
256
|
+
}
|
|
257
|
+
// Add aria-pressed role to the selected button
|
|
258
|
+
selected.setAttribute('aria-pressed', true);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
static get is() { return "order-rating"; }
|
|
262
|
+
static get originalStyleUrls() { return {
|
|
263
|
+
"$": ["order-rating.css"]
|
|
264
|
+
}; }
|
|
265
|
+
static get styleUrls() { return {
|
|
266
|
+
"$": ["order-rating.css"]
|
|
267
|
+
}; }
|
|
268
|
+
static get properties() { return {
|
|
269
|
+
"order": {
|
|
270
|
+
"type": "any",
|
|
271
|
+
"mutable": false,
|
|
272
|
+
"complexType": {
|
|
273
|
+
"original": "any",
|
|
274
|
+
"resolved": "any",
|
|
275
|
+
"references": {}
|
|
276
|
+
},
|
|
277
|
+
"required": false,
|
|
278
|
+
"optional": false,
|
|
279
|
+
"docs": {
|
|
280
|
+
"tags": [],
|
|
281
|
+
"text": ""
|
|
282
|
+
},
|
|
283
|
+
"attribute": "order",
|
|
284
|
+
"reflect": false,
|
|
285
|
+
"defaultValue": "{\n shipping: { id: 5622 },\n order_id: \"179794\",\n products: [\n {\n \"title\": \"\u0645\u064A\u0643\u0631\u0648\u0641\u0648\u0646 \u0639\u0627\u0644\u0649 \u0627\u0644\u062C\u0648\u062F\u0629\",\n \"image\": \"https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/pMdEEyMVpZFj4L1Hrdm2g48AuiSx0TrKULBiOnPo.jpg\",\n \"price\": \"\u200F10,978.00 \u0631.\u0633\",\n \"qty\": \"\u200F2\",\n \"totalBefore\": \"\u200F1120 \u0631.\u0633\",\n \"discount\": \"-5%\",\n \"total\": \"\u200F1064 \u0631.\u0633\",\n \"id\": \"2314513454\",\n \"getOptimusRouteKey\": \"7351233357\"\n\n },\n {\n \"title\": \"\u0648\u062D\u062F\u0629 \u062A\u062D\u0643\u0645 \u0644\u0645\u0634\u063A\u0644 \u0627\u0644\u0639\u0627\u0628\",\n \"image\": \"https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/NOa4kHvOkd1hBWHk3JIgAo1602oVACfuWGFz3vXv.jpg\",\n \"price\": \"\u200F10,978.00 \u0631.\u0633\",\n \"qty\": \"\u200F2\",\n \"totalBefore\": \"\u200F1120 \u0631.\u0633\",\n \"discount\": \"-5%\",\n \"total\": \"\u200F1064 \u0631.\u0633\",\n \"id\": \"9842833\",\n \"getOptimusRouteKey\": \"735152357\"\n },\n {\n \"title\": \"\u0633\u0627\u0639\u0629 \u0630\u0643\u064A\u0629 \u0628\u0646\u0638\u0627\u0645 \u0627\u0646\u062F\u0631\u0648\u064A\u062F\",\n \"image\": \"https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/T4kTqYNuPAZmPMLw1bx92RnjVMZyFszVXOUZQsFJ.jpg\",\n \"price\": \"\u200F10,978.00 \u0631.\u0633\",\n \"qty\": \"\u200F2\",\n \"totalBefore\": \"\u200F1120 \u0631.\u0633\",\n \"discount\": \"-5%\",\n \"total\": \"\u200F1064 \u0631.\u0633\",\n \"id\": \"679822376\",\n \"getOptimusRouteKey\": \"73233357\"\n\n }\n ],\n ratingMessage: {\n 1: \"\u063A\u064A\u0631 \u0631\u0627\u0636\u064A <span class='emoji mx-1'>\uD83D\uDE12</span>\",\n 2: \"\u0644\u0645 \u064A\u0639\u062C\u0628\u0646\u064A <span class='emoji mx-1'>\uD83D\uDE0C</span>\",\n 3: \"\u0645\u0639\u0642\u0648\u0644 <span class='emoji mx-1'>\uD83D\uDE44</span>\",\n 4: \"\u0623\u0639\u062C\u0628\u0646\u064A <span class='emoji mx-1'>\uD83D\uDC4D</span>\",\n 5: \"\u0623\u0639\u062C\u0628\u0646\u064A \u062C\u062F\u0627\u064B <span class='emoji mx-1'>\uD83E\uDD29</span>\"\n },\n\n settings: {\n isProductsRating: true,\n isStoreRating: true,\n isShippingRating: true,\n }\n }"
|
|
286
|
+
}
|
|
287
|
+
}; }
|
|
288
|
+
}
|