Demo for query storing
Change-Id: I947bcac841992c3f6cfd01ab337c265b0d01cb70
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index 80391d8..c834d1e 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -130,6 +130,7 @@
* @param {function} errorCB Optional. Callback function for error handling, receives JS object with status and statusText attribute
*/
function _actionJSON (requestType, url, title, jsObj, returnValueCB, errorCB) {
+ //console.log(arguments);
const req = new XMLHttpRequest();
req.open(requestType, url, true);
// Dispatch global "window" event. See Kalamar::Plugin::Piwik
@@ -194,9 +195,26 @@
};
// Call the callback function (no matter requestType) if one is given.
if (typeof(errorCB) === "function"){
+ var statusTextErrors = ""; // For some reason, the errors created in QueryReference.pm have their text stored in this.responseText.
+ // Here we try to extract this information
+ try {
+ JSON.parse(this.responseText).errors.forEach(
+ e => statusTextErrors = statusTextErrors + e["message"] || ""
+ );
+ } catch {
+ try {
+ if (requestType !== "GET"){
+ statusTextErrors += JSON.parse(this.responseText);
+ }
+ } catch {
+ //Nothing
+ }
+ }
errorCB({
"status" : this.status,
- "statusText" : this.statusText
+ "statusText" : this.statusText + " - " + (statusTextErrors || "")
+ //responseText: A DOMString which contains either the textual data received using the
+ // XMLHttpRequest or null if the request failed or "" if the request has not yet been sent by calling send().
});
};
};
@@ -297,6 +315,10 @@
/**
* Post new query by query name
+<<<<<<< HEAD
+=======
+ * CAUTION: Currently not supported by the QueryReference Plugin.
+>>>>>>> Demo for query storing
*
* @param {String} qn The name of the new query
* @param {JSObj} jsObj The query. This will be stringified
diff --git a/dev/js/src/hint/querystoringitem.js b/dev/js/src/hint/querystoringitem.js
new file mode 100644
index 0000000..7b3c4e8
--- /dev/null
+++ b/dev/js/src/hint/querystoringitem.js
@@ -0,0 +1,48 @@
+/**
+ * new menu item based on hintItem that allows for selection and later deletion
+ */
+"use strict";
+
+define(['./item', 'util'], function (itemClass) {
+ return {
+
+ /**
+ * Create new menu item object.
+ */
+ create : function (params) {
+ const obj = itemClass.create(params)
+ .upgradeTo(this)
+ ._init(params);
+ return obj;
+ },
+
+ /**
+ * Override the click action
+ * of the hint menu item.
+ */
+ onclick : function (e) {
+ var m = this.menu();
+ // m.hide();
+ var h = m.hint();
+ if ( h._hintItemMode === undefined || h._hintItemMode === "REGULAR" ) { //the same
+
+ // Reset prefix and update the input field
+ m.reset(this._action);
+
+ e.halt();
+
+ // show alt
+ h.show(true);
+ } else if ( h._hintItemMode === "DELETE SELECTION" ) { //see deleteButton in querystoringdemo.js
+
+ h._deleteTheseQueries.push( this.name() );
+ this.element().classList.add("selected-for-deletion"); //TODO @Nils Maybe a different type of highlighting?
+ //this. //Here you see why I added the content function: easier text changing.
+ e.halt();
+
+ // show alt
+ h.show(true);
+ };
+ }
+ }
+});