1/*!
2 * WHMCS Module Queue Javascript Functions
3 *
4 * @copyright Copyright (c) WHMCS Limited 2005-2016
5 * @license http://www.whmcs.com/license/ WHMCS Eula
6 */
7jQuery(document).ready(function() {
8 var moduleQueueRetryAll = jQuery('button.retry-all');
9 if (moduleQueueRetryAll.length) {
10 var processed = false,
11 queueTimeout = null,
12 count = 0;
13
14 jQuery('button.retry').click(function() {
15 processed = false;
16 var self = jQuery(this),
17 entryId = jQuery(this).data('entry-id'),
18 processingEntry = jQuery('div#processing-entry-' + entryId);
19
20 self.attr('disabled', 'disabled').addClass('disabled').find('i').addClass('fa-spin').end();
21 if (queueTimeout) {
22 processingEntry.find('div.queued').hide().end()
23 .find('div.processing').show().end();
24 } else {
25 processingEntry.find('div.messages').children('div').hide().end()
26 .find('div.processing').show().end().end()
27 .hide().removeClass('hidden').slideDown('fast');
28 }
29 var connection = WHMCS.http.jqClient.post(
30 window.location.pathname,
31 {
32 token: csrfToken,
33 action: 'retry',
34 id: entryId
35 },
36 null,
37 'json'
38 );
39
40 connection.done(function(data) {
41 if (data.error) {
42 processingEntry.find('div.processing').hide().end()
43 .find('div.error').find('span').html(data.message).parent().show().end();
44 jQuery('#last-error-' + entryId).html(data.errorMessage);
45 jQuery('div#entry-' + entryId).find('small.last-attempt').find('span').html(data.lastAttempt);
46 self.removeAttr('disabled').removeClass('disabled').find('i').removeClass('fa-spin').end();
47 count++;
48 }
49 if (data.completed) {
50 jQuery('div#entry-' + entryId).find('div.action-buttons').find('button').removeClass('retry')
51 .attr('disabled', 'disabled').addClass('disabled')
52 .find('i.fa-spin').removeClass('fa-spin').end();
53 processingEntry.find('div.processing').slideUp('fast').end()
54 .find('div.success').slideDown('fast').end();
55 }
56 });
57
58 connection.always(function() {
59 processed = true;
60 });
61 });
62
63 jQuery('button.resolve').click(function() {
64 var self = jQuery(this),
65 entryId = jQuery(this).data('entry-id'),
66 processingEntry = jQuery('div#processing-entry-' + entryId);
67
68 self.attr('disabled', 'disabled').addClass('disabled');
69
70 processingEntry.find('div.messages').children('div').hide().end()
71 .find('div.processing').show().end().end()
72 .hide().removeClass('hidden').slideDown('fast');
73
74 var connection = WHMCS.http.jqClient.post(
75 window.location.pathname,
76 {
77 token: csrfToken,
78 action: 'resolve',
79 id: entryId
80 },
81 null,
82 'json'
83 );
84
85 connection.done(function(data) {
86 if (data.completed) {
87 jQuery('div#entry-' + entryId).find('div.action-buttons').find('button').removeClass('retry')
88 .attr('disabled', 'disabled').addClass('disabled').end();
89 processingEntry.find('div.processing').slideUp('fast').end()
90 .find('div.success').find('span').html(data.message).parent().slideDown('fast').end();
91 } else {
92 processingEntry.find('div.processing').slideUp('fast').end()
93 .find('div.error').find('span').html(data.message).parent().slideDown('fast').end();
94 self.removeAttr('disabled').removeClass('disabled');
95 }
96
97 });
98 });
99
100 moduleQueueRetryAll.click(function () {
101 jQuery(this).attr('disabled', 'disabled').addClass('disabled')
102 .find('i').addClass('fa-spin').end();
103 var items = jQuery('button.retry');
104 processed = true;
105 count = 0;
106
107 items.each(function(index) {
108 var entryId = jQuery(this).data('entry-id');
109 jQuery('div#processing-entry-' + entryId).find('div.messages').children('div').hide().end()
110 .find('div.queued').show().end().end()
111 .hide().removeClass('hidden').slideDown('fast');
112 });
113
114 queueTimeout = setTimeout(nextClick, 1000);
115 });
116
117 function nextClick()
118 {
119 if (processed) {
120 var button = jQuery('button.retry:eq(' + count + ')');
121 if (button.length) {
122 button.click();
123 } else {
124 clearTimeout(queueTimeout);
125 queueTimeout = null;
126 moduleQueueRetryAll.removeAttr('disabled').removeClass('disabled')
127 .find('i').removeClass('fa-spin').end();
128 return;
129 }
130 }
131 queueTimeout = setTimeout(nextClick, 1000);
132 }
133 }
134});
135