PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.7
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.3.7, at assets/js/dist/admin/addons.js

458 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 const elAddonItem = el.closest( '.lp-addon-item' );
296 const idLabel = el.getAttribute( 'for' );
297 const elInput = document.querySelector( `#${ idLabel }` );
298 const action = elInput.getAttribute( 'data-action' );
299 const addon = dataAddons[ elAddonItem.dataset.slug ];
300 const addonSlug = addon.slug;
301 const parent = el.closest( '.lp-toggle-switch' );
302 const label = parent.querySelector( `label[for=${ idLabel }]` );
303 const dashicons = parent.querySelector( '.dashicons-update' );
304 dashicons.style.display = 'inline-block';
305 label.style.display = 'none';
306 const data = { action, addon };
307 addonsAction( data, function( status, message, data ) {
308 const elAddon = document.querySelector( `#${ addonSlug }` );
309 if ( elAddon ) {
310 const parent = elAddon.closest( '.lp-toggle-switch' );
311 if ( parent ) {
312 const dashicons = parent.querySelector( '.dashicons-update' );
313 dashicons.style.display = 'none';
314 if ( action === 'deactivate' ) {
315 elAddon.setAttribute( 'data-action', 'activate' );
316 } else if ( action === 'activate' ) {
317 elAddon.setAttribute( 'data-action', 'deactivate' );
318 }
319 const label = parent.querySelector( `label[for=${ addonSlug }]` );
320 label.style.display = 'inline-flex';
321 }
322 }
323 if ( status === 'success' ) {
324 if ( action === 'deactivate' ) {
325 elAddonItem.classList.remove( 'activated' );
326 }
327 if ( action === 'activate' ) {
328 elAddonItem.classList.add( 'activated' );
329 }
330 }
331 } );
332 }*/
333
334 // Events actions: install, update, delete.
335 if (el.closest('.btn-addon-action')) {
336 el = el.closest('.btn-addon-action');
337 e.preventDefault();
338 el.classList.add('handling');
339 let purchaseCode = '';
340 const elAddonItem = el.closest('.lp-addon-item');
341 const addon = dataAddons[elAddonItem.dataset.slug];
342 const action = el.dataset.action;
343 const elItemPurchase = elAddonItem.querySelector('.lp-addon-item__purchase');
344 //const elToggleSwitchInput = elAddonItem.querySelector( '.lp-toggle-switch-input' );
345
346 if (action === 'purchase') {
347 elItemPurchase.style.display = 'block';
348 elItemPurchase.querySelector('.purchase-install').style.display = 'flex';
349 return;
350 } else if (action === 'update-purchase-code') {
351 elItemPurchase.querySelector('.purchase-update').style.display = 'flex';
352 elItemPurchase.style.display = 'block';
353 return;
354 } else if (action === 'buy') {
355 const link = el.dataset.link;
356 window.open(link, '_blank');
357 return;
358 } else if (action === 'cancel') {
359 elItemPurchase.style.display = 'none';
360 return;
361 } else if (action === 'install') {
362 if (el.dataset.link) {
363 el.classList.remove('handling');
364 const link = el.dataset.link;
365 window.open(link, '_blank');
366 return;
367 }
368 }
369
370 // Send request to server.
371 if (elItemPurchase) {
372 purchaseCode = elItemPurchase.querySelector('input[name=purchase-code]').value;
373 }
374 const data = {
375 purchase_code: purchaseCode,
376 action,
377 addon
378 };
379 addonsAction(data, function (status, message, data) {
380 if (status === 'success') {
381 if (action === 'install') {
382 elAddonItem.classList.add('installed', 'activated');
383 elAddonItem.classList.remove('not_installed');
384 elItemPurchase.style.display = 'none';
385 /*elToggleSwitchInput.setAttribute( 'checked', 'checked' );
386 elToggleSwitchInput.setAttribute( 'data-action', 'deactivate' );*/
387 const elNavInstalled = document.querySelector('.nav-tab[data-tab=installed] span');
388 elNavInstalled.textContent = parseInt(elNavInstalled.textContent) + 1;
389 const elNavNoInstalled = document.querySelector('.nav-tab[data-tab=not_installed] span');
390 elNavNoInstalled.textContent = parseInt(elNavNoInstalled.textContent) - 1;
391 elItemPurchase.querySelector('.purchase-install').style.display = 'none';
392 elItemPurchase.querySelector('.purchase-update').querySelector('.enter-purchase-code').value = purchaseCode;
393 } else if (action === 'update') {
394 const elAddonVersionCurrent = elAddonItem.querySelector('.addon-version-current');
395 elAddonVersionCurrent.innerHTML = addon.version;
396 elAddonItem.classList.remove('update');
397 } else if (action === 'activate') {
398 elAddonItem.classList.add('activated');
399 } else if (action === 'deactivate') {
400 elAddonItem.classList.remove('activated');
401 } else if (action === 'update-purchase') {
402 elItemPurchase.style.display = 'none';
403 }
404 }
405 el.classList.remove('handling');
406 });
407 }
408 if (el.classList.contains('nav-tab')) {
409 e.preventDefault();
410 const elTabs = document.querySelectorAll('.nav-tab');
411 elTabs.forEach(function (elTab) {
412 elTab.classList.remove('nav-tab-active');
413 });
414 el.classList.add('nav-tab-active');
415 const tabName = el.dataset.tab;
416 const elAddonItems = elAddonsPage.querySelectorAll('.lp-addon-item');
417 const elSearch = elAddonsPage.querySelector('#lp-search-addons__input');
418 elSearch.value = '';
419 urlParams.set('tab', tabName);
420 window.history.pushState({}, '', `${window.location.pathname}?${urlParams.toString()}`);
421 let totalItems = 0;
422 elAddonItems.forEach(elAddonItem => {
423 elAddonItem.classList.remove('search-not-found');
424 if ('all' === tabName || elAddonItem.classList.contains(tabName)) {
425 elAddonItem.classList.remove('hide');
426 totalItems++;
427 } else {
428 elAddonItem.classList.add('hide');
429 }
430 });
431 setGridItems(totalItems);
432 }
433 });
434
435 /*** Event search addons. ***/
436 document.addEventListener('input', e => {
437 const el = e.target;
438 if ('lp-search-addons__input' === el.id) {
439 const keyword = el.value;
440 searchAddons(keyword);
441 }
442
443 // Events change input purchase code.
444 if (el.classList.contains('enter-purchase-code')) {
445 e.preventDefault();
446 const purchaseCode = el.value;
447 const elItemPurchase = el.closest('.lp-addon-item__purchase');
448 if (elItemPurchase) {
449 const input = elItemPurchase.querySelector('input[name=purchase-code]');
450 input.value = purchaseCode;
451 }
452 }
453 });
454 })();
455
456 /******/ })()
457 ;
458 //# sourceMappingURL=addons.js.map