File size: 5,642 Bytes
27867f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
$(document).ready(function(){
$('form select[class=dlevelsetting]').change(function() {
setDisplayLevel();
});
var getConfigData = function(){
$.getJSON("/config.json", function(json) {
if (json != "Nothing found."){
var currentDisplayLevel = $('form select[class=dlevelsetting]').val();
if (typeof currentLevelValue === 'undefined') {
currentDisplayLevel = json.display.display_level;
$("form select[class=dlevelsetting]").val(currentDisplayLevel);
}
$('.sectionForm').each(function(){
populateForm("#"+$(this).attr("id"), json, null)
setDisplayLevel("#"+$(this).attr("id"))
})
} else {
$('#status').html('<h2 class="loading">Were afraid nothing was returned. is the web interface disabled?</h2>');
}
return true;
})
.fail(function() {
$('#status').html('<h2 class="loading">Unable to obtain config data. Is the config web interface disabled?</h2>');
$('button#submit').prop("disabled",true);
return false;
})
return false;
}
function populateForm(form,data,parent) {
$.each(data, function(key, value) {
if(value !== null) {
if (typeof value === 'object' ) {
populateForm(form,value,key+'-')
} else {
if (parent === null) {
var ctrl = $('[name='+key+']', form);
} else {
var ctrl = $('[name='+parent+key+']', form);
}
switch(ctrl.prop("type")) {
case "radio": case "checkbox":
ctrl.each(function() {
if ($(this).attr('value') == value) $(this).attr("checked",value);
$(this).prop("checked",value);
});
break;
case undefined:
break;
case "text": case "hidden": case "password":
ctrl.val(value);
vallength = value.length+5
if (vallength < 15) {
vallength = 15
}
ctrl.attr('size', vallength)
break;
default:
ctrl.val(value);
}
}
}
});
}
function getDisplayLevel() {
var currentDisplayLevel = $('form select[class=dlevelsetting]').val();
if (typeof currentLevelValue === 'undefined') {
currentDisplayLevel = $('select[class=dlevelsetting]').val();
}
if (currentDisplayLevel == '') {
currentDisplayLevel = '1-Standard'
}
return currentDisplayLevel;
}
x=1
function setDisplayLevel() {
x+=1
var currentDisplayLevel = getDisplayLevel();
var currentLevel = currentDisplayLevel.match(/^\d+/)[0];
$('form tr[class^="dlevel"]').each(
function(index) {
var input = $(this)
var itemLevel = input.attr('class').match(/\d+$/)[0];
if (itemLevel > currentLevel) {
$(this).hide()
} else {
$(this).show()
}
});
$('form tr[class="hlevel"]').each(
function() {
allHidden = true;
$(this).nextUntil('tr[class="hlevel"]').each(
function() {
if ( $(this).css("display") != "none" ) {
allHidden = false;
}
}
)
if (allHidden) {
$(this).hide()
} else {
$(this).show()
}
});
$('a.configTab').hide();
$('form[class="sectionForm"]').each(
function() {
formname = $(this).attr("id");
$(this).find('tr[class^="dlevel"]').each(
function(i) {
if ( this.style.display !== "none" ) {
// at least one is active. turn on tab
$('a.'+formname).show();
}
}
)
});
}
getConfigData();
$('form').submit(function() { // catch the form's submit
$(this).find('input[type="checkbox"]').each(function() {
if ($(this).is(":checked") == true) {
var n = '#'+$(this).attr("id")+'hidden';
$(n).prop("disabled", true);
} else {
var n = '#'+$(this).attr("id")+'hidden';
$(n).prop("disabled", false);
}
});
$.ajax({
data: $(this).serialize(),
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'),
success: function(response) { // on success
$('#status').html(response);
}
});
return false; // cancel original submit event
});
});
|