PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
learnpress / assets / js / dist / admin / pages / addons.js

addons.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.9, at assets/js/dist/admin/pages/addons.js

392 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 /******/ "use strict";
3 /******/ var __webpack_modules__ = ({
4
5 /***/ "./assets/src/apps/js/admin/api.js":
6 /*!*****************************************!*\
7 !*** ./assets/src/apps/js/admin/api.js ***!
8 \*****************************************/
9 /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
10
11 __webpack_require__.r(__webpack_exports__);
12 /**
13 * List API on backend
14 */
15 /* harmony default export */ __webpack_exports__["default"] = ({
16 apiAdminNotice: lpGlobalSettings.rest + 'lp/v1/admin/tools/admin-notices',
17 apiAdminOrderStatic: lpGlobalSettings.rest + 'lp/v1/orders/statistic',
18 apiAddons: lpGlobalSettings.rest + 'lp/v1/addon/all',
19 apiAddonAction: lpGlobalSettings.rest + 'lp/v1/addon/action'
20 });
21
22 /***/ })
23
24 /******/ });
25 /************************************************************************/
26 /******/ // The module cache
27 /******/ var __webpack_module_cache__ = {};
28 /******/
29 /******/ // The require function
30 /******/ function __webpack_require__(moduleId) {
31 /******/ // Check if module is in cache
32 /******/ var cachedModule = __webpack_module_cache__[moduleId];
33 /******/ if (cachedModule !== undefined) {
34 /******/ return cachedModule.exports;
35 /******/ }
36 /******/ // Create a new module (and put it into the cache)
37 /******/ var module = __webpack_module_cache__[moduleId] = {
38 /******/ // no module.id needed
39 /******/ // no module.loaded needed
40 /******/ exports: {}
41 /******/ };
42 /******/
43 /******/ // Execute the module function
44 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
45 /******/
46 /******/ // Return the exports of the module
47 /******/ return module.exports;
48 /******/ }
49 /******/
50 /************************************************************************/
51 /******/ /* webpack/runtime/make namespace object */
52 /******/ !function() {
53 /******/ // define __esModule on exports
54 /******/ __webpack_require__.r = function(exports) {
55 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57 /******/ }
58 /******/ Object.defineProperty(exports, '__esModule', { value: true });
59 /******/ };
60 /******/ }();
61 /******/
62 /************************************************************************/
63 var __webpack_exports__ = {};
64 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
65 !function() {
66 /*!**************************************************!*\
67 !*** ./assets/src/apps/js/admin/pages/addons.js ***!
68 \**************************************************/
69 __webpack_require__.r(__webpack_exports__);
70 /* harmony import */ var _api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../api */ "./assets/src/apps/js/admin/api.js");
71 /**
72 * Script handle admin notices.
73 *
74 * @since 4.1.7.3.2
75 * @version 1.0.1
76 */
77
78 let elAddonsPage;
79 let dataHtml;
80 let dataAddons;
81 let elLPAddons;
82 const queryString = window.location.search;
83 const urlParams = new URLSearchParams(queryString);
84 const tab = urlParams.get('tab');
85 let elNotifyActionWrapper;
86 const isHandling = [];
87
88 // API get list addons.
89 const getAddons = (set = '') => {
90 const params = tab ? `?tab=${tab}` : `?${set}`;
91 fetch(_api__WEBPACK_IMPORTED_MODULE_0__["default"].apiAddons + params, {
92 method: 'GET',
93 headers: {
94 'X-WP-Nonce': lpGlobalSettings.nonce
95 }
96 }).then(res => res.json()).then(res => {
97 // console.log(data);
98 const {
99 status,
100 message,
101 data
102 } = res;
103 if (status === 'success') {
104 dataHtml = data.html;
105 dataAddons = data.addons;
106 } else {
107 dataHtml = message;
108 }
109 }).catch(err => {
110 console.log(err);
111 });
112 };
113 // API send action install, update, activate, deactivate.
114 const addonsAction = (data, callBack) => {
115 const addonSlug = data.addon.slug;
116 if (isHandling.indexOf(addonSlug) !== -1) {
117 return;
118 }
119 isHandling.push(addonSlug);
120 fetch(_api__WEBPACK_IMPORTED_MODULE_0__["default"].apiAddonAction, {
121 method: 'POST',
122 headers: {
123 'Content-Type': 'application/json',
124 'X-WP-Nonce': lpGlobalSettings.nonce
125 },
126 body: JSON.stringify({
127 ...data
128 })
129 }).then(res => res.json()).then(res => {
130 const indexAddonHanding = isHandling.indexOf(addonSlug);
131 if (indexAddonHanding !== -1) {
132 isHandling.splice(indexAddonHanding, 1);
133 }
134 const {
135 status,
136 message,
137 data
138 } = res;
139 if (callBack) {
140 callBack(status, message, data);
141 }
142 handleNotify(status, message);
143 }).catch(err => {
144 handleNotify('error', `error js: ${err}`);
145 console.log(err);
146 });
147 };
148 // Show notify.
149 const handleNotify = (status, message) => {
150 const elNotifyAction = elNotifyActionWrapper.querySelector('.lp-notify-action');
151 const elNotifyActionNew = elNotifyAction.cloneNode(true);
152 elNotifyActionNew.classList.remove('clone');
153 elNotifyActionWrapper.insertBefore(elNotifyActionNew, elNotifyActionWrapper[0]);
154 const elSuccess = elNotifyActionNew.querySelector(`.${elNotifyActionNew.classList.value}__success`);
155 const elFailed = elNotifyActionNew.querySelector(`.${elNotifyActionNew.classList.value}__error`);
156 if (status === 'success') {
157 elSuccess.classList.add('show');
158 elSuccess.querySelector('.message').innerHTML = message;
159 } else {
160 elFailed.classList.add('show');
161 elFailed.querySelector('.message').innerHTML = message;
162 }
163 elNotifyActionWrapper.classList.add('show');
164 setTimeout(() => {
165 elNotifyActionNew.remove();
166 const elNotifyAction = elNotifyActionWrapper.querySelectorAll('.lp-notify-action');
167 if (elNotifyAction.length === 1) {
168 elNotifyActionWrapper.classList.remove('show');
169 }
170 }, status === 'success' ? 3000 : 4000);
171 };
172 // Get addons when js loaded.
173 getAddons();
174 // Search Addons.
175 const searchAddons = name => {
176 const elAddonItems = elAddonsPage.querySelectorAll('.lp-addon-item');
177 let totalItems = 0;
178 elAddonItems.forEach(elAddonItem => {
179 const addonName = elAddonItem.querySelector('a').textContent;
180 if (elAddonItem.classList.contains('hide')) {
181 return;
182 }
183 if (addonName.toLowerCase().includes(name.toLowerCase())) {
184 elAddonItem.classList.remove('search-not-found');
185 totalItems++;
186 } else {
187 elAddonItem.classList.add('search-not-found');
188 }
189 });
190 setGridItems(totalItems);
191 };
192 // Set grid style items.
193 const setGridItems = totalItems => {
194 if (totalItems < 4) {
195 elLPAddons.classList.add('max-3-items');
196 } else {
197 elLPAddons.classList.remove('max-3-items');
198 }
199 };
200 // Check element loaded and data API returned.
201 const loadElData = setInterval(() => {
202 if (!elAddonsPage && !elNotifyActionWrapper) {
203 elAddonsPage = document.querySelector('.lp-addons-page');
204 elNotifyActionWrapper = document.querySelector('.lp-notify-action-wrapper');
205 } else if (dataHtml && elAddonsPage && elNotifyActionWrapper) {
206 elAddonsPage.innerHTML = dataHtml;
207 elLPAddons = elAddonsPage.querySelector('#lp-addons');
208 const elNavTabWrapper = document.querySelector('.lp-nav-tab-wrapper');
209 const elNavTabWrapperClone = elNavTabWrapper.cloneNode(true);
210 elAddonsPage.insertBefore(elNavTabWrapperClone, elAddonsPage.children[0]);
211 elNavTabWrapperClone.style.display = 'flex';
212 elNavTabWrapper.remove();
213 const elNavActive = elNavTabWrapperClone.querySelector('.nav-tab.nav-tab-active span');
214 setGridItems(parseInt(elNavActive.textContent));
215 clearInterval(loadElData);
216 }
217 }, 1);
218 document.addEventListener('DOMContentLoaded', e => {});
219
220 /*** Events ***/
221 document.addEventListener('click', e => {
222 const el = e.target;
223 const tagName = el.tagName.toLowerCase();
224 if (tagName === 'span') {
225 e.preventDefault();
226 const elBtnAction = el.closest('.btn-addon-action');
227 if (elBtnAction) {
228 elBtnAction.click();
229 }
230 }
231
232 // Events actions: activate, deactivate.
233 /*if ( el.classList.contains( 'lp-toggle-switch-label' ) ) {
234 //e.preventDefault();
235 const elAddonItem = el.closest( '.lp-addon-item' );
236 const idLabel = el.getAttribute( 'for' );
237 const elInput = document.querySelector( `#${ idLabel }` );
238 const action = elInput.getAttribute( 'data-action' );
239 const addon = dataAddons[ elAddonItem.dataset.slug ];
240 const addonSlug = addon.slug;
241 const parent = el.closest( '.lp-toggle-switch' );
242 const label = parent.querySelector( `label[for=${ idLabel }]` );
243 const dashicons = parent.querySelector( '.dashicons-update' );
244 dashicons.style.display = 'inline-block';
245 label.style.display = 'none';
246 const data = { action, addon };
247 addonsAction( data, function( status, message, data ) {
248 const elAddon = document.querySelector( `#${ addonSlug }` );
249 if ( elAddon ) {
250 const parent = elAddon.closest( '.lp-toggle-switch' );
251 if ( parent ) {
252 const dashicons = parent.querySelector( '.dashicons-update' );
253 dashicons.style.display = 'none';
254 if ( action === 'deactivate' ) {
255 elAddon.setAttribute( 'data-action', 'activate' );
256 } else if ( action === 'activate' ) {
257 elAddon.setAttribute( 'data-action', 'deactivate' );
258 }
259 const label = parent.querySelector( `label[for=${ addonSlug }]` );
260 label.style.display = 'inline-flex';
261 }
262 }
263 if ( status === 'success' ) {
264 if ( action === 'deactivate' ) {
265 elAddonItem.classList.remove( 'activated' );
266 }
267 if ( action === 'activate' ) {
268 elAddonItem.classList.add( 'activated' );
269 }
270 }
271 } );
272 }*/
273
274 // Events actions: install, update, delete.
275 if (el.classList.contains('btn-addon-action')) {
276 e.preventDefault();
277 el.classList.add('handling');
278 let purchaseCode = '';
279 const elAddonItem = el.closest('.lp-addon-item');
280 const addon = dataAddons[elAddonItem.dataset.slug];
281 const action = el.dataset.action;
282 const elItemPurchase = elAddonItem.querySelector('.lp-addon-item__purchase');
283 //const elToggleSwitchInput = elAddonItem.querySelector( '.lp-toggle-switch-input' );
284
285 if (action === 'purchase') {
286 elItemPurchase.style.display = 'block';
287 elItemPurchase.querySelector('.purchase-install').style.display = 'flex';
288 return;
289 } else if (action === 'update-purchase-code') {
290 elItemPurchase.querySelector('.purchase-update').style.display = 'flex';
291 elItemPurchase.style.display = 'block';
292 return;
293 } else if (action === 'buy') {
294 const link = el.dataset.link;
295 window.open(link, '_blank');
296 return;
297 } else if (action === 'cancel') {
298 elItemPurchase.style.display = 'none';
299 return;
300 } else if (action === 'install') {
301 if (el.dataset.link) {
302 el.classList.remove('handling');
303 const link = el.dataset.link;
304 window.open(link, '_blank');
305 return;
306 }
307 }
308
309 // Send request to server.
310 if (elItemPurchase) {
311 purchaseCode = elItemPurchase.querySelector('input[name=purchase-code]').value;
312 }
313 const data = {
314 purchase_code: purchaseCode,
315 action,
316 addon
317 };
318 addonsAction(data, function (status, message, data) {
319 if (status === 'success') {
320 if (action === 'install') {
321 elAddonItem.classList.add('installed', 'activated');
322 elAddonItem.classList.remove('not_installed');
323 elItemPurchase.style.display = 'none';
324 /*elToggleSwitchInput.setAttribute( 'checked', 'checked' );
325 elToggleSwitchInput.setAttribute( 'data-action', 'deactivate' );*/
326 const elNavInstalled = document.querySelector('.nav-tab[data-tab=installed] span');
327 elNavInstalled.textContent = parseInt(elNavInstalled.textContent) + 1;
328 const elNavNoInstalled = document.querySelector('.nav-tab[data-tab=not_installed] span');
329 elNavNoInstalled.textContent = parseInt(elNavNoInstalled.textContent) - 1;
330 } else if (action === 'update') {
331 const elAddonVersionCurrent = elAddonItem.querySelector('.addon-version-current');
332 elAddonVersionCurrent.innerHTML = addon.version;
333 elAddonItem.classList.remove('update');
334 } else if (action === 'activate') {
335 elAddonItem.classList.add('activated');
336 } else if (action === 'deactivate') {
337 elAddonItem.classList.remove('activated');
338 }
339 }
340 el.classList.remove('handling');
341 });
342 }
343 if (el.classList.contains('nav-tab')) {
344 e.preventDefault();
345 const elTabs = document.querySelectorAll('.nav-tab');
346 elTabs.forEach(function (elTab) {
347 elTab.classList.remove('nav-tab-active');
348 });
349 el.classList.add('nav-tab-active');
350 const tabName = el.dataset.tab;
351 const elAddonItems = elAddonsPage.querySelectorAll('.lp-addon-item');
352 const elSearch = elAddonsPage.querySelector('#lp-search-addons__input');
353 elSearch.value = '';
354 urlParams.set('tab', tabName);
355 window.history.pushState({}, '', `${window.location.pathname}?${urlParams.toString()}`);
356 let totalItems = 0;
357 elAddonItems.forEach(elAddonItem => {
358 elAddonItem.classList.remove('search-not-found');
359 if ('all' === tabName || elAddonItem.classList.contains(tabName)) {
360 elAddonItem.classList.remove('hide');
361 totalItems++;
362 } else {
363 elAddonItem.classList.add('hide');
364 }
365 });
366 setGridItems(totalItems);
367 }
368 });
369
370 /*** Event search addons. ***/
371 document.addEventListener('input', e => {
372 const el = e.target;
373 if ('lp-search-addons__input' === el.id) {
374 const keyword = el.value;
375 searchAddons(keyword);
376 }
377
378 // Events change input purchase code.
379 if (el.classList.contains('enter-purchase-code')) {
380 e.preventDefault();
381 const purchaseCode = el.value;
382 const elItemPurchase = el.closest('.lp-addon-item__purchase');
383 if (elItemPurchase) {
384 const input = elItemPurchase.querySelector('input[name=purchase-code]');
385 input.value = purchaseCode;
386 }
387 }
388 });
389 }();
390 /******/ })()
391 ;
392 //# sourceMappingURL=addons.js.map