import attributeService from '../services/attributes.js'; import NoteContextAwareWidget from "./note_context_aware_widget.js"; const TPL = `
`; export default class EditabilitySelectWidget extends NoteContextAwareWidget { doRender() { this.$widget = $(TPL); this.$editabilityActiveDesc = this.$widget.find(".editability-active-desc"); this.$widget.on('click', '.dropdown-item', async e => { this.$widget.find('.dropdown-toggle').dropdown('toggle'); const editability = $(e.target).closest("[data-editability]").attr("data-editability"); for (const ownedAttr of this.note.getOwnedLabels()) { if (['readOnly', 'autoReadOnlyDisabled'].includes(ownedAttr.name)) { await attributeService.removeAttributeById(this.noteId, ownedAttr.attributeId); } } if (editability !== 'auto') { await attributeService.addLabel(this.noteId, editability); } }); } async refreshWithNote(note) { this.$editabilityActiveDesc.text( this.note.hasLabel('readOnly') ? 'Read-Only' : ( this.note.hasLabel('autoReadOnlyDisabled') ? 'Always Editable' : 'Auto' ) ); } entitiesReloadedEvent({loadResults}) { if (loadResults.getAttributes().find(attr => attr.noteId === this.noteId)) { this.refresh(); } } }