PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / trunk
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses vtrunk
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 / src / js / admin / utils-admin.js

utils-admin.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses trunk, at assets/src/js/admin/utils-admin.js

121 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Library run on Admin
3 *
4 * @since 4.2.6.9
5 * @version 1.0.1
6 */
7 import * as Utils from '../utils.js';
8 import TomSelect from 'tom-select';
9 import Api from '../api.js';
10
11 const AdminUtilsFunctions = {
12 buildTomSelect( elTomSelect, options, fetchAPI, dataSend, callBackHandleData ) {
13 if ( ! elTomSelect ) {
14 return;
15 }
16
17 const optionDefault = {
18 plugins: {
19 remove_button: {
20 title: 'Remove this item',
21 },
22 dropdown_input: {},
23 },
24 onInitialize() {
25 },
26 onItemAdd( e ) {
27 // Get list without current item.
28 if ( fetchAPI ) {
29 const selectedOptions = Array.from( elTomSelect.selectedOptions );
30 const selectedValues = selectedOptions.map( ( option ) => option.value );
31 selectedValues.push( e );
32 dataSend.id_not_in = selectedValues.join( ',' );
33
34 fetchAPI( '', dataSend, callBackHandleData );
35 }
36 },
37 };
38
39 if ( fetchAPI ) {
40 optionDefault.load = ( keySearch, callbackTom ) => {
41 const selectedOptions = Array.from( elTomSelect.selectedOptions );
42 const selectedValues = selectedOptions.map( ( option ) => option.value );
43 dataSend.id_not_in = selectedValues.join( ',' );
44
45 fetchAPI(
46 keySearch,
47 dataSend,
48 AdminUtilsFunctions.callBackTomSelectSearchAPI( callbackTom, callBackHandleData )
49 );
50 };
51 }
52
53 options = { ...optionDefault, ...options };
54 const items_selected = options.options;
55 /*if ( options?.options?.length > 20 ) {
56 const chunkSize = 20;
57 const length = options.options.length;
58 let i = 0;
59 const chunkedOptions = { ...options };
60 chunkedOptions.options = items_selected.slice( i, chunkSize );
61
62 const tomSelect = new TomSelect( elTomSelect, chunkedOptions );
63 i += chunkSize;
64
65 const interval = setInterval( () => {
66 if ( i > ( length - 1 ) ) {
67 clearInterval( interval );
68 }
69
70 const optionsSlice = items_selected.slice( i, i + chunkSize );
71 i += chunkSize;
72 tomSelect.addOptions( optionsSlice );
73 tomSelect.setValue( options.items );
74 }, 200 );
75
76 return tomSelect;
77 }*/
78
79 return new TomSelect( elTomSelect, options );
80 },
81 callBackTomSelectSearchAPI( callbackTom, callBackHandleData ) {
82 return {
83 success: ( response ) => {
84 const options = callBackHandleData.success( response );
85 callbackTom( options );
86 },
87 };
88 },
89 fetchCourses( keySearch = '', dataSend = {}, callback ) {
90 const url = Api.admin.apiSearchCourses;
91 dataSend.search = keySearch;
92 const params = {
93 headers: {
94 'Content-Type': 'application/json',
95 'X-WP-Nonce': lpDataAdmin.nonce,
96 },
97 method: 'POST',
98 body: JSON.stringify( dataSend ),
99 };
100
101 Utils.lpFetchAPI( url, params, callback );
102 },
103 fetchUsers( keySearch = '', dataSend = {}, callback ) {
104 const url = Api.admin.apiSearchUsers;
105 dataSend.search = keySearch;
106 const params = {
107 headers: {
108 'Content-Type': 'application/json',
109 'X-WP-Nonce': lpDataAdmin.nonce,
110 },
111 method: 'POST',
112 body: JSON.stringify( dataSend ),
113 };
114
115 Utils.lpFetchAPI( url, params, callback );
116 },
117 };
118
119 export { Utils, AdminUtilsFunctions, Api };
120
121