/
util.js
100 lines (80 loc) · 2.15 KB
/
util.js
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
var gHostName = "";
function getHostName() {
if (gHostName.length == 0) {
$.ajaxSetup({ async: false });
$.post("/Myth/GetHostName",
function(data) {
gHostName = data.QString;
}, "json").error(function(data) {
alert("Error: unable to retrieve backend hostname");
});
$.ajaxSetup({ async: true });
}
return gHostName;
}
function showHostName() {
$("#hostname").html(getHostName());
}
function getSetting(hostname, key, defValue) {
var result = "";
$.ajaxSetup({ async: false });
$.getJSON("/Myth/GetSetting",
{ HostName: hostname, Key: key, Default: defValue },
function(data) {
result = data.SettingList.Settings[0].String;
}).error(function(data) {
alert("Error: unable to retrieve setting");
});
$.ajaxSetup({ async: true });
return result;
}
function interceptMenuClicks() {
$('#menu ul li a').click(function(event) {
if (this.href.match("/Config/") == "/Config/") {
event.preventDefault();
loadContent(this.href, "/setup/js/Config.js");
}
});
}
function loadScreen(menuURL, contentURL, jsURL) {
loadMenu(menuURL);
if (contentURL && contentURL != "")
loadContent(contentURL);
if (jsURL && jsURL != "")
$.getScript(jsURL);
}
function loadMenu(menuURL) {
var html = $.ajax({
url: menuURL,
async: false
}).responseText;
$("#content").html("");
$("#menu-bg").html(html);
}
function clearMenu() {
$("#menu-bg").html("");
}
function loadContent(contentURL, jsURL) {
$("#content").html("<br><br><b>Loading...</b>");
var html = $.ajax({
url: contentURL,
async: false
}).responseText;
$("#content").html(html);
if (jsURL) {
$.getScript(jsURL);
}
}
function clearContent() {
$("#content").html("");
}
function getCurrentTab(id) {
var selected = $(id).tabs('option', 'selected');
return selected;
}
function addTab(id, url, label) {
$(id).tabs("add", url, label);
}
function removeTab(id, index) {
$(id).tabs("remove", index);
}