');
if (item.color) {
newDiv.css('background-color', item.color);
}
newDiv.append(
$('
').attr('class', 'name').text(item.name)
)
return newDiv;
};
var selector ='.selectize-service-search';
var selectElement = jQuery(selector);
var module = this;
var selectized = [];
selectElement.each(function (){
var element = $(this);
var configuration = {
'valueField': 'id',
'labelField': 'name',
'render': {
item: itemDecorator
},
'preload': true,
'load': module.builder.onLoadEvent(
element.data('search-url'),
function (query) {
return {
token: csrfToken,
search: query
};
}
)
};
var instance = module.services(selector, undefined, configuration);
return selectized.push(instance);
});
if (selectized.length > 1) {
return selectized;
}
return selectized[0];
};
this.productSearch = function() {
var selector = '.selectize-product-search',
selectElement = jQuery(selector),
module = this,
selectized = [],
itemDecorator = function(data, escape) {
var newDiv = jQuery(''),
newSpan = jQuery('
').attr('class', 'name').text(escape(data.name));
newDiv.append(newSpan);
return newDiv;
};
selectElement.each(function() {
var element = jQuery(this),
configuration = {
'valueField': 'id',
'labelField': 'name',
'render': {
item: itemDecorator
},
optgroupField: 'groupid',
optgroupLabelField: 'name',
optgroupValueField: 'id',
'preload': true,
'load': module.builder.onLoadEvent(
element.data('search-url'),
function (query) {
return {
token: csrfToken,
search: query,
};
}
),
'onLoad': function(data) {
var instance = this,
listItems = jQuery('.product-recommendations-wrapper li');
data.forEach(function(item) {
if (listItems.find('input[value="' + item.id + '"]').length) {
instance.removeOption(item.id);
return;
}
instance.addOptionGroup(item.groupid, {
$order: item.order,
name: item.group,
});
});
},
'onBlur': function() {
this.clear();
},
'onItemAdd': function(value) {
var listItems = jQuery('.product-recommendations-wrapper li'),
existingItems = listItems.find('input[value="' + value + '"]').length,
recommendationAlert = jQuery('div.recommendation-alert'),
isChanged = false;
if (value && existingItems < 1) {
var newSelection = jQuery(".selectize-dropdown-content div[data-value|='" + value + "']"),
clonableItem = jQuery('.product-recommendations-wrapper .clonable-item'),
parentList = clonableItem.closest('ul'),
clonedItem = clonableItem.clone().removeClass('hidden clonable-item');
clonedItem.find('a span.recommendation-name').text(
newSelection.siblings('div.optgroup-header').text() +
' - ' +
newSelection.children("span.name").text()
);
jQuery('').attr({
type: 'hidden',
name: 'productRecommendations[]',
value: value
}).appendTo(clonedItem);
clonedItem.find('input').val(value);
clonedItem.appendTo(parentList);
instance.removeOption(value);
isChanged = true;
}
if (listItems.length > 0) {
jQuery('.product-recommendations-wrapper .placeholder-list-item').addClass('hidden');
isChanged = true;
}
if (isChanged && recommendationAlert.not(':visible')) {
jQuery('.recommendation-alert').removeClass('hidden');
}
}
},
instance = module.products(selector, undefined, configuration);
return selectized.push(instance);
});
if (selectized.length > 1) {
return selectized;
}
return selectized[0];
};
/**
* Generic selectize of users
* - no 'change' or 'load' events
*
* @param selector
* @param options
* @param configuration
* @returns {Selectize}
*/
this.clients = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
WHMCS.selectize.optionDecorator.client,
configuration
);
instance.settings.searchField = ['name', 'email', 'companyname'];
return instance;
};
this.users = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
WHMCS.selectize.optionDecorator.user,
configuration
);
instance.settings.searchField = ['name', 'email'];
return instance;
};
this.services = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
WHMCS.selectize.optionDecorator.service,
configuration
);
instance.settings.searchField = ['name', 'noResults'];
return instance;
};
this.billingContacts = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
WHMCS.selectize.optionDecorator.billingContact,
configuration
);
instance.settings.searchField = ['name', 'email', 'companyname', 'address'];
return instance;
};
this.payMethods = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
WHMCS.selectize.optionDecorator.payMethod,
configuration
);
instance.settings.searchField = ['description', 'shortAccountNumber', 'type', 'payMethodType'];
return instance;
};
this.products = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
WHMCS.selectize.optionDecorator.product,
configuration
);
instance.settings.searchField = ['id', 'name', 'noResults'];
return instance;
};
this.html = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
function(item, escape) {
return '' + item.html + '
';
},
configuration
);
instance.settings.searchField = ['html'];
return instance;
};
this.simple = function (selector, options, configuration) {
var instance = this.register(
selector,
options,
function(item, escape) {
return '' + item.value + '
';
},
configuration
);
instance.settings.searchField = ['value'];
return instance;
};
/**
* Arguments:
* selector
* CSS selector of the ');
$('#modalAjaxSubmit').before('Back');
openModal('wizard.php?wizard=GettingStarted', '', 'Getting Started Wizard', 'modal-lg', 'modal-wizard modal-setup-wizard', 'Next', '', '',true);
}
function addInvoicePayment() {
addingPayment = true;
jQuery('#modalDuplicateTransaction').modal('hide');
var post = WHMCS.http.jqClient.post(
WHMCS.adminUtils.getAdminRouteUrl('/billing/invoice/' + thisInvoiceId + '/add-payment'),
jQuery('#addPayment').serialize()
);
post.done(function (data) {
if (data.redirectUri) {
window.location = data.redirectUri;
}
});
}
function cancelAddPayment() {
jQuery('#paymentLoading').fadeOut('fast', function() {
jQuery('#paymentText').fadeIn('fast');
jQuery('#btnAddPayment').removeAttr('disabled');
});
jQuery('#modalDuplicateTransaction').modal('hide');
}
function openFeatureHighlights() {
openModal('whatsnew.php?modal=1', '', 'What\'s new in Version ...', '', 'modal-feature-highlights', '', '', '', true);
}
/**
* Submit the first form that exists within a given container.
*
* @param {string} containerId The ID name of the container
*/
function autoSubmitFormByContainer(containerId) {
if (typeof noAutoSubmit === "undefined" || noAutoSubmit === false) {
jQuery("#" + containerId).find("form:first").submit();
}
}
/**
* Sluggify a text string.
*/
function slugify(text) {
var search = "āæåãàáäâảẩấćčçđẽèéëêếēėęīįìíïîłńñœøōõòóöôốớơśšūùúüûưÿžźż·/_,:;–"; // contains Unicode dash
var replace = "aaaaaaaaaaacccdeeeeeeeeeiiiiiilnnooooooooooossuuuuuuyzzz-------";
for (var i = 0, l = search.length; i < l; i++) {
text = text.replace(new RegExp(search.charAt(i), 'g'), replace.charAt(i));
}
return text
.toString()
.toLowerCase()
.trim()
.replace(/\s+/g, '-')
.replace(/&/g, '-and-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-');
}
function generateBootstrapSwitches()
{
jQuery('.slide-toggle').bootstrapSwitch();
jQuery('.slide-toggle-mini').bootstrapSwitch({
size: 'mini'
});
}
function submitForm(frmId, addTarget) {
var formTarget = jQuery('#' + frmId);
if (addTarget) {
formTarget.attr('target', '_blank');
} else {
formTarget.removeAttr('target');
}
formTarget.submit();
}
function reverseCommissionConfirm(totalDue, remainingBalance) {
var amountValue,
form = jQuery('form#transactions'),
formData = form.serializeArray();
amountValue = formData.find(function (object) {
return object['name'] === 'amount';
}).value;
if (!amountValue) {
var transidValue = formData.find(function (object) {
return object['name'] === 'transid';
}).value;
amountValue = jQuery('form#transactions select#transid option[value="' + transidValue + '"]').data('amount');
}
if ((remainingBalance + amountValue) < totalDue) {
jQuery('#modalReverseAffiliateCommission').modal().show();
return false;
}
jQuery(
'',
{
type: 'hidden',
name: 'reverseCommission',
value: 'true'
}
).appendTo(form);
form.removeAttr('onsubmit').submit();
}
function reverseCommissionSubmit(reverseCommission = false) {
var form = jQuery('form#transactions');
if (reverseCommission) {
jQuery(
'',
{
type: 'hidden',
name: 'reverseCommission',
value: 'true'
}
).appendTo(form);
}
form.removeAttr('onsubmit').submit();
}
function autosizeTextarea(el) {
var init = function(el) {
var elements = document.querySelectorAll(el)
for (var i = 0; i < elements.length; i++) {
elements[i].style.overflowX = "hidden"
elements[i].style.height = calcHeight(elements[i])
elements[i].addEventListener("input", onInput)
}
};
var onInput = function() {
this.style.height = "auto"
this.style.height = calcHeight(this)
};
var calcHeight = function(el) {
return (el.scrollHeight + parseFloat(jQuery(el).css("borderTopWidth")) + parseFloat(jQuery(el).css("borderBottomWidth"))) + "px"
};
init(el)
}
function calculateInvoiceTotal(invoiceId, invoiceItems) {
return WHMCS.http.jqClient.post(
WHMCS.adminUtils.getAdminRouteUrl('/invoice-total/calculate'),
{
invoiceId: invoiceId,
items: invoiceItems,
token: csrfToken
}
);
}
function destroyInvoiceItem(id) {
return WHMCS.http.jqClient.post(
WHMCS.adminUtils.getAdminRouteUrl('/invoice-item/destroy'),
{
invoiceItemId: id,
token: csrfToken
}
);
}
/*!
* WHMCS Ajax Driven Modal Framework
*
* @copyright Copyright (c) WHMCS Limited 2005-2021
* @license https://www.whmcs.com/license/ WHMCS Eula
*/
var ajaxModalSubmitEvents = [],
ajaxModalPostSubmitEvents = [];
jQuery(document).ready(function(){
jQuery(document).on('click', '.open-modal', function(e) {
e.preventDefault();
var url = jQuery(this).attr('href'),
modalSize = jQuery(this).data('modal-size'),
modalClass = jQuery(this).data('modal-class'),
modalTitle = jQuery(this).data('modal-title'),
submitId = jQuery(this).data('btn-submit-id'),
submitLabel = jQuery(this).data('btn-submit-label'),
submitColor = jQuery(this).data('btn-submit-color'),
hideClose = jQuery(this).data('btn-close-hide'),
disabled = jQuery(this).attr('disabled'),
successDataTable = jQuery(this).data('datatable-reload-success');
var postData = '';
if (csrfToken) {
postData = {token: csrfToken};
}
if (!disabled) {
openModal(url, postData, modalTitle, modalSize, modalClass, submitLabel, submitId, submitColor, hideClose, successDataTable);
}
});
// define modal close reset action
jQuery('#modalAjax').on('hidden.bs.modal', function (e) {
if (jQuery(this).hasClass('modal-feature-highlights')) {
var dismissForVersion = jQuery('#cbFeatureHighlightsDismissForVersion').is(':checked');
WHMCS.http.jqClient.post(
'whatsnew.php',
{
dismiss: "1",
until_next_update: dismissForVersion ? '1' : '0',
token: csrfToken
}
);
}
jQuery('#modalAjax').find('.modal-body').empty();
jQuery('#modalAjax').children('div.modal-dialog').removeClass('modal-lg');
jQuery('#modalAjax').removeClass().addClass('modal whmcs-modal fade');
jQuery('#modalAjax .modal-title').html('Title');
jQuery('#modalAjax .modal-submit').html('Submit')
.removeClass()
.addClass('btn btn-primary modal-submit')
.removeAttr('id')
.removeAttr('disabled');
jQuery('#modalAjax .loader').show();
});
});
function openModal(url, postData, modalTitle, modalSize, modalClass, submitLabel, submitId, submitColor, hideClose, successDataTable) {
//set the text of the modal title
jQuery('#modalAjax .modal-title').html(modalTitle);
// set the modal size via a class attribute
if (modalSize) {
jQuery('#modalAjax').children('div[class="modal-dialog"]').addClass(modalSize);
}
// set the modal class
if (modalClass) {
jQuery('#modalAjax').addClass(modalClass);
}
// set the text of the submit button
if(!submitLabel){
jQuery('#modalAjax .modal-submit').hide();
} else {
jQuery('#modalAjax .modal-submit').show().html(submitLabel);
// set the button id so we can target the click function of it.
if (submitId) {
jQuery('#modalAjax .modal-submit').attr('id', submitId);
}
}
if (hideClose) {
jQuery('#modalAjaxClose').hide();
}
if (submitColor) {
jQuery('#modalAjax .modal-submit').removeClass('btn-primary')
.addClass('btn-' + submitColor);
}
jQuery('#modalAjax .modal-body').html('');
jQuery('#modalSkip').hide();
disableSubmit();
// show modal
jQuery('#modalAjax').modal({
show: true,
keyboard: true,
backdrop: jQuery('#modalAjax').hasClass('static') ? 'static' : true
});
// fetch modal content
WHMCS.http.jqClient.post(url, postData, function(data) {
updateAjaxModal(data);
}, 'json').fail(function() {
jQuery('#modalAjax .modal-body').html('An error occurred while communicating with the server. Please try again.');
jQuery('#modalAjax .loader').fadeOut();
}).always(function () {
var modalForm = jQuery('#modalAjax').find('form');
// If a submitId is present, then we're working with a form and need to override the default event
if (submitId) {
modalForm.submit(function (event) {
submitIdAjaxModalClickEvent();
return false;
});
}
if (successDataTable) {
modalForm.data('successDataTable', successDataTable);
}
// Since the content is dynamically fetched, we have to check for the elements we want here too
var inputs = jQuery(modalForm).find('input:not(input[type=checkbox],input[type=radio],input[type=hidden])');
if (inputs.length > 0) {
jQuery(inputs).first().focus();
}
});
//define modal submit button click
if (submitId) {
/**
* Reloading ajax modal multiple times on the same page can add
* multiple "on" click events which submits the same form over
* and over.
* Remove the on click event with "off" to avoid multiple growl
* and save events being run.
*
* @see http://api.jquery.com/off/
*/
var submitButton = jQuery('#' + submitId);
submitButton.off('click');
submitButton.on('click', submitIdAjaxModalClickEvent);
}
}
function submitIdAjaxModalClickEvent ()
{
var canContinue = true,
loader = jQuery('#modalAjax .loader');
disableSubmit();
loader.show();
if (ajaxModalSubmitEvents.length) {
jQuery.each(ajaxModalSubmitEvents, function (index, value) {
var fn = window[value];
if (canContinue && typeof fn === 'function') {
canContinue = fn();
}
});
}
if (!canContinue) {
enableSubmit();
loader.hide();
return;
}
var modalForm = jQuery('#modalAjax').find('form');
var modalBody = jQuery('#modalAjax .modal-body');
var modalErrorContainer = jQuery(modalBody).find('.admin-modal-error');
jQuery(modalErrorContainer).slideUp();
var modalPost = WHMCS.http.jqClient.post(
modalForm.attr('action'),
modalForm.serialize(),
function(data) {
if (modalForm.data('successDataTable')) {
data.successDataTable = modalForm.data('successDataTable');
}
/**
* When actions should occur before the ajax modal is updated
* that do not fall into the standard actions.
* Calling code (ie the function defined in fn) should validate
* that the ajax modal being updated is the one that the code should
* run for, as there is potential for multiple ajax modals on the
* same page.
*/
if (ajaxModalPostSubmitEvents.length) {
jQuery.each(ajaxModalPostSubmitEvents, function (index, value) {
var fn = window[value];
if (typeof fn === 'function') {
fn(data, modalForm);
}
});
}
updateAjaxModal(data);
},
'json'
).fail(function(xhr) {
var data = xhr.responseJSON;
var genericErrorMsg = 'An error occurred while communicating with the server. Please try again.';
if (data && data.data) {
data = data.data;
if (data.errorMsg) {
if (modalErrorContainer.length > 0) {
jQuery(modalErrorContainer)
.html(data.errorMsg)
.slideDown();
} else {
jQuery.growl.warning({title: data.errorMsgTitle, message: data.errorMsg});
}
} else if (data.data.body) {
jQuery(modalBody).html(data.body);
} else {
jQuery(modalBody).html(genericErrorMsg);
}
} else {
jQuery(modalBody).html(genericErrorMsg);
}
jQuery('#modalAjax .loader').fadeOut();
enableSubmit();
});
}
function updateAjaxModal(data) {
if (data.reloadPage) {
if (typeof data.reloadPage === 'string') {
window.location = data.reloadPage;
} else {
window.location.reload();
}
return;
}
if (data.successDataTable) {
WHMCS.ui.dataTable.getTableById(data.successDataTable, undefined).ajax.reload();
}
if (data.redirect) {
window.location = data.redirect;
}
if (data.successWindow && typeof window[data.successWindow] === "function") {
window[data.successWindow]();
}
if (data.dismiss) {
dialogClose();
}
if (data.successMsg) {
jQuery.growl.notice({ title: data.successMsgTitle, message: data.successMsg });
}
if (data.errorMsg) {
var inModalErrorContainer = jQuery('#modalAjax .modal-body .admin-modal-error');
if (inModalErrorContainer.length > 0 && !data.dismiss) {
jQuery(inModalErrorContainer)
.html(data.errorMsg)
.slideDown();
} else {
jQuery.growl.warning({title: data.errorMsgTitle, message: data.errorMsg});
}
}
if (data.title) {
jQuery('#modalAjax .modal-title').html(data.title);
}
if (data.body) {
jQuery('#modalAjax .modal-body').html(data.body);
} else {
if (data.url) {
WHMCS.http.jqClient.post(data.url, '', function(data2) {
jQuery('#modalAjax').find('.modal-body').html(data2.body);
}, 'json').fail(function() {
jQuery('#modalAjax').find('.modal-body').html('An error occurred while communicating with the server. Please try again.');
jQuery('#modalAjax').find('.loader').fadeOut();
});
}
}
if (data.submitlabel) {
jQuery('#modalAjax .modal-submit').html(data.submitlabel).show();
if (data.submitId) {
jQuery('#modalAjax').find('.modal-submit').attr('id', data.submitId);
}
}
if (data.submitId) {
/**
* Reloading ajax modal multiple times on the same page can add
* multiple "on" click events which submits the same form over
* and over.
* Remove the on click event with "off" to avoid multiple growl
* and save events being run.
*
* @see http://api.jquery.com/off/
*/
var submitButton = jQuery('#' + data.submitId);
submitButton.off('click');
submitButton.on('click', submitIdAjaxModalClickEvent);
}
if (data.disableSubmit) {
disableSubmit();
} else {
enableSubmit();
}
var dismissLoader = true;
if (typeof data.dismissLoader !== 'undefined') {
dismissLoader = data.dismissLoader;
}
dismissLoaderAfterRender(dismissLoader);
if (data.hideSubmit) {
ajaxModalHideSubmit();
}
}
// backwards compat for older dialog implementations
function dialogSubmit() {
disableSubmit();
jQuery('#modalAjax .loader').show();
var postUrl = jQuery('#modalAjax').find('form').attr('action');
WHMCS.http.jqClient.post(postUrl, jQuery('#modalAjax').find('form').serialize(),
function(data) {
updateAjaxModal(data);
}, 'json').fail(function() {
jQuery('#modalAjax .modal-body').html('An error occurred while communicating with the server. Please try again.');
jQuery('#modalAjax .loader').fadeOut();
});
}
function dialogClose() {
jQuery('#modalAjax').modal('hide');
}
function addAjaxModalSubmitEvents(functionName) {
if (functionName) {
ajaxModalSubmitEvents.push(functionName);
}
}
function removeAjaxModalSubmitEvents(functionName) {
if (functionName) {
var index = ajaxModalSubmitEvents.indexOf(functionName);
if (index >= 0) {
ajaxModalSubmitEvents.splice(index, 1);
}
}
}
function addAjaxModalPostSubmitEvents(functionName) {
if (functionName) {
ajaxModalPostSubmitEvents.push(functionName);
}
}
function removeAjaxModalPostSubmitEvents(functionName) {
if (functionName) {
var index = ajaxModalPostSubmitEvents.indexOf(functionName);
if (index >= 0) {
ajaxModalPostSubmitEvents.splice(index, 1);
}
}
}
function disableSubmit()
{
jQuery('#modalAjax .modal-submit').prop('disabled', true).addClass('disabled');
}
function enableSubmit()
{
jQuery('#modalAjax .modal-submit').prop('disabled', false).removeClass('disabled');
}
function ajaxModalHideSubmit()
{
jQuery('#modalAjax .modal-submit').hide();
}
function dismissLoaderAfterRender(showLoader)
{
if (showLoader === false) {
jQuery('#modalAjax .loader').show();
} else {
jQuery('#modalAjax .loader').fadeOut();
}
}
/*!
* WHMCS Dynamic Dropdown Library
*
* Based upon Selectize.js
*
* @copyright Copyright (c) WHMCS Limited 2005-2016
* @license http://www.whmcs.com/license/ WHMCS Eula
*/
jQuery(document).ready(
function()
{
var multiSelectize = jQuery('.selectize-multi-select'),
standardSelectize = jQuery('.selectize-select'),
promoSelectize = jQuery('.selectize-promo'),
tags = jQuery('.selectize-tags'),
newTicketCC = jQuery('.selectize-newTicketCc,.selectize-ticketCc');
jQuery(multiSelectize).selectize(
{
plugins: ['remove_button'],
valueField: jQuery(multiSelectize).attr('data-value-field'),
labelField: 'name',
searchField: 'name',
allowEmptyOption: true,
create: false,
maxItems: null,
render: {
item: function(item, escape) {
return '' + escape(item.name) + '
';
},
option: function(item, escape) {
return '' + escape(item.name) + '
';
}
},
onItemRemove: function(value) {
if (jQuery(this)[0].$input[0].id == 'multi-view' && value != 'any' && value != 'flagged') {
jQuery(this)[0].removeItem('any', true);
}
}
}
);
jQuery(standardSelectize).selectize(
{
valueField: jQuery(standardSelectize).attr('data-value-field'),
labelField: 'name',
searchField: 'name',
allowEmptyOption: jQuery(standardSelectize).attr('data-allow-empty-option'),
create: false,
maxItems: 1,
render: {
item: function(item, escape) {
var colour = '';
if (typeof item.colour !== 'undefined' && item.colour !== '#FFF') {
colour = ' style="background-color: ' + escape(item.colour) + ';"';
}
return '' + escape(item.name) + '
';
},
option: function(item, escape) {
var colour = '';
if (typeof item.colour !== 'undefined' && item.colour !== '#FFF') {
colour = ' style="background-color: ' + escape(item.colour) + ';"';
}
return '' + escape(item.name) + '
';
}
},
onInitialize: function () {
this.currentValue = '';
},
onFocus: function() {
this.currentValue = this.getValue();
this.clear();
},
onChange: function() {
if (this.getValue() === '') {
return;
}
if (this.currentValue === this.getValue()) {
return;
}
this.currentValue = this.getValue();
if (jQuery(standardSelectize).hasClass('selectize-auto-submit')) {
jQuery(standardSelectize).parent('form').submit();
}
},
onBlur: function() {
this.setValue(this.currentValue);
}
}
);
jQuery(promoSelectize).selectize(
{
valueField: jQuery(promoSelectize).attr('data-value-field'),
labelField: 'name',
searchField: 'name',
allowEmptyOption: jQuery(promoSelectize).attr('data-allow-empty-option'),
create: false,
maxItems: 1,
render: {
item: function(item, escape) {
var colour = '';
var promo = item.name.split(' - ');
if (typeof item.colour !== 'undefined' && item.colour !== '#FFF' && item.colour !== '') {
colour = ' style="background-color: ' + escape(item.colour) + ';"';
}
if (typeof otherPromos !== 'undefined'
&& item.optgroup === otherPromos
&& this.currentValue !== ''
) {
jQuery('#nonApplicablePromoWarning').show();
} else {
jQuery('#nonApplicablePromoWarning').hide();
}
if (promo[1]) {
return ''
+ '' + escape(promo[0]) + ''
+ ' - ' + escape(promo[1]) + ''
+ '
';
} else {
return ''
+ escape(promo[0])
+ '
';
}
},
option: function(item, escape) {
var colour = '';
var promo = item.name.split(' - ');
if (typeof item.colour !== 'undefined' && item.colour !== '#FFF' && item.colour !== '') {
colour = ' style="background-color: ' + escape(item.colour) + ';"';
}
if (promo[1]) {
return ''
+ '' + escape(promo[0]) + '
'
+ escape(promo[1])
+ '
';
} else {
return ''
+ escape(promo[0])
+ '
';
}
}
},
onInitialize: function () {
this.currentValue = '';
},
onFocus: function() {
this.$control.parent('div').css('overflow', 'visible');
this.currentValue = this.getValue();
this.clear();
},
onChange: function() {
if (this.getValue() === '') {
return;
}
if (this.currentValue === this.getValue()) {
return;
}
this.currentValue = this.getValue();
if (jQuery(promoSelectize).hasClass('selectize-auto-submit')) {
jQuery(promoSelectize).parent('form').submit();
}
},
onBlur: function() {
this.$control.parent('div').css('overflow', 'hidden');
this.setValue(this.currentValue);
}
}
);
jQuery(tags).selectize(
{
plugins: ['remove_button'],
valueField: 'text',
searchField: ['text'],
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
},
render: {
item: function(item, escape) {
return '' + escape(item.text) + '
';
},
option: function(item, escape) {
return '' + escape(item.text) + '
';
}
},
load: function(query, callback) {
if (!query.length) return callback();
jQuery.ajax({
url: window.location.href,
type: 'POST',
dataType: 'json',
data: {
action: 'gettags',
q: query,
token: csrfToken
},
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
},
onItemAdd: function (value)
{
jQuery.ajax({
url: window.location.href,
type: 'POST',
data: {
action: 'addTag',
newTag: value,
token: csrfToken
}
}).success(function() {
jQuery.growl.notice({ title: "", message: "Saved successfully!" });
});
},
onItemRemove: function(value)
{
jQuery.ajax({
url: window.location.href,
type: 'POST',
data: {
action: 'removeTag',
removeTag: value,
token: csrfToken
}
}).success(function() {
jQuery.growl.notice({ title: "", message: "Saved successfully!" });
});
}
}
);
jQuery(newTicketCC).selectize(
{
plugins: ['remove_button'],
valueField: 'text',
searchField: ['text'],
delimiter: ',',
persist: true,
create: function(input) {
input = input.toLowerCase();
return {
value: input,
text: input,
name: input,
iconclass: ''
}
},
render: {
item: function(item, escape) {
var name = '';
if (typeof item.iconclass !== 'undefined' && item.iconclass.length > 0) {
name = ''
+ escape(item.name);
} else {
name = escape(item.name);
}
return ''
+ '' + name + ''
+ '
';
},
option: function(item, escape) {
var name = '';
if (typeof item.iconclass !== 'undefined' && item.iconclass.length > 0) {
name = ''
+ escape(item.name);
} else {
name = escape(item.name);
}
return ''
+ '' + name + ''
+ '' + escape(item.text) + ''
+ '
';
}
}
}
);
}
);
$(document).ready(function(){
var minimisedWidgets = null;
if(typeof(Storage) !== "undefined") {
minimisedWidgets = JSON.parse(localStorage.getItem("minimisedWidgets"));
}
if (!minimisedWidgets) {
minimisedWidgets = [];
}
$(".widget-minimise").click(function(e) {
e.preventDefault();
var obj = $(this);
var icon = obj.find('i'),
widget = obj.closest('.panel').data('widget');
if (icon.hasClass('fa-chevron-up')) {
obj.closest('.panel').find('.panel-body').slideUp('fast', function() {
icon.removeClass('fa-chevron-up').addClass('fa-chevron-down');
packery.shiftLayout();
});
if (minimisedWidgets.indexOf(widget) == -1) {
minimisedWidgets.push(widget);
}
} else {
obj.closest('.panel').find('.panel-body').slideDown('fast', function(e) {
icon.removeClass('fa-chevron-down').addClass('fa-chevron-up');
packery.fit(this);
packery.shiftLayout();
});
minimisedWidgets.splice(minimisedWidgets.indexOf(widget), 1);
}
if(typeof(Storage) !== "undefined") {
localStorage.setItem("minimisedWidgets", JSON.stringify(minimisedWidgets));
}
});
$(".widget-refresh").click(function(e) {
e.preventDefault();
var obj = $(this);
var icon = obj.find('i');
var widget = obj.closest('.panel').data('widget');
var panelBody = obj.closest('.panel').find('.panel-body');
icon.addClass('fa-spin');
refreshWidget(widget, 'refresh=1');
});
var completedToggle = false;
$(".widget-hide").click(function(e) {
e.preventDefault();
var obj = $(this),
widget = obj.closest('.panel').data('widget');
completedToggle = true;
$('#panel' + widget).slideUp('fast', function() {
$(this).addClass('hidden');
WHMCS.http.jqClient.post(WHMCS.adminUtils.getAdminRouteUrl('/widget/display/toggle/' + widget)).always(function() {
$('input[data-widget="' + widget + '"]').iCheck('uncheck');
completedToggle = false;
});
$('.home-widgets-container').masonry().masonry('reloadItems');
});
});
$(document).on('ifToggled', '.display-widget', function(event) {
var self = $(this),
widget = $(this).data('widget'),
widgetPanel = $('#panel' + widget);
if (completedToggle) {
return;
}
self.iCheck('disable');
if (self.prop('checked')) {
if (widgetPanel.hasClass('hidden')) {
self.parent('div').parent('label').parent('li').addClass('active');
widgetPanel.hide().removeClass('hidden').slideDown('fast', function() {
WHMCS.http.jqClient.post(WHMCS.adminUtils.getAdminRouteUrl('/widget/display/toggle/' + widget))
.always(function() {
$('.home-widgets-container').masonry().masonry('reloadItems');
widgetPanel.find('.widget-refresh').click();
if ($('#widgetSettingsDropdown').hasClass('open') === false) {
$('#widgetSettings').dropdown('toggle');
}
self.iCheck('enable');
});
});
}
} else {
if (widgetPanel.hasClass('hidden') === false) {
self.parent('div').parent('label').parent('li').removeClass('active');
widgetPanel.slideUp('fast', function() {
$(this).addClass('hidden');
$('.home-widgets-container').masonry().masonry('reloadItems');
WHMCS.http.jqClient.post(WHMCS.adminUtils.getAdminRouteUrl('/widget/display/toggle/' + widget), function() {
if ($('#widgetSettingsDropdown').hasClass('open') === false) {
$('#widgetSettings').dropdown('toggle');
}
}, 'json').always(function() {
self.iCheck('enable');
});
});
}
}
});
$('input.display-widget').each(function(){
var self = $(this),
label = self.next(),
label_text = label.text();
label.remove();
self.iCheck({
inheritID: true,
checkboxClass: 'icheckbox_flat-blue',
increaseArea: '20%'
});
});
if ($('.home-widgets-container').length) {
minimisedWidgets.forEach(function(currentValue) {
$('#panel' + currentValue).find('.panel-body').hide().end()
.find('i.fa-chevron-up').removeClass('fa-chevron-up').addClass('fa-chevron-down');
});
Packery.prototype.getPositions = function() {
return this.items.map(function(item) {
return item.element.getAttribute("data-widget")
});
};
// init Packery
grid = document.querySelector('.home-widgets-container'),
packery = new Packery(grid, {
itemSelector: '.dashboard-panel-item',
columnWidth: '.dashboard-panel-sizer',
percentPosition: true
});
packery.stamp(document.querySelector('.dashboard-panel-static-item'));
// init draggable
var items = grid.querySelectorAll('.dashboard-panel-item');
for (var i=0; i < items.length; i++) {
var itemElem = items[i],
draggie = new Draggabilly(itemElem, {handle: '.panel-title'} );
packery.bindDraggabillyEvents(draggie);
}
// Listeners
packery.on('removeComplete', function() {
packery.shiftLayout();
});
var isSaving = false;
packery.on('dragItemPositioned', function(items) {
packery.shiftLayout();
if (!$(".home-widgets-container").children("div.dashboard-panel-item").hasClass('is-dragging')){
if (!isSaving) {
isSaving = true;
setTimeout(function () {
saveWidgetPosition();
}, 1000);
}
}
});
}
function saveWidgetPosition() {
WHMCS.http.jqClient.post(WHMCS.adminUtils.getAdminRouteUrl('/widget/order'),
{
token: csrfToken,
order: packery.getPositions()
},
function(data) {
//do nothing
},
'json'
).always(function() {
isSaving = false;
packery.shiftLayout();
});
}
jQuery('.admin-dashboard-carousel button.close').on(
'click',
dismissAdminDashboardCarouselItem
);
jQuery(window).on(
'load resize orientationchange',
normalizeAdminDashboardCarouselContent
);
function normalizeAdminDashboardCarouselContent() {
let carouselContent = jQuery('.admin-dashboard-carousel .promotion-content');
carouselContent.css('min-height', 0);
let maxHeight = Math.max
.apply(
null,
carouselContent.map(getCarouselItemOuterHeight).get()
);
carouselContent.css('min-height', maxHeight + 'px');
}
function getCarouselItemOuterHeight() {
let element = jQuery(this);
let item = element.closest('.item');
let outerHeight = 0;
if (item.hasClass('active')) {
return element.outerHeight();
}
item.addClass('active');
outerHeight = element.outerHeight();
item.removeClass('active');
return outerHeight;
}
function removeAdminDashboardSpecificPromotion(carousel, identifier) {
let carouselItems = carousel.find('.item');
let carouselIndicators = carousel.find('.carousel-indicators li');
let targetIndex = 0;
carouselItems.removeClass('active');
carouselItems.each(function(index, item) {
if (jQuery(item).find('[data-identifier="' + identifier + '"]').length > 0) {
let nextIndex = parseInt(index) + 1;
if (nextIndex >= carouselItems.length) {
nextIndex = 0;
}
targetIndex = nextIndex;
jQuery(item).remove();
jQuery(carouselItems[nextIndex]).addClass('active');
}
});
if (carouselItems.length <= 2) {
jQuery('.admin-dashboard-carousel-controls').remove();
return false;
}
if (targetIndex !== 0) {
targetIndex--;
}
carouselIndicators.removeClass('active');
carouselIndicators.each(function(index, indicator) {
if (index === targetIndex) {
jQuery(indicator).addClass('active');
}
});
carouselIndicators.last().remove();
}
function dismissAdminDashboardCarouselItem() {
let identifier = jQuery(this).closest('.alert')
.data('identifier');
let carousel = jQuery('.admin-dashboard-carousel');
if (carousel.find('.item').length <= 1) {
carousel.remove();
} else {
removeAdminDashboardSpecificPromotion(carousel, identifier);
}
WHMCS.http.jqClient.post(
WHMCS.adminUtils.getAdminRouteUrl('/promotions/dismiss/' + identifier),
{
token: csrfToken,
}
);
}
//end of $(document).ready
});
var grid, packery;
function refreshWidget(widgetName, requestString) {
var obj = $('.panel[data-widget="' + widgetName + '"]');
var panelBody = obj.find('.panel-body');
var icon = obj.find('i.fa-sync');
panelBody.addClass('panel-loading');
var jqxhr = WHMCS.http.jqClient.post(WHMCS.adminUtils.getAdminRouteUrl('/widget/refresh&widget=' + widgetName + '&' + requestString),
function(data) {
panelBody.html(data.widgetOutput);
panelBody.removeClass('panel-loading');
}, 'json')
.always(function() {
icon.removeClass('fa-spin');
});
}
/*!
* Automation Status Javascript.
*
* @copyright Copyright (c) WHMCS Limited 2005-2019
* @license http://www.whmcs.com/license/ WHMCS Eula
*/
$(document).ready(function(){
$('#statsContainer').on('click', '.btn-viewing', function (e){
e.preventDefault();
});
$('#graphContainer').on('click', '.graph-filter-metric a', function (e){
e.preventDefault();
$('.graph-filter-metric a').removeClass('active');
$(this).addClass('active');
refreshGraph();
});
$('#graphContainer').on('click', '.graph-filter-period a', function (e){
e.preventDefault();
$('.graph-filter-period a').removeClass('active');
$(this).addClass('active');
refreshGraph();
});
});
function loadAutomationStatsForDate(date) {
$('#statsContainer').css('opacity', '0.5');
WHMCS.http.jqClient.post(
"automationstatus.php",
'action=stats&date=' + date,
function(data) {
$('.widgets-container').html(data.body);
$('.day-selector').find('.btn-viewing').html(data.newDate);
}
).fail(function() {
jQuery.growl({ title: "", message: "Your session has expired. Please refresh to continue." });
}).always(function() {
$('#statsContainer').css('opacity', '1');
});
}
function refreshGraph() {
$('#graphContainer').css('opacity', '0.5');
var jqxhr = WHMCS.http.jqClient.post( "automationstatus.php",'action=graph&metric=' + $('.graph-filter-metric a.active').attr('href') + '&period=' + $('.graph-filter-period a.active').attr('href'),
function(data) {
$('#graphContainer').html(data.body);
}).fail(function() {
jQuery.growl({ title: "", message: "Your session has expired. Please refresh to continue." });
}).always(function() {
$('#graphContainer').css('opacity', '1');
});
}
jQuery(document).ready(function() {
var backupsContainer = jQuery('.database-backups');
backupsContainer.find('.activate').on('click', function() {
var self = jQuery(this),
form = self.parent('form'),
type = self.data('type'),
request = form.serialize();
self.prop('disabled', true).addClass('disabled');
request += '&action=save&activate=1&type=' + type + '&token=' + csrfToken;
WHMCS.http.jqClient.post(
window.location.href,
request,
function(data) {
if (data.success === true) {
jQuery.growl.notice(
{
title: data.successMessageTitle,
message: data.successMessage
}
);
form.find('.save, .deactivate-start').removeClass('hidden');
self.addClass('hidden');
jQuery('#' + type + 'Label').toggleClass('label-default label-success').text(data.activeText);
} else {
jQuery.growl.error(
{
title: data.errorMessageTitle,
message: data.errorMessage
}
);
}
},
'json'
).always(function() {
self.prop('disabled', false).removeClass('disabled');
});
});
backupsContainer.find('.save').on('click', function() {
var self = jQuery(this),
form = self.parent('form'),
type = self.data('type'),
request = form.serialize();
self.prop('disabled', true).addClass('disabled');
request += '&action=save&type=' + type + '&token=' + csrfToken;
WHMCS.http.jqClient.post(
window.location.href,
request,
function(data) {
if (data.success === true) {
jQuery.growl.notice(
{
title: data.successMessageTitle,
message: data.successMessage
}
);
} else {
jQuery.growl.error(
{
title: data.errorMessageTitle,
message: data.errorMessage
}
);
}
},
'json'
).always(function() {
self.prop('disabled', false).removeClass('disabled');
});
});
backupsContainer.find('.test').on('click', function() {
var self = jQuery(this),
form = self.parent('form'),
type = self.data('type'),
request = form.serialize();
self.prop('disabled', true).addClass('disabled');
jQuery('#' + type + 'Container').removeClass('hidden');
request += '&action=test&type=' + type + '&token=' + csrfToken;
jQuery('#' + type + 'Test').hide()
.removeClass('hidden alert-success alert-danger')
.addClass('alert-default')
.find('.extra-text').addClass('hidden').text('').end()
.find('.default-text').removeClass('hidden').end()
.slideDown('fast');
WHMCS.http.jqClient.post(
window.location.href,
request,
function(data) {
if (data.success === true) {
jQuery('#' + type + 'Test')
.addClass('alert-success')
.removeClass('alert-default alert-danger')
.find('.default-text').addClass('hidden').end()
.find('.extra-text').text(data.successMessage).removeClass('hidden').end()
.delay(3000).slideUp('slow');
form.find('.activate').prop('disabled', false).removeClass('disabled');
} else {
jQuery('#' + type + 'Test')
.addClass('alert-danger')
.removeClass('alert-default alert-success')
.find('.default-text').addClass('hidden').end()
.find('.extra-text').text(data.errorMessageTitle + ': ' + data.errorMessage).removeClass('hidden').end()
.delay(3000).slideUp('slow');
}
},
'json'
).always(function() {
self.prop('disabled', false).removeClass('disabled');
jQuery('#' + type + 'Container').addClass('hidden');
});
});
backupsContainer.find('.deactivate-start').on('click', function() {
var self = jQuery(this),
form = self.parent('form'),
type = self.data('type'),
modal = jQuery('#modalConfirmDeactivate');
jQuery('#confirmDeactivateYes').data('type', type);
modal.modal('show');
});
jQuery('#modalConfirmDeactivate').find('.deactivate').on('click', function() {
var self = jQuery(this),
modal = jQuery('#modalConfirmDeactivate'),
form = modal.parent('form'),
type = self.data('type'),
request = 'action=deactivate&type=' + type + '&token=' + csrfToken,
mainForm = jQuery('.deactivate-start[data-type="' + type + '"]').parent('form');
self.prop('disabled', true).addClass('disabled');
WHMCS.http.jqClient.post(
window.location.href,
request,
function(data) {
if (data.success === true) {
jQuery.growl.notice(
{
title: data.successMessageTitle,
message: data.successMessage
}
);
mainForm.find('.save, .deactivate-start').addClass('hidden');
mainForm.find('.activate').removeClass('hidden').prop('disabled', true);
if (type === 'email') {
mainForm.find('.activate').prop('disabled', false);
}
jQuery('#' + type + 'Label').toggleClass('label-default label-success').text(data.inactiveText);
} else {
jQuery.growl.error(
{
title: data.errorMessageTitle,
message: data.errorMessage
}
);
}
},
'json'
).always(function() {
self.prop('disabled', false).removeClass('disabled');
modal.modal('hide');
});
});
backupsContainer.find('#inputDestination').on('change', function() {
var destinationData = jQuery('#destinationData'),
value = jQuery(this).val();
if (value !== 'homedir' && destinationData.hasClass('hidden')) {
destinationData.hide().removeClass('hidden').slideDown('fast');
} else if (value === 'homedir' && !(destinationData.hasClass('hidden'))) {
destinationData.slideUp('fast').addClass('hidden');
}
});
});
/*!
* DateRangePicker Javascript.
*
* @copyright Copyright (c) WHMCS Limited 2005-2019
* @license http://www.whmcs.com/license/ WHMCS Eula
*/
function initDateRangePicker()
{
jQuery(document).ready(function () {
// Date range picker.
jQuery('.date-picker-search').each(function (index) {
var self = jQuery(this),
opens = self.data('opens'),
drops = self.data('drops'),
range = adminJsVars.dateRangePicker.defaultRanges,
format = adminJsVars.dateRangeFormat;
if (!opens || typeof opens === "undefined") {
opens = 'center';
}
if (!drops || typeof drops === "undefined") {
drops = 'down';
}
if (self.hasClass('future')) {
range = adminJsVars.dateRangePicker.futureRanges;
}
self.daterangepicker({
autoUpdateInput: false,
ranges: range,
alwaysShowCalendars: true,
opens: opens,
drops: drops,
showDropdowns: true,
minYear: adminJsVars.minYear,
maxYear: adminJsVars.maxYear,
locale: {
format: format,
applyLabel: adminJsVars.dateRangePicker.applyLabel,
cancelLabel: adminJsVars.dateRangePicker.cancelLabel,
customRangeLabel: adminJsVars.dateRangePicker.customRangeLabel,
monthNames: adminJsVars.dateRangePicker.months,
daysOfWeek: adminJsVars.dateRangePicker.daysOfWeek
}
}).on('show.daterangepicker', function (ev, picker) {
// Identify the date picker modal using the input ID if available.
if (picker.element[0].id != '') {
picker.container[0].id = 'dateRangePicker_' + picker.element[0].id;
}
}).on('apply.daterangepicker', function (ev, picker) {
jQuery(this).val(picker.startDate.format(adminJsVars.dateRangeFormat)
+ ' - ' + picker.endDate.format(adminJsVars.dateRangeFormat));
}).on('cancel.daterangepicker', function (ev, picker) {
jQuery(this).val('');
});
});
jQuery('.datepick,.date-picker,.date-picker-single').each(function (index) {
var self = jQuery(this),
opens = self.data('opens'),
drops = self.data('drops'),
range = adminJsVars.dateRangePicker.defaultSingleRanges,
format = adminJsVars.dateRangeFormat,
time = false;
if (!opens || typeof opens === "undefined") {
opens = 'center';
}
if (!drops || typeof drops === "undefined") {
drops = 'down';
}
if (self.hasClass('future')) {
range = adminJsVars.dateRangePicker.futureSingleRanges;
}
if (self.hasClass('time')) {
time = true;
format = adminJsVars.dateTimeRangeFormat;
if (self.hasClass('future')) {
range = adminJsVars.dateRangePicker.futureTimeSingleRanges;
}
}
self.daterangepicker({
singleDatePicker: true,
autoUpdateInput: false,
ranges: range,
alwaysShowCalendars: true,
opens: opens,
drops: drops,
showDropdowns: true,
minYear: adminJsVars.minYear,
maxYear: adminJsVars.maxYear,
timePicker: time,
timePickerSeconds: false,
locale: {
format: format,
customRangeLabel: adminJsVars.dateRangePicker.customRangeLabel,
monthNames: adminJsVars.dateRangePicker.months,
daysOfWeek: adminJsVars.dateRangePicker.daysOfWeek
}
}).on('show.daterangepicker', function (ev, picker) {
// Identify the date picker modal using the input ID if available.
if (picker.element[0].id != '') {
picker.container[0].id = 'dateRangePicker_' + picker.element[0].id;
}
}).on('apply.daterangepicker', function (ev, picker) {
jQuery(this).data(
'original-value',
picker.startDate.format(format)
)
.val(picker.startDate.format(format));
}).on('cancel.daterangepicker', function (ev, picker) {
jQuery(this).val(jQuery(this).data('original-value'));
});
});
});
}
initDateRangePicker();
/*!
* WHMCS Module Queue Javascript Functions
*
* @copyright Copyright (c) WHMCS Limited 2005-2016
* @license http://www.whmcs.com/license/ WHMCS Eula
*/
jQuery(document).ready(function() {
var moduleQueueRetryAll = jQuery('button.retry-all');
if (moduleQueueRetryAll.length) {
var processed = false,
queueTimeout = null,
count = 0;
jQuery('button.retry').click(function() {
processed = false;
var self = jQuery(this),
entryId = jQuery(this).data('entry-id'),
processingEntry = jQuery('div#processing-entry-' + entryId);
self.attr('disabled', 'disabled').addClass('disabled').find('i').addClass('fa-spin').end();
if (queueTimeout) {
processingEntry.find('div.queued').hide().end()
.find('div.processing').show().end();
} else {
processingEntry.find('div.messages').children('div').hide().end()
.find('div.processing').show().end().end()
.hide().removeClass('hidden').slideDown('fast');
}
var connection = WHMCS.http.jqClient.post(
window.location.pathname,
{
token: csrfToken,
action: 'retry',
id: entryId
},
null,
'json'
);
connection.done(function(data) {
if (data.error) {
processingEntry.find('div.processing').hide().end()
.find('div.error').find('span').html(data.message).parent().show().end();
jQuery('#last-error-' + entryId).html(data.errorMessage);
jQuery('div#entry-' + entryId).find('small.last-attempt').find('span').html(data.lastAttempt);
self.removeAttr('disabled').removeClass('disabled').find('i').removeClass('fa-spin').end();
count++;
}
if (data.completed) {
jQuery('div#entry-' + entryId).find('div.action-buttons').find('button').removeClass('retry')
.attr('disabled', 'disabled').addClass('disabled')
.find('i.fa-spin').removeClass('fa-spin').end();
processingEntry.find('div.processing').slideUp('fast').end()
.find('div.success').slideDown('fast').end();
}
});
connection.always(function() {
processed = true;
});
});
jQuery('button.resolve').click(function() {
var self = jQuery(this),
entryId = jQuery(this).data('entry-id'),
processingEntry = jQuery('div#processing-entry-' + entryId);
self.attr('disabled', 'disabled').addClass('disabled');
processingEntry.find('div.messages').children('div').hide().end()
.find('div.processing').show().end().end()
.hide().removeClass('hidden').slideDown('fast');
var connection = WHMCS.http.jqClient.post(
window.location.pathname,
{
token: csrfToken,
action: 'resolve',
id: entryId
},
null,
'json'
);
connection.done(function(data) {
if (data.completed) {
jQuery('div#entry-' + entryId).find('div.action-buttons').find('button').removeClass('retry')
.attr('disabled', 'disabled').addClass('disabled').end();
processingEntry.find('div.processing').slideUp('fast').end()
.find('div.success').find('span').html(data.message).parent().slideDown('fast').end();
} else {
processingEntry.find('div.processing').slideUp('fast').end()
.find('div.error').find('span').html(data.message).parent().slideDown('fast').end();
self.removeAttr('disabled').removeClass('disabled');
}
});
});
moduleQueueRetryAll.click(function () {
jQuery(this).attr('disabled', 'disabled').addClass('disabled')
.find('i').addClass('fa-spin').end();
var items = jQuery('button.retry');
processed = true;
count = 0;
items.each(function(index) {
var entryId = jQuery(this).data('entry-id');
jQuery('div#processing-entry-' + entryId).find('div.messages').children('div').hide().end()
.find('div.queued').show().end().end()
.hide().removeClass('hidden').slideDown('fast');
});
queueTimeout = setTimeout(nextClick, 1000);
});
function nextClick()
{
if (processed) {
var button = jQuery('button.retry:eq(' + count + ')');
if (button.length) {
button.click();
} else {
clearTimeout(queueTimeout);
queueTimeout = null;
moduleQueueRetryAll.removeAttr('disabled').removeClass('disabled')
.find('i').removeClass('fa-spin').end();
return;
}
}
queueTimeout = setTimeout(nextClick, 1000);
}
}
});
/*!
* WHMCS MarketConnect Admin JS Functions
*
* @copyright Copyright (c) WHMCS Limited 2005-2022
* @license https://www.whmcs.com/license/ WHMCS Eula
*/
jQuery(document).ready(function() {
jQuery(document).on('click', '#btnMcServiceRefresh', function(e) {
e.preventDefault();
var btn = $(this);
btn.find('i').addClass('fa-spin');
WHMCS.http.jqClient.post({
url: 'clientsservices.php',
data: btn.attr('href') + '&token=' + csrfToken,
success: function (data) {
$('#mcServiceManagementWrapper').replaceWith(data.statusOutput);
btn.find('i').removeClass('fa-spin');
}
});
});
jQuery(document).on('click', '#btnMcCancelOrder', function(e) {
swal({
title: 'Are you sure?',
html: true,
text: 'Cancelling this order will result in the service immediately ceasing to function.
You will automatically receive a credit if within the credit period. See credit period terms',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, cancel it',
cancelButtonText: 'No'
},
function(){
runModuleCommand('terminate');
});
});
jQuery(document).on('click', '#mcServiceManagementWrapper .btn:not(.open-modal,.btn-refresh,.btn-cancel)', function(e) {
e.preventDefault();
$('#growls').fadeOut('fast').remove();
$('.successbox,.errorbox').slideUp('fast').remove();
var button = $(this);
var request = button.attr('href');
var buttonIcon = button.find('i');
var iconState = buttonIcon.attr('class');
// If button is disabled, don't execute action
if (button.attr('disabled') === 'disabled') {
return;
}
buttonIcon.removeClass().addClass('fas fa-spin fa-spinner');
WHMCS.http.jqClient.post('clientsservices.php', request + '&token=' + csrfToken, function (data) {
if (data.redirectUrl) {
window.open(data.redirectUrl);
} else if (data.growl) {
if (data.growl.type == 'error') {
$.growl.error({ title: '', message: data.growl.message });
} else {
$.growl.notice({ title: '', message: data.growl.message });
$('#btnMcServiceRefresh').click();
}
} else {
$.growl.error({ title: '', message: 'Unknown response' });
console.error('[WHMCS] Unknown response: ' + JSON.stringify(data));
}
}, 'json').fail(function (xhr) {
var response = (xhr.responseText != '' ? xhr.responseText : xhr.statusText);
$.growl.error({ title: '', message: response })
}).always(function (xhr) {
buttonIcon.removeClass().addClass(iconState);
});
})
.on('click', '.feature-menu-item', function(e) {
e.preventDefault();
var self = jQuery(this),
name = self.data('name'),
shownMenu = jQuery('.feature-menu-item.shown'),
shownItem = jQuery('.feature-info-item.shown'),
target = jQuery('.feature-info-item[data-name="' + name + '"]');
shownMenu.removeClass('shown');
self.addClass('shown');
shownItem.slideUp('fast', function() {
jQuery(this).removeClass('shown');
target.hide().addClass('shown').slideDown('fast');
})
});
});
/**
* WHMCS Telephone Country Code Dropdown
*
* Using https://github.com/jackocnr/intl-tel-input
*
* @copyright Copyright (c) WHMCS Limited 2005-2019
* @license https://www.whmcs.com/license/ WHMCS Eula
*/
jQuery(document).ready(function() {
const telephoneSharedCountries = new Map([
['um', 'us'], // United States Outlying Islands shares dialing code with the US
['ic', 'es'], // Canary Islands shares dialing code with Spain
['gs', 'fk'], // South Georgia and Sandwich Islands shares dialing code with Falkland Islands
['aq', 'nf'], // Antarctica shares dialing code with Norfolk Island
['tf', 're'], // French Southern Territories shares dialing code with Réunion (La Réunion)
['hm', 'nf'], // Heard Island and Mcdonald Islands shares dialing code with Norfolk Island
['an', 'bq'], // Netherlands Antilles shares dialing code with Caribbean Netherlands
['pn', 'nz'], // Pitcairn shares dialing code with New Zealand
]);
function assertTelephoneCountry(country) {
country = country.toLowerCase();
if (telephoneSharedCountries.has(country)) {
return telephoneSharedCountries.get(country);
}
return country;
}
if (typeof customCountryData !== "undefined") {
var teleCountryData = $.fn['intlTelInput'].getCountryData();
for (var code in customCountryData) {
if (customCountryData.hasOwnProperty(code)) {
var countryDetails = customCountryData[code];
codeLower = code.toLowerCase();
if (countryDetails === false) {
for (var i = 0; i < teleCountryData.length; i++) {
if (codeLower === teleCountryData[i].iso2) {
teleCountryData.splice(i, 1);
break;
}
}
} else {
teleCountryData.push(
{
name: countryDetails.name,
iso2: codeLower,
dialCode: countryDetails.callingCode,
priority: 0,
areaCodes: null
}
);
}
}
}
}
if (jQuery('body').data('phone-cc-input')) {
var phoneInput = jQuery('input[name^="phone"], input[name$="phone"], input[name="domaincontactphonenumber"]').not('input[type="hidden"]');
if (phoneInput.length) {
var countryInput = jQuery('[name^="country"], [name$="country"]'),
initialCountry = 'us';
if (countryInput.length) {
initialCountry = assertTelephoneCountry(countryInput.val());
}
phoneInput.each(function(){
var thisInput = jQuery(this),
inputName = thisInput.attr('name');
if (inputName === 'domaincontactphonenumber') {
initialCountry = jQuery('[name="domaincontactcountry"]').val().toLowerCase();
}
jQuery(this).before(
''
);
try {
thisInput.intlTelInput({
preferredCountries: [initialCountry, "us", "gb"].filter(function (value, index, self) {
return self.indexOf(value) === index;
}),
initialCountry: initialCountry,
autoPlaceholder: 'polite', //always show the helper placeholder
separateDialCode: true
});
} catch (error) {
console.log(error.message);
return false;
}
thisInput.on('countrychange', function (e, countryData) {
jQuery('#populatedCountryCode' + inputName).val(countryData.dialCode);
if (jQuery(this).val() === '+' + countryData.dialCode) {
jQuery(this).val('');
}
});
thisInput.on('blur keydown', function (e) {
if (e.type === 'blur' || (e.type === 'keydown' && e.keyCode === 13)) {
var number = jQuery(this).intlTelInput("getNumber"),
countryData = jQuery(this).intlTelInput("getSelectedCountryData"),
countryPrefix = '+' + countryData.dialCode;
if (number.indexOf(countryPrefix) === 0 && (number.match(/\+/g) || []).length > 1) {
number = number.substr(countryPrefix.length);
}
jQuery(this).intlTelInput("setNumber", number);
}
});
jQuery('#populatedCountryCode' + inputName).val(thisInput.intlTelInput('getSelectedCountryData').dialCode);
countryInput.on('change', function() {
if (thisInput.val() === '') {
var country = assertTelephoneCountry(jQuery(this).val());
try {
phoneInput.intlTelInput('setCountry', country);
} catch (error) {
console.log(error.message);
return false;
}
}
});
// this must be .attr (not .data) in order for it to be found by [data-initial-value] selector
thisInput.attr('data-initial-value', $(thisInput).val());
thisInput.parents('form').find('input[type=reset]').each(function() {
var resetButton = this;
var form = $(resetButton).parents('form');
if (!$(resetButton).data('phone-handler')) {
$(resetButton).data('phone-handler', true);
$(resetButton).click(function(e) {
e.stopPropagation();
$(form).trigger('reset');
$(form).find('input[data-initial-value]').each(function() {
var inputToReset = this;
$(inputToReset).val(
$(inputToReset).attr('data-initial-value')
);
});
return false;
});
}
});
});
/**
* In places where a form icon is present, hide it.
* Where the input has a class of field, remove that and add form-control in place.
*/
phoneInput.parents('div.form-group').find('.field-icon').hide().end();
phoneInput.removeClass('field').addClass('form-control');
}
var registrarPhoneInput = jQuery('input[name$="][Phone Number]"], input[name$="][Phone]"]').not('input[type="hidden"]');
if (registrarPhoneInput.length) {
jQuery.each(registrarPhoneInput, function(index, input) {
var thisInput = jQuery(this),
inputName = thisInput.attr('name');
inputName = inputName.replace('contactdetails[', '').replace('][Phone Number]', '').replace('][Phone]', '');
var countryInput = jQuery('[name$="' + inputName + '][Country]"]'),
initialCountry = assertTelephoneCountry(countryInput.val());
thisInput.before('');
thisInput.intlTelInput({
preferredCountries: [initialCountry, "us", "gb"].filter(function(value, index, self) {
return self.indexOf(value) === index;
}),
initialCountry: initialCountry,
autoPlaceholder: 'polite', //always show the helper placeholder
separateDialCode: true
});
thisInput.on('countrychange', function (e, countryData) {
jQuery('#populated' + inputName + 'CountryCode').val(countryData.dialCode);
if (jQuery(this).val() === '+' + countryData.dialCode) {
jQuery(this).val('');
}
});
thisInput.on('blur keydown', function (e) {
if (e.type === 'blur' || (e.type === 'keydown' && e.keyCode === 13)) {
var number = jQuery(this).intlTelInput("getNumber"),
countryData = jQuery(this).intlTelInput("getSelectedCountryData"),
countryPrefix = '+' + countryData.dialCode;
if (number.indexOf(countryPrefix) === 0 && (number.match(/\+/g) || []).length > 1) {
number = number.substr(countryPrefix.length);
}
jQuery(this).intlTelInput("setNumber", number);
}
});
jQuery('#populated' + inputName + 'CountryCode').val(thisInput.intlTelInput('getSelectedCountryData').dialCode);
countryInput.on('blur', function() {
if (thisInput.val() === '') {
var country = assertTelephoneCountry(jQuery(this).val());
thisInput.intlTelInput('setCountry', country);
}
});
});
}
}
});