PluginProbe
Autoptimize / 2.7.3
Autoptimize v2.7.3
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
autoptimize / classes / critcss-inc / admin_settings_queue.js.php

admin_settings_queue.js.php in Autoptimize 2.7.3, at classes/critcss-inc/admin_settings_queue.js.php

219 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * JS code to manage queue.
4 */
5
6 ?>
7 // Hide object text box
8 var queueOriginEl = document.getElementById('ao-ccss-queue' );
9 if (queueOriginEl) {
10 queueOriginEl.style.display = 'none';
11
12 // Get queue object and call table renderer
13 jQuery(document).ready(function() {
14 // Instance and parse queue object
15 var aoCssQueueRaw = document.getElementById('ao-ccss-queue').value;
16 var aoCssQueue = aoCssQueueRaw.indexOf('{"') === 0 ?
17 JSON.parse(aoCssQueueRaw) :
18 "";
19 var aoCssQueueLog = aoCssQueue === "" ?
20 "empty" :
21 aoCssQueue;
22 <?php
23 if ( $ao_ccss_debug ) {
24 echo "console.log( 'Queue Object:', aoCssQueueLog );\n";
25 }
26 ?>
27
28 // hook up "remove all jobs" button to the JS action.
29 jQuery("#removeAllJobs").click(function(){removeAllJobs();});
30
31 // Render queue table
32 drawQueueTable(aoCssQueue);
33
34 // Make queue table sortable if there are any elements
35 var queueBodyEl = jQuery('#queue > tr').length;
36 if (queueBodyEl > 0) {
37 jQuery('#queue-tbl').tablesorter({
38 sortList: [[0,0]],
39 headers: {6: {sorter: false}}
40 });
41 }
42 });
43 }
44
45 // Render the queue in a table
46 function drawQueueTable(queue) {
47 jQuery('#queue').empty();
48 rowNumber=0;
49 jQuery.each(queue, function(path, keys) {
50 // Prepare commom job values
51 ljid = keys.ljid;
52 targetArr = keys.rtarget.split('|' );
53 target = targetArr[1];
54 type = keys.ptype;
55 ctime = EpochToDate(keys.jctime);
56 rbtn = false;
57 dbtn = false;
58 hbtn = false;
59
60 // Prepare job statuses
61 if (keys.jqstat === 'NEW') {
62 // Status: NEW (N, sort order 1)
63 status = '<span class="hidden">1</span>N';
64 statusClass = 'new';
65 title = '<?php _e( 'New', 'autoptimize' ); ?> (' + ljid + ')';
66 buttons = '<?php _e( 'None', 'autoptimize' ); ?>';
67 } else if (keys.jqstat === 'JOB_QUEUED' || keys.jqstat === 'JOB_ONGOING') {
68 // Status: PENDING (P, sort order 2)
69 status = '<span class="hidden">2</span>P';
70 statusClass = 'pending';
71 title = '<?php _e( 'PENDING', 'autoptimize' ); ?> (' + ljid + ')';
72 buttons = '<?php _e( 'None', 'autoptimize' ); ?>';
73 } else if (keys.jqstat === 'JOB_DONE' && keys.jrstat === 'GOOD' && (keys.jvstat === 'WARN' || keys.jvstat === 'BAD')) {
74 // Status: REVIEW (R, sort order 5)
75 status = '<span class="hidden">5</span>R';
76 statusClass = 'review';
77 title = "<?php _e( 'REVIEW', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
78 buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>';
79 dbtn = true;
80 } else if (keys.jqstat === 'JOB_DONE') {
81 // Status: DONE (D, sort order 6)
82 status = '<span class="hidden">6</span>D';
83 statusClass = 'done';
84 title = '<?php _e( 'DONE', 'autoptimize' ); ?> (' + ljid + ')';
85 buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>';
86 dbtn = true;
87 } else if (keys.jqstat === 'JOB_FAILED' || keys.jqstat === 'STATUS_JOB_BAD' || keys.jqstat === 'INVALID_JWT_TOKEN' || keys.jqstat === 'NO_CSS' || keys.jqstat === 'NO_RESPONSE') {
88 // Status: ERROR (E, sort order 4)
89 status = '<span class="hidden">4</span>E';
90 statusClass = 'error';
91 title = "<?php _e( 'ERROR', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
92 buttons = '<span class="button-secondary" id="' + ljid + '_retry" title="<?php _e( 'Retry Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-update"></span></span><span class="button-secondary to-right" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>';
93 rbtn = true;
94 dbtn = true;
95 hbtn = true;
96 } else {
97 // Status: UNKNOWN (U, sort order 5)
98 status = '<span class="hidden">5</span>U';
99 statusClass = 'unknown';
100 title = "<?php _e( 'UNKNOWN', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
101 buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>';
102 dbtn = true;
103 hbtn = true;
104 }
105
106 // Prepare job finish time
107 if (keys.jftime === null) {
108 ftime = '<?php _e( 'N/A', 'autoptimize' ); ?>';
109 } else {
110 ftime = EpochToDate(keys.jftime);
111 }
112
113 // Append job entry
114 jQuery("#queue").append("<tr id='" + ljid + "' class='job " + statusClass + "'><td class='status'><span class='badge " + statusClass + "' title='<?php _e( 'Job status is ', 'autoptimize' ); ?>" + title + "'>" + status + "</span></td><td>" + target.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + path + "</td><td>" + type.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + ctime + "</td><td>" + ftime + "</td><td class='btn'>" + buttons + "</td></tr>");
115
116 // Attach button actions
117 if (rbtn) {
118 jQuery('#' + ljid + '_retry').click(function(){retryJob(queue, this.id, path);});
119 }
120 if (dbtn) {
121 jQuery('#' + ljid + '_remove').click(function(){delJob(queue, this.id, path);});
122 }
123 if (hbtn) {
124 jQuery('#' + ljid + '_help').click(function(){jid=this.id.split('_' );window.open('https://criticalcss.com/faq?aoid=' + jid[0], '_blank' );});
125 }
126 });
127 }
128
129 // Delete a job from the queue
130 function delJob(queue, jid, jpath) {
131 jid = jid.split('_' );
132 jQuery('#queue-confirm-rm').dialog({
133 resizable: false,
134 height: 180,
135 modal: true,
136 buttons: {
137 "<?php _e( 'Delete', 'autoptimize' ); ?>": function() {
138 delete queue[jpath];
139 updateQueue(queue);
140 jQuery(this).dialog('close' );
141 },
142 "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
143 jQuery(this).dialog('close' );
144 }
145 }
146 });
147 }
148
149 function removeAllJobs() {
150 jQuery( "#queue-confirm-rm-all" ).dialog({
151 resizable: false,
152 height:235,
153 modal: true,
154 buttons: {
155 "<?php _e( 'Delete all jobs?', 'autoptimize' ); ?>": function() {
156 queue=[];
157 updateQueue(queue);
158 jQuery( this ).dialog( "close" );
159 },
160 "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
161 jQuery( this ).dialog( "close" );
162 }
163 }
164 });
165 }
166
167 // Retry jobs with error
168 function retryJob(queue, jid, jpath) {
169 jid = jid.split('_' );
170 jQuery('#queue-confirm-retry').dialog({
171 resizable: false,
172 height: 180,
173 modal: true,
174 buttons: {
175 "<?php _e( 'Retry', 'autoptimize' ); ?>": function() {
176 <?php
177 if ( $ao_ccss_debug ) {
178 echo "console.log( 'SHOULD retry job:', jid[0], jpath );\n";
179 }
180 ?>
181 queue[jpath].jid = null;
182 queue[jpath].jqstat = 'NEW';
183 queue[jpath].jrstat = null;
184 queue[jpath].jvstat = null;
185 queue[jpath].jctime = (new Date).getTime() / 1000;
186 queue[jpath].jftime = null;
187 updateQueue(queue);
188 jQuery(this).dialog('close' );
189 },
190 "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
191 jQuery(this).dialog('close' );
192 }
193 }
194 });
195 }
196
197 // Refresh queue
198 function updateQueue(queue) {
199 document.getElementById('ao-ccss-queue').value=JSON.stringify(queue);
200 drawQueueTable(queue);
201 jQuery('#unSavedWarning').show();
202 document.getElementById('ao_title_and_button').scrollIntoView();
203 <?php
204 if ( $ao_ccss_debug ) {
205 echo "console.log('Updated Queue Object:', queue);\n";
206 }
207 ?>
208 }
209
210 // Convert epoch to date for job times
211 function EpochToDate(epoch) {
212 if (epoch < 10000000000)
213 epoch *= 1000;
214 var epoch = epoch + (new Date().getTimezoneOffset() * -1); //for timeZone
215 var sdate = new Date(epoch);
216 var ldate = sdate.toLocaleString();
217 return ldate;
218 }
219