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

sync-data.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9, at assets/js/dist/admin/pages/sync-data.js

288 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 var __webpack_exports__ = {};
3 /*!*****************************************************!*\
4 !*** ./assets/src/apps/js/admin/pages/sync-data.js ***!
5 \*****************************************************/
6 (function ($) {
7 const Sync_Base = {
8 id: 'sync-base',
9 syncing: false,
10 items: false,
11 completed: false,
12 callback: null,
13 methodGetItems: '',
14 itemsKey: '',
15 chunkSize: 50,
16
17 sync(callback) {
18 if (this.syncing) {
19 return;
20 }
21
22 this.callback = callback;
23
24 if (this.items === false) {
25 this.get_items();
26 } else if (!this.dispatch()) {
27 this.completed = true;
28 this.callToCallback();
29 return;
30 }
31
32 this.syncing = true;
33 },
34
35 init() {
36 this.syncing = false;
37 this.items = false;
38 this.completed = false;
39 },
40
41 is_completed() {
42 return this.completed;
43 },
44
45 dispatch() {
46 const that = this,
47 items = this.items ? this.items.splice(0, this.chunkSize) : false;
48
49 if (!items || items.length === 0) {
50 return false;
51 }
52
53 $.ajax({
54 url: '',
55 data: {
56 'lp-ajax': this.id,
57 sync: items
58 },
59 method: 'post',
60
61 success(response) {
62 response = LP.parseJSON(response);
63 that.syncing = false;
64
65 if (response.result !== 'success') {
66 that.completed = true;
67 }
68
69 that.callToCallback();
70
71 if (that.is_completed()) {
72 return;
73 }
74
75 that.sync(that.callback);
76 }
77
78 });
79 return true;
80 },
81
82 callToCallback() {
83 this.callback && this.callback.call(this);
84 },
85
86 get_items() {
87 const that = this;
88 $.ajax({
89 url: '',
90 data: {
91 'lp-ajax': this.id,
92 sync: this.methodGetItems
93 },
94
95 success(response) {
96 that.syncing = false;
97 response = LP.parseJSON(response);
98
99 if (response[that.itemsKey]) {
100 that.items = response[that.itemsKey];
101 that.sync(that.callback);
102 } else {
103 that.completed = true;
104 that.items = [];
105 that.callToCallback();
106 }
107 }
108
109 });
110 }
111
112 };
113 const Sync_Course_Orders = $.extend({}, Sync_Base, {
114 id: 'sync-course-orders',
115 methodGetItems: 'get-courses',
116 itemsKey: 'courses'
117 });
118 const Sync_User_Courses = $.extend({}, Sync_Base, {
119 id: 'sync-user-courses',
120 methodGetItems: 'get-users',
121 itemsKey: 'users',
122 chunkSize: 500
123 });
124 const Sync_User_Orders = $.extend({}, Sync_Base, {
125 id: 'sync-user-orders',
126 methodGetItems: 'get-users',
127 itemsKey: 'users',
128 chunkSize: 500
129 });
130 const Sync_Course_Final_Quiz = $.extend({}, Sync_Base, {
131 id: 'sync-course-final-quiz',
132 methodGetItems: 'get-courses',
133 itemsKey: 'courses',
134 chunkSize: 500
135 });
136 const Sync_Remove_Older_Data = $.extend({}, Sync_Base, {
137 id: 'sync-remove-older-data',
138 methodGetItems: 'remove-older-data',
139 itemsKey: '_nothing_here',
140 chunkSize: 500
141 });
142 const Sync_Calculate_Course_Results = $.extend({}, Sync_Base, {
143 id: 'sync-calculate-course-results',
144 methodGetItems: 'get-users',
145 itemsKey: 'users',
146 chunkSize: 1
147 });
148 window.LP_Sync_Data = {
149 syncs: [],
150 syncing: 0,
151 options: {},
152
153 start(options) {
154 this.syncs = [];
155 this.options = $.extend({
156 onInit() {},
157
158 onStart() {},
159
160 onCompleted() {},
161
162 onCompletedAll() {}
163
164 }, options || {});
165
166 if (!this.get_syncs()) {
167 return;
168 }
169
170 this.reset();
171 this.options.onInit.call(this);
172
173 var that = this,
174 syncing = 0,
175 totalSyncs = this.syncs.length,
176 syncCallback = function ($sync) {
177 if ($sync.is_completed()) {
178 syncing++;
179 that.options.onCompleted.call(that, $sync);
180
181 if (syncing >= totalSyncs) {
182 that.options.onCompletedAll.call(that);
183 return;
184 }
185
186 that.sync(syncing, syncCallback);
187 }
188 };
189
190 this.sync(syncing, syncCallback);
191 },
192
193 reset() {
194 for (const sync in this.syncs) {
195 try {
196 this[this.syncs[sync]].init();
197 } catch (e) {}
198 }
199 },
200
201 sync(sync, callback) {
202 const that = this,
203 $sync = this[this.syncs[sync]];
204 that.options.onStart.call(that, $sync);
205 $sync.sync(function () {
206 callback.call(that, $sync);
207 });
208 },
209
210 get_syncs() {
211 const syncs = $('input[name^="lp-repair"]:checked').serializeJSON()['lp-repair'];
212
213 if (!syncs) {
214 return false;
215 }
216
217 for (let sync in syncs) {
218 if (syncs[sync] !== 'yes') {
219 continue;
220 }
221
222 sync = sync.replace(/[-]+/g, '_');
223
224 if (!this[sync]) {
225 continue;
226 }
227
228 this.syncs.push(sync);
229 }
230
231 return this.syncs;
232 },
233
234 get_sync(id) {
235 id = id.replace(/[-]+/g, '_');
236 return this[id];
237 },
238
239 sync_course_orders: Sync_Course_Orders,
240 sync_user_orders: Sync_User_Orders,
241 sync_user_courses: Sync_User_Courses,
242 sync_course_final_quiz: Sync_Course_Final_Quiz,
243 sync_remove_older_data: Sync_Remove_Older_Data,
244 sync_calculate_course_results: Sync_Calculate_Course_Results
245 };
246 $(document).ready(function () {
247 function initSyncs() {
248 const $chkAll = $('#learn-press-check-all-syncs'),
249 $chks = $('#learn-press-syncs').find('[name^="lp-repair"]');
250 $chkAll.on('click', function () {
251 $chks.prop('checked', this.checked);
252 });
253 $chks.on('click', function () {
254 $chkAll.prop('checked', $chks.filter(':checked').length === $chks.length);
255 });
256 }
257
258 initSyncs();
259 }).on('click', '.lp-button-repair', function () {
260 function getInput(sync) {
261 return $('ul#learn-press-syncs').find('input[name*="' + sync + '"]');
262 }
263
264 LP_Sync_Data.start({
265 onInit() {
266 $('ul#learn-press-syncs').children().removeClass('syncing synced');
267 $('.lp-button-repair').prop('disabled', true);
268 },
269
270 onStart($sync) {
271 getInput($sync.id).closest('li').addClass('syncing');
272 },
273
274 onCompleted($sync) {
275 getInput($sync.id).closest('li').removeClass('syncing').addClass('synced');
276 },
277
278 onCompletedAll() {
279 $('ul#learn-press-syncs').children().removeClass('syncing synced');
280 $('.lp-button-repair').prop('disabled', false);
281 }
282
283 });
284 });
285 })(jQuery);
286 /******/ })()
287 ;
288 //# sourceMappingURL=sync-data.js.map