| Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1 | /** | 
|  | 2 | * Create virtual collections with a visual user interface. | 
| Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 3 | * This resembles the collection type objects of a KoralQuery | 
|  | 4 | * "collection" object. | 
|  | 5 | * | 
|  | 6 | * KoralQuery v0.3 is expected. | 
| Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 7 | * | 
|  | 8 | * @author Nils Diewald | 
|  | 9 | */ | 
| Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 10 | /* | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 11 | * This replaces a previous version written by Mengfei Zhou | 
| Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 12 | */ | 
| Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 13 |  | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 14 | /* | 
| Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 15 | TODO: Disable "and" or "or" in case it's followed | 
|  | 16 | by an unspecified document | 
| Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 17 | TODO: Add "and"-method to root to add further constraints based on match- | 
|  | 18 | input (like clicking on a pubDate timestamp in a match) | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 19 | TODO: Implement "persistence"-Option, | 
| Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 20 | injecting the current creation date stamp | 
| Nils Diewald | 709f52f | 2015-05-21 18:32:58 +0000 | [diff] [blame] | 21 | TODO: Implement vec-Type for document-id vectors | 
|  | 22 | like docID in [1,2,3,4 ...] | 
| Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 23 |  | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 24 | Error codes: | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 25 | 701: "JSON-LD group has no @type attribute" | 
|  | 26 | 704: "Operation needs operand list" | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 27 | 802: "Match type is not supported by value type" | 
|  | 28 | 804: "Unknown value type" | 
|  | 29 | 805: "Value is invalid" | 
|  | 30 | 806: "Value is not a valid date string" | 
|  | 31 | 807: "Value is not a valid regular expression" | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 32 | 810: "Unknown document group operation" (like 711) | 
|  | 33 | 811: "Document group expects operation" (like 703) | 
|  | 34 | 812: "Operand not supported in document group" (like 744) | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 35 | 813: "Collection type is not supported" (like 713) | 
| Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 36 | 814: "Unknown rewrite operation" | 
|  | 37 | 815: "Rewrite expects source" | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 38 |  | 
|  | 39 | Localization strings: | 
|  | 40 | KorAP.Locale = { | 
|  | 41 | EMPTY : '...', | 
|  | 42 | AND : 'and', | 
|  | 43 | OR : 'or', | 
|  | 44 | DELETE : 'x' | 
|  | 45 | } | 
| Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 46 | and various field names with the prefix 'VC_' | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 47 | */ | 
|  | 48 |  | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 49 | define([ | 
|  | 50 | 'vc/unspecified', | 
|  | 51 | 'vc/doc', | 
|  | 52 | 'vc/docgroup', | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 53 | 'vc/menu', | 
| hebasta | 3dc77da | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 54 | 'vc/statistic', | 
| Nils Diewald | 8750783 | 2015-05-01 23:36:41 +0000 | [diff] [blame] | 55 | 'datepicker', | 
| hebasta | 3dc77da | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 56 | 'util', | 
|  | 57 | ], function (unspecDocClass, docClass, docGroupClass, menuClass, statClass, dpClass) { | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 58 | "use strict"; | 
|  | 59 |  | 
| Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 60 | KorAP._validUnspecMatchRE = new RegExp("^(?:eq|ne|contains(?:not)?|excludes)$"); | 
|  | 61 | KorAP._validStringMatchRE = new RegExp("^(?:eq|ne)$"); | 
|  | 62 | KorAP._validTextMatchRE = KorAP._validUnspecMatchRE; | 
|  | 63 | KorAP._validTextOnlyMatchRE = new RegExp("^(?:contains(?:not)?|excludes)$"); | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 64 | KorAP._overrideStyles     = false; | 
| Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 65 | // KorAP._validDateMatchRE is defined in datepicker.js! | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 66 |  | 
| Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 67 | const loc = KorAP.Locale; | 
| hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 68 | loc.SHOWSTAT = loc.SHOWSTAT || 'Statistics'; | 
|  | 69 | loc.VERB_SHOWSTAT = loc.VERB_SHOWSTAT || 'Corpus Statistics'; | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 70 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 71 | KorAP._vcKeyMenu = undefined; | 
| Nils Diewald | 8750783 | 2015-05-01 23:36:41 +0000 | [diff] [blame] | 72 | KorAP._vcDatePicker = dpClass.create(); | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 73 |  | 
| Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 74 | // Create match menus .... | 
|  | 75 | KorAP._vcMatchopMenu = { | 
|  | 76 | 'string' : menuClass.create([ | 
|  | 77 | ['eq', null], | 
|  | 78 | ['ne', null] | 
|  | 79 | ]), | 
|  | 80 | 'text' : menuClass.create([ | 
|  | 81 | ['eq', null],         // Requires exact match | 
|  | 82 | ['ne', null], | 
|  | 83 | ['contains', null],   // Requires token sequence match | 
|  | 84 | ['containsnot', null] | 
|  | 85 | ]), | 
|  | 86 | 'date' : menuClass.create([ | 
|  | 87 | ['eq', null], | 
| Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 88 | ['ne', null], | 
| Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 89 | ['geq', null], | 
|  | 90 | ['leq', null] | 
|  | 91 | ]), | 
|  | 92 | 'regex' : menuClass.create([ | 
|  | 93 | ['eq', null], | 
|  | 94 | ['ne', null] | 
|  | 95 | ]) | 
|  | 96 | }; | 
|  | 97 |  | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 98 | /** | 
|  | 99 | * Virtual Collection | 
|  | 100 | */ | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 101 | return { | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 102 |  | 
|  | 103 | /** | 
|  | 104 | * The JSON-LD type of the virtual collection | 
|  | 105 | */ | 
| Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 106 | ldType : function () { | 
|  | 107 | return null; | 
|  | 108 | }, | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 109 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 110 | // Initialize virtual collection | 
|  | 111 | _init : function (keyList) { | 
|  | 112 |  | 
|  | 113 | // Inject localized css styles | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 114 | if (!KorAP._overrideStyles) { | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 115 | var sheet = KorAP.newStyleSheet(); | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 116 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 117 | // Add css rule for OR operations | 
|  | 118 | sheet.insertRule( | 
|  | 119 | '.vc .docGroup[data-operation=or] > .doc::before,' + | 
|  | 120 | '.vc .docGroup[data-operation=or] > .docGroup::before ' + | 
|  | 121 | '{ content: "' + loc.OR + '" }', | 
|  | 122 | 0 | 
|  | 123 | ); | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 124 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 125 | // Add css rule for AND operations | 
|  | 126 | sheet.insertRule( | 
|  | 127 | '.vc .docGroup[data-operation=and] > .doc::before,' + | 
|  | 128 | '.vc .docGroup[data-operation=and] > .docGroup::before ' + | 
|  | 129 | '{ content: "' + loc.AND + '" }', | 
|  | 130 | 1 | 
|  | 131 | ); | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 132 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 133 | KorAP._overrideStyles = true; | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 134 | }; | 
|  | 135 |  | 
| Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 136 | // Create key menu | 
|  | 137 | KorAP._vcKeyMenu = menuClass.create(keyList); | 
|  | 138 | KorAP._vcKeyMenu.limit(6); | 
|  | 139 |  | 
| Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 140 | return this; | 
|  | 141 | }, | 
|  | 142 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 143 | /** | 
|  | 144 | * Create a new virtual collection. | 
|  | 145 | */ | 
|  | 146 | create : function (keyList) { | 
| Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 147 | var obj = Object.create(this)._init(keyList); | 
|  | 148 | obj._root = unspecDocClass.create(obj); | 
|  | 149 | return obj; | 
| Nils Diewald | 4019bd2 | 2015-01-08 19:57:50 +0000 | [diff] [blame] | 150 | }, | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 151 |  | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 152 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 153 | /** | 
|  | 154 | * Create and render a new virtual collection | 
|  | 155 | * based on a KoralQuery collection document | 
|  | 156 | */ | 
| Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 157 | fromJson : function (json) { | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 158 | if (json !== undefined) { | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 159 | // Parse root document | 
|  | 160 | if (json['@type'] == 'koral:doc') { | 
|  | 161 | this._root = docClass.create(this, json); | 
|  | 162 | } | 
|  | 163 | // parse root group | 
|  | 164 | else if (json['@type'] == 'koral:docGroup') { | 
|  | 165 | this._root = docGroupClass.create(this, json); | 
|  | 166 | } | 
|  | 167 | // Unknown collection type | 
|  | 168 | else { | 
|  | 169 | KorAP.log(813, "Collection type is not supported"); | 
|  | 170 | return; | 
|  | 171 | }; | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
|  | 174 | else { | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 175 | // Add unspecified object | 
|  | 176 | this._root = unspecDocClass.create(this); | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 177 | }; | 
|  | 178 |  | 
| Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 179 | // Init element and update | 
| Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 180 | this.update(); | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 181 |  | 
| Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 182 | return this; | 
|  | 183 | }, | 
|  | 184 |  | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 185 |  | 
| Akron | 04671e7 | 2017-05-11 20:47:32 +0200 | [diff] [blame] | 186 | // Check if the virtual corpus contains a rewrite | 
|  | 187 | // This is a class method | 
|  | 188 | checkRewrite : function (json) { | 
|  | 189 |  | 
|  | 190 | // There is a rewrite attribute | 
|  | 191 | if (json['rewrites'] !== undefined) { | 
|  | 192 | return true; | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | // There is a group to check for rewrites | 
|  | 196 | else if (json['@type'] === 'koral:docGroup') { | 
|  | 197 | var ops = json['operands']; | 
|  | 198 | if (ops === undefined) | 
|  | 199 | return false; | 
|  | 200 |  | 
|  | 201 | for (var i in ops) { | 
|  | 202 |  | 
|  | 203 | // "this" is the class | 
|  | 204 | if (this.checkRewrite(ops[i])) { | 
|  | 205 | return true; | 
|  | 206 | }; | 
|  | 207 | }; | 
|  | 208 | }; | 
|  | 209 | return false; | 
|  | 210 | }, | 
|  | 211 |  | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 212 | /** | 
|  | 213 | * Clean the virtual document to uspecified doc. | 
|  | 214 | */ | 
| Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 215 | clean : function () { | 
|  | 216 | if (this._root.ldType() !== "non") { | 
| Akron | 04671e7 | 2017-05-11 20:47:32 +0200 | [diff] [blame] | 217 | this._root.destroy(); | 
|  | 218 | this.root(unspecDocClass.create(this)); | 
| Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 219 | }; | 
|  | 220 | return this; | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 221 | }, | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 222 |  | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 223 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 224 | /** | 
|  | 225 | * Get or set the root object of the | 
|  | 226 | * virtual collection. | 
|  | 227 | */ | 
| Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 228 | root : function (obj) { | 
| Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 229 | if (arguments.length === 1) { | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 230 | var e = this.element(); | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 231 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 232 | if (e.firstChild !== null) { | 
|  | 233 | if (e.firstChild !== obj.element()) { | 
|  | 234 | e.replaceChild(obj.element(), e.firstChild); | 
|  | 235 | }; | 
|  | 236 | } | 
| Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 237 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 238 | // Append root element | 
|  | 239 | else { | 
|  | 240 | e.appendChild(obj.element()); | 
|  | 241 | }; | 
| Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 242 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 243 | // Update parent child relations | 
|  | 244 | this._root = obj; | 
|  | 245 | obj.parent(this); | 
| Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 246 |  | 
| Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 247 | this.update(); | 
| Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 248 | }; | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 249 | return this._root; | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 250 | }, | 
| Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 251 |  | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 252 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 253 | /** | 
|  | 254 | * Get the element associated with the virtual collection | 
|  | 255 | */ | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 256 | element : function () { | 
| Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 257 | if (this._element !== undefined) { | 
|  | 258 | return this._element; | 
|  | 259 | }; | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 260 |  | 
|  | 261 | this._element = document.createElement('div'); | 
|  | 262 | this._element.setAttribute('class', 'vc'); | 
| Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 263 |  | 
| Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 264 | // Initialize root | 
|  | 265 | this._element.appendChild(this._root.element()); | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 266 |  | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 267 | //Add corpus statistic button | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 268 | this.addStatBut(); | 
| hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 269 |  | 
| Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 270 | return this._element; | 
| Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 271 | }, | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 272 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 273 |  | 
|  | 274 | /** | 
|  | 275 | * Update the whole object based on the underlying | 
|  | 276 | * data structure | 
|  | 277 | */ | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 278 | update : function () { | 
|  | 279 | this._root.update(); | 
|  | 280 | return this; | 
|  | 281 | }, | 
|  | 282 |  | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 283 | /** | 
|  | 284 | * Make the vc persistant by injecting the current timestamp | 
|  | 285 | * as a creation date limit criterion. | 
|  | 286 | */ | 
|  | 287 | makePersistant : function () { | 
| Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 288 | // this.root().wrapOnRoot('and'); | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 289 | var todayStr = KorAP._vcDatePicker.today(); | 
|  | 290 | var doc = docClass.create(); | 
|  | 291 | var root = this.root(); | 
|  | 292 |  | 
|  | 293 | if (root.ldType() === 'docGroup' && | 
| Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 294 | root.operation === 'and') { | 
|  | 295 | root.append(cond); | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 296 | } | 
|  | 297 | else { | 
| Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 298 | root.wrapOnRoot('and'); | 
|  | 299 | root.append(doc); | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 300 | }; | 
|  | 301 |  | 
|  | 302 | doc.key("creationDate"); | 
|  | 303 | doc.type("date"); | 
|  | 304 | doc.matchop("leq"); | 
|  | 305 | doc.value(todayStr); | 
|  | 306 |  | 
|  | 307 | /* | 
|  | 308 | { | 
|  | 309 | "@type" : "koral:doc", | 
|  | 310 | "key" : "creationDate", | 
|  | 311 | "type" : "type:date", | 
|  | 312 | "match" : "match:leq", | 
|  | 313 | "value" : todayStr | 
|  | 314 | } | 
|  | 315 | this.root().append(cond); | 
|  | 316 | */ | 
|  | 317 | this.update(); | 
|  | 318 | }, | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 319 |  | 
|  | 320 | /** | 
|  | 321 | * Get the generated json string | 
|  | 322 | */ | 
| Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 323 | toJson : function () { | 
|  | 324 | return this._root.toJson(); | 
|  | 325 | }, | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 326 |  | 
| Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 327 |  | 
|  | 328 | /** | 
|  | 329 | * Get the generated query string | 
|  | 330 | */ | 
| Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 331 | toQuery : function () { | 
|  | 332 | return this._root.toQuery(); | 
| hebasta | 3dc77da | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 333 | }, | 
|  | 334 |  | 
| hebasta | d03682d | 2018-06-29 14:24:15 +0200 | [diff] [blame] | 335 | /* | 
|  | 336 | * Returns ld type of associated doc, docGroup or unspecified doc | 
|  | 337 | */ | 
|  | 338 | getLdType:function(){ | 
|  | 339 | return this._root.ldType(); | 
|  | 340 | }, | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 341 |  | 
|  | 342 | /** | 
|  | 343 | * Adds Corpus Statistic Button | 
|  | 344 | **/ | 
|  | 345 | addStatBut : function(){ | 
| hebasta | 3dc77da | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 346 |  | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 347 | //add div element 'corpStat' with id 'dCorpStat' | 
|  | 348 | var dv = this._element.addE('div'); | 
|  | 349 | dv.id = "dCorpStat"; | 
|  | 350 |  | 
|  | 351 | //add button | 
|  | 352 | var bu = dv.addE('div'); | 
| hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 353 | bu.classList.add('bottom', 'button-stat'); | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 354 | var stat = bu.addE('span'); | 
| hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 355 | stat.addT(loc.SHOWSTAT); | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 356 | //localize the buttons title attribute | 
| hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 357 | //stat.setAttribute('title', loc.SHOWSTAT); | 
| hebasta | 68d5fa6 | 2018-06-20 16:00:57 +0200 | [diff] [blame] | 358 | stat.classList.add('statistic'); | 
|  | 359 |  | 
|  | 360 | /* | 
|  | 361 | * In ECMAScript Language Specification this is set incorrectly for inner functions, | 
|  | 362 | * therefore thatelement and that is defined. | 
|  | 363 | */ | 
|  | 364 | var thatelement = this._element; | 
|  | 365 | var that = this; | 
|  | 366 |  | 
|  | 367 | //show corpus statistic if button is clicked | 
|  | 368 | stat.addEventListener('click', function(e){ | 
|  | 369 | e.halt(); | 
|  | 370 | statClass.showCorpStat(thatelement, that); | 
|  | 371 | }); | 
|  | 372 |  | 
|  | 373 | } | 
|  | 374 |  | 
| Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 375 | }; | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 376 | }); |