PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.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 4.2.1 All 138 releases
learnpress / assets / js / dist / admin / addons.js

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

460 lines 16.2 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 /******/ var __webpack_module_cache__ = {};
61 /******/
62 /******/ // The require function
63 /******/ function __webpack_require__(moduleId) {
64 /******/ // Check if module is in cache
65 /******/ var 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 /******/ var 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 /******/ var 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 functions for harmony exports
93 /******/ __webpack_require__.d = (exports, definition) => {
94 /******/ for(var key in definition) {
95 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
96 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
97 /******/ }
98 /******/ }
99 /******/ };
100 /******/ })();
101 /******/
102 /******/ /* webpack/runtime/hasOwnProperty shorthand */
103 /******/ (() => {
104 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
105 /******/ })();
106 /******/
107 /******/ /* webpack/runtime/make namespace object */
108 /******/ (() => {
109 /******/ // define __esModule on exports
110 /******/ __webpack_require__.r = (exports) => {
111 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
112 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
113 /******/ }
114 /******/ Object.defineProperty(exports, '__esModule', { value: true });
115 /******/ };
116 /******/ })();
117 /******/
118 /************************************************************************/
119 var __webpack_exports__ = {};
120 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
121 (() => {
122 /*!***************************************!*\
123 !*** ./assets/src/js/admin/addons.js ***!
124 \***************************************/
125 __webpack_require__.r(__webpack_exports__);
126 /* harmony import */ var _api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../api */ "./assets/src/js/api.js");
127 /**
128 * Script handle admin notices.
129 *
130 * @since 4.1.7.3.2
131 * @version 1.0.1
132 */
133
134 let elAddonsPage;
135 let dataHtml;
136 let dataAddons;
137 let elLPAddons;
138 const queryString = window.location.search;
139 const urlParams = new URLSearchParams(queryString);
140 const tab = urlParams.get('tab');
141 let elNotifyActionWrapper;
142 const isHandling = [];
143
144 // API get list addons.
145 const getAddons = (set = '') => {
146 const params = tab ? `?tab=${tab}` : `?${set}`;
147 fetch(_api__WEBPACK_IMPORTED_MODULE_0__["default"].admin.apiAddons + params, {
148 method: 'GET',
149 headers: {
150 'X-WP-Nonce': lpDataAdmin.nonce
151 }
152 }).then(res => res.json()).then(res => {
153 // console.log(data);
154 const {
155 status,
156 message,
157 data
158 } = res;
159 if (status === 'success') {
160 dataHtml = data.html;
161 dataAddons = data.addons;
162 } else {
163 dataHtml = message;
164 }
165 }).catch(err => {
166 console.log(err);
167 });
168 };
169 // API send action install, update, activate, deactivate.
170 const addonsAction = (data, callBack) => {
171 const addonSlug = data.addon.slug;
172 if (isHandling.indexOf(addonSlug) !== -1) {
173 return;
174 }
175 isHandling.push(addonSlug);
176 fetch(_api__WEBPACK_IMPORTED_MODULE_0__["default"].admin.apiAddonAction, {
177 method: 'POST',
178 headers: {
179 'Content-Type': 'application/json',
180 'X-WP-Nonce': lpDataAdmin.nonce
181 },
182 body: JSON.stringify({
183 ...data
184 })
185 }).then(res => res.json()).then(res => {
186 const indexAddonHanding = isHandling.indexOf(addonSlug);
187 if (indexAddonHanding !== -1) {
188 isHandling.splice(indexAddonHanding, 1);
189 }
190 const {
191 status,
192 message,
193 data
194 } = res;
195 if (callBack) {
196 callBack(status, message, data);
197 }
198 handleNotify(status, message);
199 }).catch(err => {
200 handleNotify('error', `error js: ${err}`);
201 console.log(err);
202 });
203 };
204 // Show notify.
205 const handleNotify = (status, message) => {
206 const elNotifyAction = elNotifyActionWrapper.querySelector('.lp-notify-action');
207 const elNotifyActionNew = elNotifyAction.cloneNode(true);
208 elNotifyActionNew.classList.remove('clone');
209 elNotifyActionWrapper.insertBefore(elNotifyActionNew, elNotifyActionWrapper[0]);
210 const elSuccess = elNotifyActionNew.querySelector(`.${elNotifyActionNew.classList.value}__success`);
211 const elFailed = elNotifyActionNew.querySelector(`.${elNotifyActionNew.classList.value}__error`);
212 if (status === 'success') {
213 elSuccess.classList.add('show');
214 elSuccess.querySelector('.message').innerHTML = message;
215 } else {
216 elFailed.classList.add('show');
217 elFailed.querySelector('.message').innerHTML = message;
218 }
219 elNotifyActionWrapper.classList.add('show');
220 setTimeout(() => {
221 elNotifyActionNew.remove();
222 const elNotifyAction = elNotifyActionWrapper.querySelectorAll('.lp-notify-action');
223 if (elNotifyAction.length === 1) {
224 elNotifyActionWrapper.classList.remove('show');
225 }
226 }, status === 'success' ? 3000 : 4000);
227 };
228 // Get addons when js loaded.
229 getAddons();
230 // Search Addons.
231 const searchAddons = name => {
232 const elAddonItems = elAddonsPage.querySelectorAll('.lp-addon-item');
233 let totalItems = 0;
234 elAddonItems.forEach(elAddonItem => {
235 const addonName = elAddonItem.querySelector('a').textContent;
236 if (elAddonItem.classList.contains('hide')) {
237 return;
238 }
239 if (addonName.toLowerCase().includes(name.toLowerCase())) {
240 elAddonItem.classList.remove('search-not-found');
241 totalItems++;
242 } else {
243 elAddonItem.classList.add('search-not-found');
244 }
245 });
246 setGridItems(totalItems);
247 };
248 // Set grid style items.
249 const setGridItems = totalItems => {
250 if (totalItems < 4) {
251 elLPAddons.classList.add('max-3-items');
252 } else {
253 elLPAddons.classList.remove('max-3-items');
254 }
255 };
256 // Check element loaded and data API returned.
257 const loadElData = setInterval(() => {
258 if (!elAddonsPage || !elNotifyActionWrapper) {
259 elAddonsPage = document.querySelector('.lp-addons-page');
260 elNotifyActionWrapper = document.querySelector('.lp-notify-action-wrapper');
261 } else if (dataHtml && elAddonsPage && elNotifyActionWrapper) {
262 elAddonsPage.innerHTML = dataHtml;
263 elLPAddons = elAddonsPage.querySelector('#lp-addons');
264 const elNavTabWrapper = document.querySelector('.lp-nav-tab-wrapper');
265 if (!elNavTabWrapper) {
266 clearInterval(loadElData);
267 return;
268 }
269 const elNavTabWrapperClone = elNavTabWrapper.cloneNode(true);
270 elAddonsPage.insertBefore(elNavTabWrapperClone, elAddonsPage.children[0]);
271 elNavTabWrapperClone.style.display = 'flex';
272 elNavTabWrapper.remove();
273 const elNavActive = elNavTabWrapperClone.querySelector('.nav-tab.nav-tab-active span');
274 setGridItems(parseInt(elNavActive.textContent));
275 clearInterval(loadElData);
276 }
277 }, 1);
278 document.addEventListener('DOMContentLoaded', e => {});
279
280 /*** Events ***/
281 document.addEventListener('click', e => {
282 let el = e.target;
283 const tagName = el.tagName.toLowerCase();
284 if (tagName === 'span') {
285 e.preventDefault();
286 const elBtnAction = el.closest('.btn-addon-action');
287 if (elBtnAction) {
288 elBtnAction.click();
289 }
290 }
291
292 // Events actions: activate, deactivate.
293 /*if ( el.classList.contains( 'lp-toggle-switch-label' ) ) {
294 //e.preventDefault();
295
296 const elAddonItem = el.closest( '.lp-addon-item' );
297 const idLabel = el.getAttribute( 'for' );
298 const elInput = document.querySelector( `#${ idLabel }` );
299 const action = elInput.getAttribute( 'data-action' );
300 const addon = dataAddons[ elAddonItem.dataset.slug ];
301 const addonSlug = addon.slug;
302 const parent = el.closest( '.lp-toggle-switch' );
303 const label = parent.querySelector( `label[for=${ idLabel }]` );
304 const dashicons = parent.querySelector( '.dashicons-update' );
305 dashicons.style.display = 'inline-block';
306 label.style.display = 'none';
307 const data = { action, addon };
308 addonsAction( data, function( status, message, data ) {
309 const elAddon = document.querySelector( `#${ addonSlug }` );
310 if ( elAddon ) {
311 const parent = elAddon.closest( '.lp-toggle-switch' );
312 if ( parent ) {
313 const dashicons = parent.querySelector( '.dashicons-update' );
314 dashicons.style.display = 'none';
315 if ( action === 'deactivate' ) {
316 elAddon.setAttribute( 'data-action', 'activate' );
317 } else if ( action === 'activate' ) {
318 elAddon.setAttribute( 'data-action', 'deactivate' );
319 }
320 const label = parent.querySelector( `label[for=${ addonSlug }]` );
321 label.style.display = 'inline-flex';
322 }
323 }
324
325 if ( status === 'success' ) {
326 if ( action === 'deactivate' ) {
327 elAddonItem.classList.remove( 'activated' );
328 }
329 if ( action === 'activate' ) {
330 elAddonItem.classList.add( 'activated' );
331 }
332 }
333 } );
334 }*/
335
336 // Events actions: install, update, delete.
337 if (el.closest('.btn-addon-action')) {
338 el = el.closest('.btn-addon-action');
339 e.preventDefault();
340 el.classList.add('handling');
341 let purchaseCode = '';
342 const elAddonItem = el.closest('.lp-addon-item');
343 const addon = dataAddons[elAddonItem.dataset.slug];
344 const action = el.dataset.action;
345 const elItemPurchase = elAddonItem.querySelector('.lp-addon-item__purchase');
346 //const elToggleSwitchInput = elAddonItem.querySelector( '.lp-toggle-switch-input' );
347
348 if (action === 'purchase') {
349 elItemPurchase.style.display = 'block';
350 elItemPurchase.querySelector('.purchase-install').style.display = 'flex';
351 return;
352 } else if (action === 'update-purchase-code') {
353 elItemPurchase.querySelector('.purchase-update').style.display = 'flex';
354 elItemPurchase.style.display = 'block';
355 return;
356 } else if (action === 'buy') {
357 const link = el.dataset.link;
358 window.open(link, '_blank');
359 return;
360 } else if (action === 'cancel') {
361 elItemPurchase.style.display = 'none';
362 return;
363 } else if (action === 'install') {
364 if (el.dataset.link) {
365 el.classList.remove('handling');
366 const link = el.dataset.link;
367 window.open(link, '_blank');
368 return;
369 }
370 }
371
372 // Send request to server.
373 if (elItemPurchase) {
374 purchaseCode = elItemPurchase.querySelector('input[name=purchase-code]').value;
375 }
376 const data = {
377 purchase_code: purchaseCode,
378 action,
379 addon
380 };
381 addonsAction(data, function (status, message, data) {
382 if (status === 'success') {
383 if (action === 'install') {
384 elAddonItem.classList.add('installed', 'activated');
385 elAddonItem.classList.remove('not_installed');
386 elItemPurchase.style.display = 'none';
387 /*elToggleSwitchInput.setAttribute( 'checked', 'checked' );
388 elToggleSwitchInput.setAttribute( 'data-action', 'deactivate' );*/
389 const elNavInstalled = document.querySelector('.nav-tab[data-tab=installed] span');
390 elNavInstalled.textContent = parseInt(elNavInstalled.textContent) + 1;
391 const elNavNoInstalled = document.querySelector('.nav-tab[data-tab=not_installed] span');
392 elNavNoInstalled.textContent = parseInt(elNavNoInstalled.textContent) - 1;
393 elItemPurchase.querySelector('.purchase-install').style.display = 'none';
394 elItemPurchase.querySelector('.purchase-update').querySelector('.enter-purchase-code').value = purchaseCode;
395 } else if (action === 'update') {
396 const elAddonVersionCurrent = elAddonItem.querySelector('.addon-version-current');
397 elAddonVersionCurrent.innerHTML = addon.version;
398 elAddonItem.classList.remove('update');
399 } else if (action === 'activate') {
400 elAddonItem.classList.add('activated');
401 } else if (action === 'deactivate') {
402 elAddonItem.classList.remove('activated');
403 } else if (action === 'update-purchase') {
404 elItemPurchase.style.display = 'none';
405 }
406 }
407 el.classList.remove('handling');
408 });
409 }
410 if (el.classList.contains('nav-tab')) {
411 e.preventDefault();
412 const elTabs = document.querySelectorAll('.nav-tab');
413 elTabs.forEach(function (elTab) {
414 elTab.classList.remove('nav-tab-active');
415 });
416 el.classList.add('nav-tab-active');
417 const tabName = el.dataset.tab;
418 const elAddonItems = elAddonsPage.querySelectorAll('.lp-addon-item');
419 const elSearch = elAddonsPage.querySelector('#lp-search-addons__input');
420 elSearch.value = '';
421 urlParams.set('tab', tabName);
422 window.history.pushState({}, '', `${window.location.pathname}?${urlParams.toString()}`);
423 let totalItems = 0;
424 elAddonItems.forEach(elAddonItem => {
425 elAddonItem.classList.remove('search-not-found');
426 if ('all' === tabName || elAddonItem.classList.contains(tabName)) {
427 elAddonItem.classList.remove('hide');
428 totalItems++;
429 } else {
430 elAddonItem.classList.add('hide');
431 }
432 });
433 setGridItems(totalItems);
434 }
435 });
436
437 /*** Event search addons. ***/
438 document.addEventListener('input', e => {
439 const el = e.target;
440 if ('lp-search-addons__input' === el.id) {
441 const keyword = el.value;
442 searchAddons(keyword);
443 }
444
445 // Events change input purchase code.
446 if (el.classList.contains('enter-purchase-code')) {
447 e.preventDefault();
448 const purchaseCode = el.value;
449 const elItemPurchase = el.closest('.lp-addon-item__purchase');
450 if (elItemPurchase) {
451 const input = elItemPurchase.querySelector('input[name=purchase-code]');
452 input.value = purchaseCode;
453 }
454 }
455 });
456 })();
457
458 /******/ })()
459 ;
460 //# sourceMappingURL=addons.js.map