-
Notifications
You must be signed in to change notification settings - Fork 469
/
script.js
167 lines (149 loc) · 4.92 KB
/
script.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
/*jshint esversion: 6 */
/*********** MessageBox ****************/
// simply show info. Only close button
function infoMessageBox(message, title){
$("#info-body").html(message);
$("#info-title").html(title);
$("#info-popup").modal('show');
}
// modal with full control
function messageBox(body, title, ok_text, close_text, callback){
$("#modal-body").html(body);
$("#modal-title").html(title);
if (ok_text) $("#modal-button").html(ok_text);
if(close_text) $("#modal-close-button").html(close_text);
$("#modal-button").unbind("click"); // remove existing events attached to this
$("#modal-button").click(callback);
$("#popup").modal("show");
}
/*********** crontab actions ****************/
function deleteJob(_id){
// TODO fix this. pass callback properly
messageBox("<p> Do you want to delete this Job? </p>", "Confirm delete", null, null, function(){
$.post(routes.remove, {_id: _id}, function(){
location.reload();
});
});
}
function stopJob(_id){
messageBox("<p> Do you want to stop this Job? </p>", "Confirm stop job", null, null, function(){
$.post(routes.stop, {_id: _id}, function(){
location.reload();
});
});
}
function startJob(_id){
messageBox("<p> Do you want to start this Job? </p>", "Confirm start job", null, null, function(){
$.post(routes.start, {_id: _id}, function(){
location.reload();
});
});
}
function setCrontab(){
messageBox("<p> Do you want to set the crontab file? </p>", "Confirm crontab setup", null, null, function(){
$.get(routes.crontab, { "env_vars": $("#env_vars").val() }, function(){
// TODO show only if success
infoMessageBox("Successfuly set crontab file!","Information");
});
});
}
function getCrontab(){
messageBox("<p> Do you want to get the crontab file? </p>", "Confirm crontab retrieval", null, null, function(){
$.get(routes.import_crontab, { "env_vars": $("#env_vars").val() }, function(){
// TODO show only if success
infoMessageBox("Successfuly got the crontab file!","Information");
location.reload();
});
});
}
function editJob(_id){
var job = null;
crontabs.forEach(function(crontab){
if(crontab._id == _id)
job = crontab;
});
if(job){
$("#job").modal("show");
$("#job-name").val(job.name);
$("#job-command").val(job.command);
// if macro not used
if(job.schedule.indexOf("@") != 0){
var components = job.schedule.split(" ");
$("#job-minute").val(components[0]);
$("#job-hour").val(components[1]);
$("#job-day").val(components[2]);
$("#job-month").val(components[3]);
$("#job-week").val(components[4]);
}
schedule = job.schedule;
job_command = job.command;
if (job.logging && job.logging != "false")
$("#job-logging").prop("checked", true);
job_string();
}
$("#job-save").unbind("click"); // remove existing events attached to this
$("#job-save").click(function(){
// TODO good old boring validations
$.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id, logging: $("#job-logging").prop("checked")}, function(){
location.reload();
});
});
}
function newJob(){
schedule = "";
job_command = "";
$("#job-minute").val("*");
$("#job-hour").val("*");
$("#job-day").val("*");
$("#job-month").val("*");
$("#job-week").val("*");
$("#job").modal("show");
$("#job-name").val("");
$("#job-command").val("");
job_string();
$("#job-save").unbind("click"); // remove existing events attached to this
$("#job-save").click(function(){
// TODO good old boring validations
$.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1, logging: $("#job-logging").prop("checked")}, function(){
location.reload();
});
});
}
function doBackup(){
messageBox("<p> Do you want to take backup? </p>", "Confirm backup", null, null, function(){
$.get(routes.backup, {}, function(){
location.reload();
});
});
}
function delete_backup(db_name){
messageBox("<p> Do you want to delete this backup? </p>", "Confirm delete", null, null, function(){
$.get(routes.delete_backup, {db: db_name}, function(){
location = routes.root;
});
});
}
function restore_backup(db_name){
messageBox("<p> Do you want to restore this backup? </p>", "Confirm restore", null, null, function(){
$.get(routes.restore_backup, {db: db_name}, function(){
location = routes.root;
});
});
}
function import_db(){
messageBox("<p> Do you want to import crontab?<br /> <b style='color:red'>NOTE: It is recommended to take a backup before this.</b> </p>", "Confirm import from crontab", null, null, function(){
$('#import_file').click();
});
}
// script corresponding to job popup management
var schedule = "";
var job_command = "";
function job_string(){
$("#job-string").val(schedule + " " + job_command);
return schedule + " " + job_command;
}
function set_schedule(){
schedule = $("#job-minute").val() + " " +$("#job-hour").val() + " " +$("#job-day").val() + " " +$("#job-month").val() + " " +$("#job-week").val();
job_string();
}
// popup management ends