(w http.ResponseWriter, r *http.Request)
| 578 | } |
| 579 | |
| 580 | func (h *handler) handleChangedoc(w http.ResponseWriter, r *http.Request) { |
| 581 | ctx := r.Context() |
| 582 | if r.Method != "POST" { |
| 583 | http.Error(w, "not a POST", http.StatusMethodNotAllowed) |
| 584 | return |
| 585 | } |
| 586 | |
| 587 | docRef, ok := blob.Parse(r.FormValue("docref")) |
| 588 | if !ok { |
| 589 | httputil.ServeError(w, r, fmt.Errorf("invalid document blobRef %q", r.FormValue("docref"))) |
| 590 | return |
| 591 | } |
| 592 | |
| 593 | mode := r.FormValue("mode") |
| 594 | if mode == "break" { |
| 595 | if err := h.breakAndDeleteDoc(ctx, docRef); err != nil { |
| 596 | httputil.ServeError(w, r, fmt.Errorf("could not delete document %v: %v", docRef, err)) |
| 597 | return |
| 598 | } |
| 599 | fmt.Fprintf(w, "<html><body>[<< <a href='%s'>Back</a>] Doc %s deleted and images broken out as un-annotated.</body></html>", baseURL(r), docRef) |
| 600 | return |
| 601 | } |
| 602 | if mode == "delete" { |
| 603 | if err := h.deleteDocAndImages(ctx, docRef); err != nil { |
| 604 | httputil.ServeError(w, r, fmt.Errorf("could not do full delete of %v: %v", docRef, err)) |
| 605 | return |
| 606 | } |
| 607 | fmt.Fprintf(w, "<html><body>[<< <a href='%s'>Back</a>] Doc %s and its images deleted.</body></html>", baseURL(r), docRef) |
| 608 | return |
| 609 | } |
| 610 | |
| 611 | document := &document{} |
| 612 | document.physicalLocation = r.FormValue("physical_location") |
| 613 | document.title = r.FormValue("title") |
| 614 | document.tags = newSeparatedString(r.FormValue("tags")) |
| 615 | |
| 616 | docDate, err := dateOrZero(r.FormValue("date"), dateformatYyyyMmDd) |
| 617 | if err != nil { |
| 618 | httputil.ServeError(w, r, fmt.Errorf("could not assign new date to document: %v", err)) |
| 619 | return |
| 620 | } |
| 621 | document.docDate = docDate |
| 622 | |
| 623 | duedate, err := dateOrZero(r.FormValue("due_date"), dateformatYyyyMmDd) |
| 624 | if err != nil { |
| 625 | httputil.ServeError(w, r, fmt.Errorf("could not assign new due date to document: %v", err)) |
| 626 | return |
| 627 | } |
| 628 | document.dueDate = duedate |
| 629 | |
| 630 | if err := h.updateDocument(ctx, docRef, document); err != nil { |
| 631 | httputil.ServeError(w, r, fmt.Errorf("could not update document %v: %v", docRef, err)) |
| 632 | return |
| 633 | } |
| 634 | |
| 635 | http.Redirect(w, r, fmt.Sprintf("%s?saved_doc=%s", baseURL(r), docRef), http.StatusFound) |
| 636 | } |
| 637 |
nothing calls this directly
no test coverage detected