1/*!
2 * WHMCS MarketConnect Admin JS Functions
3 *
4 * @copyright Copyright (c) WHMCS Limited 2005-2022
5 * @license https://www.whmcs.com/license/ WHMCS Eula
6 */
7jQuery(document).ready(function() {
8 jQuery(document).on('click', '#btnMcServiceRefresh', function(e) {
9 e.preventDefault();
10 var btn = $(this);
11 btn.find('i').addClass('fa-spin');
12 WHMCS.http.jqClient.post({
13 url: 'clientsservices.php',
14 data: btn.attr('href') + '&token=' + csrfToken,
15 success: function (data) {
16 $('#mcServiceManagementWrapper').replaceWith(data.statusOutput);
17 btn.find('i').removeClass('fa-spin');
18 }
19 });
20 });
21 jQuery(document).on('click', '#btnMcCancelOrder', function(e) {
22 swal({
23 title: 'Are you sure?',
24 html: true,
25 text: 'Cancelling this order will result in the service immediately ceasing to function.<br><br>You will automatically receive a credit if within the credit period. <a href="https://go.whmcs.com/1281/marketconnect-credit-terms" target="_blank">See credit period terms</a>',
26 type: 'warning',
27 showCancelButton: true,
28 confirmButtonText: 'Yes, cancel it',
29 cancelButtonText: 'No'
30 },
31 function(){
32 runModuleCommand('terminate');
33 });
34 });
35 jQuery(document).on('click', '#mcServiceManagementWrapper .btn:not(.open-modal,.btn-refresh,.btn-cancel)', function(e) {
36 e.preventDefault();
37 $('#growls').fadeOut('fast').remove();
38 $('.successbox,.errorbox').slideUp('fast').remove();
39 var button = $(this);
40 var request = button.attr('href');
41 var buttonIcon = button.find('i');
42 var iconState = buttonIcon.attr('class');
43
44 // If button is disabled, don't execute action
45 if (button.attr('disabled') === 'disabled') {
46 return;
47 }
48
49 buttonIcon.removeClass().addClass('fas fa-spin fa-spinner');
50
51 WHMCS.http.jqClient.post('clientsservices.php', request + '&token=' + csrfToken, function (data) {
52 if (data.redirectUrl) {
53 window.open(data.redirectUrl);
54 } else if (data.growl) {
55 if (data.growl.type == 'error') {
56 $.growl.error({ title: '', message: data.growl.message });
57 } else {
58 $.growl.notice({ title: '', message: data.growl.message });
59 $('#btnMcServiceRefresh').click();
60 }
61 } else {
62 $.growl.error({ title: '', message: 'Unknown response' });
63 console.error('[WHMCS] Unknown response: ' + JSON.stringify(data));
64 }
65 }, 'json').fail(function (xhr) {
66 var response = (xhr.responseText != '' ? xhr.responseText : xhr.statusText);
67 $.growl.error({ title: '', message: response })
68 }).always(function (xhr) {
69 buttonIcon.removeClass().addClass(iconState);
70 });
71 })
72 .on('click', '.feature-menu-item', function(e) {
73 e.preventDefault();
74 var self = jQuery(this),
75 name = self.data('name'),
76 shownMenu = jQuery('.feature-menu-item.shown'),
77 shownItem = jQuery('.feature-info-item.shown'),
78 target = jQuery('.feature-info-item[data-name="' + name + '"]');
79
80 shownMenu.removeClass('shown');
81 self.addClass('shown');
82 shownItem.slideUp('fast', function() {
83 jQuery(this).removeClass('shown');
84 target.hide().addClass('shown').slideDown('fast');
85 })
86 });
87});
88