PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.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 All 140 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.4.9, at assets/js/dist/admin/pages/sync-data.js

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