mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Add "Clear old" for deleting crossed list items
Former-commit-id: f43b6caae264ef5f8cd46f8a40143501a39d5948 [formerly 328a9724705837f8287a6d519578513fb868c962] [formerly b006fff403bdf2421495a4d4e8f9ef246e15adec [formerly fb4118be424a81a90072ad987c886af08923917a]]
Former-commit-id: da4974f66bfcea8602d9b08f129b73ba06d69ea8 [formerly 8215c6a461f8bd2a9baee02176e64ec99a401ec9]
Former-commit-id: 4e070f07eef46a9f140a778dca7dc6c20adc76d5
Former-commit-id: 2980f1e193
This commit is contained in:
parent
bbf55f539f
commit
3b7e35f9ef
@ -1 +1 @@
|
||||
8241bf42c5b3ba0d768c26f3df5e4b20779790a5
|
||||
34bb35db683f8a7a61bc69989052e94f30862994
|
34
handlers.go
34
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"})
|
||||
}
|
||||
|
@ -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 }}
|
||||
<li class="pure-menu-item"><span id="saveEditButton">Encrypted</span></li>
|
||||
{{ end }}
|
||||
{{else}}<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li>
|
||||
{{else}}
|
||||
{{ if .ListPage }}
|
||||
<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="#" class="pure-menu-link" id="clearOld">Clear old</a></li>
|
||||
{{ else }}
|
||||
<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li>
|
||||
{{ end }}
|
||||
<li class="pure-menu-item {{ with .EditPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/edit" class="pure-menu-link"><span id="saveEditButton">Edit</span></a></li>
|
||||
{{end}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user