store mail options in db
							parent
							
								
									b84a04adb0
								
							
						
					
					
						commit
						3d56cb1db0
					
				|  | @ -0,0 +1,2 @@ | |||
| Mailing and Hooks | ||||
| ================= | ||||
							
								
								
									
										2
									
								
								app.js
								
								
								
								
							
							
						
						
									
										2
									
								
								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{ | ||||
|  |  | |||
							
								
								
									
										11
									
								
								crontab.js
								
								
								
								
							
							
						
						
									
										11
									
								
								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){ | ||||
|  |  | |||
|  | @ -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 = "<p>This is based on nodemailer. Refer <a href='https://github.com/nodemailer/nodemailer'>this</a> for more details.</p>"; | ||||
| 	let message = "<p>This is based on nodemailer. Refer <a href='https://github.com/alseambusher/crontab-ui/tree/master/README/mail.md'>this</a> for more details.</p>"; | ||||
| 	container.innerHTML += message; | ||||
| 
 | ||||
| 	let transporterLabel = document.createElement("label"); | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ | |||
| 	<label>Job</label> | ||||
| 	<input type='text' class='form-control' id='job-string' disabled='disabled'/><br /> | ||||
| 	<label><input type="checkbox" id="job-logging" style="position:relative;top:2px"/> Enable error logging.</label><br /> | ||||
| 	<a class="btn btn-primary btn-small" data-json="{}" onclick="setMailConfig(this);">Mailing</a> | ||||
| 	<a class="btn btn-primary btn-small" data-json="{}" onclick="setMailConfig(this);" id="job-mailing">Mailing</a> | ||||
| 	<a class="btn btn-primary btn-small" data-json="{}" onclick="setHookConfig(this);">Hooks</a> | ||||
|       </div> | ||||
|       <div class="modal-footer"> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 alseambusher
						alseambusher