diff --git a/src/core/js/caosdb.js b/src/core/js/caosdb.js index c6b3ce81c432c987c49a62e1fea8484b85d6bf2b..7fe4e9441822bf6c706a09c95aa65f0a2fef06a8 100644 --- a/src/core/js/caosdb.js +++ b/src/core/js/caosdb.js @@ -832,7 +832,7 @@ function _createDocument(root) { * @param id The id of the entity. Can be undefined. * @param properties A list of properties. * @param parents A list of parents. - * @return {Document|DocumentFragement} - An xml document holding the newly + * @return {Document|DocumentFragment} - An xml document holding the newly * created entity. * */ diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js index 50325e97d4dabcd16fae2a2817314f4a7ddf3243..0c52f403d5d9b2f0b2feb60a9dc21403c12dc0b2 100644 --- a/src/core/js/edit_mode.js +++ b/src/core/js/edit_mode.js @@ -398,17 +398,24 @@ var edit_mode = new function() { return await insert(xmls); } - this.form_to_xml = function(ent_element) { - const obj = form_elements.form_to_object($(ent_element).find("form")[0]); + /** + * Generate an XML from the form of the edited/newly created entity. + * + * @param {HTMLElement} entity_form - FORM of new/changed entity. + * @returns {Document|DocumentFragment} - An xml document containing the + * entity in XML representation. + */ + this.form_to_xml = function(entity_form) { + const obj = form_elements.form_to_object($(entity_form).find("form")[0]); return createEntityXML( - getEntityRole(ent_element), - getEntityName(ent_element), - getEntityID(ent_element), - edit_mode.getProperties(ent_element), - getParents(ent_element), + getEntityRole(entity_form), + getEntityName(entity_form), + getEntityID(entity_form), + edit_mode.getProperties(entity_form), + getParents(entity_form), true, edit_mode.get_datatype_str(obj), - getEntityDescription(ent_element), + getEntityDescription(entity_form), obj.unit, ); } @@ -636,6 +643,21 @@ var edit_mode = new function() { return datatype.substring(5, datatype.length - 1); } + /** + * Append listeners to all input elements depending on the datatype. + * + * The relevant input elements are those for the unit and the + * reference_scope. + * + * Only when the atomic_datatype is either "DOUBLE" or "INTEGER" the unit + * field should be visible and enabled. Only when the atomic_datatype is + * "REFERENCE", the reference_scope field shoudl be visible and enabled. + * + * The listener `on_datatype_change` is added to the datatype field and + * triggered right away for the first time. + * + * @param {HTMLElement} form - The form containing the input fields. + */ this.make_datatype_input_logic = function(form) { const datatype = form_elements.get_fields(form, "atomic_datatype"); @@ -649,6 +671,14 @@ var edit_mode = new function() { edit_mode.on_datatype_change(form, $(datatype).find("select").val()); } + /** + * The listener which is added by `make_datatype_input_logic`. + * + * @param {HTMLElement} form - The form containing the datatype and unit + * input elements. + * @param {string} new_type - the new datatype which is used by this + * listener to determine which fields need to be enabled or disabled. + */ this.on_datatype_change = function (form, new_type) { logger.trace('enter on_datatype_change', form, new_type); @@ -666,6 +696,12 @@ var edit_mode = new function() { } + /** + * Generate a text input element for the unit of an abstract property. + * + * @param {string} unit - the initial value of the input element. + * @returns {HTMLElement} - a labeled form field. + */ this.make_unit_input = function(unit) { const unit_input = $(form_elements .make_text_input({ diff --git a/src/core/js/query_shortcuts.js b/src/core/js/query_shortcuts.js index aac82000663cb47453147ef63d51d3a8d138b15d..426a6db4ea3b25d10e0bb6c0289caa664b34e71f 100644 --- a/src/core/js/query_shortcuts.js +++ b/src/core/js/query_shortcuts.js @@ -831,6 +831,15 @@ var query_shortcuts = new function() { return form; } + /** + * Add the "caosdb-f-entity-property" class to the form fields. Thus the + * fields are findable by the `getEntityXML` method which is used in + * `get_shortcut_entities` to generate the entity xml from the shortcut + * form. + * + * @param {HTMLElement} form - form which contains the fields where the + * class is to be added. + */ this._toggle_entity_property_class = function(form) { form.addEventListener("caosdb.form.ready", () => { $(form).find(".caosdb-f-field").toggleClass("caosdb-f-entity-property", true);