diff --git a/README/mail.md b/README/mail.md new file mode 100644 index 0000000..2e72454 --- /dev/null +++ b/README/mail.md @@ -0,0 +1,2 @@ +Mailing and Hooks +================= diff --git a/app.js b/app.js index 25cc60c..e95ee28 100755 --- a/app.js +++ b/app.js @@ -57,7 +57,7 @@ If it is a new job @param _id is set to -1 app.post(routes.save, function(req, res) { // new job if(req.body._id == -1){ - crontab.create_new(req.body.name, req.body.command, req.body.schedule, req.body.logging); + crontab.create_new(req.body.name, req.body.command, req.body.schedule, req.body.logging, req.body.mailing); } // edit job else{ diff --git a/crontab.js b/crontab.js index 84065e7..5707610 100644 --- a/crontab.js +++ b/crontab.js @@ -15,7 +15,7 @@ var os = require("os"); exports.log_folder = __dirname + '/crontabs/logs'; exports.env_file = __dirname + '/crontabs/env.db'; -crontab = function(name, command, schedule, stopped, logging){ +crontab = function(name, command, schedule, stopped, logging, mailing){ var data = {}; data.name = name; data.command = command; @@ -25,17 +25,20 @@ crontab = function(name, command, schedule, stopped, logging){ } data.timestamp = (new Date()).toString(); data.logging = logging; + if (!mailing) + mailing = {}; + data.mailing = mailing; return data; }; -exports.create_new = function(name, command, schedule, logging){ - var tab = crontab(name, command, schedule, false, logging); +exports.create_new = function(name, command, schedule, logging, mailing){ + var tab = crontab(name, command, schedule, false, logging, mailing); tab.created = new Date().valueOf(); db.insert(tab); }; exports.update = function(data){ - db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null, data.logging)); + db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null, data.logging, data.mailing)); }; exports.status = function(_id, stopped){ diff --git a/public/js/script.js b/public/js/script.js index f7ba184..9777b19 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -95,6 +95,9 @@ function editJob(_id){ $("#job-month").val(components[3]); $("#job-week").val(components[4]); } + if (job.mailing) { + $("#job-mailing").attr("data-json", JSON.stringify(job.mailing)); + } schedule = job.schedule; job_command = job.command; if (job.logging && job.logging != "false") @@ -108,7 +111,10 @@ function editJob(_id){ if (!schedule) { schedule = "* * * * *"; } - $.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id, logging: $("#job-logging").prop("checked")}, function(){ + let name = $("#job-name").val(); + let mailing = JSON.parse($("#job-mailing").attr("data-json")); + let logging = $("#job-logging").prop("checked"); + $.post(routes.save, {name: name, command: job_command , schedule: schedule, _id: _id, logging: logging, mailing: mailing}, function(){ location.reload(); }); }); @@ -126,6 +132,7 @@ function newJob(){ $("#job").modal("show"); $("#job-name").val(""); $("#job-command").val(""); + $("#job-mailing").attr("data-json", "{}"); job_string(); $("#job-save").unbind("click"); // remove existing events attached to this $("#job-save").click(function(){ @@ -133,7 +140,10 @@ function newJob(){ if (!schedule) { schedule = "* * * * *"; } - $.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1, logging: $("#job-logging").prop("checked")}, function(){ + let name = $("#job-name").val(); + let mailing = JSON.parse($("#job-mailing").attr("data-json")); + let logging = $("#job-logging").prop("checked"); + $.post(routes.save, {name: name, command: job_command , schedule: schedule, _id: -1, logging: logging, mailing: mailing}, function(){ location.reload(); }); }); @@ -173,7 +183,7 @@ function setMailConfig(a){ let data = JSON.parse(a.getAttribute("data-json")); let container = document.createElement("div"); - let message = "
This is based on nodemailer. Refer this for more details.
"; + let message = "This is based on nodemailer. Refer this for more details.
"; container.innerHTML += message; let transporterLabel = document.createElement("label"); diff --git a/views/popup.ejs b/views/popup.ejs index ea64f10..06bc9d7 100644 --- a/views/popup.ejs +++ b/views/popup.ejs @@ -40,7 +40,7 @@