diff --git a/bindata.go.REMOVED.git-id b/bindata.go.REMOVED.git-id index c86cd7f..f0c00ad 100644 --- a/bindata.go.REMOVED.git-id +++ b/bindata.go.REMOVED.git-id @@ -1 +1 @@ -8241bf42c5b3ba0d768c26f3df5e4b20779790a5 \ No newline at end of file +34bb35db683f8a7a61bc69989052e94f30862994 \ No newline at end of file diff --git a/handlers.go b/handlers.go index ed79116..ac698fb 100755 --- a/handlers.go +++ b/handlers.go @@ -29,6 +29,7 @@ func serve(port string) { router.POST("/prime", handlePrime) router.POST("/lock", handleLock) router.POST("/encrypt", handleEncrypt) + router.DELETE("/oldlist", handleClearOldListItems) router.DELETE("/listitem", deleteListItem) router.Run(":" + port) @@ -315,3 +316,36 @@ func deleteListItem(c *gin.Context) { }) } } + +func handleClearOldListItems(c *gin.Context) { + type QueryJSON struct { + Page string `json:"page"` + } + + var json QueryJSON + if c.BindJSON(&json) != nil { + c.String(http.StatusBadRequest, "Problem binding keys") + return + } + p := Open(json.Page) + if p.IsEncrypted { + c.JSON(http.StatusOK, gin.H{"success": false, "message": "Encrypted"}) + return + } + if p.IsLocked { + c.JSON(http.StatusOK, gin.H{"success": false, "message": "Locked"}) + return + } + lines := strings.Split(p.Text.GetCurrent(), "\n") + newLines := make([]string, len(lines)) + newLinesI := 0 + for _, line := range lines { + if strings.Count(line, "~~") != 2 { + newLines[newLinesI] = line + newLinesI++ + } + } + p.Update(strings.Join(newLines[0:newLinesI], "\n")) + p.Save() + c.JSON(http.StatusOK, gin.H{"success": true, "message": "Cleared"}) +} diff --git a/templates/index.tmpl b/templates/index.tmpl index 2e126ff..7562885 100755 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -242,6 +242,33 @@ }); } + function clearOld() { + $.ajax({ + type: 'DELETE', + url: '/oldlist', + data: JSON.stringify({ + page: "{{ .Page }}" + }), + success: function(data) { + $('#saveEditButton').removeClass() + if (data.success == true) { + $('#saveEditButton').addClass("success"); + } else { + $('#saveEditButton').addClass("failure"); + } + $('#saveEditButton').text(data.message); + if (data.success == true) { + window.location = "/{{ .Page }}/list"; + } + }, + error: function(xhr, error) { + $('#saveEditButton').text(error); + }, + contentType: "application/json", + dataType: 'json' + }); + } + $("#encryptPage").click(function(e) { e.preventDefault(); @@ -289,6 +316,16 @@ } }); + $("#clearOld").click(function(e) { + e.preventDefault(); + var r = confirm("This will erase all cleared list items, are you sure you want to do that?"); + if (r == true) { + clearOld() + } else { + x = "You pressed Cancel!"; + } + }); + $("textarea").keydown(function(e) { if(e.keyCode === 9) { // tab was pressed // get caret position/selection @@ -368,7 +405,12 @@ {{ else }}