2018-01-11 13:01:16 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const attributesDialog = (function() {
|
|
|
|
const dialogEl = $("#attributes-dialog");
|
2018-01-12 10:40:09 +08:00
|
|
|
const attributesModel = new AttributesModel();
|
2018-01-11 13:01:16 +08:00
|
|
|
|
2018-01-12 10:40:09 +08:00
|
|
|
function AttributesModel() {
|
|
|
|
const self = this;
|
2018-01-11 13:01:16 +08:00
|
|
|
|
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);
|
|
|
|
};
|
2018-01-11 13:01:16 +08:00
|
|
|
|
|
|
|
this.addNewRow = function() {
|
2018-01-12 10:40:09 +08:00
|
|
|
self.attributes.push({
|
2018-01-29 08:30:14 +08:00
|
|
|
attributeId: '',
|
2018-01-11 13:01:16 +08:00
|
|
|
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.");
|
|
|
|
};
|
2018-01-11 13:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function showDialog() {
|
|
|
|
glob.activeDialog = dialogEl;
|
|
|
|
|
|
|
|
dialogEl.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 800,
|
2018-02-04 01:44:22 +08:00
|
|
|
height: 500
|
2018-01-11 13:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-01-12 10:40:09 +08:00
|
|
|
attributesModel.loadAttributes();
|
2018-01-11 13:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$(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
|
|
|
|
2018-01-11 13:01:16 +08:00
|
|
|
return {
|
|
|
|
showDialog
|
|
|
|
};
|
|
|
|
})();
|