-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathtemplates.js
281 lines (248 loc) · 7.89 KB
/
templates.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
*
* Server Templates
*
*/
// Create template
function template_show_create(tplID)
{
if(tplID == "")
{
alert("No template ID given");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=template_create_form&id='+tplID,
success:function(html){
/*
// Show modal with info
$("#modal").html(html).modal({overlayClose:true,opacity:70,overlayCss:{backgroundColor:"#000"},onClose: function (dialog) {
dialog.data.fadeOut('fast',function () { $.modal.close(); });
}});
*/
$('#panel_center').hide().html(html).fadeIn('fast');
}
});
}
// Edit Template
function template_edit(tplID)
{
if(tplID == "")
{
alert("No template ID given");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=template_edit&id='+tplID,
success:function(html){
// Show modal with info
$("#modal").html(html).modal({overlayClose:true,opacity:70,overlayCss:{backgroundColor:"#000"},onClose: function (dialog) {
dialog.data.fadeOut('fast',function () { $.modal.close(); });
}});
}
});
}
// Save template edits
function template_save(tplID,netID)
{
if(tplID == "" || netID == "")
{
alert("No Template ID or Network ID given!");
return false;
}
var desc = encodeURIComponent($('#desc').val());
var isDefault = $('#is_default').val();
var datastr = "&id="+tplID+"&netid="+netID+"&do=save&desc="+desc+"&default="+isDefault;
$.ajax({
url: ajaxURL,
type: "POST",
data: 'a=template_actions'+datastr,
success:function(html){
if(html == 'success') infobox('s','');
else infobox('f','Failed: '+html);
// Update page
//mainpage('templates',"+tplID+")
setTimeout("$.modal.close();", 1000);
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
// Confirm deleting Template
function template_confirm_delete(tplID)
{
if(tplID == "")
{
alert("No template ID given");
return false;
}
var answer = confirm("Are you sure?\n\nDelete this template?");
if(answer) template_delete(tplID);
else return false;
}
// Delete Template
function template_delete(tplID)
{
if(tplID == "")
{
alert("No template ID given");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=template_actions&id='+tplID+"&do=delete",
success:function(html){
if(html == 'success') infobox('s','');
else infobox('f','Failed: '+html);
// Close modal
$.modal.close();
// page_templates(); // and redirect to templates
// Remove row
$('#tpl_'+tplID).fadeOut('slow');
}
});
}
// Create Template
function template_create()
{
var gameID = $('#create_tpl_game').val();
var netID = $('#create_tpl_network').val();
var filePath = $('#create_tpl_file_path').val();
var tplisDef = $('#create_tpl_is_default').val();
var descript = $('#create_tpl_desc').val();
// Check empty
if(gameID == "")
{
alert("Please choose a Game!");
return false;
}
else if(netID == "")
{
alert("Please choose a Network Server");
return false;
}
$.ajax({
url: ajaxURL,
data: "a=template_actions&do=create&gameid="+gameID+"&netid="+netID+"&default="+tplisDef+"&file_path="+filePath+"&description="+descript,
beforeSend:function(){
// Show progress
infobox('i','<i>Starting ...</i>');
},
success:function(html){
if(html == 'success')
{
infobox('s','');
// Refresh status
setTimeout("mainpage('templates',"+gameID+")", 1000);
}
else
{
infobox('f','Failed: '+html);
}
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
// Check one-time if running templates are completed
function template_checkdone()
{
$.ajax({
url: ajaxURL,
data: 'a=template_actions&do=checkdone',
success:function(html){
// Only print if erroneous
if(html == 'success')
{
$('#results').html('Templates OK');
}
// Updated a status
else if(html == 'updated')
{
$('#results').html('Updated!');
var tplID = $('#tplid').val();
setTimeout("mainpage('templates',"+tplID+")", 1000);
}
else
{
infobox('f','Error: '+html);
}
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
function tpl_check_statuses()
{
$('#results').append('Checking...<br>');
$.ajax({
url: ajaxURL,
data:"a=template_status",
dataType:"JSON",
beforeSend:function(){
$('#results').html('<b>RT:</b> Updating ...');
},
success:function(html){
$('#results').html('<b>RT:</b> Idle.');
// Loop through options
$.each(html, function(index, value) {
thisID = value.id;
thisSteamPercent = value.steam_percent;
thisStatus = value.status;
if(thisStatus == 'steam_running') $('#status_'+thisID).html('<font color="blue">Steam Install: '+thisSteamPercent+'%</font>');
else if(thisStatus == 'running') $('#status_'+thisID).html('<font color="orange">Running</font>');
else if(thisStatus == 'complete') $('#status_'+thisID).html('<font color="green">Complete</font>');
else if(thisStatus == 'failed') $('#status_'+thisID).html('<font color="red">Failed</font>');
else $('#status_'+thisID).html('<font color="orange">Unknown</font>');
});
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
function template_browse_dir()
{
var netID = $('#network').val();
if(netID == "")
{
alert("Please select a Network Server first!");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=file_load_dir&browsetpl=1&reset=1&id='+netID,
beforeSend:function(){
$('#browse_done').hide();
$("#modal").html('<i>Loading ...</i>').modal({overlayClose:true,opacity:70,overlayCss:{backgroundColor:"#000"},onClose: function (dialog) {
dialog.data.fadeOut('fast',function () { $.modal.close(); });
}});
},
success:function(html){
// Show modal with info
$("#modal").html(html); /*.modal({overlayClose:true,opacity:70,overlayCss:{backgroundColor:"#000"},onClose: function (dialog) {
dialog.data.fadeOut('fast',function () { $.modal.close(); });
}});*/
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
function template_browse_select(thisDir)
{
if(thisDir == "")
{
alert("No directory provided!");
return false;
}
$.modal.close();
$('#create_tpl_file_path').val(thisDir);
$('#browse_done').fadeIn();
$('#create_tpl_file_path').focus();
}