[30382] | 1 | //hierarchy storage object
|
---|
| 2 |
|
---|
| 3 | //Find first ancestor element by tag name
|
---|
| 4 | function findAncestorByTagName (element, tagName) {
|
---|
| 5 | while ((element.tagName != tagName) && (element = element.parentElement));
|
---|
| 6 | return element;
|
---|
| 7 | }
|
---|
| 8 | // Function to set Id as TEXTAREA value
|
---|
[31063] | 9 | function chooseHierarchyOption(a)
|
---|
[30382] | 10 | {
|
---|
| 11 |
|
---|
[31023] | 12 | var metaValue = a.getAttribute("metavalue");
|
---|
| 13 | var metaTitle = a.getAttribute("metatitle");
|
---|
[31014] | 14 |
|
---|
[30382] | 15 | // If ID defined and not null
|
---|
[31023] | 16 | if (metaValue && (metaValue != null))
|
---|
[30382] | 17 | {
|
---|
| 18 | //find TR Ancestor to get TEXTAREA
|
---|
| 19 | var tr = findAncestorByTagName(a,"TR");
|
---|
| 20 | //Set value to id of clicked element
|
---|
[31023] | 21 | $(tr.getElementsByTagName("TEXTAREA")).val(metaValue);
|
---|
[30382] | 22 | // Set button name
|
---|
[31063] | 23 | setHierarchyButtonText(tr, metaTitle);
|
---|
| 24 | removeSuggestionsMenu(tr);
|
---|
[30382] | 25 | //Hide menu after click
|
---|
| 26 | $(tr).find(".metaDataHierarchyMenu").find("ul li ul li").hide();
|
---|
[31063] | 27 | //Set focus on textarea
|
---|
[30382] | 28 | tr.getElementsByTagName("TEXTAREA")[0].focus();
|
---|
| 29 |
|
---|
| 30 | createSuggestionsMenu(tr);
|
---|
| 31 |
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | function openHierarchyMenuLevel(menuItem)
|
---|
| 35 | {
|
---|
[31063] | 36 | var tr = findAncestorByTagName(menuItem,"TR");
|
---|
| 37 | //get current MetaDataName
|
---|
| 38 | var metaName = getMetaName(tr);
|
---|
[30382] | 39 | //Get current hierarchy from storages
|
---|
| 40 | var hierarchyData = hierarchyStorage[metaName];
|
---|
| 41 | menuItem = $(menuItem);
|
---|
| 42 | if (menuItem.find('ul').length == 0)
|
---|
| 43 | {
|
---|
| 44 | //Expression to extract hierarchy identifier from menu item id
|
---|
| 45 | var getIdExp = /[0-9.]+/;
|
---|
| 46 | //Extracted hierarchy identifier
|
---|
| 47 | var id;
|
---|
| 48 | //Expression to get childs
|
---|
| 49 | var childExpr;
|
---|
| 50 | if (menuItem.attr('id'))
|
---|
| 51 | {
|
---|
| 52 | id = menuItem.attr('id').match(getIdExp);
|
---|
[31063] | 53 | }
|
---|
[30382] | 54 | if (id == null)
|
---|
| 55 | {
|
---|
| 56 | childExpr = /^[0-9]+$/;
|
---|
| 57 | }
|
---|
| 58 | else
|
---|
| 59 | {
|
---|
| 60 | childExpr = new RegExp("^" + id + "." + "[0-9]+$");
|
---|
| 61 | }
|
---|
| 62 | var levelItems = {};
|
---|
| 63 | for(var key in hierarchyData)
|
---|
| 64 | {
|
---|
| 65 | if(childExpr.test(key)){
|
---|
[31063] | 66 | levelItems[key]='<li class="hierarchyOption" id="'+key+'" ><button onclick="chooseHierarchyOption(this)" metavalue="'+ hierarchyData[key][0] +'" metatitle="'+ hierarchyData[key][1] +'">' + hierarchyData[key][1] + '</button></li>';
|
---|
[30382] | 67 | }
|
---|
| 68 | }
|
---|
[31063] | 69 | //If no elements in hierarchy level
|
---|
[30382] | 70 | if (jQuery.isEmptyObject(levelItems))
|
---|
| 71 | {
|
---|
| 72 | //add empty menu. Invisible. Used by checks in setHierarchyEventsWrappers focusout to prevent menu hiding while choosing suggestion menu item leaf
|
---|
| 73 | menuItem.append("<ul></ul>");
|
---|
| 74 |
|
---|
| 75 | }
|
---|
| 76 | else {
|
---|
[36027] | 77 | //wrap elements in hierarchy level
|
---|
| 78 | var levelMenu = '<ul>';
|
---|
| 79 | for(var key in levelItems)
|
---|
| 80 | {
|
---|
| 81 | //Fill menu with items
|
---|
| 82 | levelMenu += levelItems[key];
|
---|
| 83 | }
|
---|
| 84 | levelMenu += "</ul>";
|
---|
| 85 | menuItem.append(levelMenu);
|
---|
| 86 | menuItem.find("li")
|
---|
| 87 | .on("mouseenter", function()
|
---|
[30382] | 88 | {
|
---|
[36027] | 89 | openHierarchyMenuLevel(this);
|
---|
| 90 | })
|
---|
| 91 | .on("mouseleave", function()
|
---|
| 92 | {
|
---|
| 93 | closeHierarchyMenuLevel(this);
|
---|
| 94 | });
|
---|
| 95 |
|
---|
| 96 | //menuItem.find('ul');
|
---|
| 97 | menuItem.children('ul').slideDown();
|
---|
| 98 | }
|
---|
[30382] | 99 | } else {
|
---|
| 100 | //stop animation
|
---|
| 101 | menuItem.find('ul').stop(true, true);
|
---|
| 102 | //show menu items
|
---|
| 103 | menuItem.children('ul').children('li').show();
|
---|
| 104 | //slide down menu
|
---|
| 105 | menuItem.children('ul').slideDown();
|
---|
| 106 | }
|
---|
| 107 | menuItem.addClass("active");
|
---|
| 108 | }
|
---|
| 109 | function closeHierarchyMenuLevel(menuItem)
|
---|
| 110 | {
|
---|
| 111 | $(menuItem).removeClass("active");
|
---|
| 112 | $(menuItem).find('ul').hide();
|
---|
| 113 | }
|
---|
| 114 | // Download hierarchy file and process it
|
---|
| 115 | function downloadAndProcessHierarchyFile(hierarchyFileName,metaName)
|
---|
| 116 | {
|
---|
| 117 |
|
---|
| 118 | var xmlhttp=new XMLHttpRequest();
|
---|
| 119 | xmlhttp.open("GET",hierarchyFileName,true);
|
---|
| 120 | xmlhttp.send();
|
---|
| 121 | xmlhttp.onreadystatechange=function()
|
---|
| 122 | {
|
---|
| 123 | if (xmlhttp.readyState==4 && xmlhttp.status==200)
|
---|
| 124 | {
|
---|
[31063] | 125 | var hierarchyFile = xmlhttp.responseText;
|
---|
| 126 | var StringData = [];
|
---|
| 127 | var hierarchyData = {};
|
---|
| 128 | var expr = /^(\S*|\"[^\"]*\")\ +([0-9]+(?:\.[0-9]+)*)\ +(.*)/m;
|
---|
| 129 | StringData = hierarchyFile.split('\n');
|
---|
| 130 | for (var i = 0; i < StringData.length; i++) {
|
---|
| 131 | var result = StringData[i].match(expr);
|
---|
| 132 | // If result not null
|
---|
| 133 | if (result != null && result.length == 4) {
|
---|
| 134 | // populate hierarchy object
|
---|
| 135 | hierarchyData[result[2]] = [ result[1].replace(/^\"|\"$/g, ''), result[3].replace(/^\"|\"$/g, '') ];
|
---|
| 136 | }
|
---|
[30382] | 137 |
|
---|
[31063] | 138 | }
|
---|
| 139 | addHierarchyToStorage(metaName, hierarchyData);
|
---|
| 140 | setHierarchyEventsWrappers(metaName);
|
---|
[30382] | 141 | }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 |
|
---|
| 147 | function setHierarchyHoverEvent(father,className)
|
---|
| 148 | {
|
---|
[36027] | 149 | $(father).find(className)
|
---|
| 150 | .on("mouseenter", function()
|
---|
| 151 | {
|
---|
| 152 | openHierarchyMenuLevel(this);
|
---|
| 153 | })
|
---|
| 154 | .on("mouseleave", function()
|
---|
| 155 | {
|
---|
| 156 | closeHierarchyMenuLevel(this);
|
---|
| 157 | });
|
---|
[30382] | 158 |
|
---|
| 159 | }
|
---|
| 160 | function createHierarchyMenuButton(row)
|
---|
| 161 | {
|
---|
| 162 | //get current MetaDataName
|
---|
[31063] | 163 | var metaName = getMetaName(row);
|
---|
[31067] | 164 | defaultHierarchyButtonText = gs.text.de.top_level_menu; //'Top level menu';
|
---|
[31063] | 165 | var hierarchyButtonText = defaultHierarchyButtonText;
|
---|
[30382] | 166 | // Check if textarea already contain right menu key
|
---|
| 167 | var textAreaValue = $(row).find('TEXTAREA').val();
|
---|
| 168 |
|
---|
| 169 | //Get current hierarchy from storages
|
---|
| 170 | var hierarchyData = hierarchyStorage[metaName];
|
---|
[31063] | 171 | //TODO Modificate
|
---|
[30382] | 172 |
|
---|
[31063] | 173 |
|
---|
| 174 | for(var key in hierarchyData)
|
---|
| 175 | {
|
---|
| 176 | if (hierarchyData[key][0] == textAreaValue)
|
---|
| 177 | {
|
---|
| 178 | hierarchyButtonText = hierarchyData[key][1];
|
---|
| 179 | break;
|
---|
| 180 | }
|
---|
[30382] | 181 | }
|
---|
[31023] | 182 |
|
---|
[30382] | 183 | //Menu element
|
---|
[31063] | 184 | var mainmenu = '<td class="metaDataHierarchyMenu" style="display: none;"><ul><li id="hierarchyLevel"><button class="hierarchyMenuButton" title="Menu">' + hierarchyButtonText + '</button></li></ul></td>'
|
---|
[30382] | 185 | //Insert hierarchy menu
|
---|
| 186 | $(row).find('.metaTableCellRemove').after(mainmenu);
|
---|
| 187 | //Set hover event on hierarchy menu
|
---|
| 188 | $(row).each(function(){setHierarchyHoverEvent($(this),".metaDataHierarchyMenu ul li")});
|
---|
| 189 | //Set menu name or SuggestionsMenu on change of textarea set menu name to appropriate menu item if exists
|
---|
[36027] | 190 | $(row).find('.metaTableCellArea').on('input propertychange',function()
|
---|
[30382] | 191 | {
|
---|
| 192 | var input = $(this).val();
|
---|
[31063] | 193 | var hierarchyButtonText;
|
---|
[30382] | 194 | var row = this.parentElement.parentElement;
|
---|
| 195 | //RegExp to test a valid key in input
|
---|
| 196 | var KeyExp = /^[0-9]+(?:\.[0-9]+)*$/;
|
---|
| 197 | //RegExp to test a valid key start in input
|
---|
| 198 | var KeyStartExp = /^(?:[0-9]+(?:\.[0-9]+)*)?\.$/;
|
---|
| 199 | //if input valid and key found
|
---|
[31063] | 200 | removeSuggestionsMenu(row);
|
---|
| 201 | createSuggestionsMenu(row);
|
---|
| 202 | /*if ( KeyExp.test(input) && hierarchyData[input] || KeyStartExp.test(input))
|
---|
[30382] | 203 | {
|
---|
| 204 | createSuggestionsMenu(row);
|
---|
| 205 | }
|
---|
[31063] | 206 | */
|
---|
| 207 | if (hierarchyData[input]){
|
---|
| 208 | hierarchyButtonText = hierarchyData[input][1];
|
---|
| 209 | } else {
|
---|
| 210 | hierarchyButtonText = defaultHierarchyButtonText;
|
---|
[30382] | 211 | }
|
---|
[31063] | 212 | setHierarchyButtonText(row, hierarchyButtonText);
|
---|
| 213 |
|
---|
[30382] | 214 | });
|
---|
| 215 | //Show created menu
|
---|
| 216 | $(row).find('.metaDataHierarchyMenu').show();
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | function createSuggestionsMenu(row)
|
---|
| 220 | {
|
---|
| 221 | //get current MetaDataName
|
---|
[31063] | 222 | var metaName = getMetaName(row);
|
---|
| 223 | //Get current hierarchy from storage
|
---|
[30382] | 224 | var hierarchyData = hierarchyStorage[metaName];
|
---|
[31063] | 225 | //Hierarchy suggestions menu
|
---|
| 226 | var SuggestionsMenu = "";
|
---|
[30382] | 227 |
|
---|
| 228 | var input = $(row.getElementsByClassName("metaTableCellArea")[0]).val();
|
---|
[30464] | 229 |
|
---|
[31063] | 230 | if (input.replace(/[0-9\.\s]/g, '') === "")
|
---|
[30382] | 231 | {
|
---|
[31063] | 232 | //RegExp to get SuggestionsMenu
|
---|
| 233 | var SuggestionsMenuExp = new RegExp("^0*" + input.replace(/\./g, '\\.0*') + "\\.?[0-9]+$")
|
---|
[30382] | 234 |
|
---|
[31063] | 235 | for(var key in hierarchyData)
|
---|
[30382] | 236 | {
|
---|
[31063] | 237 | if (SuggestionsMenuExp.test(key))
|
---|
| 238 | {
|
---|
| 239 | SuggestionsMenu +='<li class="hierarchySuggestionsMenu hierarchyOption" id="'+key+'" ><button metavalue="'+ hierarchyData[key][0] +'" metatitle="'+ hierarchyData[key][1] +'" onclick="chooseHierarchyOption(this)" >' + key.substring(String(input).length) + " " + hierarchyData[key][1] + '</button></li>';
|
---|
| 240 | }
|
---|
[30382] | 241 | }
|
---|
[31063] | 242 | } else {
|
---|
[31064] | 243 | var escapedInput = input.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
---|
[31063] | 244 | //RegExp to get SuggestionsMenu
|
---|
[31064] | 245 | var SuggestionsMenuExp = new RegExp( escapedInput,"i");
|
---|
[30382] | 246 |
|
---|
[31063] | 247 | for(var key in hierarchyData)
|
---|
[30382] | 248 | {
|
---|
[31063] | 249 | if (SuggestionsMenuExp.test(hierarchyData[key][1]) && input !== hierarchyData[key][0])
|
---|
| 250 | {
|
---|
| 251 | SuggestionsMenu +='<li class="hierarchySuggestionsMenu hierarchyOption" id="'+key+'" ><button metavalue="'+ hierarchyData[key][0] +'" metatitle="'+ hierarchyData[key][1] +'" onclick="chooseHierarchyOption(this)" >' + hierarchyData[key][1] + '</button></li>';
|
---|
| 252 | }
|
---|
[30382] | 253 | }
|
---|
| 254 | }
|
---|
| 255 |
|
---|
[31063] | 256 |
|
---|
| 257 |
|
---|
[30382] | 258 | //Append new SuggestionsMenu
|
---|
| 259 | $(row).find(".metaDataHierarchyMenu ul").append(SuggestionsMenu);
|
---|
| 260 | //Register event
|
---|
| 261 | $(row).each(function(){setHierarchyHoverEvent($(this),".hierarchySuggestionsMenu")});
|
---|
| 262 | }
|
---|
[31063] | 263 | //function removeSuggestionsMenu(row,menuNewText)
|
---|
| 264 | function removeSuggestionsMenu(row)
|
---|
[30382] | 265 | {
|
---|
| 266 | $(row).find(".hierarchySuggestionsMenu").remove();
|
---|
| 267 | }
|
---|
[31063] | 268 | function setHierarchyButtonText(row, title){
|
---|
| 269 | $(row).find(".hierarchyMenuButton").text(title);
|
---|
| 270 | }
|
---|
[30382] | 271 |
|
---|
| 272 | function setHierarchyEventsWrappers(metaName)
|
---|
| 273 | {
|
---|
| 274 | //Loop through every metaTableCell
|
---|
| 275 | $(".metaTableCellName").each(function() {
|
---|
| 276 | //Check if it is a hierarchy row
|
---|
| 277 | var currentMetaName = $(this).text();
|
---|
| 278 | if (currentMetaName in hierarchyStorage && currentMetaName == metaName)
|
---|
| 279 | {
|
---|
| 280 | var row = this.parentElement;
|
---|
| 281 | var textArea = row.getElementsByClassName("metaTableCellArea")[0];
|
---|
| 282 |
|
---|
| 283 | //Mouse leave row
|
---|
| 284 | $(row).mouseleave(function() {
|
---|
| 285 | //textArea = this.getElementsByClassName("metaTableCellArea")[0];
|
---|
| 286 | if (this.getElementsByClassName("metaDataHierarchyMenu").length != 0 && document.activeElement.tagName != "TEXTAREA")
|
---|
| 287 | {
|
---|
| 288 | $(this).find('ul').stop(true, true);
|
---|
| 289 | //Remove hierarchy menu
|
---|
| 290 | $(this).find('.metaDataHierarchyMenu').hide();
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | });
|
---|
| 294 | // Mouse enter row
|
---|
| 295 | $(row).mouseenter(
|
---|
| 296 | function()
|
---|
| 297 | {
|
---|
| 298 | var row = this;
|
---|
| 299 | var table = row.parentElement;
|
---|
| 300 | //If focused on TEXTAREA do nothing
|
---|
| 301 | if (document.activeElement.tagName != "TEXTAREA")
|
---|
| 302 | {
|
---|
| 303 | //Hide all menus in table except this one
|
---|
| 304 | $(table).find('.metaDataHierarchyMenu').each(function() {
|
---|
| 305 | var currentRow = this.parentElement;
|
---|
| 306 | if (!$(currentRow).is($(row)) )
|
---|
| 307 | {
|
---|
| 308 | $(this).hide();
|
---|
| 309 | }
|
---|
| 310 | });
|
---|
| 311 |
|
---|
| 312 | // createHierarchyMenuButton($(row));
|
---|
| 313 | if ( $(row).find('ul').length == 0 )
|
---|
| 314 | {
|
---|
| 315 | createHierarchyMenuButton(row);
|
---|
| 316 | createSuggestionsMenu(row);
|
---|
| 317 | }
|
---|
| 318 | else
|
---|
| 319 | {
|
---|
| 320 | //Unhide menu
|
---|
| 321 | $(row).find('.metaDataHierarchyMenu').show();
|
---|
| 322 | //Minimize nested menus
|
---|
| 323 | $(row).find('.metaDataHierarchyMenu ul').find('ul').hide();
|
---|
| 324 | }
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 |
|
---|
| 328 | }
|
---|
| 329 | );
|
---|
| 330 |
|
---|
| 331 |
|
---|
| 332 | // Textarea focus
|
---|
| 333 | $(textArea).focus(
|
---|
| 334 | function()
|
---|
| 335 | {
|
---|
| 336 | var row = this.parentElement.parentElement;
|
---|
| 337 | var table = row.parentElement;
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | //Hide all menus in table except this one
|
---|
| 341 | $(table).find('.metaDataHierarchyMenu').each(function() {
|
---|
| 342 | var currentRow = this.parentElement;
|
---|
| 343 | if (!$(currentRow).is($(row)) )
|
---|
| 344 | {
|
---|
| 345 | $(this).hide();
|
---|
| 346 | }
|
---|
| 347 | });
|
---|
| 348 | //Create button
|
---|
| 349 | if ( $(row).find('ul').length == 0 )
|
---|
| 350 | {
|
---|
| 351 | createHierarchyMenuButton(row);
|
---|
| 352 | createSuggestionsMenu(row);
|
---|
| 353 | }
|
---|
| 354 | else
|
---|
| 355 | {
|
---|
| 356 | //Unhide menu
|
---|
| 357 | $(row).find('.metaDataHierarchyMenu').show();
|
---|
| 358 | //Minimize nested menus
|
---|
| 359 | $(row).find('.metaDataHierarchyMenu ul').find('ul').slideUp();
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 |
|
---|
| 363 | }
|
---|
| 364 | );
|
---|
| 365 | $(textArea).focusout(
|
---|
| 366 | function()
|
---|
| 367 | {
|
---|
| 368 | var row = this.parentElement.parentElement;
|
---|
[31063] | 369 |
|
---|
[30382] | 370 | var found = $(row).find('.metaDataHierarchyMenu ul li ul').filter(":visible")[0];
|
---|
[31063] | 371 | //Test if there are open submenu and cursor left tr element
|
---|
| 372 | if ( found === undefined && !$(row).is(':hover'))
|
---|
[30382] | 373 | {
|
---|
[31063] | 374 | //Hide hierarchy menu if there are no open submenus
|
---|
[30382] | 375 | $(row).find('.metaDataHierarchyMenu').hide();
|
---|
[31063] | 376 |
|
---|
| 377 | //Set metadata value if textarea contains hierarchy path
|
---|
| 378 | substituteHierarchyMetaValue(row);
|
---|
[30382] | 379 | }
|
---|
| 380 |
|
---|
| 381 |
|
---|
| 382 | }
|
---|
| 383 | );
|
---|
| 384 | }
|
---|
| 385 | });
|
---|
| 386 | }
|
---|
[31063] | 387 |
|
---|
| 388 | function substituteHierarchyMetaValue(row){
|
---|
| 389 | var text = $(row).find('TEXTAREA').val();
|
---|
| 390 | var metaName = getMetaName(row);
|
---|
| 391 | var hierarchyData = hierarchyStorage[metaName];
|
---|
| 392 | if (hierarchyData[text]){
|
---|
| 393 | var metaValue = hierarchyData[text][0];
|
---|
| 394 | $(row).find('TEXTAREA').val(metaValue);
|
---|
| 395 |
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | }
|
---|
| 399 | function getMetaName(row){
|
---|
| 400 | return $(row.getElementsByClassName("metaTableCellName")[0]).text();
|
---|
| 401 | }
|
---|
[30382] | 402 | var hierarchyStorage = {};
|
---|
| 403 | function addHierarchyToStorage(metaDataName,processedHierarchy)
|
---|
| 404 | {
|
---|
| 405 | hierarchyStorage[metaDataName] = processedHierarchy;
|
---|
| 406 |
|
---|
| 407 | }
|
---|
| 408 |
|
---|