trilium/src/public/javascripts/dialogs/attributes.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

"use strict";
const attributesDialog = (function() {
const dialogEl = $("#attributes-dialog");
2018-01-12 10:40:09 +08:00
const attributesModel = new AttributesModel();
2018-01-12 10:40:09 +08:00
function AttributesModel() {
const self = this;
2018-01-12 10:40:09 +08:00
this.attributes = ko.observableArray();
this.loadAttributes = async function() {
const noteId = noteEditor.getCurrentNoteId();
const attributes = await server.get('notes/' + noteId + '/attributes');
this.attributes(attributes);
};
this.addNewRow = function() {
2018-01-12 10:40:09 +08:00
self.attributes.push({
2018-01-29 08:30:14 +08:00
attributeId: '',
name: '',
value: ''
});
2018-01-12 10:40:09 +08:00
};
this.save = async function() {
const noteId = noteEditor.getCurrentNoteId();
const attributes = await server.put('notes/' + noteId + '/attributes', this.attributes());
self.attributes(attributes);
showMessage("Attributes have been saved.");
};
}
async function showDialog() {
glob.activeDialog = dialogEl;
dialogEl.dialog({
modal: true,
width: 800,
2018-02-04 01:44:22 +08:00
height: 500
});
2018-01-12 10:40:09 +08:00
attributesModel.loadAttributes();
}
$(document).bind('keydown', 'alt+a', e => {
showDialog();
e.preventDefault();
});
2018-01-22 12:06:25 +08:00
ko.applyBindings(attributesModel, document.getElementById('attributes-dialog'));
2018-01-12 10:40:09 +08:00
return {
showDialog
};
})();