2021-06-15 22:59:13 +02:00
|
|
|
import ButtonWidget from "./button_widget.js";
|
2021-06-24 23:50:56 +02:00
|
|
|
import appContext from "../../services/app_context.js";
|
2021-06-15 22:59:13 +02:00
|
|
|
|
|
|
|
export default class EditButton extends ButtonWidget {
|
|
|
|
isEnabled() {
|
|
|
|
return super.isEnabled() && this.noteContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.icon("bx-edit-alt")
|
|
|
|
.title("Edit this note")
|
|
|
|
.titlePlacement("bottom")
|
|
|
|
.onClick(widget => {
|
|
|
|
this.noteContext.readOnlyTemporarilyDisabled = true;
|
|
|
|
|
2021-06-24 23:50:56 +02:00
|
|
|
appContext.triggerEvent('readOnlyTemporarilyDisabled', {noteContext: this.noteContext});
|
2021-06-15 22:59:13 +02:00
|
|
|
|
|
|
|
this.refresh();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshWithNote(note) {
|
|
|
|
// can't do this in isEnabled() since isReadOnly is async
|
|
|
|
this.toggleInt(await this.noteContext.isReadOnly());
|
|
|
|
|
|
|
|
await super.refreshWithNote(note);
|
|
|
|
}
|
|
|
|
}
|