trilium/public/javascripts/dialogs/attributes.js

62 lines
1.5 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({
attribute_id: '',
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,
height: 700
});
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
};
})();