summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jobs.go81
-rw-r--r--main.go1
-rw-r--r--tpls.go2
-rw-r--r--tpls/jobs.tpl43
4 files changed, 127 insertions, 0 deletions
diff --git a/jobs.go b/jobs.go
new file mode 100644
index 0000000..d4787fa
--- /dev/null
+++ b/jobs.go
@@ -0,0 +1,81 @@
+package main
+
+import (
+ "github.com/gorilla/sessions"
+ "kch42.de/gostuff/mailremind/model"
+ "net/http"
+)
+
+type jobTpldata struct {
+ ID, Subject, Excerpt, Next string
+}
+
+func jobToTpldata(job model.Job, user model.User) *jobTpldata {
+ excerpt := string(job.Content())
+ if len(excerpt) > 100 {
+ excerpt = string([]rune(excerpt)[0:100]) + " (...)"
+ }
+
+ return &jobTpldata{
+ ID: job.ID().String(),
+ Subject: job.Subject(),
+ Excerpt: excerpt,
+ Next: job.Next().In(user.Location()).Format("2006-Jan-02 15:04:05"),
+ }
+}
+
+type jobsTpldata struct {
+ Error, Success string
+ Jobs []*jobTpldata
+ Fatal bool
+}
+
+func jobs(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+ if user == nil {
+ return &jobsTpldata{Error: "You need to be logged in to do that.", Fatal: true}
+ }
+
+ outdata := new(jobsTpldata)
+
+ if req.Method == "POST" {
+ if err := req.ParseForm(); err != nil {
+ outdata.Error = "Could not understand form data."
+ goto listjobs
+ }
+
+ if req.FormValue("Delconfirm") != "yes" {
+ goto listjobs
+ }
+
+ for _, _id := range req.Form["Jobs"] {
+ id, err := db.ParseDBID(_id)
+ if err != nil {
+ outdata.Error = "Not all jobs could be deleted."
+ continue
+ }
+
+ job, err := user.JobByID(id)
+ if err != nil {
+ outdata.Error = "Not all jobs could be deleted."
+ continue
+ }
+
+ if job.Delete() != nil {
+ outdata.Error = "Not all jobs could be deleted."
+ continue
+ }
+
+ outdata.Success = "Jobs deleted."
+ }
+ }
+
+listjobs:
+ jobs := user.Jobs()
+ outdata.Jobs = make([]*jobTpldata, len(jobs))
+
+ for i, job := range jobs {
+ outdata.Jobs[i] = jobToTpldata(job, user)
+ }
+
+ return outdata
+}
diff --git a/main.go b/main.go
index 58d71c7..d8cec10 100644
--- a/main.go
+++ b/main.go
@@ -89,6 +89,7 @@ func main() {
router.HandleFunc("/delete-acc", mkHttpHandler(deleteask, tplReallyDelete))
router.HandleFunc("/pwreset", mkHttpHandler(pwreset, tplPwreset))
router.HandleFunc("/forgotpw", mkHttpHandler(forgotpw, tplForgotpw))
+ router.HandleFunc("/jobs", mkHttpHandler(jobs, tplJobs))
http.Handle("/", router)
diff --git a/tpls.go b/tpls.go
index 14b8918..fdc6ca8 100644
--- a/tpls.go
+++ b/tpls.go
@@ -23,6 +23,7 @@ var (
tplReallyDelete *template.Template
tplPwreset *template.Template
tplForgotpw *template.Template
+ tplJobs *template.Template
)
func initTpls() {
@@ -37,6 +38,7 @@ func initTpls() {
tplReallyDelete = loadTpl(tplpath, "reallydelete")
tplPwreset = loadTpl(tplpath, "pwreset")
tplForgotpw = loadTpl(tplpath, "forgotpw")
+ tplJobs = loadTpl(tplpath, "jobs")
}
type msgTpldata struct {
diff --git a/tpls/jobs.tpl b/tpls/jobs.tpl
new file mode 100644
index 0000000..578791e
--- /dev/null
+++ b/tpls/jobs.tpl
@@ -0,0 +1,43 @@
+{{define "title"}}Jobs{{end}}
+
+{{define "content"}}
+ {{if .Error}}
+ <div class="error">{{.Error}}</div>
+ {{end}}
+
+ {{if not .Fatal}}
+ {{if .Success}}
+ <div class="success">{{.Success}}</div>
+ {{end}}
+
+ <form action="/jobs" method="post">
+ <table class="fullwidth">
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th>Subject</th>
+ <th>Excerpt</th>
+ <th>Next</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{range .Jobs}}<tr>
+ <td><input type="checkbox" name="Jobs" value="{{.ID}}" /></td>
+ <td><a href="/edit/{{.ID}}">{{.Subject}}</a></td>
+ <td>{{.Excerpt}}</td>
+ <td>{{.Next}}</td>
+ </tr>{{end}}
+ </tbody>
+ </table>
+ <hr />
+ <p>
+ Delete selected:
+ <select name="Delconfirm" size="0">
+ <option value="no" selected="selected">No</option>
+ <option value="yes">Yes</option>
+ </select>
+ <input type="submit" />
+ </p>
+ </form>
+ {{end}}
+{{end}} \ No newline at end of file