Browse Source

log-contents: Added remove log form.

1.0
Gisle Aune 6 years ago
parent
commit
7323d41654
  1. 1
      marko/page/logs-content/components/edit-log-modal/component.js
  2. 5
      marko/page/logs-content/components/page/component.js
  3. 8
      marko/page/logs-content/components/page/index.marko
  4. 33
      marko/page/logs-content/components/remove-log-modal/component.js
  5. 9
      marko/page/logs-content/components/remove-log-modal/index.marko

1
marko/page/logs-content/components/edit-log-modal/component.js

@ -51,7 +51,6 @@ module.exports = class {
}
const input = Object.assign({id: this.input.log.id}, this.state.values)
console.log(input)
this.state.loading = true
logsApi.edit(input).then(data => {

5
marko/page/logs-content/components/page/component.js

@ -7,6 +7,7 @@ module.exports = class {
this.state = {
log: input.log,
modal: null,
removed: false,
}
}
@ -92,6 +93,10 @@ module.exports = class {
this.state.log = Object.assign({}, this.state.log)
}
logRemoved() {
this.state.removed = true
}
get title() {
if (this.state.log.title) {
return this.state.log.title

8
marko/page/logs-content/components/page/index.marko

@ -4,7 +4,14 @@
<div class="header">
<h1 class="color-primary">${component.title}</h1>
<a on-click("open", "log.edit") class="color-menu">Edit</a>
<a on-click("open", "log.remove") class="color-menu">Remove</a>
</div>
<annotation if(state.removed) level="error">
<p>
This log has been removed. Your browser has not refreshed the page yet,
so you can still read it (or back it up) before leaving the page.
</p>
</annotation>
<post for(post in state.log.posts)
key=post.id
on-move("movePost", post)
@ -18,4 +25,5 @@
<add-post-modal enabled=(state.modal === "post.add") logId=state.log.id on-close("close") on-added("postAdded") />
<edit-log-modal enabled=(state.modal === "log.edit") log=state.log on-close("close") on-edited("logEdited") />
<remove-log-modal enabled=(state.modal === "log.remove") logId=state.log.id on-close("close") on-removed("logRemoved") />
</main>

33
marko/page/logs-content/components/remove-log-modal/component.js

@ -0,0 +1,33 @@
const {logsApi} = require("../../../../../rpdata/api/Log")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
}
}
open() {
}
close() {
this.emit("close")
}
doIt() {
this.state.loading = true
logsApi.remove({id: this.input.logId}).then(() => {
this.emit("removed")
this.emit("close")
}).catch(errs => {
console.warn("Failed to remove:", errs)
this.state.error = "Failed to remove: " + errs.message || errs[0].message
}).then(() => {
this.state.loading = false
})
}
}

9
marko/page/logs-content/components/remove-log-modal/index.marko

@ -0,0 +1,9 @@
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) notification closable on-close("close") on-open("open") >
<h1>Remove Log</h1>
<p class="color-error">${state.error}</p>
<p class="color-danger">Removal is final!</p>
<button disabled=state.loading on-click("doIt")>I will destroy you!</button>
</modal>
Loading…
Cancel
Save