PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 4.2.0 All 139 releases
learnpress / assets / js / dist / admin / addons.js

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

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