diff --git a/CHANGELOG.md b/CHANGELOG.md index da29dae97810e71d3e4fbaf2bc9149cb072988e2..dd575475b36d6d1d914dde278485385951271f5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### +* Query shortcuts are now displayed when using the new query panel. + ### Security ### ### Documentation ### diff --git a/src/core/js/query_shortcuts.js b/src/core/js/query_shortcuts.js index cd69b4cf791e4281ff8e35be8698a91d71abc0a4..08a23efdc44d634f2c588173a6ac2f3d2ca0e06e 100644 --- a/src/core/js/query_shortcuts.js +++ b/src/core/js/query_shortcuts.js @@ -44,7 +44,7 @@ * } * ] */ -var query_shortcuts = new function() { +var query_shortcuts = new function () { this.dependencies = ["form_elements", "log", "transaction"]; @@ -68,7 +68,7 @@ var query_shortcuts = new function() { * * @return {HTMLElement} The toolbox drop-down. */ - this.make_toolbox_button = function() { + this.make_toolbox_button = function () { var ret = $( `<div class="dropdown text-end caosdb-f-shortcuts-toolbox-button"> <button title="Shortcuts Toolbox" class="btn dropdown-bs-toggle" type="button" @@ -86,17 +86,17 @@ var query_shortcuts = new function() { // bind callback functions ret.find("button[data-tool='delete']") - .click(function() { + .click(function () { var shortcuts_panel = $(".caosdb-shortcuts-container"); query_shortcuts.init_delete_shortcut_form(shortcuts_panel[0]); }); ret.find("button[data-tool='create']") - .click(function() { + .click(function () { var shortcuts_panel = $(".caosdb-shortcuts-container"); query_shortcuts.init_create_shortcut_form(shortcuts_panel[0]); }); ret.find("button[data-tool='edit']") - .click(function() { + .click(function () { var shortcuts_panel = $(".caosdb-shortcuts-container"); query_shortcuts.init_update_shortcut_form(shortcuts_panel[0]); }); @@ -104,13 +104,13 @@ var query_shortcuts = new function() { return ret[0]; } - this.init_datamodel = function() { + this.init_datamodel = function () { // TODO handle the datamodel dependencies in a save way (lazy-loading is // bad, if the data-model is not there). - if(typeof this._shortcuts_property_query_id == "undefined") { + if (typeof this._shortcuts_property_query_id == "undefined") { query("FIND Property " + query_shortcuts._shortcuts_property_query_name) .then(result => { - if(result.length > 0) { + if (result.length > 0) { query_shortcuts._shortcuts_property_query_id = getEntityID(result[0]); } else { query_shortcuts._shortcuts_property_query_id = null; @@ -118,10 +118,10 @@ var query_shortcuts = new function() { }) .catch(query_shortcuts.logger.error); } - if(typeof this._shortcuts_property_description_id == "undefined") { + if (typeof this._shortcuts_property_description_id == "undefined") { query("FIND Property " + this._shortcuts_property_description_name) .then(result => { - if(result.length > 0) { + if (result.length > 0) { query_shortcuts._shortcuts_property_description_id = getEntityID(result[0]); } else { query_shortcuts._shortcuts_property_description_id = null; @@ -129,10 +129,10 @@ var query_shortcuts = new function() { }) .catch(query_shortcuts.logger.error); } - if(typeof this._shortcuts_record_type_id == "undefined") { + if (typeof this._shortcuts_record_type_id == "undefined") { query("FIND RecordType " + query_shortcuts._shortcuts_record_type_name) .then(result => { - if(result.length > 0) { + if (result.length > 0) { query_shortcuts._shortcuts_record_type_id = getEntityID(result[0]); } else { query_shortcuts._shortcuts_record_type_id = null; @@ -142,7 +142,7 @@ var query_shortcuts = new function() { } } - this.init = async function() { + this.init = async function () { this.init_datamodel(); var header = $('<details class="caosdb-f-shortcuts-panel-header"><summary class="caosdb-f-shortcuts-panel-header-title">Shortcuts</summary></details>') header.find("summary").append(this.make_toolbox_button()); @@ -153,13 +153,19 @@ var query_shortcuts = new function() { body.append(await this.retrieve_global_shortcuts()); - if(isAuthenticated()) { + if (isAuthenticated()) { body.append(await this.retrieve_user_shortcuts()); } if (body.children(".caosdb-f-query-shortcut").length > 0) { // append if not empty - $("#caosdb-query-panel").append(shortcuts_panel); + if ("${BUILD_MODULE_LEGACY_QUERY_FORM}" != "ENABLED") { + // The selector has a different name with the new panel + const queryPanelSelectorName = ".caosdb-f-query-form"; + $(queryPanelSelectorName).after(shortcuts_panel); + } else { + $("#caosdb-query-panel").append(shortcuts_panel); + } } return shortcuts_panel[0]; @@ -178,9 +184,9 @@ var query_shortcuts = new function() { * @param {string} str * @returns {string[]} array with all ids of placeholders */ - this.find_placeholders = function(str) { + this.find_placeholders = function (str) { const re = /\{(\w*?)\}/g; - var match = [...str.matchAll(re)]; + var match = [...str.matchAll(re)]; var ret = [] for (const ph of match) { @@ -202,7 +208,7 @@ var query_shortcuts = new function() { * @return {string} the description with all placeholders replaced with * input form elements. */ - this.replace_placeholders_with_inputs = function(description) { + this.replace_placeholders_with_inputs = function (description) { var placeholders = this.find_placeholders(description); var ret = description; @@ -229,7 +235,7 @@ var query_shortcuts = new function() { * @return {string} the query string with all placeholders replaced by the * values in the dictionary. */ - this.replace_placeholders_with_values = function(query, values) { + this.replace_placeholders_with_values = function (query, values) { var placeholders = this.find_placeholders(query); var ret = query; @@ -251,7 +257,7 @@ var query_shortcuts = new function() { * @param {HTMLElement} shortcut_form - a single shortcut form. * @returns {object} a dictionary with the inputs' names as keys. */ - this.extract_placeholder_values = function(shortcut_form) { + this.extract_placeholder_values = function (shortcut_form) { var ret = {} for (const input of $(shortcut_form).find("input")) { ret[input.name] = input.value; @@ -272,7 +278,7 @@ var query_shortcuts = new function() { * @param {string} query_string * @param {HTMLElement} A `DIV.caosdb-f-query-shortcut.row`. */ - this.generate_shortcut_form = function(description, query_string) { + this.generate_shortcut_form = function (description, query_string) { var preparedstr = query_shortcuts.replace_placeholders_with_inputs(description); var shortcut_form = $( `<div class="row caosdb-f-query-shortcut"> @@ -285,18 +291,28 @@ var query_shortcuts = new function() { ); // function for inserting the generated query string into the query panel - var insert_to_query_panel = (_) => { + var insert_to_query_panel = (inputSelectorName) => { var values = query_shortcuts.extract_placeholder_values(shortcut_form[0]); var replaced_query_string = query_shortcuts.replace_placeholders_with_values(query_string, values); - $("#caosdb-query-textarea") + + $(inputSelectorName) .focus() .val(replaced_query_string); + + return replaced_query_string; }; // callback for the submission var execute = (_) => { - insert_to_query_panel(); - $("#caosdb-query-form").submit(); + + if ("${BUILD_MODULE_LEGACY_QUERY_FORM}" != "ENABLED") { + const queryString = insert_to_query_panel(".caosdb-f-query-form input"); + window.localStorage.setItem("query.queryString", queryString); + $(".caosdb-f-query-panel form").submit() + } else { + insert_to_query_panel("#caosdb-query-textarea"); + $("#caosdb-query-form").submit(); + } }; shortcut_form.find(".caosdb-f-query-shortcut-right-col") @@ -304,7 +320,7 @@ var query_shortcuts = new function() { return shortcut_form[0]; } - this.generate_user_shortcut = function(description, query_string, id) { + this.generate_user_shortcut = function (description, query_string, id) { const ret = query_shortcuts.generate_shortcut_form(description, query_string); $(ret).toggleClass("caosdb-f-user-query-shortcut", true) .attr("data-entity-id", id) @@ -321,7 +337,7 @@ var query_shortcuts = new function() { * * @returns {HTMLElement[]} array of query shortcut forms. */ - this.retrieve_global_shortcuts = async function() { + this.retrieve_global_shortcuts = async function () { try { var temparray = await query_shortcuts._query_global_shortcuts(); @@ -332,7 +348,7 @@ var query_shortcuts = new function() { ret.push(this.generate_shortcut_form(tempel.description, tempel.query)); } return ret; - } catch (err){ + } catch (err) { query_shortcuts.logger.error(err); } @@ -350,7 +366,7 @@ var query_shortcuts = new function() { * * @returns {HTMLElement[]} array of query shortcut forms. */ - this.retrieve_user_shortcuts = async function() { + this.retrieve_user_shortcuts = async function () { try { var temparray = await query_shortcuts._query_user_shortcuts(); @@ -359,7 +375,7 @@ var query_shortcuts = new function() { var entity_id = getEntityID(temparray[i]); var description = getProperty(temparray[i], query_shortcuts._shortcuts_property_description_name, false); var query_string = getProperty(temparray[i], query_shortcuts._shortcuts_property_query_name, false); - if(query_string && description) { + if (query_string && description) { ret.push(this.generate_user_shortcut(description, query_string, entity_id)); } else { this.logger.warn("User-defined query shortcut without description or query", temparray[i]); @@ -367,8 +383,8 @@ var query_shortcuts = new function() { } return ret; } catch (err) { - if (typeof err.message === "string" - || err.message instanceof String) { + if (typeof err.message === "string" || + err.message instanceof String) { if (err.message.indexOf("404") > -1) { query_shortcuts.logger.warn(err); return; @@ -412,28 +428,28 @@ var query_shortcuts = new function() { * @param {HTMLElement} panel - the shortcuts panel with global and * user-defined shortcuts. */ - this.init_delete_shortcut_form = function(panel) { + this.init_delete_shortcut_form = function (panel) { $(panel).find(".alert").remove(); var form = this.make_delete_form(panel, this.delete_callback, this.handle_delete_success, this.handle_delete_error); this.init_cud_shortcut_form(panel, form); return panel; } - this.init_create_shortcut_form = function(panel) { + this.init_create_shortcut_form = function (panel) { $(panel).find(".alert").remove(); var form = this.make_create_form(panel, this.create_callback, this.handle_create_success, this.handle_create_error); this.init_cud_shortcut_form(panel, form); return panel; } - this.init_update_shortcut_form = function(panel) { + this.init_update_shortcut_form = function (panel) { $(panel).find(".alert").remove(); var selector = this.make_update_selector(panel, this.init_update_single_shortcut_form); this.init_cud_shortcut_form(panel, selector); } - this.init_update_single_shortcut_form = function(panel, entity_id) { + this.init_update_single_shortcut_form = function (panel, entity_id) { $(panel).find(".alert").remove(); var form = query_shortcuts.make_update_form(panel, entity_id, query_shortcuts.update_callback, query_shortcuts.handle_update_success, query_shortcuts.handle_update_error); query_shortcuts.init_cud_shortcut_form(panel, form); @@ -441,7 +457,7 @@ var query_shortcuts = new function() { } - this.handle_update_error = function(panel, results) { + this.handle_update_error = function (panel, results) { query_shortcuts.logger.trace("enter handle_update_error", panel, results); var errors = $(results).find(".alert-danger"); @@ -451,7 +467,7 @@ var query_shortcuts = new function() { } - this.handle_create_error = function(panel, results) { + this.handle_create_error = function (panel, results) { query_shortcuts.logger.trace("enter handle_create_error", panel, results); var errors = $(results).find(".alert-danger"); @@ -465,7 +481,7 @@ var query_shortcuts = new function() { * Add an "Edit" button to each query shortcut which opens the actual * update form. */ - this.make_update_selector = function(panel, init_update_form) { + this.make_update_selector = function (panel, init_update_form) { caosdb_utils.assert_html_element(panel, "param `panel`"); // clone panel @@ -485,7 +501,7 @@ var query_shortcuts = new function() { // remove old buttons wrapper.children().remove(); - if($(item).hasClass("caosdb-f-user-query-shortcut")) { + if ($(item).hasClass("caosdb-f-user-query-shortcut")) { // user shortcut // insert "UPDATE" button var entity_id = $(item).attr("data-entity-id"); @@ -497,75 +513,84 @@ var query_shortcuts = new function() { // global shortcut // gray out and add hint that this is a global shortcut which cannot be deleted. $(item) - .css({"color": "#CCCCCC"}) + .css({ + "color": "#CCCCCC" + }) .attr("title", "This is a global shortcut which cannot be updated via the browser."); } }); - var form = form_elements.make_form({fields: cloned.children().toArray(), submit: false}); + var form = form_elements.make_form({ + fields: cloned.children().toArray(), + submit: false + }); return form; } - this.init_cud_shortcut_form = function(panel, form) { + this.init_cud_shortcut_form = function (panel, form) { // hide content $(panel).children().hide(); var query_panel = $(".caosdb-query-form").hide(); // show original again on cancel - form.addEventListener("caosdb.form.cancel", function(e) { + form.addEventListener("caosdb.form.cancel", function (e) { query_panel.show(); $(panel).children().show(); }, true); // show results in query panel - form.addEventListener("caosdb.form.success", function(e) { + form.addEventListener("caosdb.form.success", function (e) { query_panel.show(); }, true); - form.addEventListener("caosdb.form.submit", function(e) { + form.addEventListener("caosdb.form.submit", function (e) { $(panel).find(".alert").remove(); }, true); $(panel).append(form); } - this.highlight_resulting_entities = function(panel, results) { + this.highlight_resulting_entities = function (panel, results) { for (const elem of $(results).find("[data-entity-id]")) { var result_id = $(elem).attr("data-entity-id"); var highlight = $(panel) - .find(".caosdb-f-user-query-shortcut[data-entity-id='" - + result_id + "']") - .toggleClass("caosdb-v-success-query-shortcut",true); + .find(".caosdb-f-user-query-shortcut[data-entity-id='" + + result_id + "']") + .toggleClass("caosdb-v-success-query-shortcut", true); highlight - .css({"background": "#90EE90"}); + .css({ + "background": "#90EE90" + }); } setTimeout(() => { $(".caosdb-v-success-query-shortcut") - .css({"background": "unset"}); - setTimeout(() => { - $(".caosdb-v-success-query-shortcut") - .toggleClass("caosdb-v-success-query-shortcut",false); - }, 2000); + .css({ + "background": "unset" + }); + setTimeout(() => { + $(".caosdb-v-success-query-shortcut") + .toggleClass("caosdb-v-success-query-shortcut", false); + }, 2000); }, 5000); } - this.append_messages_handler = function(panel, results) { + this.append_messages_handler = function (panel, results) { for (const entity of results) { var result_id = undefined; - if($(entity).is("[data-entity-id]")){ + if ($(entity).is("[data-entity-id]")) { result_id = $(entity).attr("data-entity-id"); } else { result_id = $(elem).attr("data-entity-id"); } - if(typeof result_id !== "undefined") { + if (typeof result_id !== "undefined") { var alerts = $(entity) .find("div.alert") .toggleClass("col-md-12"); $(panel) - .find(".caosdb-f-user-query-shortcut[data-entity-id='" - + result_id + "']") + .find(".caosdb-f-user-query-shortcut[data-entity-id='" + + result_id + "']") .append(alerts); } } @@ -575,7 +600,7 @@ var query_shortcuts = new function() { * Reset the query shortcuts, i.e. remove the old container and call init * again. */ - this.reset = async function() { + this.reset = async function () { $(".caosdb-shortcuts-container").remove(); return await query_shortcuts.init(); } @@ -583,7 +608,7 @@ var query_shortcuts = new function() { /** * Reset the shortcut container, highlight the new shortcuts. */ - this.handle_create_success = async function(panel, results) { + this.handle_create_success = async function (panel, results) { query_shortcuts.logger.trace("enter handle_create_success", panel, results); var new_panel = await query_shortcuts.reset(); query_shortcuts.highlight_resulting_entities(new_panel, results); @@ -596,7 +621,7 @@ var query_shortcuts = new function() { /** * Reset the shortcut container, highlight the updated shortcuts. */ - this.handle_update_success = async function(panel, results) { + this.handle_update_success = async function (panel, results) { query_shortcuts.logger.trace("enter handle_update_success", panel, results); var new_panel = await query_shortcuts.reset(); query_shortcuts.highlight_resulting_entities(new_panel, results); @@ -605,7 +630,7 @@ var query_shortcuts = new function() { query_shortcuts.logger.trace("leave handle_update_success"); } - this.make_dismissible_alert = function(type, content) { + this.make_dismissible_alert = function (type, content) { var ret = $( `<div class="alert alert-` + type + ` alert-dismissible" role="alert"> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> @@ -621,7 +646,7 @@ var query_shortcuts = new function() { * This method does not reset the shortcuts container, so the form's [OK] * button is still visible. */ - this.handle_delete_success = function(panel, results) { + this.handle_delete_success = function (panel, results) { query_shortcuts.logger.trace("enter handle_delete_success", panel, results); query_shortcuts.append_messages_handler(panel, results); @@ -636,7 +661,7 @@ var query_shortcuts = new function() { * This method does not reset the shortcuts container, so the form's * [Submit] and [Cancel] buttons are still visible. */ - this.handle_delete_error = function(panel, results) { + this.handle_delete_error = function (panel, results) { query_shortcuts.logger.trace("enter handle_delete_error", panel, results); query_shortcuts.append_messages_handler(panel, results); @@ -645,35 +670,46 @@ var query_shortcuts = new function() { } - this.make_shortcut_buttons = function(execute, customize) { + this.make_shortcut_buttons = function (execute, customize) { const execute_button = $('<button class="btn btn-primary" type="button" title="Execute query."><i class="bi-search"></i></button>') - .css({"font-size": "12px"}) + .css({ + "font-size": "12px" + }) .click(execute); const customize_button = $('<button class="btn btn-primary" type="button" title="Write to the Query Panel for customization."><i class="bi-pencil"></i></button>') - .css({"font-size": "12px"}) + .css({ + "font-size": "12px" + }) .click(customize) - .mouseenter(function(e) { + .mouseenter(function (e) { $("#caosdb-query-textarea") - .css({"border-color": "#66afe9", + .css({ + "border-color": "#66afe9", "outline": 0, - "-webkit-box-shadow": - "inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)", - "box-shadow": - "inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)"}); + "-webkit-box-shadow": "inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)", + "box-shadow": "inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)" + }); }) - .mouseleave(function(e) { + .mouseleave(function (e) { $('#caosdb-query-textarea').attr("style", ""); }); const button_group = $('<div class="btn-group"/>') - .css({"font-size": "12px", position: "absolute", top: 0, right: "12px"}) + .css({ + "font-size": "12px", + position: "absolute", + top: 0, + right: "12px" + }) .append(customize_button, execute_button) .hide() - .mouseleave(function(e) { + .mouseleave(function (e) { $(this).hide(); }); const hover = $('<button class="btn btn-secondary caosdb-button-search"><i class="bi-search" aria-hidden="true"></i></button>') - .css({"font-size": "12px"}) + .css({ + "font-size": "12px" + }) .click(execute) .mouseenter(() => { button_group.fadeIn(150); @@ -692,7 +728,7 @@ var query_shortcuts = new function() { * @param {function} delete_callback - the submit function for the form. * @returns {HTMLElement} a form. */ - this.make_delete_form = function(panel, delete_callback, success_handler, error_handler) { + this.make_delete_form = function (panel, delete_callback, success_handler, error_handler) { caosdb_utils.assert_html_element(panel, "param `panel`"); caosdb_utils.assert_type(delete_callback, "function", "param `delete_callback`"); // clone panel @@ -713,7 +749,7 @@ var query_shortcuts = new function() { // remove old buttons wrapper.children().remove(); - if($(item).hasClass("caosdb-f-user-query-shortcut")) { + if ($(item).hasClass("caosdb-f-user-query-shortcut")) { // user shortcut // insert checkbox var entity_id = $(item).attr("data-entity-id"); @@ -726,7 +762,9 @@ var query_shortcuts = new function() { // global shortcut // gray out and add hint that this is a global shortcut which cannot be deleted. $(item) - .css({"color": "#CCCCCC"}) + .css({ + "color": "#CCCCCC" + }) .attr("title", "This is a global shortcut which cannot be deleted."); } }); @@ -744,22 +782,22 @@ var query_shortcuts = new function() { return form; } - this.make_form_entity = function(entity_id) { + this.make_form_entity = function (entity_id) { var entity = $(` <div class="invisible" data-entity-role="Record"> </div>`); - if(typeof entity_id === "string" || entity instanceof String) { + if (typeof entity_id === "string" || entity instanceof String) { entity.attr("data-entity-id", entity_id); - entity.append(`<div class="caosdb-id">` - + entity_id + `</div>`); + entity.append(`<div class="caosdb-id">` + + entity_id + `</div>`); } return entity[0]; } - this.make_query_shortcut_parent = function() { - return $(`<div class="caosdb-parent-name">` - + query_shortcuts._shortcuts_record_type_name + `</div>`)[0]; + this.make_query_shortcut_parent = function () { + return $(`<div class="caosdb-parent-name">` + + query_shortcuts._shortcuts_record_type_name + `</div>`)[0]; } @@ -771,7 +809,7 @@ var query_shortcuts = new function() { * @param {function} create_callback - the submit function for the form. * @returns {HTMLElement} a form. */ - this.make_create_form = function(panel, create_callback, success_handler, error_handler) { + this.make_create_form = function (panel, create_callback, success_handler, error_handler) { caosdb_utils.assert_html_element(panel, "param `panel`"); caosdb_utils.assert_type(create_callback, "function", "param `create_callback`"); // clone panel @@ -812,30 +850,36 @@ var query_shortcuts = new function() { * @param {HTMLElement} form - form which contains the fields where the * class is to be added. */ - this._toggle_entity_property_class = function(form) { + this._toggle_entity_property_class = function (form) { form.addEventListener("caosdb.form.ready", () => { $(form).find(".caosdb-f-field").toggleClass("caosdb-f-entity-property", true); }); $(form).find(".caosdb-f-field").toggleClass("caosdb-f-entity-property", true); } - this.make_create_fields = function(include) { + this.make_create_fields = function (include) { return [ include, { - type: "text", name: query_shortcuts._shortcuts_property_description_name, - label: "Description", required: true, cached: true, + type: "text", + name: query_shortcuts._shortcuts_property_description_name, + label: "Description", + required: true, + cached: true, //help: query_shortcuts._description_help, TODO }, { - type: "text", name: query_shortcuts._shortcuts_property_query_name, - label: "Query", required: true, cached: true, + type: "text", + name: query_shortcuts._shortcuts_property_query_name, + label: "Query", + required: true, + cached: true, //help: query_shortcuts._query_help, TODO } ]; } - this.make_update_fields = function(include, old_description, old_query) { + this.make_update_fields = function (include, old_description, old_query) { var fields = this.make_create_fields(include); fields[1]["cached"] = false; fields[2]["cached"] = false; @@ -845,23 +889,23 @@ var query_shortcuts = new function() { } - this.get_description_id = function() { - while(typeof query_shortcuts._shortcuts_property_description_id == "undefined") { + this.get_description_id = function () { + while (typeof query_shortcuts._shortcuts_property_description_id == "undefined") { // wait } return query_shortcuts._shortcuts_property_description_id; } - this.get_query_id = function() { - while(typeof query_shortcuts._shortcuts_property_query_id == "undefined") { + this.get_query_id = function () { + while (typeof query_shortcuts._shortcuts_property_query_id == "undefined") { // wait } return query_shortcuts._shortcuts_property_query_id; } - this.get_record_type_id = function() { - while(typeof query_shortcuts._shortcuts_record_type_id == "undefined") { + this.get_record_type_id = function () { + while (typeof query_shortcuts._shortcuts_record_type_id == "undefined") { // wait } return query_shortcuts._shortcuts_record_type_id; @@ -890,7 +934,7 @@ var query_shortcuts = new function() { * @param {function} update_callback - the submit function for the form. * @returns {HTMLElement} a form. */ - this.make_update_form = function(panel, entity_id, update_callback, success_handler, error_handler) { + this.make_update_form = function (panel, entity_id, update_callback, success_handler, error_handler) { caosdb_utils.assert_html_element(panel, "param `panel`"); caosdb_utils.assert_type(update_callback, "function", "param `update_callback`"); caosdb_utils.assert_type(success_handler, "function", "param `success_handler`"); @@ -940,18 +984,18 @@ var query_shortcuts = new function() { /** * Return the check entities of the form as an array of ids. */ - this.get_checked_ids = function(form) { + this.get_checked_ids = function (form) { var checked = []; $(form).find(":checked").each((idx, item) => { checked.push(item.name); }); - return checked; + return checked; } /** * Return the entities of the form in XML representation. */ - this.get_shortcut_entities = function(form) { + this.get_shortcut_entities = function (form) { var entities = []; entities.push(getEntityXML(form)); return entities; @@ -961,7 +1005,7 @@ var query_shortcuts = new function() { * @throws {HTMLElement[]} if the results contains `DIV.alert-errors`. * @returns {HTMLElement[]} if the transaction was successful. */ - this.delete_callback = async function(form) { + this.delete_callback = async function (form) { query_shortcuts.logger.trace("enter delete_callback", form); var dels_array = query_shortcuts.get_checked_ids(form); @@ -979,7 +1023,7 @@ var query_shortcuts = new function() { * @throws {HTMLElement[]} if the results contains `DIV.alert-errors`. * @returns {HTMLElement[]} if the transaction was successful. */ - this.create_callback = async function(form) { + this.create_callback = async function (form) { query_shortcuts.logger.trace("enter create_callback", form); var insert_xml = query_shortcuts.get_shortcut_entities(form); @@ -997,7 +1041,7 @@ var query_shortcuts = new function() { * @throws {HTMLElement[]} if the results contains `DIV.alert-errors`. * @returns {HTMLElement[]} if the transaction was successful. */ - this.update_callback = async function(form) { + this.update_callback = async function (form) { query_shortcuts.logger.trace("enter update_callback", form); var update_xml = query_shortcuts.get_shortcut_entities(form); @@ -1009,8 +1053,8 @@ var query_shortcuts = new function() { // the recordtype for user-defined query shortcuts var qs_id = query_shortcuts.get_record_type_id(); - $(update_xml).find("Property[name='"+ query_shortcuts._shortcuts_property_description_name+"']").attr("id", desc_id); - $(update_xml).find("Property[name='" + query_shortcuts._shortcuts_property_query_name + "']").attr("id", query_id); + $(update_xml).find("Property[name='" + query_shortcuts._shortcuts_property_description_name + "']").attr("id", desc_id); + $(update_xml).find("Property[name='" + query_shortcuts._shortcuts_property_query_name + "']").attr("id", query_id); $(update_xml).find("Parent[name='" + query_shortcuts._shortcuts_record_type_name + "']").attr("id", qs_id); query_shortcuts.logger.debug("update shortcuts", update_xml); @@ -1026,7 +1070,7 @@ var query_shortcuts = new function() { * Transform the reponse XML into an array of entities in HTML * representation. */ - this.transform_entities = async function(response) { + this.transform_entities = async function (response) { var ret = await query_shortcuts._transformEntities(response); // throw errors: @@ -1100,6 +1144,9 @@ var query_shortcuts = new function() { color: #333; } + .caosdb-f-query-panel.condensed .caosdb-shortcuts-container { + display: none; + } `; var styleSheet = document.createElement("style"); @@ -1111,6 +1158,6 @@ var query_shortcuts = new function() { -$(document).ready(function() { +$(document).ready(function () { caosdb_modules.register(query_shortcuts); });