summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jobedit.go14
-rw-r--r--static/mailremind.js42
2 files changed, 31 insertions, 25 deletions
diff --git a/jobedit.go b/jobedit.go
index 5519551..f2f086f 100644
--- a/jobedit.go
+++ b/jobedit.go
@@ -169,7 +169,14 @@ func (jt *jobeditTpldata) interpretForm(form url.Values, u model.User) (subject
if !ok {
jt.Error = "Some schedules were wrong (wrong time format, negative repetition counts)"
+ return
}
+
+ if len(mc) == 0 {
+ jt.Error = "No schedule."
+ ok = false
+ }
+
return
}
@@ -221,7 +228,9 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) (interf
subject, content, mc, ok := outdata.interpretForm(req.Form, user)
if ok {
next := mc.NextAfter(time.Now())
- if job != nil {
+ if next.IsZero() {
+ outdata.Error = "The schedule would not send any mail."
+ } else if job != nil {
if logfail("setting subject", job.SetSubject(subject)) &&
logfail("setting content", job.SetContent(content)) &&
logfail("setting chronos", job.SetChronos(mc)) &&
@@ -231,8 +240,7 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) (interf
outdata.Error = "Could not save everything."
}
} else {
- var err error
- if job, err = user.AddJob(subject, content, mc, next); logfail("creating new job", err) {
+ if job, err := user.AddJob(subject, content, mc, next); logfail("creating new job", err) {
outdata.fillFromJob(job, user)
outdata.Success = "Job created"
} else {
diff --git a/static/mailremind.js b/static/mailremind.js
index 8f3079f..0e3725a 100644
--- a/static/mailremind.js
+++ b/static/mailremind.js
@@ -1,15 +1,15 @@
$(function() {
var mkRow = function() {
var row = $("<tr/>");
-
+
row.append($("<td><input type=\"text\" name=\"Start\" /></td>"));
-
+
var yn = mkYNCheckbox("RepetitionEnabled", false);
var cell = $("<td/>");
cell.append(yn.hidden);
cell.append(yn.checkbox);
row.append(cell);
-
+
cell = $("<td/>");
cell.append($("<input type=\"text\" class=\"quant\" name=\"Count\" /><span> </span>"));
var unitsel = $("<select name=\"Unit\" size=\"0\" />");
@@ -19,79 +19,77 @@ $(function() {
}
cell.append(unitsel);
row.append(cell);
-
+
yn = mkYNCheckbox("EndEnabled", false);
cell = $("<td/>");
cell.append(yn.hidden);
cell.append(yn.checkbox);
row.append(cell);
-
+
row.append($("<td><input type=\"text\" name=\"End\" /></td>"));
-
+
attachFocusHandler($("input, select", row));
return row;
};
-
+
var mkYNCheckbox = function(name, b) {
var hidden = $("<input type=\"hidden\" />");
hidden.prop("value", b ? "yes" : "no");
hidden.prop("name", name);
-
+
var checkbox = $("<input type=\"checkbox\" />");
checkbox.prop("checked", b);
checkbox.change(function() {
hidden.prop("value", checkbox.prop("checked") ? "yes" : "no");
});
-
+
return {"hidden": hidden, "checkbox": checkbox};
};
-
+
$("select.enabler").each(function(i) {
var self = $(this);
var yn = mkYNCheckbox(self.prop("name"), self.val() == "yes");
-
+
self.before(yn.hidden);
self.before(yn.checkbox);
self.remove();
});
-
+
var maxSchedules = $("table.schedules tbody tr").length;
var checkInsRow = function() {
if($("table.schedules tbody tr").length >= maxSchedules) {
return;
}
-
+
$("table.schedules tbody").append(mkRow());
};
-
+
var attachFocusHandler = function(q) {
q.focus(function() {
var myrow = $(this).parent().parent();
$("table.schedules tbody tr").not(myrow).each(function(i) {
checkRemoveRow($(this));
});
-
+
checkInsRow();
});
};
-
-
-
+
var checkRemoveRow = function(row) {
if($("input[name=\"Start\"]", row).val() == "") {
row.remove();
}
};
-
+
var updateSchedulesTab = function() {
$("table.schedules tbody tr").each(function(i) {
checkRemoveRow($(this));
});
-
+
checkInsRow();
};
-
+
attachFocusHandler($("table.schedules input, table.schedules select"));
-
+
updateSchedulesTab();
}); \ No newline at end of file