Leo Repp | 8e21cbe | 2021-08-18 16:37:52 +0200 | [diff] [blame^] | 1 | requirejs.config({ |
| 2 | baseUrl: '../js/src', |
| 3 | paths : { |
| 4 | 'lib': '../lib' |
| 5 | } |
| 6 | }); |
| 7 | |
| 8 | var hint = undefined; |
| 9 | |
| 10 | require(['plugin/server','panel/query', 'hint','hint/foundries/cnx','lib/domReady','api'], function (pluginClass, queryPanelClass, hintClass, hintArray, domReady) { |
| 11 | KorAP.hintArray = hintArray; |
| 12 | KorAP.Hint = null; |
| 13 | |
| 14 | domReady(function() { |
| 15 | KorAP.URL="http://localhost:3000" |
| 16 | //console.log(KorAP.URL=http://localhost:3003); |
| 17 | |
| 18 | KorAP.Hint = hintClass.create(); |
| 19 | |
| 20 | KorAP.restoreMinusMenuButton = { // Whenever used is at location 0 |
| 21 | defaultTextValue : "Back", |
| 22 | onclick : function (e) { |
| 23 | this._menu.hint().unReadQueries(); |
| 24 | //e.halt(); |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | KorAP.triggerDeleteModeButton = { // Whenever used is at location 1 |
| 29 | defaultTextValue : "Delete Queries", |
| 30 | onclick : function (e) { |
| 31 | if (this._menu.hint()._queryReadMode === "READ") { |
| 32 | this._menu.hint()._deleteTheseQueries = []; |
| 33 | this.content("Delete Selected Queries"); |
| 34 | this._menu.hint()._queryReadMode = "DELETE"; |
| 35 | |
| 36 | |
| 37 | } else if (this._menu.hint()._queryReadMode === "DELETE") { |
| 38 | this._menu.hint()._deleteTheseQueries.forEach(function (query){ |
| 39 | KorAP.API.deleteQuery(qn,console.log); |
| 40 | },undefined); |
| 41 | this._menu.hint()._deleteTheseQueries = []; |
| 42 | this._menu.hint()._queryReadMode = "READ"; |
| 43 | this.content("Delete Queries"); |
| 44 | |
| 45 | } else { |
| 46 | //ERROR |
| 47 | console.log("What?"); |
| 48 | }; |
| 49 | this.menu("-").show(); |
| 50 | //e.halt(); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | JSONListToQueryTemplates= function(JSONList) { |
| 55 | var queryItemTemplates = []; |
| 56 | JSONList.forEach(function(query){ //I need to see what this actually looks like! |
| 57 | queryItemTemplates.push([query["qname"],query["q"],query["desc"]]) |
| 58 | }, undefined); //no "this" needed |
| 59 | return queryItemTemplates |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | KorAP.SaveButton = { // Whenever used is at location 0 |
| 64 | onclick : function (e) { |
| 65 | var query = {} |
| 66 | query.q = "this._menu._hint._inputField._el.value"; |
| 67 | query.ql = "a"; |
| 68 | query.desc = "b"; |
| 69 | KorAP.API.putQuery("query1",query,console.log); |
| 70 | this.menu("-").show(); |
| 71 | //e.halt(); |
| 72 | }, |
| 73 | defaultTextValue : "Save Query" |
| 74 | }; |
| 75 | |
| 76 | KorAP.DisplayQueriesButton = { // Whenever used is at location 1 |
| 77 | onclick : function (e) { |
| 78 | KorAP.API.getQueryList(KorAP.Hint.readQueries,console.log); |
| 79 | this.menu("-").show(); |
| 80 | //e.halt(); |
| 81 | }, |
| 82 | defaultTextValue : "Display Stored Queries" |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | KorAP.Hint.menu("-").container().addItem(KorAP.SaveButton); //must be added to a specific context menu. |
| 87 | KorAP.Hint.menu("-").container().addItem(KorAP.DisplayQueriesButton); //must be added to a specific context menu. |
| 88 | |
| 89 | KorAP.Hint.readQueries = function (JSONList) { |
| 90 | console.log(JSONList); |
| 91 | //Need to check what JSONList looks like |
| 92 | // 0: _name |
| 93 | // 1: _action (query) |
| 94 | // 2: _desc |
| 95 | var queryItemTemplates = JSONListToQueryTemplates(JSONList); |
| 96 | queryItemTemplates.push(["ExampleName","value","descr"]); |
| 97 | this.menu("-").readItems(queryItemTemplates); |
| 98 | this._queryReadMode = "READ"; //alternative: "DELETE" |
| 99 | this._deleteTheseQueries = []; |
| 100 | // add first, remove later to avoid empty lists |
| 101 | this.menu("-").container().addItem(KorAP.restoreMinusMenuButton); |
| 102 | this.menu("-").container().addItem(KorAP.triggerDeleteModeButton); |
| 103 | this.menu("-").container().removeItemByIndex(0); //Save Button |
| 104 | this.menu("-").container().removeItemByIndex(0); //Display Button |
| 105 | this.menu("-").show(); |
| 106 | }.bind(KorAP.Hint); |
| 107 | |
| 108 | KorAP.Hint.unReadQueries = function () { |
| 109 | KorAP.log("unread"); |
| 110 | this.menu("-").readItems(KorAP.annotationHelper["-"]); |
| 111 | this._queryReadMode = "READ"; //alternative: "DELETE" |
| 112 | this._deleteTheseQueries = []; |
| 113 | // add first, remove later to avoid empty lists |
| 114 | this.menu("-").container().addItem(KorAP.SaveButton); |
| 115 | this.menu("-").container().addItem(KorAP.DisplayQueriesButton); |
| 116 | this.menu("-").container().removeItemByIndex(0); //restoreMinusMenuButton |
| 117 | this.menu("-").container().removeItemByIndex(0); //triggerDeleteModeButton |
| 118 | this.menu("-").show(); |
| 119 | |
| 120 | }.bind(KorAP.Hint); |
| 121 | |
| 122 | /** |
| 123 | * Add query panel |
| 124 | */ |
| 125 | var queryPanel = queryPanelClass.create(); |
| 126 | |
| 127 | // Get input field |
| 128 | var sform = document.getElementById("searchform"); |
| 129 | var vcView = document.getElementById('vc-view') |
| 130 | if (sform && vcView) { |
| 131 | // The views are below the query bar |
| 132 | sform.insertBefore(queryPanel.element(),vcView); |
| 133 | KorAP.Panel = KorAP.Panel || {}; |
| 134 | KorAP.Panel['query'] = queryPanel; |
| 135 | } |
| 136 | |
| 137 | // Load plugin server |
| 138 | KorAP.Plugin = pluginClass.create(); |
| 139 | KorAP.Plugin.register |
| 140 | // Register match plugin |
| 141 | KorAP.Plugin.register({ |
| 142 | 'name' : 'Example New', |
| 143 | 'desc' : 'Some content about cats', |
| 144 | 'embed' : [{ |
| 145 | 'panel' : 'query', |
| 146 | 'title' : 'Translate', |
| 147 | 'classes' : ['translate'], |
| 148 | 'onClick' : { |
| 149 | "template" : "http://localhost:3003/demo/plugin-client.html" |
| 150 | } |
| 151 | },{ |
| 152 | 'panel' : 'query', |
| 153 | 'title' : 'Glemm', |
| 154 | 'classes' : ['glemm'], |
| 155 | 'onClick' : { |
| 156 | "action":"toggle", |
| 157 | "template" : "http://localhost:3003/demo/plugin-client.html" |
| 158 | } |
| 159 | }] |
| 160 | }); |
| 161 | |
| 162 | // Register match plugin |
| 163 | KorAP.Plugin.register({ |
| 164 | 'name' : 'Glimpse', |
| 165 | 'desc' : 'Shorten all queries', |
| 166 | 'embed' : [{ |
| 167 | 'panel' : 'query', |
| 168 | 'title' : 'Glimpse', |
| 169 | 'classes' : ['glimpse'], |
| 170 | 'onClick' : { |
| 171 | "action" : "toggle", |
| 172 | "template" : "http://localhost:3003/demo/plugin-client.html" |
| 173 | } |
| 174 | }] |
| 175 | }); |
| 176 | |
| 177 | console.log(KorAP.Hint); |
| 178 | }); |
| 179 | }); |
| 180 | |
| 181 | function demoAlert (pos, msg) { |
| 182 | if (KorAP.hint !== undefined) |
| 183 | KorAP.Hint.alert(pos, msg); |
| 184 | } |