Files
Froxlor/templates/Sparkle/assets/js/customers.js
Michael Kaufmann (d00p) bb792f228f add new hosting-plans feature
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
2018-02-12 13:28:13 +01:00

75 lines
2.3 KiB
JavaScript

$(document).ready(function() {
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
/**
* disable unusable php-configuration by customer settings
*/
$('#use_plan').change(function() {
var pid = $(this).val();
if (pid > 0) {
var sid = getUrlParameter('s');
$.ajax({
url: "admin_plans.php?s="+sid+"&page=overview&action=jqGetPlanValues",
type: "POST",
data: {
planid: pid
},
dataType: "json",
success: function(json) {
for (i in json) {
if (i == 'email_imap' || i == 'email_pop3' || i == 'perlenabled' || i == 'phpenabled' || i == 'dnsenabled') {
/** handle checkboxes **/
if (json[i] == 1) {
$("input[name='"+i+"']").attr('checked', 'checked');
} else {
$("input[name='"+i+"']").removeAttr('checked');
}
} else if (i == 'allowed_phpconfigs') {
/** handle array of values **/
$("input[name='allowed_phpconfigs[]']").each(function(index) {
$(this).removeAttr('checked');
for (j in json[i]) {
if ($(this).val() == json[i][j]) {
$(this).attr('checked', 'checked');
}
}
});
} else if (json[i] == -1) {
/** handle unlimited checkboxes **/
$("input[name='" + i + "_ul']").attr('checked', 'checked');
$("input[name='"+i+"']").prop({
readonly: true
});
} else {
/** handle normal value **/
$("input[name='"+i+"']").val(json[i]);
$("input[name='"+i+"']").prop({
readonly: false
});
$("input[name='" + i + "_ul']").removeAttr('checked');
}
}
},
error: function(a, b) {
console.log(a, b);
}
});
}
});
});