PluginProbe
Cooked – Recipe Management / 1.9.1
Cooked – Recipe Management v1.9.1
1.16.1 1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 All 37 releases
cooked / assets / admin / js / cooked-migration.js

cooked-migration.js in Cooked – Recipe Management 1.9.1, at assets/admin/js/cooked-migration.js

279 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2
3 $(document).ready(function() {
4
5 var $_CookedMigrationButton = $('#cooked-migration-button'),
6 $_CookedImportButton = $('#cooked-import-button'),
7 $_CookedMigrationProgress = $('#cooked-migration-progress'),
8 $_CookedMigrationProgressText = $('#cooked-migration-progress-text');
9
10 // Migration Button Exists?
11 if ($_CookedMigrationButton.length) {
12 $_CookedMigrationButton.on('click',function(e) {
13 e.preventDefault();
14
15 var thisButton = $(this),
16 confirm_migrate = confirm(cooked_js_vars.i18n_confirm_migrate_recipe);
17
18 if (confirm_migrate && !thisButton.hasClass('disabled')) {
19 thisButton.addClass('disabled').attr('disabled', true);
20 thisButton.hide();
21
22 var ajax__bulk_migrate_recipes = $.post(
23 cooked_js_vars.ajax_url,
24 {
25 action: 'cooked_get_migrate_ids'
26 },
27 function (json_recipe_ids) {
28 if (json_recipe_ids) {
29 var recipe_ids = JSON.parse(json_recipe_ids),
30 total_recipes = Object.keys(recipe_ids).length;
31
32 if (total_recipes > 0) {
33 cooked_migrate_recipes(json_recipe_ids, total_recipe);
34 }
35 }
36 }
37 );
38 }
39 });
40 }
41
42 // Import Button Exists?
43 if ($_CookedImportButton.length) {
44 $_CookedImportButton.on('click', function(e) {
45 e.preventDefault();
46
47 var thisButton = $(this),
48 import_type = thisButton.data('import-type'),
49 confirm_import = confirm(cooked_js_vars.i18n_confirm_import_recipes);
50
51 if (confirm_import && !thisButton.hasClass('disabled')) {
52 thisButton.addClass('disabled').attr('disabled', true);
53 thisButton.hide();
54
55 var ajax__bulk_import_recipes = $.post(
56 cooked_js_vars.ajax_url,
57 {
58 action: 'cooked_get_import_ids',
59 import_type: import_type
60 },
61 function (json_recipe_ids) {
62 if (json_recipe_ids) {
63 var recipe_ids = JSON.parse(json_recipe_ids),
64 total_recipes = Object.keys(recipe_ids).length;
65
66 if (total_recipes > 0) {
67 cooked_import_recipes(json_recipe_ids, total_recipes, import_type);
68 }
69 } else {
70 console.log('Something went wrong');
71 thisButton.addClass('disabled').attr('disabled', false);
72 thisButton.show();
73 }
74 },
75 );
76 }
77 });
78 }
79 });
80 })( jQuery );
81
82 if (typeof cookedDecimalAdjust != 'function') {
83 function cookedDecimalAdjust(type, value, exp) {
84 // If the exp is undefined or zero...
85 if (typeof exp === 'undefined' || +exp === 0) {
86 return Math[type](value);
87 }
88 value = +value;
89 exp = +exp;
90 // If the value is not a number or the exp is not an integer...
91 if (value === null || isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
92 return NaN;
93 }
94 // If the value is negative...
95 if (value < 0) {
96 return -cookedDecimalAdjust(type, -value, exp);
97 }
98 // Shift
99 value = value.toString().split('e');
100 value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
101 // Shift back
102 value = value.toString().split('e');
103 return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
104 }
105 }
106
107 if ( !Math.round10 ) {
108 Math.round10 = function(value, exp) {
109 var percent = cookedDecimalAdjust('round', value, exp);
110 return percent;
111 };
112 }
113
114 var cooked_recipe_migrate_counter = 0;
115 var progressIterations = 0;
116
117 function cooked_migrate_recipes(recipe_ids, total_recipes ) {
118 var temp_counter = 0,
119 total_counter = 0,
120 progress_percent = 0;
121
122 if (total_recipes > 0) {
123 var progress = jQuery( '#cooked-migration-progress' );
124 var progress_bar = progress.find( '.cooked-progress-bar' );
125 var progress_text = jQuery( '#cooked-migration-progress-text' );
126
127 if ( !progress.hasClass('cooked-active') ) {
128 progress.addClass('cooked-active');
129 progress_text.addClass('cooked-active');
130 progress_bar.css( { "width" : "0%" } );
131 }
132
133 var this_recipe_ids = JSON.parse( recipe_ids ),
134 this_total_recipe_ids = Object.keys(this_recipe_ids).length;
135
136 var formattedTotal = total_recipes;
137 formattedTotal.toLocaleString();
138
139 var ajax__bulk_migrate_recipes = jQuery.post(
140 cooked_js_vars.ajax_url,
141 {
142 action: 'cooked_migrate_recipes',
143 recipe_ids: recipe_ids
144 },
145 function( new_recipe_ids ) {
146 if ( new_recipe_ids && new_recipe_ids != 'false' && new_recipe_ids != false ){
147 var leftover_recipe_ids = JSON.parse( new_recipe_ids ),
148 leftover_recipes = Object.keys(leftover_recipe_ids).length;
149
150 cooked_recipe_migrate_counter = total_recipes - leftover_recipes;
151
152 var formattedTotal = total_recipes;
153 formattedTotal.toLocaleString();
154
155 var formattedComplete = cooked_recipe_migrate_counter;
156 formattedComplete.toLocaleString();
157
158 progress_percent = Math.round10( ( cooked_recipe_migrate_counter / total_recipes ) * 100, -1 );
159 if ( progress_percent < 2 ){ progress_percent = 2; }
160 progress_bar.css( { "width" : progress_percent + "%" } );
161
162 var remainingProgress = 100 - progress_percent;
163 var estimatedCompletionTime = Math.round( ( remainingProgress / progress_percent ) * progressIterations );
164 var estimatedHours, estimatedMinutes;
165 progressIterations += 1;
166
167 if ( progress_percent < 100 && progress_percent > 3 && isFinite( estimatedCompletionTime ) ){
168 estimatedHours = Math.floor(estimatedCompletionTime / 3600);
169 estimatedMinutes = Math.floor((estimatedCompletionTime / 60) % 60);
170 if ( estimatedHours >= 1 ){
171 progress_text.html( formattedComplete + " / " + formattedTotal + "<strong style='display:inline-block; float:right;'>" + estimatedHours + " hrs, " + estimatedMinutes + " mins " + cooked_js_vars.i18n_remaining + "</strong>" );
172 } else if ( estimatedMinutes >= 1 ){
173 progress_text.html( formattedComplete + " / " + formattedTotal + "<strong style='display:inline-block; float:right;'>" + estimatedMinutes + " mins " + cooked_js_vars.i18n_remaining + "</strong>" );
174 } else {
175 progress_text.text( formattedComplete + " / " + formattedTotal );
176 }
177
178 } else {
179 progress_text.text( formattedComplete + " / " + formattedTotal );
180 }
181
182 cooked_migrate_recipes( new_recipe_ids, total_recipes );
183 } else {
184 progress.hide();
185 progress_text.hide();
186
187 jQuery('.recipe-setting-block.migrate_button').find('h3').hide();
188 jQuery('.recipe-setting-block.migrate_button').find('p:nth-child(2)').hide();
189 jQuery('.recipe-setting-block.migrate_button').find('ul.cooked-admin-ul').hide();
190 jQuery('#cooked-migration-button').hide();
191 jQuery('#cooked-migration-completed').addClass('cooked-active');
192 }
193 }
194 )
195 }
196 }
197
198
199 function cooked_import_recipes(recipe_ids, total_recipes, import_type) {
200 var temp_counter = 0,
201 total_counter = 0,
202 progress_percent = 0;
203
204 if (total_recipes > 0) {
205 var progress = jQuery( '#cooked-import-progress' );
206 var progress_bar = progress.find( '.cooked-progress-bar' );
207 var progress_text = jQuery( '#cooked-import-progress-text' );
208
209 if (!progress.hasClass('cooked-active')) {
210 progress.addClass('cooked-active');
211 progress_text.addClass('cooked-active');
212 progress_bar.css( { "width" : "0%" } );
213 }
214
215 var this_recipe_ids = JSON.parse(recipe_ids),
216 this_total_recipe_ids = Object.keys(this_recipe_ids).length;
217
218 var formattedTotal = total_recipes;
219 formattedTotal.toLocaleString();
220
221 var ajax__bulk_migrate_recipes = jQuery.post(
222 cooked_js_vars.ajax_url,
223 {
224 action: 'cooked_import_recipes',
225 recipe_ids: recipe_ids,
226 import_type: import_type
227 },
228 function (new_recipe_ids) {
229 if (new_recipe_ids && new_recipe_ids != 'false' && new_recipe_ids != false) {
230 var leftover_recipe_ids = JSON.parse( new_recipe_ids ),
231 leftover_recipes = Object.keys(leftover_recipe_ids).length;
232
233 cooked_recipe_migrate_counter = total_recipes - leftover_recipes;
234
235 var formattedTotal = total_recipes;
236 formattedTotal.toLocaleString();
237
238 var formattedComplete = cooked_recipe_migrate_counter;
239 formattedComplete.toLocaleString();
240
241 progress_percent = Math.round10( ( cooked_recipe_migrate_counter / total_recipes ) * 100, -1 );
242 if ( progress_percent < 2 ) { progress_percent = 2; }
243 progress_bar.css({ "width" : progress_percent + "%" });
244
245 var remainingProgress = 100 - progress_percent;
246 var estimatedCompletionTime = Math.round( ( remainingProgress / progress_percent ) * progressIterations );
247 var estimatedHours, estimatedMinutes;
248 progressIterations += 1;
249
250 if ( progress_percent < 100 && progress_percent > 3 && isFinite( estimatedCompletionTime ) ) {
251 estimatedHours = Math.floor(estimatedCompletionTime / 3600);
252 estimatedMinutes = Math.floor((estimatedCompletionTime / 60) % 60);
253 if ( estimatedHours >= 1 ){
254 progress_text.html( formattedComplete + " / " + formattedTotal + "<strong style='display:inline-block; float:right;'>" + estimatedHours + " hrs, " + estimatedMinutes + " mins " + cooked_js_vars.i18n_remaining + "</strong>" );
255 } else if ( estimatedMinutes >= 1 ){
256 progress_text.html( formattedComplete + " / " + formattedTotal + "<strong style='display:inline-block; float:right;'>" + estimatedMinutes + " mins " + cooked_js_vars.i18n_remaining + "</strong>" );
257 } else {
258 progress_text.text( formattedComplete + " / " + formattedTotal );
259 }
260
261 } else {
262 progress_text.text( formattedComplete + " / " + formattedTotal );
263 }
264
265 cooked_import_recipes( new_recipe_ids, total_recipes, import_type );
266 } else {
267 progress.hide();
268 progress_text.hide();
269
270 jQuery('.recipe-setting-block.import_button').find('h3').hide();
271 jQuery('.recipe-setting-block.import_button').find('p:nth-child(2)').hide();
272 jQuery('.recipe-setting-block.import_button').find('.cooked-import-note').hide();
273 jQuery('.recipe-setting-block.import_button').find('ul.cooked-admin-ul').hide();
274 jQuery('#cooked-import-button').hide();
275 jQuery('#cooked-import-completed').addClass('cooked-active');
276 }
277 })
278 }
279 }