00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 var ConfigurationAPI = ConfigurationAPI || {};
00039
00040 if (typeof Debug == 'undefined')
00041 alert('ERROR: Debug is undefined! Must include Debug.js before ConfigurationAPI.js');
00042 if (typeof Globals == 'undefined')
00043 alert('ERROR: Globals is undefined! Must include Globals.js before ConfigurationAPI.js');
00044 if (typeof DesktopContent == 'undefined' &&
00045 typeof Desktop == 'undefined')
00046 alert('ERROR: DesktopContent is undefined! Must include DesktopContent.js before ConfigurationAPI.js');
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 ConfigurationAPI._activeGroups = {};
00082
00083
00084 ConfigurationAPI._DEFAULT_COMMENT = "No comment.";
00085 ConfigurationAPI._POP_UP_DIALOG_ID = "ConfigurationAPI-popUpDialog";
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 ConfigurationAPI._VERSION_ALIAS_PREPEND = "ALIAS:";
00116 ConfigurationAPI._SCRATCH_VERSION = 2147483647;
00117 ConfigurationAPI._SCRATCH_ALIAS = "Scratch";
00118
00119 ConfigurationAPI._OK_CANCEL_DIALOG_STR = "";
00120 ConfigurationAPI._OK_CANCEL_DIALOG_STR += "<div title='' style='padding:5px;background-color:#eeeeee;border:1px solid #555555;position:relative;z-index:2000;" +
00121 "width:95px;height:20px;margin:0 -122px -64px 10px; font-size: 16px; white-space:nowrap; text-align:center;'>";
00122 ConfigurationAPI._OK_CANCEL_DIALOG_STR += "<a class='popUpOkCancel' onclick='javascript:ConfigurationAPI.handleEditableFieldEditOK(); event.stopPropagation();' onmouseup='event.stopPropagation();' title='Accept Changes' style='color:green'>" +
00123 "<b style='color:green;font-size: 16px;'>OK</b></a> | " +
00124 "<a class='popUpOkCancel' onclick='javascript:ConfigurationAPI.handleEditableFieldEditCancel(); event.stopPropagation();' onmouseup='event.stopPropagation();' title='Discard Changes' style='color:red'>" +
00125 "<b style='color:red;font-size: 16px;'>Cancel</b></a>";
00126 ConfigurationAPI._OK_CANCEL_DIALOG_STR += "</div>";
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 ConfigurationAPI.getActiveGroups = function(responseHandler)
00143 {
00144
00145 DesktopContent.XMLHttpRequest("Request?RequestType=getActiveConfigGroups",
00146 "", function(req)
00147 {
00148 responseHandler(ConfigurationAPI.extractActiveGroups(req));
00149 },
00150 0,0,true
00151 );
00152 }
00153 ConfigurationAPI.extractActiveGroups = function(req)
00154 {
00155
00156 try
00157 {
00158 var activeConfigGroups = [
00159 DesktopContent.getXMLValue(req,"Context-ActiveGroupName"),
00160 DesktopContent.getXMLValue(req,"Context-ActiveGroupKey"),
00161 DesktopContent.getXMLValue(req,"Backbone-ActiveGroupName"),
00162 DesktopContent.getXMLValue(req,"Backbone-ActiveGroupKey"),
00163 DesktopContent.getXMLValue(req,"Iterate-ActiveGroupName"),
00164 DesktopContent.getXMLValue(req,"Iterate-ActiveGroupKey"),
00165 DesktopContent.getXMLValue(req,"Configuration-ActiveGroupName"),
00166 DesktopContent.getXMLValue(req,"Configuration-ActiveGroupKey")];
00167 var i=0;
00168 var retObj = {};
00169 retObj.Context = {};
00170 retObj.Context.groupName = activeConfigGroups[i++];
00171 retObj.Context.groupKey = activeConfigGroups[i++];
00172 retObj.Backbone = {};
00173 retObj.Backbone.groupName = activeConfigGroups[i++];
00174 retObj.Backbone.groupKey = activeConfigGroups[i++];
00175 retObj.Iterate = {};
00176 retObj.Iterate.groupName = activeConfigGroups[i++];
00177 retObj.Iterate.groupKey = activeConfigGroups[i++];
00178 retObj.Configuration = {};
00179 retObj.Configuration.groupName = activeConfigGroups[i++];
00180 retObj.Configuration.groupKey = activeConfigGroups[i++];
00181 }
00182 catch(e)
00183 {
00184 Debug.log("Error extracting active groups: " + e);
00185 return undefined;
00186 }
00187
00188 ConfigurationAPI._activeGroups = {};
00189 ConfigurationAPI._activeGroups = retObj;
00190
00191 return retObj;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 ConfigurationAPI.getAliasesAndGroups = function(responseHandler,optionForNoAliases,
00225 optionForNoGroups)
00226 {
00227 var retObj = {};
00228 var reqCount = 0;
00229
00230
00231 if(!optionForNoAliases)
00232 DesktopContent.XMLHttpRequest("Request?RequestType=getGroupAliases" +
00233 "",
00234 "",
00235 function(req)
00236 {
00237
00238 Debug.log("getGroupAliases handler");
00239
00240 var groupAliases = req.responseXML.getElementsByTagName("GroupAlias");
00241 var groupNames = req.responseXML.getElementsByTagName("GroupName");
00242 var groupKeys = req.responseXML.getElementsByTagName("GroupKey");
00243 var groupComments = req.responseXML.getElementsByTagName("GroupComment");
00244 var groupTypes = req.responseXML.getElementsByTagName("GroupType");
00245 var aliasComments = req.responseXML.getElementsByTagName("AliasComment");
00246
00247 retObj.aliases = {};
00248 var type;
00249
00250 for(var i=0;i<groupAliases.length;++i)
00251 {
00252 type = groupTypes[i].getAttribute('value');
00253
00254 if(type == "") continue;
00255
00256 if(!retObj.aliases[type])
00257 retObj.aliases[type] = [];
00258
00259 retObj.aliases[type].push({
00260 "alias" : groupAliases[i].getAttribute('value'),
00261 "name" : groupNames[i].getAttribute('value'),
00262 "key" : groupKeys[i].getAttribute('value'),
00263 "groupComment" : groupComments[i].getAttribute('value'),
00264 "groupComment" : groupTypes[i].getAttribute('value'),
00265 "aliasComment" : aliasComments[i].getAttribute('value')
00266 });
00267 }
00268
00269 ++reqCount;
00270
00271 if(reqCount == 2 ||
00272 (reqCount == 1 && optionForNoGroups))
00273 {
00274
00275 console.log("getAliasesAndGroups retObj ",retObj);
00276 responseHandler(retObj);
00277 }
00278
00279 },
00280 0,
00281 0,true,
00282 );
00283
00284
00285
00286 if(!optionForNoGroups)
00287 DesktopContent.XMLHttpRequest("Request?RequestType=getConfigurationGroups"
00288 +"&doNotReturnMembers=1",
00289 "",
00290 function(req)
00291 {
00292 Debug.log("getConfigurationGroups handler");
00293
00294 retObj.activeGroups = {};
00295 retObj.activeGroups = ConfigurationAPI.extractActiveGroups(req);
00296
00297 var groupNames = req.responseXML.getElementsByTagName("ConfigurationGroupName");
00298 var groupKeys = req.responseXML.getElementsByTagName("ConfigurationGroupKey");
00299 var groupTypes = req.responseXML.getElementsByTagName("ConfigurationGroupType");
00300 var groupComments = req.responseXML.getElementsByTagName("ConfigurationGroupComment");
00301
00302 retObj.groups = {};
00303
00304 var type, name;
00305 for(var i=0;i<groupNames.length;++i)
00306 {
00307 type = groupTypes[i].getAttribute('value');
00308
00309 if(type == "") continue;
00310
00311
00312
00313
00314
00315
00316
00317 if(!retObj.groups[type])
00318 retObj.groups[type] = {};
00319
00320 name = groupNames[i].getAttribute('value');
00321 if(!retObj.groups[type][name])
00322 {
00323 retObj.groups[type][name] = {};
00324
00325 retObj.groups[type][name].groupComment = groupComments[i].getAttribute('value');
00326 retObj.groups[type][name].keys = [];
00327 }
00328
00329 retObj.groups[type][name].keys.push(groupKeys[i].getAttribute('value'));
00330 }
00331
00332 ++reqCount;
00333
00334 if(reqCount == 2 ||
00335 (reqCount == 1 && optionForNoAliases))
00336 {
00337
00338 console.log("getAliasesAndGroups retObj ",retObj);
00339 responseHandler(retObj);
00340 }
00341 },
00342 0,
00343 0,true);
00344
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 ConfigurationAPI.getSubsetRecords = function(subsetBasePath,
00370 filterList,responseHandler,modifiedTables)
00371 {
00372 var modifiedTablesListStr = "";
00373 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
00374 {
00375 if(i) modifiedTablesListStr += ",";
00376 modifiedTablesListStr += modifiedTables[i].tableName + "," +
00377 modifiedTables[i].tableVersion;
00378 }
00379 if(filterList === undefined) filterList = "";
00380
00381 DesktopContent.XMLHttpRequest("Request?RequestType=getTreeView" +
00382 "&configGroup=" +
00383 "&configGroupKey=-1" +
00384 "&hideStatusFalse=0" +
00385 "&depth=1",
00386 "startPath=/" + subsetBasePath +
00387 "&filterList=" + filterList +
00388 "&modifiedTables=" + modifiedTablesListStr,
00389 function(req)
00390 {
00391 ConfigurationAPI.extractActiveGroups(req);
00392
00393 var records = [];
00394 var err = DesktopContent.getXMLValue(req,"Error");
00395 if(err)
00396 {
00397 Debug.log(err,Debug.HIGH_PRIORITY);
00398 if(responseHandler) responseHandler(records);
00399 return;
00400 }
00401
00402
00403
00404 var tree = DesktopContent.getXMLNode(req,"tree");
00405 var nodes = tree.children;
00406 for(var i=0;i<nodes.length;++i)
00407 records.push(nodes[i].getAttribute("value"));
00408 Debug.log("Records: " + records);
00409 if(responseHandler) responseHandler(records);
00410
00411 },
00412 0,
00413 0,true);
00414 }
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 ConfigurationAPI.getTree = function(treeBasePath,depth,modifiedTables,
00425 responseHandler,responseHandlerParam)
00426 {
00427 var modifiedTablesListStr = "";
00428 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
00429 {
00430 if(i) modifiedTablesListStr += ",";
00431 modifiedTablesListStr += modifiedTables[i].tableName + "," +
00432 modifiedTables[i].tableVersion;
00433 }
00434
00435 treeBasePath = treeBasePath.trim();
00436 if(treeBasePath == "/") treeBasePath = "";
00437
00438 DesktopContent.XMLHttpRequest("Request?RequestType=getTreeView" +
00439 "&configGroup=" +
00440 "&configGroupKey=-1" +
00441 "&hideStatusFalse=0" +
00442 "&depth=" + depth,
00443 "startPath=/" + treeBasePath +
00444 "&filterList=" + "" +
00445 "&modifiedTables=" + modifiedTablesListStr,
00446 function(req)
00447 {
00448 var err = DesktopContent.getXMLValue(req,"Error");
00449 if(err)
00450 {
00451 Debug.log(err,Debug.HIGH_PRIORITY);
00452 if(responseHandler) responseHandler(undefined,responseHandlerParam);
00453 return;
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 if(responseHandler) responseHandler(
00467 DesktopContent.getXMLNode(req,"tree"),
00468 responseHandlerParam);
00469
00470 },
00471 0,
00472 0,true);
00473 }
00474
00475
00476
00477
00478
00479
00480 ConfigurationAPI.getTreeChildren = function(tree,pathToChildren)
00481 {
00482 var pathArr = pathToChildren?pathToChildren.split('/'):"";
00483 var children;
00484 var found;
00485
00486 children = tree.children;
00487
00488
00489 for(var i=0;i<pathArr.length;++i)
00490 {
00491 if(pathArr[i].trim().length == 0) continue;
00492
00493 Debug.log(i + ": " + pathArr[i]);
00494
00495 found = false;
00496 for(var j=0;j<children.length;++j)
00497 if(children[j].getAttribute("value") == pathArr[i])
00498 {
00499 found = true;
00500
00501 children = children[j].children;
00502 Debug.log("found " + pathArr[i]);
00503 break;
00504 }
00505
00506 if(!found)
00507 {
00508 Debug.log("Invalid path '" + pathToChildren + "' through tree! How did you get here? Notify admins.", Debug.HIGH_PRIORITY);
00509 return undefined;
00510 }
00511 }
00512
00513
00514
00515 var retArr = [];
00516 for(var i=0;i<children.length;++i)
00517 if(children[i].nodeName == "node")
00518 retArr.push(children[i]);
00519
00520 return retArr;
00521
00522 }
00523
00524
00525
00526
00527
00528 ConfigurationAPI.getTreeRecordLinks = function(node)
00529 {
00530 var children = node.children;
00531 var retArr = [];
00532 var subchildren;
00533
00534
00535 for(var i=0;i<children.length;++i)
00536 {
00537 if(children[i].nodeName != "node") continue;
00538
00539 subchildren = children[i].children;
00540
00541 for(var j=0;j<subchildren.length;++j)
00542 {
00543 if(subchildren[j].nodeName == "LinkConfigurationName")
00544 {
00545 retArr.push(children[i]);
00546 break;
00547 }
00548 }
00549 }
00550
00551 return retArr;
00552 }
00553
00554
00555
00556
00557
00558
00559 ConfigurationAPI.getTreeRecordName = function(node)
00560 {
00561
00562
00563 var children = node.children;
00564 if(children.length > 2)
00565 {
00566 if(children[0].nodeName == "valueType" &&
00567 children[0].getAttribute("value") == "Disconnected")
00568 throw("Disconnected link!");
00569
00570 if(children[0].nodeName == "UID")
00571 return children[0].getAttribute("value");
00572
00573 if(children[1].nodeName == "UID")
00574 return children[0].getAttribute("value");
00575 }
00576
00577 return node.getAttribute("value");
00578 }
00579
00580
00581
00582
00583
00584 ConfigurationAPI.getTreeLinkChildren = function(link)
00585 {
00586 var children = link.children;
00587 var retArr = [];
00588
00589 for(var i=0;i<children.length;++i)
00590 {
00591 if(children[i].nodeName == "UID")
00592 {
00593 retArr.push(link);
00594 break;
00595 }
00596 else if(children[i].nodeName == "node")
00597 retArr.push(children[i]);
00598 }
00599
00600 return retArr;
00601 }
00602
00603
00604
00605
00606
00607 ConfigurationAPI.getTreeLinkTable = function(link)
00608 {
00609 var children = link.children;
00610 for(var i=0;i<children.length;++i)
00611 if(children[i].nodeName == "LinkConfigurationName")
00612 return children[i].getAttribute("value");
00613 throw("Table name not found!");
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648 ConfigurationAPI.getFieldsOfRecords = function(subsetBasePath,recordArr,fieldList,
00649 maxDepth,responseHandler,modifiedTables)
00650 {
00651 var modifiedTablesListStr = "";
00652 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
00653 {
00654 if(i) modifiedTablesListStr += ",";
00655 modifiedTablesListStr += modifiedTables[i].tableName + "," +
00656 modifiedTables[i].tableVersion;
00657 }
00658
00659 var recordListStr = "";
00660 if(Array.isArray(recordArr))
00661 for(var i=0;i<recordArr.length;++i)
00662 {
00663 if(i) recordListStr += ",";
00664 recordListStr += encodeURIComponent(recordArr[i]);
00665 }
00666 else
00667 recordListStr = encodeURIComponent(recordArr);
00668
00669 subsetBasePath = subsetBasePath.trim();
00670 if(subsetBasePath == "/") subsetBasePath = "";
00671
00672 DesktopContent.XMLHttpRequest("Request?RequestType=getTreeNodeCommonFields" +
00673 "&configGroup=" +
00674 "&configGroupKey=-1" +
00675 "&depth=" + (maxDepth|0),
00676 "startPath=/" + subsetBasePath +
00677 "&recordList=" + recordListStr +
00678 "&fieldList=" + fieldList +
00679 "&modifiedTables=" + modifiedTablesListStr,
00680 function(req)
00681 {
00682 var recFields = [];
00683 var err = DesktopContent.getXMLValue(req,"Error");
00684 if(err)
00685 {
00686 Debug.log(err,Debug.HIGH_PRIORITY);
00687 if(responseHandler) responseHandler(recFields);
00688 return;
00689 }
00690
00691 var fields = DesktopContent.getXMLNode(req,"fields");
00692
00693 var FieldTableNames = fields.getElementsByTagName("FieldTableName");
00694 var FieldColumnNames = fields.getElementsByTagName("FieldColumnName");
00695 var FieldRelativePaths = fields.getElementsByTagName("FieldRelativePath");
00696 var FieldColumnTypes = fields.getElementsByTagName("FieldColumnType");
00697 var FieldColumnDataTypes = fields.getElementsByTagName("FieldColumnDataType");
00698 var FieldColumnDataChoices = fields.getElementsByTagName("FieldColumnDataChoices");
00699 var FieldColumnDefaultValues = fields.getElementsByTagName("FieldColumnDefaultValue");
00700
00701
00702 for(var i=0;i<FieldTableNames.length;++i)
00703 {
00704 var obj = {};
00705 obj.fieldTableName = DesktopContent.getXMLValue(FieldTableNames[i]);
00706 obj.fieldColumnName = DesktopContent.getXMLValue(FieldColumnNames[i]);
00707 obj.fieldRelativePath = DesktopContent.getXMLValue(FieldRelativePaths[i]);
00708 obj.fieldColumnType = DesktopContent.getXMLValue(FieldColumnTypes[i]);
00709 obj.fieldColumnDataType = DesktopContent.getXMLValue(FieldColumnDataTypes[i]);
00710 obj.fieldColumnDefaultValue = DesktopContent.getXMLValue(FieldColumnDefaultValues[i]);
00711
00712 var FieldColumnDataChoicesArr = FieldColumnDataChoices[i].getElementsByTagName("FieldColumnDataChoice");
00713 obj.fieldColumnDataChoicesArr = [];
00714 for(var j=0; j<FieldColumnDataChoicesArr.length;++j)
00715 obj.fieldColumnDataChoicesArr.push(DesktopContent.getXMLValue(FieldColumnDataChoicesArr[j]));
00716
00717 recFields.push(obj);
00718 }
00719 Debug.log("Records length: " + recFields.length);
00720 if(responseHandler) responseHandler(recFields);
00721
00722 },
00723 0,
00724 0,true);
00725 }
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749 ConfigurationAPI.getFieldValuesForRecords = function(subsetBasePath,recordArr,fieldObjArr,
00750 responseHandler,modifiedTables)
00751 {
00752 var modifiedTablesListStr = "";
00753 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
00754 {
00755 if(i) modifiedTablesListStr += ",";
00756 modifiedTablesListStr += modifiedTables[i].tableName + "," +
00757 modifiedTables[i].tableVersion;
00758 }
00759
00760 var recordListStr = "";
00761 if(Array.isArray(recordArr))
00762 for(var i=0;i<recordArr.length;++i)
00763 {
00764 if(i) recordListStr += ",";
00765 recordListStr += encodeURIComponent(recordArr[i]);
00766 }
00767 else
00768 recordListStr = encodeURIComponent(recordArr);
00769
00770
00771 var fieldListStr = "";
00772 if(fieldObjArr.length && (typeof fieldObjArr[0] === "string"))
00773 {
00774
00775
00776 if(Array.isArray(fieldObjArr))
00777 for(var i=0;i<fieldObjArr.length;++i)
00778 {
00779 if(i) fieldListStr += ",";
00780 fieldListStr += encodeURIComponent(fieldObjArr[i]);
00781 }
00782 else
00783 fieldListStr = encodeURIComponent(fieldObjArr);
00784 }
00785 else
00786 {
00787
00788
00789 for(var i=0;i<fieldObjArr.length;++i)
00790 {
00791 if(i) fieldListStr += ",";
00792 fieldListStr += fieldObjArr[i].fieldRelativePath +
00793 fieldObjArr[i].fieldColumnName;
00794 }
00795 }
00796
00797 DesktopContent.XMLHttpRequest("Request?RequestType=getTreeNodeFieldValues" +
00798 "&configGroup=" +
00799 "&configGroupKey=-1",
00800 "startPath=/" + subsetBasePath +
00801 "&recordList=" + recordListStr +
00802 "&fieldList=" + fieldListStr +
00803 "&modifiedTables=" + modifiedTablesListStr,
00804 function(req)
00805 {
00806 var recFieldValues = [];
00807 var err = DesktopContent.getXMLValue(req,"Error");
00808 if(err)
00809 {
00810 Debug.log(err,Debug.HIGH_PRIORITY);
00811 if(responseHandler) responseHandler(recFieldValues);
00812 return;
00813 }
00814
00815 var fieldValues = req.responseXML.getElementsByTagName("fieldValues");
00816
00817 for(var f=0;f<fieldValues.length;++f)
00818 {
00819 var FieldPaths = fieldValues[f].getElementsByTagName("FieldPath");
00820 var FieldValues = fieldValues[f].getElementsByTagName("FieldValue");
00821 for(var i=0;i<FieldPaths.length;++i)
00822 {
00823 var obj = {};
00824 obj.fieldUID = DesktopContent.getXMLValue(fieldValues[f]);
00825 obj.fieldPath = DesktopContent.getXMLValue(FieldPaths[i]);
00826 obj.fieldValue = DesktopContent.getXMLValue(FieldValues[i]);
00827 recFieldValues.push(obj);
00828 }
00829 }
00830
00831 if(responseHandler) responseHandler(recFieldValues);
00832
00833 },
00834 0,
00835 0,true);
00836 }
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 ConfigurationAPI.getUniqueFieldValuesForRecords = function(subsetBasePath,recordArr,fieldList,
00862 responseHandler,modifiedTables)
00863 {
00864 var modifiedTablesListStr = "";
00865 for(var i=0;modifiedTables && i<modifiedTables.length;++i)
00866 {
00867 if(i) modifiedTablesListStr += ",";
00868 modifiedTablesListStr += modifiedTables[i].tableName + "," +
00869 modifiedTables[i].tableVersion;
00870 }
00871
00872 var recordListStr = "";
00873 if(Array.isArray(recordArr))
00874 for(var i=0;i<recordArr.length;++i)
00875 {
00876 if(i) recordListStr += ",";
00877 recordListStr += encodeURIComponent(recordArr[i]);
00878 }
00879 else
00880 recordListStr = encodeURIComponent(recordArr);
00881
00882 DesktopContent.XMLHttpRequest("Request?RequestType=getUniqueFieldValuesForRecords" +
00883 "&configGroup=" +
00884 "&configGroupKey=-1",
00885 "startPath=/" + subsetBasePath +
00886 "&recordList=" + recordListStr +
00887 "&fieldList=" + fieldList +
00888 "&modifiedTables=" + modifiedTablesListStr,
00889 function(req)
00890 {
00891 var fieldUniqueValues = [];
00892 var err = DesktopContent.getXMLValue(req,"Error");
00893 if(err)
00894 {
00895 Debug.log(err,Debug.HIGH_PRIORITY);
00896 if(responseHandler) responseHandler(fieldUniqueValues);
00897 return;
00898 }
00899
00900 var fields = req.responseXML.getElementsByTagName("field");
00901
00902 for(var i=0;i<fields.length;++i)
00903 {
00904
00905 var uniqueValues = fields[i].getElementsByTagName("uniqueValue");
00906
00907 var obj = {};
00908 obj.fieldName = DesktopContent.getXMLValue(fields[i]);
00909 obj.fieldUniqueValueArray = [];
00910 for(var j=0;j<uniqueValues.length;++j)
00911 obj.fieldUniqueValueArray.push(DesktopContent.getXMLValue(uniqueValues[j]));
00912 fieldUniqueValues.push(obj);
00913 }
00914 Debug.log("fieldUniqueValues length: " + fieldUniqueValues.length);
00915 if(responseHandler) responseHandler(fieldUniqueValues);
00916
00917 },
00918 0,
00919 0,true);
00920 }
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948 ConfigurationAPI.setFieldValuesForRecords = function(subsetBasePath,recordArr,fieldObjArr,
00949 valueArr,responseHandler,modifiedTablesIn,silenceErrors)
00950 {
00951 var modifiedTablesListStr = "";
00952 for(var i=0;modifiedTablesIn && i<modifiedTablesIn.length;++i)
00953 {
00954 if(i) modifiedTablesListStr += ",";
00955 modifiedTablesListStr += modifiedTablesIn[i].tableName + "," +
00956 modifiedTablesIn[i].tableVersion;
00957 }
00958
00959 var fieldListStr = "";
00960 if(fieldObjArr.length && (typeof fieldObjArr[0] === "string"))
00961 {
00962
00963
00964 if(Array.isArray(fieldObjArr))
00965 for(var i=0;i<fieldObjArr.length;++i)
00966 {
00967 if(i) fieldListStr += ",";
00968 fieldListStr += encodeURIComponent(fieldObjArr[i]);
00969 }
00970 else
00971 fieldListStr = encodeURIComponent(fieldObjArr);
00972 }
00973 else
00974 {
00975
00976
00977 for(var i=0;i<fieldObjArr.length;++i)
00978 {
00979 if(i) fieldListStr += ",";
00980 fieldListStr += fieldObjArr[i].fieldRelativePath +
00981 fieldObjArr[i].fieldColumnName;
00982 }
00983 }
00984
00985
00986 var valueListStr = "";
00987 if(Array.isArray(valueArr))
00988 for(var i=0;i<valueArr.length;++i)
00989 {
00990 if(i) valueListStr += ",";
00991 valueListStr += encodeURIComponent(valueArr[i]);
00992 }
00993 else
00994 valueListStr = encodeURIComponent(valueArr);
00995
00996
00997 var recordListStr = "";
00998 if(Array.isArray(recordArr))
00999 for(var i=0;i<recordArr.length;++i)
01000 {
01001 if(i) recordListStr += ",";
01002 recordListStr += encodeURIComponent(recordArr[i]);
01003 }
01004 else
01005 recordListStr = encodeURIComponent(recordArr);
01006
01007 DesktopContent.XMLHttpRequest("Request?RequestType=setTreeNodeFieldValues" +
01008 "&configGroup=" +
01009 "&configGroupKey=-1",
01010 "startPath=/" + subsetBasePath +
01011 "&recordList=" + recordListStr +
01012 "&valueList=" + valueListStr +
01013 "&fieldList=" + fieldListStr +
01014 "&modifiedTables=" + modifiedTablesListStr,
01015 function(req)
01016 {
01017 var modifiedTables = [];
01018
01019 var err = DesktopContent.getXMLValue(req,"Error");
01020 if(err)
01021 {
01022 if(!silenceErrors)
01023 Debug.log(err,Debug.HIGH_PRIORITY);
01024 if(responseHandler) responseHandler(modifiedTables,err);
01025 return;
01026 }
01027
01028 var tableNames = req.responseXML.getElementsByTagName("NewActiveTableName");
01029 var tableVersions = req.responseXML.getElementsByTagName("NewActiveTableVersion");
01030 var tableComments = req.responseXML.getElementsByTagName("NewActiveTableComment");
01031 var tableVersion;
01032
01033
01034 for(var i=0;i<tableNames.length;++i)
01035 {
01036 tableVersion = DesktopContent.getXMLValue(tableVersions[i])|0;
01037 if(tableVersion >= -1) continue;
01038 var obj = {};
01039 obj.tableName = DesktopContent.getXMLValue(tableNames[i]);
01040 obj.tableVersion = DesktopContent.getXMLValue(tableVersions[i]);
01041 obj.tableComment = DesktopContent.getXMLValue(tableComments[i]);
01042 modifiedTables.push(obj);
01043 }
01044
01045 if(responseHandler) responseHandler(modifiedTables);
01046
01047 },
01048 0,
01049 0,true);
01050 }
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082 ConfigurationAPI.popUpSaveModifiedTablesForm = function(modifiedTables,responseHandler)
01083 {
01084
01085
01086 Debug.log("ConfigurationAPI popUpSaveModifiedTablesForm");
01087
01088 var str = "";
01089
01090 var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
01091 if(!el)
01092 {
01093 el = document.createElement("div");
01094 el.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID);
01095 }
01096 el.style.display = "none";
01097
01098 var gh = 50;
01099 var w = 380;
01100 var h = 330;
01101 ConfigurationAPI.setPopUpPosition(el,w ,h-gh*2 );
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 var modTblCount = 0;
01124 var modTblStr = "";
01125 var modifiedTablesListStr = "";
01126
01127 for(var j=0;j<modifiedTables.length;++j)
01128 if((modifiedTables[j].tableVersion|0) < -1)
01129 {
01130 if(modTblCount++)
01131 modTblStr += ",";
01132 modTblStr += modifiedTables[j].tableName;
01133
01134 if(modifiedTablesListStr.length)
01135 modifiedTablesListStr += ",";
01136 modifiedTablesListStr += modifiedTables[j].tableName;
01137 modifiedTablesListStr += ",";
01138 modifiedTablesListStr += modifiedTables[j].tableVersion;
01139 }
01140
01141 var str = "<a id='" +
01142 ConfigurationAPI._POP_UP_DIALOG_ID +
01143 "-cancel' href='#'>Cancel</a><br><br>";
01144
01145 str += "<div id='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-div'>";
01146 str += "Saving will create new persistent versions of each modified table." +
01147 "<br><br>" +
01148 "Here is the list of modified tables (count=" + modTblCount +
01149 "):" +
01150 "<br>";
01151
01152
01153
01154 str += "<div style='white-space:nowrap; width:" + w + "px; height:40px; " +
01155 "overflow:auto; font-weight: bold;'>";
01156 str += modTblStr;
01157 str += "</div>";
01158
01159
01160
01162 DesktopContent.XMLHttpRequest("Request?RequestType=getAffectedActiveGroups" +
01163 "&groupName=" +
01164 "&groupKey=-1",
01165 "&modifiedTables=" + modifiedTablesListStr,
01166 function(req)
01167 {
01168 var err = DesktopContent.getXMLValue(req,"Error");
01169 if(err)
01170 {
01171 Debug.log(err,Debug.HIGH_PRIORITY);
01172 el.innerHTML = str;
01173 return;
01174 }
01175
01176
01177
01178 var groups = req.responseXML.getElementsByTagName("AffectedActiveGroup");
01179 var memberNames, memberVersions;
01180 var xmlGroupName;
01181 modTblStr = "";
01182 for(var i=0;i<groups.length;++i)
01183 {
01184 xmlGroupName = DesktopContent.getXMLValue(groups[i],"GroupName");
01185 str += "<div style='display:none' class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01186 "-affectedGroups' >";
01187 str += xmlGroupName;
01188 str += "," + DesktopContent.getXMLValue(groups[i],"GroupKey");
01189
01190 memberNames = groups[i].getElementsByTagName("MemberName");
01191 memberVersions = groups[i].getElementsByTagName("MemberVersion");
01192 Debug.log("memberNames.length " + memberNames.length);
01193 for(var j=0;j<memberNames.length;++j)
01194 str += "," + DesktopContent.getXMLValue(memberNames[j]) +
01195 "," + DesktopContent.getXMLValue(memberVersions[j]);
01196 str += "</div>";
01197
01198
01199 if(modTblStr.length)
01200 modTblStr += ",";
01201
01202
01203 modTblStr += "<a style='color:black' href='#' onclick='javascript:" +
01204 "var forFirefox = ConfigurationAPI.handleGroupCommentToggle(\"" +
01205 xmlGroupName + "\");" +
01206 " ConfigurationAPI.handlePopUpHeightToggle(" + h + "," + gh + ");'>";
01207 modTblStr += xmlGroupName;
01208 modTblStr += "</a>";
01209
01210
01211 modTblStr += "<div id='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment-" +
01212 xmlGroupName + "' " +
01213 "class='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment-cache' " +
01214 "style='display:none'>" +
01215 decodeURIComponent(DesktopContent.getXMLValue(groups[i],"GroupComment")) +
01216 "</div>";
01217 }
01218
01219 str += "Please choose the options you want and click 'Save':" +
01220 "<br>";
01221
01222
01223 str += "<input type='checkbox' id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01224 "-bumpGroupVersions' checked " +
01225 "onclick='ConfigurationAPI.handlePopUpHeightToggle(" + h + "," + gh + ");'>";
01226
01227 str += "<a href='#' onclick='javascript:" +
01228 "var el = document.getElementById(\"" + ConfigurationAPI._POP_UP_DIALOG_ID +
01229 "-bumpGroupVersions\");" +
01230 "var forFirefox = (el.checked = !el.checked);" +
01231 " ConfigurationAPI.handlePopUpHeightToggle(" + h + "," + gh + "); return false;'>";
01232 str += "Save Affected Groups as New Keys";
01233 str += "</a>";
01234 str += "</input><br>";
01235
01236
01237 str += "<input type='checkbox' id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01238 "-activateBumpedGroupVersions' checked " +
01239 ">";
01240
01241 str += "<a href='#' onclick='javascript:" +
01242 "var el = document.getElementById(\"" + ConfigurationAPI._POP_UP_DIALOG_ID +
01243 "-activateBumpedGroupVersions\");" +
01244 "if(el.disabled) return false; " +
01245 "var forFirefox = (el.checked = !el.checked);" +
01246 "return false;'>";
01247 str += "Also Activate New Groups";
01248 str += "</a>";
01249 str += "</input><br>";
01250
01251 str += "Here is the list of affected groups (count=" + groups.length +
01252 "):" +
01253 "<br>";
01254
01255
01256 str += "<div style='white-space:nowrap; width:" + w + "px; margin-bottom:20px; " +
01257 "overflow:auto; font-weight: bold;'>";
01258 str += modTblStr;
01259 str += "<div id='clearDiv'></div>";
01260 str += "<center>";
01261
01262 str += "<div id='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment-header'></div>";
01263
01264 str += "<div id='clearDiv'></div>";
01265
01266 str += "<textarea id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01267 "-groupComment' rows='4' cols='50' " +
01268 "style='width:417px;height:68px;display:none;margin:0;'>";
01269 str += ConfigurationAPI._DEFAULT_COMMENT;
01270 str += "</textarea>";
01271 str += "</center>";
01272
01273 str += "</div>";
01274
01275 str += "<div id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01276 "-groupAliasArea' ><center>";
01277
01278
01280 DesktopContent.XMLHttpRequest("Request?RequestType=getGroupAliases" +
01281 "",
01282 "",
01283 function(req)
01284 {
01285 var err = DesktopContent.getXMLValue(req,"Error");
01286 if(err)
01287 {
01288 Debug.log(err,Debug.HIGH_PRIORITY);
01289 el.innerHTML = str;
01290 return;
01291 }
01292
01293 var aliases = req.responseXML.getElementsByTagName("GroupAlias");
01294 var aliasGroupNames = req.responseXML.getElementsByTagName("GroupName");
01295 var aliasGroupKeys = req.responseXML.getElementsByTagName("GroupKey");
01296
01297
01298
01299
01300
01301
01302 var alias, aliasGroupName, aliasGroupKey;
01303 var groupName, groupKey;
01304 var groupOptionIndex = [];
01305 for(var i=0;i<groups.length;++i)
01306 {
01307 groupOptionIndex.push([-1,0]);
01308
01309 groupName = DesktopContent.getXMLValue(groups[i],"GroupName");
01310 groupKey = DesktopContent.getXMLValue(groups[i],"GroupKey");
01311
01312
01313 modTblStr = "";
01314 for(var j=0;j<aliasGroupNames.length;++j)
01315 {
01316 alias = DesktopContent.getXMLValue(aliases[j]);
01317 aliasGroupName = DesktopContent.getXMLValue(aliasGroupNames[j]);
01318 aliasGroupKey = DesktopContent.getXMLValue(aliasGroupKeys[j]);
01319
01320
01321
01322
01323
01324 modTblStr += "<option value='" + alias + "' ";
01325
01326
01327 if(aliasGroupName == groupName)
01328 {
01329 if(groupOptionIndex[i][0] == -1 ||
01330 Math.abs(groupKey - aliasGroupKey) < groupOptionIndex[i][1])
01331 {
01332 Debug.log("found alias");
01333 groupOptionIndex[i][0] = j;
01334 groupOptionIndex[i][1] = Math.abs(groupKey - aliasGroupKey);
01335 }
01336 }
01337 modTblStr += ">";
01338 modTblStr += alias;
01339 modTblStr += "</option>";
01340 }
01341
01342 str += "<input type='checkbox' class='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-setGroupAlias' " +
01343 (groupOptionIndex[i][0] >= 0?"checked":"") +
01344 ">";
01345
01346 str += "<a href='#' onclick='javascript:" +
01347 "var el = document.getElementsByClassName(\"" + ConfigurationAPI._POP_UP_DIALOG_ID + "-setGroupAlias\");" +
01348 "var forFirefox = (el[" + i + "].checked = !el[" + i + "].checked);" +
01349 " return false;'>";
01350 str += "Set '<b style='font-size:16px'>" + groupName + "</b>' to System Alias:";
01351 str += "</a><br>";
01352
01353 str += "<table cellpadding='0' cellspacing='0' border='0'><tr><td>";
01354 str += "<select " +
01355 "id='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasSelect-" + (i) + "' " +
01356 "style='margin:2px; height:" + (25) + "px'>";
01357 str += modTblStr;
01358 str += "</select>";
01359
01360 str += "<input type='text' " +
01361 "id='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasTextBox-" + (i) + "' " +
01362 "style='display:none; margin:2px; width:150px; height:" +
01363 (19) + "px'>";
01364 str += "";
01365 str += "</input>";
01366 str += "</td><td>";
01367
01368 str += "<div style='display:block' " +
01369 "class='" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editIcon' id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01370 "-editIcon-" +
01371 (i) + "' " +
01372 "onclick='ConfigurationAPI.handlePopUpAliasEditToggle(" +
01373 i +
01374 ");' " +
01375 "title='Toggle free-form system alias editing' " +
01376 "></div>";
01377
01378 str += "<div class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01379 "-preloadImage' id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01380 "-preloadImage-editIconHover'></div>";
01381
01382 str += "</td></tr></table>";
01383
01384 str += "</input>";
01385
01386
01387 h += gh;
01388 el.style.height = h + "px";
01389 }
01390
01391 str += "</center></div>";
01392
01393
01394
01395
01396
01397 str += "</div><br>";
01398
01399
01400
01401
01402
01403
01404
01405 str += "<input id='" + ConfigurationAPI._POP_UP_DIALOG_ID +
01406 "-submitButton' type='button' " +
01407
01408 "value='Save' title='" +
01409 "Save new versions of every modified table\n" +
01410 "(Optionally, save new active groups and assign system aliases)" +
01411 "'/>";
01412 el.innerHTML = str;
01413
01414
01415 document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID +
01416 "-submitButton").onmouseup = function() {
01417 Debug.log("Submit mouseup");
01418 this.disabled = true;
01419 ConfigurationAPI.handleGroupCommentToggle(0,1);
01420 ConfigurationAPI.handlePopUpHeightToggle(h,gh);
01421
01422 var savingGroups =
01423 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID +
01424 "-bumpGroupVersions").checked;
01425 var activatingSavedGroups =
01426 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID +
01427 "-activateBumpedGroupVersions").checked;
01428
01429 ConfigurationAPI.saveModifiedTables(modifiedTables,responseHandler,
01430 true);
01431
01432 };
01433
01434
01435 document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID +
01436 "-cancel").onclick = function(event) {
01437 Debug.log("Cancel click");
01438 var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
01439 if(el) el.parentNode.removeChild(el);
01440 if(responseHandler) responseHandler([],[],[]);
01441 return false;
01442 };
01443
01444
01445
01446 for(var i=0;i<groups.length;++i)
01447 if(groupOptionIndex[i][0] != -1)
01448 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasSelect-" +
01449 i).selectedIndex = groupOptionIndex[i][0];
01450
01451 },0,0,true
01452 );
01453
01454 },0,0,true
01455 );
01456
01457
01458 document.body.appendChild(el);
01459 el.style.display = "block";
01460
01461 }
01462
01463
01464
01465
01466
01467 ConfigurationAPI.handleGroupCommentToggle = function(groupName,setHideVal)
01468 {
01469 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment");
01470 var hel = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment-header");
01471 var cel;
01472
01473 var doHide = el.style.display != "none";
01474 if(setHideVal !== undefined)
01475 doHide = setHideVal;
01476
01477 if(doHide)
01478 {
01479 if(hel.textContent == "") return;
01480
01481
01482 var gn = hel.textContent.split("'")[1];
01483 Debug.log("gn " + gn);
01484 cel = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment-" +
01485 gn);
01486 cel.innerHTML = "";
01487 cel.appendChild(document.createTextNode(el.value));
01488
01489
01490 hel.innerHTML = "";
01491 el.style.display = "none";
01492
01493
01494 if(gn == groupName || setHideVal !== undefined)
01495 return;
01496
01497 }
01498
01499
01500 {
01501 cel = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment-" +
01502 groupName);
01503 el.value = cel.textContent;
01504 el.style.display = "block";
01505 ConfigurationAPI.setCaretPosition(el,0,cel.textContent.length);
01506
01507 hel.innerHTML = ("'" + groupName + "' group comment:");
01508 }
01509 }
01510
01511
01512
01513
01514
01515
01516
01517 ConfigurationAPI.handlePopUpHeightToggle = function(h,gh)
01518 {
01519 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-bumpGroupVersions");
01520 Debug.log("ConfigurationAPI.handlePopUpHeightToggle " + el.checked);
01521
01522 var ael = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-activateBumpedGroupVersions");
01523
01524 var groupCommentEl = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupComment");
01525 var groupCommentHeight = 0;
01526
01527 if(groupCommentEl && groupCommentEl.style.display != "none")
01528 groupCommentHeight += 100;
01529
01530 var popEl = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
01531 if(!el.checked)
01532 {
01533
01534
01535 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupAliasArea").style.display = "none";
01536 popEl.style.height = (h + groupCommentHeight) + "px";
01537 ael.disabled = true;
01538 }
01539 else
01540 {
01541
01542
01543
01544 var grps = document.getElementsByClassName("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-affectedGroups");
01545 popEl.style.height = (h + grps.length*gh + groupCommentHeight) + "px";
01546 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-groupAliasArea").style.display = "block";
01547 ael.disabled = false;
01548 }
01549 }
01550
01551
01552
01553 ConfigurationAPI.handlePopUpAliasEditToggle = function(i)
01554 {
01555 Debug.log("handlePopUpAliasEditToggle " + i);
01556
01557 var sel = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasSelect-"+i);
01558 var tel = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasTextBox-"+i);
01559 Debug.log("sel.style.display " + sel.style.display);
01560 if(sel.style.display == "none")
01561 {
01562 sel.style.display = "block";
01563 tel.style.display = "none";
01564 }
01565 else
01566 {
01567 tel.style.width = (sel.offsetWidth-2) + "px";
01568 sel.style.display = "none";
01569 tel.style.display = "block";
01570 ConfigurationAPI.setCaretPosition(tel,0,tel.value.length);
01571 }
01572 }
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611 ConfigurationAPI.saveModifiedTables = function(modifiedTables,responseHandler,
01612 doNotIgnoreWarnings,doNotSaveAffectedGroups,
01613 doNotActivateAffectedGroups,doNotSaveAliases,
01614 doNotIgnoreGroupActivationWarnings,
01615 doNotKillPopUpEl)
01616 {
01617
01618
01619 var savedTables = [];
01620 var savedGroups = [];
01621 var savedAliases = [];
01622
01623 if(!modifiedTables.length)
01624 {
01625 Debug.log("No tables were modified. Nothing to do.", Debug.WARN_PRIORITY);
01626 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
01627 return;
01628 }
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642 var numberOfRequests = 0;
01643 var numberOfReturns = 0;
01644 var allRequestsSent = false;
01645
01646
01647
01648 function localHandleAffectedGroups()
01649 {
01650 Debug.log("Done with table saving.");
01651
01652
01653 var savingGroups;
01654 var activatingSavedGroups;
01655 var doRequestAffectedGroups = false;
01656 try
01657 {
01658 savingGroups =
01659 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-bumpGroupVersions").checked;
01660
01661 activatingSavedGroups =
01662 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-activateBumpedGroupVersions").checked;
01663 }
01664 catch(err)
01665 {
01666 savingGroups = !doNotSaveAffectedGroups;
01667 activatingSavedGroups = !doNotActivateAffectedGroups;
01668 doRequestAffectedGroups = true;
01669 }
01670
01671 if(!savingGroups)
01672 {
01673
01674 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
01675 if(el && !doNotKillPopUpEl) el.parentNode.removeChild(el);
01676 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
01677 return;
01678 }
01679
01680
01681
01682
01683
01684
01685
01686 Debug.log("On to saving groups");
01687
01688 numberOfRequests = 0;
01689 numberOfReturns = 0;
01690 allRequestsSent = false;
01691
01692 var affectedGroupNames = [];
01693 var affectedGroupComments = [];
01694 var affectedGroupConfigMap = [];
01695
01696 var affectedGroupKeys = [];
01697
01698 if(doRequestAffectedGroups)
01699 {
01700
01701 var modifiedTablesListStr = "";
01702 var modTblCount = 0;
01703 var modTblStr = "";
01704 for(var j=0;j<modifiedTables.length;++j)
01705 if((modifiedTables[j].tableVersion|0) < -1)
01706 {
01707 if(modTblCount++)
01708 modTblStr += ",";
01709 modTblStr += modifiedTables[j].tableName;
01710
01711 if(modifiedTablesListStr.length)
01712 modifiedTablesListStr += ",";
01713 modifiedTablesListStr += modifiedTables[j].tableName;
01714 modifiedTablesListStr += ",";
01715 modifiedTablesListStr += modifiedTables[j].tableVersion;
01716 }
01717
01718
01719
01721 DesktopContent.XMLHttpRequest("Request?RequestType=getAffectedActiveGroups" +
01722 "&groupName=" +
01723 "&groupKey=-1",
01724 "&modifiedTables=" + modifiedTablesListStr,
01725 function(req)
01726 {
01727 var err = DesktopContent.getXMLValue(req,"Error");
01728 if(err)
01729 {
01730 Debug.log(err,Debug.HIGH_PRIORITY);
01731 el.innerHTML = str;
01732 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
01733 return;
01734 }
01735
01736
01737 var groups = req.responseXML.getElementsByTagName("AffectedActiveGroup");
01738 var memberNames, memberVersions;
01739 var xmlGroupName;
01740 modTblStr = "";
01741 for(var i=0;i<groups.length;++i)
01742 {
01743 affectedGroupNames.push( DesktopContent.getXMLValue(groups[i],"GroupName"));
01744 affectedGroupComments.push(decodeURIComponent(DesktopContent.getXMLValue(groups[i],"GroupComment")));
01745
01746 memberNames = groups[i].getElementsByTagName("MemberName");
01747 memberVersions = groups[i].getElementsByTagName("MemberVersion");
01748
01749 Debug.log("memberNames.length " + memberNames.length);
01750
01751
01752 affectedGroupConfigMap[i] = "configList=";
01753 var memberVersion, memberName;
01754 for(var j=0;j<memberNames.length;++j)
01755 {
01756 memberVersion = DesktopContent.getXMLValue(memberVersions[j])|0;
01757 memberName = DesktopContent.getXMLValue(memberNames[j]);
01758 if(memberVersion < -1)
01759 {
01760 Debug.log("affectedArr " + memberName + "-v" + memberVersion);
01761
01762 for(var k=0;k<savedTables.length;++k)
01763 if(memberName == savedTables[k].tableName)
01764 {
01765 Debug.log("found " + savedTables[k].tableName + "-v" +
01766 savedTables[k].tableVersion);
01767 affectedGroupConfigMap[i] += memberName + "," +
01768 savedTables[k].tableVersion + ",";
01769 break;
01770 }
01771 }
01772 else
01773 affectedGroupConfigMap[i] += memberName +
01774 "," + memberVersion + ",";
01775 }
01776 }
01777
01778 localHandleSavingAffectedGroups();
01779 },0,0,true
01780 );
01781 }
01782 else
01783 {
01784 var affectedGroupEls =
01785 document.getElementsByClassName(ConfigurationAPI._POP_UP_DIALOG_ID +
01786 "-affectedGroups");
01787 var affectedGroupCommentEls =
01788 document.getElementsByClassName(ConfigurationAPI._POP_UP_DIALOG_ID +
01789 "-groupComment-cache");
01790
01791
01792 for(var i=0;i<affectedGroupEls.length;++i)
01793 {
01794 Debug.log(affectedGroupEls[i].textContent);
01795 Debug.log("group comment: " + affectedGroupCommentEls[i].textContent);
01796
01797 var affectedArr = affectedGroupEls[i].textContent.split(',');
01798
01799 affectedGroupComments.push(affectedGroupCommentEls[i].textContent);
01800 affectedGroupNames.push(affectedArr[0]);
01801
01802
01803 affectedGroupConfigMap[i] = "configList=";
01804
01805 for(var a=2;a<affectedArr.length;a+=2)
01806 if((affectedArr[a+1]|0) < -1)
01807 {
01808 Debug.log("affectedArr " + affectedArr[a] + "-v" + affectedArr[a+1]);
01809
01810 for(var k=0;k<savedTables.length;++k)
01811 if(affectedArr[a] == savedTables[k].tableName)
01812 {
01813 Debug.log("found " + savedTables[k].tableName + "-v" +
01814 savedTables[k].tableVersion);
01815 affectedGroupConfigMap[i] += affectedArr[a] + "," +
01816 savedTables[k].tableVersion + ",";
01817 break;
01818 }
01819 }
01820 else
01821 affectedGroupConfigMap[i] += affectedArr[a] + "," + affectedArr[a+1] + ",";
01822 }
01823
01824 localHandleSavingAffectedGroups();
01825 }
01826
01827
01828
01829 function localHandleSavingAffectedGroups()
01830 {
01831
01832 for(var i=0;i<affectedGroupNames.length;++i)
01833 {
01834 reqStr = "";
01835 reqStr = "Request?RequestType=saveNewConfigurationGroup" +
01836 "&groupName=" + affectedGroupNames[i] +
01837 "&allowDuplicates=0" +
01838 "&lookForEquivalent=1" +
01839 "&ignoreWarnings=" + (doNotIgnoreWarnings?0:1) +
01840 "&groupComment=" + encodeURIComponent(affectedGroupComments[i]);
01841 Debug.log(reqStr);
01842 Debug.log(affectedGroupConfigMap[i]);
01843
01844 ++numberOfRequests;
01846 DesktopContent.XMLHttpRequest(reqStr, affectedGroupConfigMap[i],
01847 function(req,affectedGroupIndex)
01848 {
01849
01850 var attemptedNewGroupName = DesktopContent.getXMLValue(req,"AttemptedNewGroupName");
01851 var treeErr = DesktopContent.getXMLValue(req,"TreeErrors");
01852 if(treeErr)
01853 {
01854 Debug.log(treeErr,Debug.HIGH_PRIORITY);
01855 Debug.log("There were problems identified in the tree view of the " +
01856 "attempted new group '" +
01857 attemptedNewGroupName +
01858 "'.\nThe new group was not created.\n" +
01859 "(Note: Other tables and groups may have been successfully created, " +
01860 "and would have success indications below this error info)\n\n" +
01861 "You can save the group anyway (if you think it is a good idea) by clicking " +
01862 "the button in the pop-up dialog " +
01863 "'<u>Save Groups with Warnings Ignored</u>.' " +
01864 "\n\nOtherwise, you can hit '<u>Cancel</u>.' and fix the tree. " +
01865 "Below you will find the description of the problem:",
01866 Debug.HIGH_PRIORITY);
01867
01868
01869 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-submitButton");
01870 if(el)
01871 {
01872 el.onmouseup = function() {
01873 Debug.log("Submit mouseup");
01874 this.disabled = true;
01875 ConfigurationAPI.handleGroupCommentToggle(0,1);
01876 ConfigurationAPI.handlePopUpHeightToggle(h,gh);
01877
01878 var savingGroups =
01879 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID +
01880 "-bumpGroupVersions").checked;
01881 var activatingSavedGroups =
01882 document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID +
01883 "-activateBumpedGroupVersions").checked;
01884
01885 ConfigurationAPI.saveModifiedTables(modifiedTables,responseHandler,
01886 false,
01887 doNotSaveAffectedGroups,
01888 doNotActivateAffectedGroups,doNotSaveAliases
01889 );
01890 };
01891 el.value = "Save Groups with Warnings Ignored";
01892 el.disabled = false;
01893 }
01894 return;
01895 }
01896
01897 var err = DesktopContent.getXMLValue(req,"Error");
01898 if(err)
01899 {
01900 Debug.log(err,Debug.HIGH_PRIORITY);
01901
01902
01903 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
01904 if(el && !doNotKillPopUpEl) el.parentNode.removeChild(el);
01905 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
01906 return;
01907 }
01908
01909 ++numberOfReturns;
01910
01911 var newGroupKey = DesktopContent.getXMLValue(req,"ConfigurationGroupKey");
01912 affectedGroupKeys.push(newGroupKey);
01913
01914 {
01915 var obj = {};
01916 obj.groupName = attemptedNewGroupName;
01917 obj.groupKey = newGroupKey;
01918 obj.groupComment = affectedGroupComments[affectedGroupIndex];
01919 savedGroups.push(obj);
01920 }
01921
01922
01923 var foundEquivalentKey = DesktopContent.getXMLValue(req,"foundEquivalentKey");
01924 if(foundEquivalentKey)
01925 Debug.log("Using existing group '" + attemptedNewGroupName +
01926 " (" + newGroupKey + ")'", Debug.INFO_PRIORITY);
01927 else
01928 Debug.log("Successfully created new group '" + attemptedNewGroupName +
01929 " (" + newGroupKey + ")'", Debug.INFO_PRIORITY);
01930
01931
01932
01933
01934 if(activatingSavedGroups)
01935 ConfigurationAPI.activateGroup(attemptedNewGroupName,newGroupKey,
01936 doNotIgnoreGroupActivationWarnings?false:true );
01937
01938
01939 if(allRequestsSent &&
01940 numberOfReturns == numberOfRequests)
01941 {
01942 Debug.log("Done with group saving.");
01943
01944 Debug.log("Moving on to Alias creation...");
01945
01946
01947
01948
01949
01950
01951
01952 var setAliasCheckboxes;
01953
01954 var groupAlias, groupName, groupKey;
01955 var setAliasCheckboxIndex = -1;
01956 var groupAliasName, groupAliasVersion;
01957
01958 var affectedGroupAliases = [];
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969 try
01970 {
01971 setAliasCheckboxes =
01972 document.getElementsByClassName("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-setGroupAlias");
01973
01974
01975 if(setAliasCheckboxes.length != affectedGroupNames.length)
01976 throw("no popup");
01977
01978
01979 localNextAliasHandler();
01980 Debug.log("Aliases set in motion");
01981 }
01982 catch(err)
01983 {
01984
01985 setAliasCheckboxes = [];
01986 for(var i in affectedGroupNames)
01987 setAliasCheckboxes.push({"checked" : ((!doNotSaveAliases)?1:0) });
01988
01989
01990
01991
01992
01993
01994
01995
01997 DesktopContent.XMLHttpRequest("Request?RequestType=getGroupAliases" +
01998 "",
01999 "",
02000 function(req)
02001 {
02002 var err = DesktopContent.getXMLValue(req,"Error");
02003 if(err)
02004 {
02005 Debug.log(err,Debug.HIGH_PRIORITY);
02006 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
02007 return;
02008 }
02009
02010 var aliases = req.responseXML.getElementsByTagName("GroupAlias");
02011 var aliasGroupNames = req.responseXML.getElementsByTagName("GroupName");
02012 var aliasGroupKeys = req.responseXML.getElementsByTagName("GroupKey");
02013
02014
02015
02016
02017 var alias, aliasGroupName, aliasGroupKey;
02018 var groupName, groupKey;
02019 var groupOptionIndex = [];
02020 for(var i=0;i<affectedGroupNames.length;++i)
02021 {
02022 groupOptionIndex.push([-1,0]);
02023
02024 groupName = affectedGroupNames[i];
02025 groupKey = affectedGroupKeys[i];
02026
02027
02028 for(var j=0;j<aliasGroupNames.length;++j)
02029 {
02030 alias = DesktopContent.getXMLValue(aliases[j]);
02031 aliasGroupName = DesktopContent.getXMLValue(aliasGroupNames[j]);
02032 aliasGroupKey = DesktopContent.getXMLValue(aliasGroupKeys[j]);
02033
02034
02035
02036
02037
02038 if(aliasGroupName == groupName)
02039 {
02040 if(groupOptionIndex[i][0] == -1 ||
02041 Math.abs(groupKey - aliasGroupKey) < groupOptionIndex[i][1])
02042 {
02043 Debug.log("found alias");
02044 groupOptionIndex[i][0] = j;
02045 groupOptionIndex[i][1] = Math.abs(groupKey - aliasGroupKey);
02046 }
02047 }
02048 }
02049
02050
02051 setAliasCheckboxes[i].checked = (groupOptionIndex[i][0] >= 0?1:0);
02052
02053 affectedGroupAliases.push(groupOptionIndex[i][0] >= 0?
02054 DesktopContent.getXMLValue(aliases[groupOptionIndex[i][0]]):"");
02055 }
02056
02057
02058 localNextAliasHandler();
02059 Debug.log("Aliases set in motion");
02060
02061 },0,0,true
02062 );
02063
02064 }
02065
02066
02067
02068
02069
02070
02071
02072 function localNextAliasHandler(retParams)
02073 {
02074
02075 if(setAliasCheckboxIndex >= 0)
02076 {
02077 if(retParams)
02078 {
02079 if(retParams.newGroupCreated)
02080 {
02081 Debug.log("Successfully modified the active Backbone group " +
02082 " to set the System Alias '" + groupAlias + "' to " +
02083 " refer to the current group '" + groupName +
02084 " (" + groupKey + ").'" +
02085 "\n\n" +
02086 "Backbone group '" + retParams.groupName + " (" +
02087 retParams.groupKey + ")' was created and activated.",
02088 Debug.INFO_PRIORITY);
02089
02090 {
02091 var obj = {};
02092 obj.groupName = groupName;
02093 obj.groupKey = groupKey;
02094 obj.groupAlias = groupAlias;
02095 savedAliases.push(obj);
02096 }
02097 }
02098 else
02099 Debug.log("Success, but no need to create a new Backbone group. " +
02100 "An existing Backbone group " +
02101 " already has the System Alias '" + groupAlias + "' " +
02102 " referring to the current group '" + groupName +
02103 " (" + groupKey + ").'" +
02104 "\n\n" +
02105 "Backbone group '" + retParams.groupName + " (" +
02106 retParams.groupKey + ")' was activated.",
02107 Debug.INFO_PRIORITY);
02108 }
02109 else
02110 {
02111 Debug.log("Process interrupted. Failed to modify the currently active Backbone!",Debug.HIGH_PRIORITY);
02112
02113
02114 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
02115 if(el && !doNotKillPopUpEl) el.parentNode.removeChild(el);
02116 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
02117 return;
02118 }
02119
02120 ++setAliasCheckboxIndex;
02121 }
02122 else
02123 setAliasCheckboxIndex = 0;
02124
02125
02126 while(setAliasCheckboxIndex < setAliasCheckboxes.length &&
02127 !setAliasCheckboxes[setAliasCheckboxIndex].checked)
02128 Debug.log("Skipping checkbox " + (++setAliasCheckboxIndex));
02129
02130 if(setAliasCheckboxIndex >= setAliasCheckboxes.length)
02131 {
02132 Debug.log("Done with alias checkboxes ");
02133
02134 if(!retParams)
02135 {
02136 Debug.log("No System Aliases were changed, so Backbone was not modified. Done.");
02137
02138
02139 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
02140 if(el && !doNotKillPopUpEl) el.parentNode.removeChild(el);
02141 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
02142 return;
02143 }
02144
02145 Debug.log("Saving and activating Backbone done.");
02146
02147
02148 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
02149 if(el && !doNotKillPopUpEl) el.parentNode.removeChild(el);
02150 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
02151 return;
02152 }
02153
02154
02155 try
02156 {
02157 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasSelect-" +
02158 setAliasCheckboxIndex);
02159 if(el.style.display == "none")
02160 {
02161
02162 el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "-editAliasTextBox-" +
02163 setAliasCheckboxIndex);
02164 }
02165 groupAlias = el.value;
02166 }
02167 catch(err)
02168 {
02169
02170
02171 groupAlias = affectedGroupAliases[setAliasCheckboxIndex];
02172 }
02173
02174 groupName = affectedGroupNames[setAliasCheckboxIndex];
02175 groupKey = affectedGroupKeys[setAliasCheckboxIndex];
02176
02177 Debug.log("groupAlias = " + groupAlias);
02178 Debug.log("groupName = " + groupName);
02179 Debug.log("groupKey = " + groupKey);
02180
02181 ConfigurationAPI.setGroupAliasInActiveBackbone(groupAlias,groupName,groupKey,
02182 "SaveWiz",
02183 localNextAliasHandler,
02184 true);
02185 }
02186
02187 }
02188
02189 },i,0,true
02190 );
02191 }
02192
02193 allRequestsSent = true;
02194 if(numberOfRequests == 0)
02195 {
02196
02197 Debug.log("There were no groups to save!", Debug.INFO_PRIORITY);
02198
02199
02200 var el = document.getElementById("" + ConfigurationAPI._POP_UP_DIALOG_ID + "");
02201 if(el && !doNotKillPopUpEl) el.parentNode.removeChild(el);
02202 }
02203 }
02204 }
02205
02206
02207
02208
02209
02210
02211 for(var j=0;j<modifiedTables.length;++j)
02212 if((modifiedTables[j].tableVersion|0) < -1)
02213 {
02214 var reqStr = "Request?RequestType=saveSpecificConfiguration" +
02215 "&dataOffset=0&chunkSize=0" +
02216 "&configName=" + modifiedTables[j].tableName +
02217 "&version="+modifiedTables[j].tableVersion +
02218 "&temporary=0" +
02219 "&tableComment=" +
02220 encodeURIComponent(modifiedTables[j].tableComment?modifiedTables[j].tableComment:"") +
02221 "&sourceTableAsIs=1" +
02222 "&lookForEquivalent=1";
02223 Debug.log(reqStr);
02224
02225 ++numberOfRequests;
02226
02227
02229 DesktopContent.XMLHttpRequest(reqStr, "",
02230 function(req,modifiedTableIndex)
02231 {
02232 var err = DesktopContent.getXMLValue(req,"Error");
02233 if(err)
02234 {
02235 Debug.log(err,Debug.HIGH_PRIORITY);
02236
02237
02238 var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
02239
02240 if(responseHandler) responseHandler(savedTables,savedGroups,savedAliases);
02241 return;
02242 }
02243
02244 var configName = DesktopContent.getXMLValue(req,"savedName");
02245 var version = DesktopContent.getXMLValue(req,"savedVersion");
02246 var foundEquivalentVersion = DesktopContent.getXMLValue(req,"foundEquivalentVersion") | 0;
02247
02248 if(foundEquivalentVersion)
02249 Debug.log("Using existing table '" + configName + "-v" +
02250 version + "'",Debug.INFO_PRIORITY);
02251 else
02252 Debug.log("Successfully created new table '" + configName + "-v" +
02253 version + "'",Debug.INFO_PRIORITY);
02254
02255
02256 {
02257 var obj = {};
02258 obj.tableName = configName;
02259 obj.tableVersion = version;
02260 obj.tableComment = modifiedTables[modifiedTableIndex].tableComment;
02261 savedTables.push(obj);
02262 }
02263
02264 ++numberOfReturns;
02265
02266 if(allRequestsSent &&
02267 numberOfReturns == numberOfRequests)
02268 {
02269 if(!doNotSaveAffectedGroups)
02270 localHandleAffectedGroups();
02271 }
02272 },j,0,true
02273 );
02274 }
02275
02276 allRequestsSent = true;
02277 if(numberOfRequests == 0)
02278 {
02279
02280 Debug.log("No tables were modified. Should be impossible to get here.", Debug.HIGH_PRIORITY);
02281 }
02282 }
02283
02284
02285
02286
02287 ConfigurationAPI.activateGroup = function(groupName, groupKey,
02288 ignoreWarnings, doneHandler)
02289 {
02290 DesktopContent.XMLHttpRequest("Request?RequestType=activateConfigGroup" +
02291 "&groupName=" + groupName +
02292 "&groupKey=" + groupKey +
02293 "&ignoreWarnings=" + (ignoreWarnings?"1":"0") +
02294 "",
02295 "",
02296 function(req)
02297 {
02298
02299 var err = DesktopContent.getXMLValue(req,"Error");
02300 if(err)
02301 {
02302 Debug.log(err,Debug.HIGH_PRIORITY);
02303
02304
02305
02306
02307 var str = "";
02308
02309
02310 str += " <a href='#' onclick='javascript:ConfigurationAPI.activateGroup(\"" +
02311 groupName +
02312 "\",\"" + groupKey + "\",true); return false;'>";
02313 str += "Activate " +
02314 groupName + "(" + groupKey + ") w/warnings ignored</a>";
02315
02316 Debug.log("If you are are sure it is a good idea you can try to " +
02317 "activate the group with warnings ignored: " +
02318 str,Debug.HIGH_PRIORITY);
02319 return;
02320 }
02321
02322 if(doneHandler) doneHandler();
02323 },
02324 true, 0 , true);
02325 }
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340 ConfigurationAPI.setGroupAliasInActiveBackbone = function(groupAlias,groupName,groupKey,
02341 newBackboneNameAdd,doneHandler,doReturnParams)
02342 {
02343 Debug.log("setGroupAliasInActiveBackbone groupAlias=" + groupAlias);
02344 Debug.log("setGroupAliasInActiveBackbone groupName=" + groupName);
02345 Debug.log("setGroupAliasInActiveBackbone groupKey=" + groupKey);
02346
02347 if(!groupAlias || groupAlias.trim() == "")
02348 {
02349 Debug.log("Process interrupted. Invalid empty alias given!",Debug.HIGH_PRIORITY);
02350 if(doneHandler) doneHandler();
02351 return;
02352 }
02353
02354 if(!groupName || groupName.trim() == "" || !groupKey || groupKey.trim() == "")
02355 {
02356 Debug.log("Process interrupted. Invalid group name and key given!",Debug.HIGH_PRIORITY);
02357 if(doneHandler) doneHandler();
02358 return;
02359 }
02360
02361 if(!newBackboneNameAdd || newBackboneNameAdd == "")
02362 newBackboneNameAdd = "Wiz";
02363 newBackboneNameAdd += "Backbone";
02364 Debug.log("setGroupAliasInActiveBackbone newBackboneNameAdd=" + newBackboneNameAdd);
02365
02366 DesktopContent.XMLHttpRequest("Request?RequestType=setGroupAliasInActiveBackbone" +
02367 "&groupAlias=" + groupAlias +
02368 "&groupName=" + groupName +
02369 "&groupKey=" + groupKey, "",
02370 ConfigurationAPI.newWizBackboneMemberHandler,
02371 [("GroupAlias" + newBackboneNameAdd),doneHandler,doReturnParams],
02372 0,true
02373 );
02374 }
02375
02376
02377
02378
02379
02380
02381
02382
02383 ConfigurationAPI.newWizBackboneMemberHandler = function(req,params)
02384 {
02385 var err = DesktopContent.getXMLValue(req,"Error");
02386 if(err)
02387 {
02388 Debug.log(err,Debug.HIGH_PRIORITY);
02389 Debug.log("Process interrupted. Failed to modify the currently active Backbone!",Debug.HIGH_PRIORITY);
02390
02391 if(params[1])
02392 params[1]();
02393 return;
02394 }
02395
02396 var groupAliasName = DesktopContent.getXMLValue(req,"savedName");
02397 var groupAliasVersion = DesktopContent.getXMLValue(req,"savedVersion");
02398
02399 Debug.log("groupAliasName=" + groupAliasName);
02400 Debug.log("groupAliasVersion=" + groupAliasVersion);
02401
02402 var configNames = req.responseXML.getElementsByTagName("oldBackboneName");
02403 var configVersions = req.responseXML.getElementsByTagName("oldBackboneVersion");
02404
02405
02406 var configMap = "configList=";
02407 var name;
02408 for(var i=0;i<configNames.length;++i)
02409 {
02410 name = configNames[i].getAttribute("value");
02411
02412 if(name == groupAliasName)
02413 {
02414 configMap += name + "," +
02415 groupAliasVersion + ",";
02416 continue;
02417 }
02418
02419 configMap += name + "," +
02420 configVersions[i].getAttribute("value") + ",";
02421 }
02422
02423 ConfigurationAPI.saveGroupAndActivate(params[0],configMap,params[1],params[2],
02424 true );
02425 }
02426
02427
02428
02429 ConfigurationAPI.saveGroupAndActivate = function(groupName,configMap,doneHandler,doReturnParams,
02430 lookForEquivalent)
02431 {
02432 DesktopContent.XMLHttpRequest("Request?RequestType=saveNewConfigurationGroup&groupName=" +
02433 groupName +
02434 "&allowDuplicates=" + (lookForEquivalent?"0":"1") +
02435 "&lookForEquivalent=" + (lookForEquivalent?"1":"0") +
02436 "",
02437 configMap,
02438 function(req)
02439 {
02440 var err = DesktopContent.getXMLValue(req,"Error");
02441 var name = DesktopContent.getXMLValue(req,"ConfigurationGroupName");
02442 var key = DesktopContent.getXMLValue(req,"ConfigurationGroupKey");
02443 var newGroupCreated = true;
02444 if(err)
02445 {
02446 if(!name || !key)
02447 {
02448 Debug.log(err,Debug.HIGH_PRIORITY);
02449 Debug.log("Process interrupted. Failed to create a new group!" +
02450 " Please see details below.",
02451 Debug.HIGH_PRIORITY);
02452
02453 if(doneHandler) doneHandler();
02454 return;
02455 }
02456 else
02457 {
02458 Debug.log(err,Debug.WARN_PRIORITY);
02459 Debug.log("Process interrupted. Failed to create a new group!" +
02460 " (Likely the currently active group already represents what is being requested)\n\n" +
02461 "Going on with existing backbone group, name=" + name + " & key=" + key,
02462 Debug.WARN_PRIORITY);
02463 newGroupCreated = false;
02464 }
02465 }
02466
02467
02468
02469 DesktopContent.XMLHttpRequest("Request?RequestType=activateConfigGroup" +
02470 "&groupName=" + name +
02471 "&groupKey=" + key, "",
02472 function(req)
02473 {
02474 try
02475 {
02476 activateSystemConfigHandler(req);
02477 }
02478 catch(err) {}
02479
02480 if(doneHandler)
02481 {
02482
02483 if(!doReturnParams)
02484 doneHandler();
02485 else
02486 {
02487 var retParams = {
02488 "groupName" : name,
02489 "groupKey" : key,
02490 "newGroupCreated" : newGroupCreated
02491 }
02492 doneHandler(retParams);
02493 }
02494 }
02495 });
02496
02497 },0,0,true
02498 );
02499 }
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510 ConfigurationAPI.getGroupTypeMemberNames = function(groupType,responseHandler)
02511 {
02512 DesktopContent.XMLHttpRequest("Request?RequestType=get" + groupType + "MemberNames", "",
02513 function (req)
02514 {
02515 var retArr = [];
02516
02517 var err = DesktopContent.getXMLValue(req,"Error");
02518 if(err)
02519 {
02520 Debug.log(err,Debug.HIGH_PRIORITY);
02521 if(responseHandler) responseHandler(retArr);
02522 return;
02523 }
02524 var memberNames = req.responseXML.getElementsByTagName(groupType + "Member");
02525
02526 for(var i=0;i<memberNames.length;++i)
02527 retArr[i] = memberNames[i].getAttribute("value");
02528
02529 Debug.log("Members found for group type " + groupType + " = " + retArr.length);
02530 if(responseHandler) responseHandler(retArr);
02531
02532 },
02533 0,0,true
02534 );
02535
02536 }
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546 ConfigurationAPI.bitMapDialog = function(fieldName,bitMapParams,initBitMapValue,okHandler,cancelHandler)
02547 {
02548 Debug.log("ConfigurationAPI bitMapDialog");
02549
02550 var str = "";
02551
02552 var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
02553 if(!el)
02554 {
02555 el = document.createElement("div");
02556 el.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID);
02557 }
02558 el.style.display = "none";
02559 el.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmapDialog");
02560
02561 var padding = 10;
02562 var popSz;
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620 var rows, cols;
02621
02622 var bitFieldSize;
02623 var bitMask;
02624
02625 var minValue, maxValue;
02626 var midValue;
02627 var stepValue;
02628
02629 var forcedAspectH, forcedAspectW;
02630
02631 var minValueColor, midValueColor, maxValueColor;
02632 var ceilValueColor, floorValueColor;
02633
02634 var doDisplayRowsAscending, doDisplayColsAscending;
02635 var doSnakeColumns, doSnakeRows;
02636
02637
02638 if(!localValidateInputs())
02639 {
02640 Debug.log("Input parameters array to the Bitmap Dialog was as follows:\n " +
02641 bitMapParams, Debug.HIGH_PRIORITY);
02642 Debug.log("Input parameters to the Bitmap Dialog are invalid. Aborting.", Debug.HIGH_PRIORITY);
02643 return cancelHandler();
02644 }
02645
02646
02647 var numberDigitW = 8, numberDigitH = 12;
02648 var axisPaddingExtra = numberDigitW;
02649 function localCalcExtraAxisPadding() {
02650 var lrows = rows;
02651 while((lrows /= 10) > 1) axisPaddingExtra += numberDigitW;
02652 } localCalcExtraAxisPadding();
02653 var butttonSz = 20;
02654 var axisPaddingMargin = 5;
02655 var axisPadding = axisPaddingMargin + axisPaddingExtra + axisPaddingMargin + butttonSz + axisPaddingMargin;
02656 var bmpGridThickness = 1;
02657 var bmpBorderSize = 1;
02658
02659
02660 var hdr;
02661 var hdrX;
02662 var hdrY;
02663 var hdrW;
02664 var hdrH;
02665
02666 var bmp;
02667 var bmpGrid;
02668 var allRowBtns, allColBtns, allBtn;
02669 var rowLeftNums, rowRightNums, colTopNums, colBottomNums;
02670 var bmpCanvas, bmpContext;
02671 var bmpData;
02672 var bmpDataImage;
02673 var bmpX;
02674 var bmpY;
02675 var bmpW;
02676 var bmpH;
02677 var bmpOverlay;
02678 var cursorInfo, hdrCursorInfo;
02679
02680 var cellW;
02681 var cellH;
02682
02683 var clickColors = [];
02684 var clickValues = [];
02685
02686
02687 localCreateHeader();
02688 localCreateBitmap();
02689 localCreateGridButtons();
02690
02691 localInitBitmapData();
02692
02693 localPaint();
02694 window.addEventListener("resize",localPaint);
02695
02696 document.body.appendChild(el);
02697 el.style.display = "block";
02698
02699
02700
02701
02702
02703 function localCreateCancelClickHandler()
02704 {
02705 document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID +
02706 "-cancel").onclick = function(event) {
02707 Debug.log("Cancel click");
02708 var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
02709 if(el) el.parentNode.removeChild(el);
02710 window.removeEventListener("resize",localPaint);
02711 cancelHandler();
02712 return false;
02713 };
02714 } localCreateCancelClickHandler();
02715
02716
02717
02718
02719 function localCreateOkClickHandler()
02720 {
02721 var convertFunc = localConvertFullGridToRowCol;
02722 document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID +
02723 "-ok").onclick = function(event) {
02724 Debug.log("OK click");
02725 var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
02726 if(el) el.parentNode.removeChild(el);
02727 window.removeEventListener("resize",localPaint);
02728
02729 var transGrid = convertFunc();
02730 var dataJsonStr = "[\n";
02731 for(var r=0;r<transGrid.length;++r)
02732 {
02733 if(r) dataJsonStr += ",\n";
02734 dataJsonStr += "\t[";
02735 for(var c=0;c<transGrid[0].length;++c)
02736 {
02737 if(c) dataJsonStr += ",";
02738 dataJsonStr += transGrid[r][c];
02739 }
02740 dataJsonStr += "]";
02741 }
02742 dataJsonStr += "\n]";
02743 okHandler(dataJsonStr);
02744 return false;
02745 };
02746 } localCreateOkClickHandler();
02747
02748
02749
02750
02751 function localCreateMouseHandler()
02752 {
02753 var stopProp = false;
02754 var rLast = -1, cLast = -1;
02755
02756 var buttonDown = -1;
02757
02758
02759
02760
02761
02762
02763 function localGetRowCol(x,y) {
02764 x -= popSz.x + bmpX + 1;
02765 y -= popSz.y + bmpY + 1;
02766 var r = (y/cellH)|0;
02767 if(y < 0) r = -1;
02768 var c = (x/cellW)|0;
02769 if(x < 0) c = -1;
02770 var inRowBtnsX = (x >= - axisPaddingMargin - bmpBorderSize - butttonSz) &&
02771 (x <= - axisPaddingMargin - bmpBorderSize);
02772 var inColBtnsY = (y >= bmpH + axisPaddingMargin) &&
02773 (y <= bmpH + axisPaddingMargin + butttonSz + bmpBorderSize*2);
02774
02775
02776
02777
02778
02779
02780
02781 if(inRowBtnsX && r >= 0 && r < rows)
02782 return {"r":r, "c":-2};
02783 else if(inColBtnsY && c >= 0 && c < cols)
02784 return {"r":-2, "c":c};
02785 else if(inRowBtnsX && inColBtnsY)
02786 return {"r":-2, "c":-2};
02787 else if(r < 0 || c < 0 || r >= rows || c >= cols)
02788 return {"r":-1, "c":-1};
02789 return {"r":r, "c":c};
02790 }
02791
02792
02793
02794 el.onmousemove = function(event) {
02795 var cell = localGetRowCol(event.pageX,event.pageY);
02796 var r = cell.r, c = cell.c;
02797
02798 var cursorT = (event.pageX - popSz.x - bmpX);
02799 if(cursorT < 0) cursorT = 0;
02800 if(cursorT > bmpW) cursorT = bmpW;
02801
02802 cursorInfo.style.left = (event.pageX - popSz.x +
02803
02804
02805 (cursorT)/bmpW*(-cursorInfo.innerHTML.length*8-20) + (bmpW-cursorT)/bmpW*(2))+
02806 "px";
02807 cursorInfo.style.top = (event.pageY - popSz.y - 35) + "px";
02808
02809
02810 hdrCursorInfo.style.left = (bmpX + bmpW/2 +
02811 (-332)/2) + "px";
02812 hdrCursorInfo.style.top = (bmpY - 45) + "px";
02813
02814
02815 if(rLast == r && cLast == c)
02816 return;
02817 rLast = r; cLast = c;
02818
02819 if(r == -1 || c == -1)
02820 {
02821
02822 rLast = -1; cLast = -1;
02823 bmpOverlay.style.display = "none";
02824 cursorInfo.style.display = "none";
02825 hdrCursorInfo.style.display = "none";
02826 return;
02827 }
02828
02829 cursorInfo.style.display = "block";
02830
02831
02832 var transRC;
02833 var infoStr;
02834
02835
02836 if(r != -2 && c == -2)
02837 {
02838 if(doSnakeColumns)
02839 transRC = localConvertGridToRowCol(r,
02840 doDisplayColsAscending?0:cols-1);
02841 else
02842 transRC = localConvertGridToRowCol(r,0);
02843
02844
02845 {
02846 bmpOverlay.src = ConfigurationAPI.getOnePixelPngData([216,188,188]);
02847
02848 bmpOverlay.style.left = (bmpX - axisPaddingMargin - bmpBorderSize - butttonSz) + "px";
02849 bmpOverlay.style.top = (bmpY + r*cellH - 1 + (r?bmpGridThickness+bmpBorderSize*2:0)) + "px";
02850 bmpOverlay.style.width = (butttonSz) + "px";
02851 bmpOverlay.style.height = (cellH - (r?bmpGridThickness+bmpBorderSize*2:0)) + "px";
02852 bmpOverlay.style.display = "block";
02853 }
02854
02855 infoStr = "Set all pixels in row " + transRC[0] + ".";
02856 }
02857 else if(r == -2 && c != -2)
02858 {
02859 if(doSnakeRows)
02860 transRC = localConvertGridToRowCol(
02861 doDisplayRowsAscending?0:rows-1,c);
02862 else
02863 transRC = localConvertGridToRowCol(0,c);
02864
02865
02866
02867 {
02868 bmpOverlay.src = ConfigurationAPI.getOnePixelPngData([216,188,188]);
02869
02870 bmpOverlay.style.left = (bmpX + c*cellW - 1 + (c?bmpGridThickness+bmpBorderSize*2:0)) + "px";
02871 bmpOverlay.style.top = (bmpY + bmpH + axisPaddingMargin - bmpBorderSize) + "px";
02872 bmpOverlay.style.width = (cellW + 1 - (c?bmpGridThickness+bmpBorderSize*2:0)) + "px";
02873 bmpOverlay.style.height = (butttonSz) + "px";
02874 bmpOverlay.style.display = "block";
02875 }
02876
02877 infoStr = "Set all pixels in column " + transRC[1] + ".";
02878 }
02879 else if(r == -2 && c == -2)
02880 {
02881
02882 {
02883 bmpOverlay.src = ConfigurationAPI.getOnePixelPngData([216,188,188]);
02884
02885 bmpOverlay.style.left = (bmpX - axisPaddingMargin - bmpBorderSize - butttonSz) + "px";
02886 bmpOverlay.style.top = (bmpY + bmpH + axisPaddingMargin - bmpBorderSize) + "px";
02887 bmpOverlay.style.width = (butttonSz) + "px";
02888 bmpOverlay.style.height = (butttonSz) + "px";
02889 bmpOverlay.style.display = "block";
02890 }
02891
02892 infoStr = "Set all pixels.";
02893 }
02894 else
02895 {
02896 transRC = localConvertGridToRowCol(r,c);
02897
02898
02899 {
02900
02901
02902 var overClr = (bmpDataImage.data[(r*cols+c)*4+0] +
02903 bmpDataImage.data[(r*cols+c)*4+1] +
02904 bmpDataImage.data[(r*cols+c)*4+2]) < (256+128)?255:0;
02905
02906 bmpOverlay.src = ConfigurationAPI.getOnePixelPngData(
02907 [overClr,overClr,overClr,100]);
02908
02909 bmpOverlay.style.left = (bmpX + c*cellW) + "px";
02910 bmpOverlay.style.top = (bmpY + r*cellH) + "px";
02911 bmpOverlay.style.width = (cellW) + "px";
02912 bmpOverlay.style.height = (cellH) + "px";
02913 bmpOverlay.style.display = "block";
02914 }
02915
02916
02917 infoStr = "Value = " + bmpData[r][c] + " @ (Row,Col) = (" +
02918 transRC[0] + "," + transRC[1] + ")";
02919 }
02920 cursorInfo.innerHTML = infoStr;
02921 hdrCursorInfo.innerHTML = infoStr;
02922
02923
02924 if(r == -2 && c == -2)
02925 return;
02926
02927 if(buttonDown >= 0)
02928 {
02929 stopProp = true;
02930 localSetBitMap(r,c);
02931 }
02932
02933 }
02934
02935
02936
02937 el.onmousedown = function(event) {
02938
02939 var cell = localGetRowCol(event.pageX,event.pageY);
02940 var r = cell.r, c = cell.c;
02941
02942
02943
02944 buttonDown = event.button;
02945
02946 if(r == -1 || c == -1)
02947 {
02948 rLast = -1; cLast = -1;
02949 stopProp = false;
02950 return;
02951 }
02952
02953 rLast = r; cLast = c;
02954 localSetBitMap(r,c);
02955
02956 stopProp = true;
02957 event.stopPropagation();
02958
02959 }
02960
02961
02962
02963 el.onmouseup = function(event) {
02964
02965 buttonDown = -1;
02966 }
02967
02968
02969
02970 el.oncontextmenu = function(event) {
02971
02972
02973 if(stopProp)
02974 {
02975 stopProp = false;
02976 event.stopPropagation();
02977 return false;
02978 }
02979 }
02980
02981
02982
02983 function localSetBitMap(r,c) {
02984
02985 Debug.log("set r,c " + buttonDown + " @ " + r + "," + c );
02986 buttonDown = buttonDown?1:0;
02987
02988 var maxr = r==-2?rows-1:r;
02989 var minr = r==-2?0:r;
02990 var maxc = c==-2?cols-1:c;
02991 var minc = c==-2?0:c;
02992
02993 for(r=minr;r<=maxr;++r)
02994 for(c=minc;c<=maxc;++c)
02995 {
02996 bmpData[r][c] = clickValues[buttonDown];
02997 bmpDataImage.data[(r*cols + c)*4 + 0] =
02998 clickColors[buttonDown][0];
02999 bmpDataImage.data[(r*cols + c)*4 + 1] =
03000 clickColors[buttonDown][1];
03001 bmpDataImage.data[(r*cols + c)*4 + 2] =
03002 clickColors[buttonDown][2];
03003 bmpDataImage.data[(r*cols + c)*4 + 3] =
03004 clickColors[buttonDown][3];
03005 }
03006
03007 bmpContext.putImageData(bmpDataImage,0,0);
03008 bmp.src = bmpCanvas.toDataURL();
03009 }
03010
03011 } localCreateMouseHandler();
03012
03013
03014
03015
03016
03017 function localValidateInputs() {
03018
03019
03020 if(bitMapParams.length != 16)
03021 {
03022 Debug.log("Illegal input parameters, expecting 16 parameters and count is " + bitMapParams.length + ". There is a mismatch in Table Editor handling of BitMap fields (contact an admin to fix)." +
03023 "\nHere is a printout of the input parameters: " + bitMapParams,Debug.HIGH_PRIORITY);
03024 return false;
03025 }
03026 var DEFAULT = "DEFAULT";
03027
03028 rows = bitMapParams[0]|0;
03029 cols = bitMapParams[1]|0;
03030 bitFieldSize = bitMapParams[2]|0;
03031
03032
03033
03034 if(rows < 1 || rows >= 1<<30)
03035 {
03036 Debug.log("Illegal input parameters, rows of " + rows + " is illegal. " +
03037 "(rows possible values are from 1 to " + ((1<<30)-1) + ".)",Debug.HIGH_PRIORITY);
03038 return false;
03039 }
03040 if(cols < 1 || cols >= 1<<30)
03041 {
03042 Debug.log("Illegal input parameters, cols of " + cols + " is illegal. " +
03043 "(cols possible values are from 1 to " + ((1<<30)-1) + ".)",Debug.HIGH_PRIORITY);
03044 return false;
03045 }
03046 if(bitFieldSize < 1 || bitFieldSize > 31)
03047 {
03048 Debug.log("Illegal input parameters, bitFieldSize of " + bitFieldSize + " is illegal. " +
03049 "(bitFieldSize possible values are from 1 to " + (31) + ".)",Debug.HIGH_PRIORITY);
03050 return false;
03051 }
03052
03053
03054 if(bitFieldSize > 30)
03055 {
03056 bitMask = 0;
03057 for(var i=0;i<bitFieldSize;++i)
03058 bitMask |= 1 << i;
03059 }
03060 else
03061 bitMask = (1<<bitFieldSize) - 1;
03062
03063 minValue = bitMapParams[3] == "DEFAULT" || bitMapParams[3] == ""?0:(bitMapParams[3]|0);
03064 maxValue = bitMapParams[4] == "DEFAULT" || bitMapParams[4] == ""?bitMask:(bitMapParams[4]|0);
03065 if(maxValue < minValue)
03066 maxValue = bitMask;
03067 midValue = (maxValue + minValue)/2;
03068 stepValue = bitMapParams[5] == "DEFAULT" || bitMapParams[5] == ""?1:(bitMapParams[5]|0);
03069
03070 if(minValue < 0 || minValue > bitMask)
03071 {
03072 Debug.log("Illegal input parameters, minValue of " + minValue + " is illegal. " +
03073 "(minValue possible values are from 0 to " + bitMask + ".)",Debug.HIGH_PRIORITY);
03074 return false;
03075 }
03076 if(maxValue < 0 || maxValue > bitMask)
03077 {
03078 Debug.log("Illegal input parameters, maxValue of " + maxValue + " is illegal. " +
03079 "(maxValue possible values are from 0 to " + bitMask + ".)",Debug.HIGH_PRIORITY);
03080 return false;
03081 }
03082 if(minValue > maxValue)
03083 {
03084 Debug.log("Illegal input parameters, minValue > maxValue is illegal.",Debug.HIGH_PRIORITY);
03085 return false;
03086 }
03087 if(stepValue < 1 || stepValue > maxValue - minValue)
03088 {
03089 Debug.log("Illegal input parameters, stepValue of " + stepValue + " is illegal. " +
03090 "(stepValue possible values are from 1 to " + (maxValue - minValue) + ".)",Debug.HIGH_PRIORITY);
03091 return false;
03092 }
03093 if((((maxValue-minValue)/stepValue)|0) != (maxValue-minValue)/stepValue)
03094 {
03095 Debug.log("Illegal input parameters, maxValue of " + maxValue +
03096 " must be an integer number of stepValue (stepValue=" + stepValue +
03097 ") steps away from minValue (minValue=" + minValue + ").",Debug.HIGH_PRIORITY);
03098 return false;
03099 }
03100
03101 if(bitMapParams[6] != "" &&
03102 bitMapParams[6] != DEFAULT)
03103 {
03104 forcedAspectH = bitMapParams[6].split(':');
03105 if(forcedAspectH.length != 2)
03106 {
03107 Debug.log("Illegal input parameter, expecting ':' in string defining cell display aspect ratio " +
03108 "Height:Width (e.g. 100:150)." +
03109 "\nInput aspect ratio string '" + bitMapParams[6] + "' is invalid.",Debug.HIGH_PRIORITY);
03110 return false;
03111 }
03112 forcedAspectW = forcedAspectH[1].trim()|0;
03113 forcedAspectH = forcedAspectH[0].trim()|0;
03114 }
03115 else
03116 forcedAspectW = forcedAspectH = 1;
03117
03118
03119
03120 minValueColor = bitMapParams[7] == DEFAULT || bitMapParams[7] == ""?"red":bitMapParams[7];
03121 midValueColor = bitMapParams[8] == DEFAULT || bitMapParams[8] == ""?"yellow":bitMapParams[8];
03122 maxValueColor = bitMapParams[9] == DEFAULT || bitMapParams[9] == ""?"green":bitMapParams[9];
03123 floorValueColor = bitMapParams[10] == DEFAULT || bitMapParams[10] == ""?minValueColor:bitMapParams[10];
03124 ceilValueColor = bitMapParams[11] == DEFAULT || bitMapParams[11] == ""?maxValueColor:bitMapParams[11];
03125
03126
03127 minValueColor = DesktopContent.getColorAsRGBA(minValueColor).split("(")[1].split(")")[0].split(",");
03128 midValueColor = DesktopContent.getColorAsRGBA(midValueColor).split("(")[1].split(")")[0].split(",");
03129 maxValueColor = DesktopContent.getColorAsRGBA(maxValueColor).split("(")[1].split(")")[0].split(",");
03130 ceilValueColor = DesktopContent.getColorAsRGBA(ceilValueColor).split("(")[1].split(")")[0].split(",");
03131 floorValueColor = DesktopContent.getColorAsRGBA(floorValueColor).split("(")[1].split(")")[0].split(",");
03132
03133
03134 doDisplayRowsAscending = bitMapParams[12] == "Yes"?1:0;
03135 doDisplayColsAscending = bitMapParams[13] == "Yes"?1:0;
03136 doSnakeColumns = bitMapParams[14] == "Yes"?1:0;
03137 doSnakeRows = bitMapParams[15] == "Yes"?1:0;
03138
03139 if(doSnakeColumns && doSnakeRows)
03140 {
03141 Debug.log("Can not have a bitmap that snakes both rows and columns, please choose one or the other (or neither).",Debug.HIGH_PRIORITY);
03142 return false;
03143 }
03144
03145
03146 return true;
03147 }
03148
03149
03150
03151
03152
03153
03154 function localInitBitmapData()
03155 {
03156
03157 bmpData = [];
03158
03159 try
03160 {
03161 var jsonMatrix = JSON.parse(initBitMapValue);
03162
03163
03164 for(var r=0;r<rows;++r)
03165 {
03166 bmpData.push([]);
03167
03168 for(var c=0;c<cols;++c)
03169 bmpData[r][c] = 0;
03170 }
03171 localConvertFullRowColToGrid(jsonMatrix);
03172 }
03173 catch(err)
03174 {
03175 Debug.log("The input initial value of the bitmap is illegal JSON format. " +
03176 "See error below: \n\n" + err,Debug.HIGH_PRIORITY);
03177 Debug.log("Defaulting to initial bitmap with min-value fill.",Debug.HIGH_PRIORITY);
03178
03179
03180 var color;
03181 for(var r=0;r<rows;++r)
03182 {
03183 bmpData.push([]);
03184
03185 for(var c=0;c<cols;++c)
03186 {
03187 bmpData[r][c] = minValue;
03188
03189 color = localConvertValueToRGBA(bmpData[r][c]);
03190 bmpDataImage.data[(r*cols + c)*4+0]=color[0];
03191 bmpDataImage.data[(r*cols + c)*4+1]=color[1];
03192 bmpDataImage.data[(r*cols + c)*4+2]=color[2];
03193 bmpDataImage.data[(r*cols + c)*4+3]=color[3];
03194 }
03195 }
03196
03197 bmpContext.putImageData(bmpDataImage,0,0);
03198 bmp.src = bmpCanvas.toDataURL();
03199 }
03200 }
03201
03202
03203
03204
03205
03206
03207
03208
03209 function localConvertGridToRowCol(r,c)
03210 {
03211 var retVal = [r,c];
03212 if(!doDisplayRowsAscending)
03213 retVal[0] = rows - 1 - retVal[0];
03214 if(!doDisplayColsAscending)
03215 retVal[1] = cols - 1 - retVal[1];
03216 if(doSnakeRows && retVal[0]%2 == 1)
03217 retVal[1] = cols + (cols - 1 - retVal[1]);
03218 if(doSnakeColumns && retVal[1]%2 == 1)
03219 retVal[0] = rows + (rows - 1 - retVal[0]);
03220
03221 return retVal;
03222 }
03223
03224
03225
03226
03227 function localConvertValueToRGBA(val)
03228 {
03229 if(val >= maxValue)
03230 return [ceilValueColor[0],
03231 ceilValueColor[1],
03232 ceilValueColor[2],
03233 255];
03234
03235 if(val <= minValue)
03236 return [floorValueColor[0],
03237 floorValueColor[1],
03238 floorValueColor[2],
03239 255];
03240
03241 if(val == midValue)
03242 return [midValueColor[0],
03243 midValueColor[1],
03244 midValueColor[2],
03245 255];
03246
03247
03248 var t;
03249 if(val <= midValue)
03250 {
03251 t = (val - minValue)/(midValue - minValue);
03252 return [minValueColor[0]*(1-t) + t*midValueColor[0],
03253 minValueColor[1]*(1-t) + t*midValueColor[1],
03254 minValueColor[2]*(1-t) + t*midValueColor[2],
03255 255];
03256 }
03257
03258
03259 {
03260 t = (val - midValue)/(maxValue - midValue);
03261 return [midValueColor[0]*(1-t) + t*maxValueColor[0],
03262 midValueColor[1]*(1-t) + t*maxValueColor[1],
03263 midValueColor[2]*(1-t) + t*maxValueColor[2],
03264 255];
03265 }
03266 }
03267
03268
03269
03270
03271
03272 function localConvertFullGridToRowCol()
03273 {
03274 var retArr = [];
03275 var convertedRC;
03276 for(var r=0;r<rows;++r)
03277 for(var c=0;c<cols;++c)
03278 {
03279 convertedRC = localConvertGridToRowCol(r,c);
03280
03281 if(doSnakeColumns)
03282 convertedRC[1] = (convertedRC[1]/2)|0;
03283
03284 if(doSnakeRows)
03285 convertedRC[0] = (convertedRC[0]/2)|0;
03286
03287 if(retArr[convertedRC[0]] === undefined)
03288 retArr[convertedRC[0]] = [];
03289 retArr[convertedRC[0]][convertedRC[1]] = bmpData[r][c];
03290 }
03291 return retArr;
03292 }
03293
03294
03295
03296
03297
03298 function localConvertFullRowColToGrid(srcMatrix)
03299 {
03300 var convertedRC;
03301 var color;
03302 var noErrors = true;
03303 for(var r=0;r<rows;++r)
03304 for(var c=0;c<cols;++c)
03305 {
03306 convertedRC = localConvertGridToRowCol(r,c);
03307
03308
03309 if(doSnakeColumns)
03310 convertedRC[1] = (convertedRC[1]/2)|0;
03311
03312 if(doSnakeRows)
03313 convertedRC[0] = (convertedRC[0]/2)|0;
03314 try
03315 {
03316 bmpData[r][c] = srcMatrix[convertedRC[0]][convertedRC[1]]|0;
03317 if(bmpData[r][c] < minValue)
03318 throw("There was an illegal value less than minValue: " +
03319 bmpData[r][c] + " < " + minValue + " @ (row,col) = (" +
03320 convertedRC[0] + "," + convertedRC[0] + ")");
03321 if(bmpData[r][c] > maxValue)
03322 throw("There was an illegal value greater than maxValue: " +
03323 bmpData[r][c] + " > " + maxValue + " @ (row,col) = (" +
03324 convertedRC[0] + "," + convertedRC[0] + ")");
03325 if((((bmpData[r][c]-minValue)/stepValue)|0) != (bmpData[r][c]-minValue)/stepValue)
03326 throw("There was an illegal value not following stepValue from minValue: " +
03327 bmpData[r][c] + " != " +
03328 (stepValue*(((bmpData[r][c]-minValue)/stepValue)|0)) +
03329 " @ (row,col) = (" +
03330 convertedRC[0] + "," + convertedRC[0] + ")");
03331 color = localConvertValueToRGBA(bmpData[r][c]);
03332 bmpDataImage.data[(r*cols + c)*4+0]=color[0];
03333 bmpDataImage.data[(r*cols + c)*4+1]=color[1];
03334 bmpDataImage.data[(r*cols + c)*4+2]=color[2];
03335 bmpDataImage.data[(r*cols + c)*4+3]=color[3];
03336 }
03337 catch(err)
03338 {noErrors = false;}
03339 }
03340 bmpContext.putImageData(bmpDataImage,0,0);
03341 bmp.src = bmpCanvas.toDataURL();
03342
03343 if(!noErrors)
03344 throw("There was a mismatch in row/col dimensions. Input matrix was " +
03345 "dimension [row,col] = [" + srcMatrix.length + "," +
03346 (srcMatrix.length?srcMatrix[0].length:0) + "]");
03347 }
03348
03349
03350
03351
03352 function localCreateBitmap()
03353 {
03354 bmp = document.createElement("img");
03355 bmp.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap");
03356
03357 bmpGrid = document.createElement("div");
03358 bmpGrid.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-grid");
03359
03360 bmpOverlay = document.createElement("img");
03361 bmpOverlay.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-overlay");
03362
03363 cursorInfo = document.createElement("div");
03364 cursorInfo.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-cursor-info");
03365 hdrCursorInfo = document.createElement("div");
03366 hdrCursorInfo.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-cursor-hdrInfo");
03367
03368
03369 rowLeftNums = document.createElement("div");
03370 rowRightNums = document.createElement("div");
03371 colTopNums = document.createElement("div");
03372 colBottomNums = document.createElement("div");
03373 rowLeftNums.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-numbers-rowLeft");
03374 rowRightNums.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-numbers-rowRight");
03375 colTopNums.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-numbers-colTop");
03376 colBottomNums.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-numbers-colBottom");
03377
03378 var tmpEl;
03379
03380
03381 {
03382 bmpCanvas=document.createElement("canvas");
03383 bmpCanvas.width = cols;
03384 bmpCanvas.height = rows;
03385 bmpContext = bmpCanvas.getContext("2d");
03386
03387 if(bmpDataImage) delete bmpDataImage;
03388 bmpDataImage = bmpContext.createImageData(cols,rows);
03389
03390
03391 tmpEl = document.createElement("div");
03392 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-grid-box");
03393 bmpGrid.appendChild(tmpEl);
03394
03395 for(var i=0;i<rows;++i)
03396 {
03397 if(i < rows - 1)
03398 {
03399 tmpEl = document.createElement("div");
03400 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-grid-row-dark");
03401 bmpGrid.appendChild(tmpEl);
03402 tmpEl = document.createElement("div");
03403 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-grid-row");
03404 bmpGrid.appendChild(tmpEl);
03405 }
03406
03407 for(var j=0;j<cols;++j)
03408 {
03409 if(i == rows-1 & j < cols-1)
03410 {
03411 tmpEl = document.createElement("div");
03412 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-grid-col-dark");
03413 bmpGrid.appendChild(tmpEl);
03414 tmpEl = document.createElement("div");
03415 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-grid-col");
03416 bmpGrid.appendChild(tmpEl);
03417 }
03418 }
03419 }
03420
03421 bmpContext.putImageData(bmpDataImage,0,0);
03422 bmp.src = bmpCanvas.toDataURL();
03423 }
03424
03425 bmp.style.position = "absolute";
03426 bmp.draggable = false;
03427
03428 bmpGrid.style.position = "absolute";
03429
03430 bmpOverlay.style.display = "none";
03431 bmpOverlay.style.position = "absolute";
03432 bmpOverlay.draggable = false;
03433
03434 cursorInfo.style.position = "absolute";
03435 cursorInfo.style.display = "none";
03436 hdrCursorInfo.style.position = "absolute";
03437 hdrCursorInfo.style.display = "none";
03438 hdrCursorInfo.style.width = "320px";
03439
03440 rowLeftNums.style.position = "absolute";
03441 rowRightNums.style.position = "absolute";
03442 colTopNums.style.position = "absolute";
03443 colBottomNums.style.position = "absolute";
03444
03445 el.appendChild(bmp);
03446 el.appendChild(bmpGrid);
03447 el.appendChild(bmpOverlay);
03448
03449 el.appendChild(hdrCursorInfo);
03450 el.appendChild(cursorInfo);
03451
03452 el.appendChild(rowLeftNums);
03453 el.appendChild(rowRightNums);
03454 el.appendChild(colTopNums);
03455 el.appendChild(colBottomNums);
03456 }
03457
03458
03459
03460
03461 function localCreateGridButtons()
03462 {
03463 allRowBtns = document.createElement("div");
03464
03465 allColBtns = document.createElement("div");
03466
03467 allBtn = document.createElement("div");
03468 allBtn.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-btn-all");
03469
03470 var tmpEl;
03471 for(var i=0;i<rows;++i)
03472 {
03473 tmpEl = document.createElement("div");
03474 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-btn-all");
03475 tmpEl.style.position = "absolute";
03476 allRowBtns.appendChild(tmpEl);
03477 }
03478 for(var i=0;i<cols;++i)
03479 {
03480 tmpEl = document.createElement("div");
03481 tmpEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-btn-all");
03482 tmpEl.style.position = "absolute";
03483 allColBtns.appendChild(tmpEl);
03484 }
03485
03486 allRowBtns.style.position = "absolute";
03487 el.appendChild(allRowBtns);
03488 allColBtns.style.position = "absolute";
03489 el.appendChild(allColBtns);
03490 allBtn.style.position = "absolute";
03491 el.appendChild(allBtn);
03492 }
03493
03494
03495
03496
03497 function localCreateHeader()
03498 {
03499 hdr = document.createElement("div");
03500 hdr.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-header");
03501
03502 var str = "";
03503
03504 str += "<div style='float:left; margin: 0 0 20px 0;'>";
03505 str += "<div style='float:left; '>";
03506 str += fieldName;
03507
03508
03509
03510
03511 str += "</div>";
03512
03513 str += "<div style='float:left; margin-left: 50px;'>";
03514 str += "Number of [Rows,Cols]: " + "[" + rows + "," + cols + "]";
03515 str += "</div>";
03516 str += "</div>";
03517
03518 str += "<div style='float:right; '>";
03519 str += "<a id='" +
03520 ConfigurationAPI._POP_UP_DIALOG_ID +
03521 "-cancel' href='#'>Cancel</a>";
03522 str += "</div>";
03523
03524 str += "<div id='clearDiv'></div>";
03525
03526 str += "<div style='float:right; margin: 40px 20px -50px 0;'>";
03527 str += "<a id='" +
03528 ConfigurationAPI._POP_UP_DIALOG_ID +
03529 "-ok' href='#'>OK</a>";
03530 str += "</div>";
03531
03532 str += "<div style='float:left; margin: 0 0 0 0;'>";
03533 for(var clickIndex=0;clickIndex<2;++clickIndex)
03534 {
03535 str += "<div style='float:left; margin: 5px 0 0 0;'>";
03536 str += "<div style='float:left; width:180px; text-align:right; margin-top: 3px;'>";
03537 str += (clickIndex?"Right":"Left") + "-Click Value:";
03538 str += "</div>";
03539 str += "<input class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03540 "-bitmap-scrollbar' style='float:left;' " +
03541 "type='range' min='" + minValue +
03542 "' max='" + maxValue + "' value='" + (clickIndex?maxValue:minValue) +
03543 "' step='" + stepValue +
03544 "' oninput='ConfigurationAPI.bitMapDialog.localUpdateScroll(" + clickIndex + ")' />";
03545 str += "<input class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03546 "-bitmap-btnInput' style='float:left; margin: 0 1px 0 5px;' " +
03547 "type='button' value='<' " +
03548 "onmousedown='ConfigurationAPI.bitMapDialog.localUpdateButtonInput(" + clickIndex + ",0,0)' " +
03549 "onmouseup='ConfigurationAPI.bitMapDialog.localUpdateButtonInput(" + clickIndex + ",0,1)' " +
03550 "/> ";
03551 str += "<input class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03552 "-bitmap-btnInput' style='float:left;' " +
03553 "type='button' value='>' " +
03554 "onmousedown='ConfigurationAPI.bitMapDialog.localUpdateButtonInput(" + clickIndex + ",1,0)' " +
03555 "onmouseup='ConfigurationAPI.bitMapDialog.localUpdateButtonInput(" + clickIndex + ",1,1)' " +
03556 "/> ";
03557 str += "<input class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03558 "-bitmap-textInput' style='float:left; margin: 0 5px 0 5px; width: 50px;' " +
03559 "type='text' " +
03560 "onchange='ConfigurationAPI.bitMapDialog.localUpdateTextInput(" + clickIndex + ",1)' " +
03561 "onkeydown='ConfigurationAPI.bitMapDialog.localUpdateTextInput(" + clickIndex + ",0)' " +
03562 "onkeyup='ConfigurationAPI.bitMapDialog.localUpdateTextInput(" + clickIndex + ",0)' " +
03563 "/>";
03564 str += "<img class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03565 "-bitmap-colorSample' style='float:left;width:25px; height:25px; margin: -2px 0 2px 0;' " +
03566 "ondragstart='return false;' " +
03567 "draggable='false'" +
03568 "'/>";
03569
03570
03571 str += "</div>";
03572
03573 str += "<div id='clearDiv'></div>";
03574 }
03575 str += "</div>";
03576
03577
03578 str += "<div style='float:left; margin: 5px 0 0 40px;'>";
03579 str += "<input class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03580 "-bitmap-btnCsv' style='float:left;' " +
03581 "type='button' value='Download as CSV' " +
03582 "onclick='ConfigurationAPI.bitMapDialog.localDownloadCSV()' " +
03583 "/> ";
03584 str += "<input class='" + ConfigurationAPI._POP_UP_DIALOG_ID +
03585 "-bitmap-btnCsv' style='float:left; margin: 0 0 0 10px;' " +
03586 "type='button' value='Upload CSV' " +
03587 "onclick='ConfigurationAPI.bitMapDialog.locaPopupUploadCSV()' " +
03588 "/> ";
03589 str += "</div>";
03590
03591 hdr.innerHTML = str;
03592 hdr.style.overflowY = "auto";
03593 hdr.style.position = "absolute";
03594
03595 var scrollEls = hdr.getElementsByClassName(ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-scrollbar");
03596 var textInputEls = hdr.getElementsByClassName(ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-textInput");
03597 var colorSampleEls = hdr.getElementsByClassName(ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-colorSample");
03598
03599
03600
03601
03602 ConfigurationAPI.bitMapDialog.localUpdateScroll = function(i)
03603 {
03604 Debug.log("localUpdateScroll " + i);
03605
03606 clickValues[i] = scrollEls[i].value|0;
03607 clickColors[i] = localConvertValueToRGBA(clickValues[i]);
03608
03609 textInputEls[i].value = clickValues[i];
03610 colorSampleEls[i].src = ConfigurationAPI.getOnePixelPngData(clickColors[i]);
03611 };
03612
03613
03614
03615 ConfigurationAPI.bitMapDialog.localUpdateTextInput = function(i,finalChange)
03616 {
03617 Debug.log("localUpdateTextInput " + textInputEls[i].value + " " + finalChange);
03618
03619 clickValues[i] = textInputEls[i].value|0;
03620
03621 if(finalChange)
03622 {
03623 if(clickValues[i] < minValue) clickValues[i] = minValue;
03624 if(clickValues[i] > maxValue) clickValues[i] = maxValue;
03625 clickValues[i] = (((clickValues[i]-minValue)/stepValue)|0)*stepValue + minValue;
03626 textInputEls[i].value = clickValues[i];
03627 }
03628 else
03629 {
03630 if(clickValues[i] < minValue) return;
03631 if(clickValues[i] > maxValue) return;
03632 if((((clickValues[i]-minValue)/stepValue)|0) != (clickValues[i]-minValue)/stepValue)
03633 return;
03634 Debug.log("displaying change");
03635 }
03636 clickColors[i] = localConvertValueToRGBA(clickValues[i]);
03637
03638 scrollEls[i].value = clickValues[i];
03639 colorSampleEls[i].src = ConfigurationAPI.getOnePixelPngData(clickColors[i]);
03640 };
03641
03642
03643
03644 var mouseDownTimer = 0;
03645 ConfigurationAPI.bitMapDialog.localUpdateButtonInput = function(i,dir,mouseUp,delay)
03646 {
03647 window.clearInterval(mouseDownTimer);
03648 if(mouseUp)
03649 {
03650 Debug.log("cancel mouse down");
03651 return;
03652 }
03653
03654 mouseDownTimer = window.setInterval(function()
03655 {
03656
03657 if(delay > 50) delay -= 50;
03658 ConfigurationAPI.bitMapDialog.localUpdateButtonInput(i,dir,0,50);
03659 },delay!==undefined?delay:300);
03660
03661 Debug.log("localUpdateButtonInput " + textInputEls[i].value + " " + dir);
03662
03663 clickValues[i] = clickValues[i] + (dir?stepValue:-stepValue);
03664 if(clickValues[i] < minValue) clickValues[i] = minValue;
03665 if(clickValues[i] > maxValue) clickValues[i] = maxValue;
03666
03667 clickColors[i] = localConvertValueToRGBA(clickValues[i]);
03668
03669 textInputEls[i].value = clickValues[i];
03670 scrollEls[i].value = clickValues[i];
03671 colorSampleEls[i].src = ConfigurationAPI.getOnePixelPngData(clickColors[i]);
03672
03673 };
03674
03675
03676
03677
03678
03679
03680
03681 ConfigurationAPI.bitMapDialog.localDownloadCSV = function()
03682 {
03683 var transGrid = localConvertFullGridToRowCol();
03684 console.log(transGrid);
03685
03686 var dataStr = "data:text/csv;charset=utf-8,";
03687
03688 for(var r=0;r<transGrid.length;++r)
03689 {
03690 if(r) dataStr += encodeURI("\n");
03691 for(var c=0;c<transGrid[0].length;++c)
03692 {
03693 if(c) dataStr += ",";
03694 dataStr += transGrid[r][c];
03695 }
03696 }
03697
03698 Debug.log("ConfigurationAPI.bitMapDialog.localDownloadCSV dataStr=" + dataStr);
03699
03700 var link = document.createElement("a");
03701 link.setAttribute("href", dataStr);
03702 link.setAttribute("style", "display:none");
03703 link.setAttribute("download", _currentConfigName + "_" +
03704 fieldName + "_download.csv");
03705 document.body.appendChild(link);
03706
03707 link.click();
03708
03709 link.parentNode.removeChild(link);
03710 };
03711
03712
03713
03714
03715
03716 ConfigurationAPI.bitMapDialog._csvUploadDataStr;
03717 ConfigurationAPI.bitMapDialog.locaUploadCSV = function()
03718 {
03719 Debug.log("locaUploadCSV ConfigurationAPI.bitMapDialog._csvUploadDataStr = " + ConfigurationAPI.bitMapDialog._csvUploadDataStr);
03720 var srcDataStr = ConfigurationAPI.bitMapDialog._csvUploadDataStr.split('\n');
03721 var src = [];
03722 for(var i=0;i<srcDataStr.length;++i)
03723 src.push(srcDataStr[i].split(','));
03724 console.log(src);
03725
03726 try
03727 {
03728 localConvertFullRowColToGrid(src);
03729
03730 Debug.log("Successfully uploaded CSV file to bitmap!", Debug.INFO_PRIORITY);
03731
03732
03733 el = document.getElementById("popUpDialog");
03734 if(el) el.parentNode.removeChild(el);
03735 }
03736 catch(err)
03737 {
03738 Debug.log("Errors occured during upload. Bitmap may not reflect contents of CSV file." +
03739 "\nHere is the error description: \n" + err, Debug.HIGH_PRIORITY);
03740
03741
03742 document.getElementById('popUpDialog-submitButton').disabled = false;
03743 }
03744 }
03745
03746
03747
03748 ConfigurationAPI.bitMapDialog.locaPopupUploadCSV = function()
03749 {
03750 Debug.log("ConfigurationAPI.bitMapDialog.locaPopupUploadCSV");
03751 ConfigurationAPI.bitMapDialog._csvUploadDataStr = "";
03752
03753 var str = "";
03754
03755 var pel = document.getElementById("popUpDialog");
03756 if(!pel)
03757 {
03758 pel = document.createElement("div");
03759 pel.setAttribute("id", "popUpDialog");
03760 }
03761 pel.style.display = "none";
03762
03763
03764 var w = 380;
03765 var h = 195;
03766 ConfigurationAPI.setPopUpPosition(pel,w ,h );
03767
03768 var str = "<a id='" +
03769 "popUpDialog" +
03770 "-header' href='#' onclick='javascript:ConfigurationAPI.bitMapDialog._csvUploadDataStr = \"\"; var pel = document.getElementById(" +
03771 "\"popUpDialog\"); if(pel) pel.parentNode.removeChild(pel); return false;'>Cancel</a><br><br>";
03772
03773 str += "<div id='popUpDialog-div'>";
03774
03775 str += "Please choose a CSV formatted data file (i.e. commas for columns, and new lines for rows) " +
03776 "to upload:<br><br>";
03777
03778 str += "<center>";
03779
03780 str += "<input type='file' id='popUpDialog-fileUpload' " +
03781 "accept='.csv' enctype='multipart/form-data' />";
03782
03783
03784
03785 str += "</center></div><br><br>";
03786
03787 var onmouseupJS = "";
03788 onmouseupJS += "document.getElementById(\"popUpDialog-submitButton\").disabled = true;";
03789 onmouseupJS += "ConfigurationAPI.bitMapDialog.locaUploadCSV();";
03790
03791 str += "<input id='popUpDialog-submitButton' disabled type='button' onmouseup='" +
03792 onmouseupJS + "' " +
03793 "value='Upload File' title='" +
03794 "Upload the chosen file to replace the row,col data in the current bitmap." +
03795 "'/>";
03796
03797 pel.innerHTML = str;
03798 el.appendChild(pel);
03799 pel.style.display = "block";
03800
03801 document.getElementById('popUpDialog-fileUpload').addEventListener(
03802 'change', function(evt) {
03803 var files = evt.target.files;
03804 var file = files[0];
03805 var reader = new FileReader();
03806 reader.onload = function() {
03807
03808 ConfigurationAPI.bitMapDialog._csvUploadDataStr = this.result;
03809 Debug.log("ConfigurationAPI.bitMapDialog._csvUploadDataStr = " + ConfigurationAPI.bitMapDialog._csvUploadDataStr);
03810 document.getElementById('popUpDialog-submitButton').disabled = false;
03811 }
03812 reader.readAsText(file);
03813 }, false);
03814
03815 };
03816
03817
03818 el.appendChild(hdr);
03819
03820 ConfigurationAPI.bitMapDialog.localUpdateScroll(0);
03821 ConfigurationAPI.bitMapDialog.localUpdateScroll(1);
03822
03823 }
03824
03825
03826
03827
03828 function localPaint()
03829 {
03830 Debug.log("localPaint");
03831
03832 popSz = ConfigurationAPI.setPopUpPosition(el,undefined,undefined,padding,undefined,
03833 30 , true );
03834
03835 hdrW = popSz.w;
03836
03837 hdrX = padding;
03838 hdrY = padding;
03839 hdrW = popSz.w;
03840 hdrH = 150;
03841 bmpX = padding;
03842 bmpY = hdrY+hdrH+padding;
03843 bmpW = popSz.w - 2*axisPadding;
03844 bmpH = popSz.h - hdrH - padding - 2*axisPadding;
03845
03846 cellW = bmpW/cols;
03847 cellH = bmpH/rows;
03848
03849 localOptimizeAspectRatio();
03850
03851
03852 hdr.style.left = hdrX + "px";
03853 hdr.style.top = hdrY + "px";
03854 hdr.style.width = hdrW + "px";
03855 hdr.style.height = hdrH + "px";
03856
03857
03858 bmp.style.left = bmpX + "px";
03859 bmp.style.top = bmpY + "px";
03860 bmp.style.width = bmpW + "px";
03861 bmp.style.height = bmpH + "px";
03862
03863
03864
03865 {
03866
03867 bmpGrid.style.left = (bmpX-bmpBorderSize) + "px";
03868 bmpGrid.style.top = (bmpY-bmpBorderSize) + "px";
03869 bmpGrid.style.width = (bmpW) + "px";
03870 bmpGrid.style.height = (bmpH) + "px";
03871
03872 var bmpGridChildren = bmpGrid.childNodes;
03873
03874
03875 allRowBtns.style.left = (bmpX - bmpBorderSize - axisPaddingMargin - bmpBorderSize - butttonSz) + "px";
03876 allRowBtns.style.top = (bmpY - bmpBorderSize) + "px";
03877
03878 allColBtns.style.left = (bmpX - bmpBorderSize) + "px";
03879 allColBtns.style.top = (bmpY + bmpH + axisPaddingMargin - bmpBorderSize*2) + "px";
03880
03881 allBtn.style.left = (bmpX - bmpBorderSize - axisPaddingMargin - bmpBorderSize - butttonSz) + "px";
03882 allBtn.style.top = (bmpY + bmpH + axisPaddingMargin - bmpBorderSize*2) + "px";
03883 allBtn.style.width = butttonSz + "px";
03884 allBtn.style.height = butttonSz + "px";
03885
03886 var allRowsChildren = allRowBtns.childNodes;
03887 var allColsChildren = allColBtns.childNodes;
03888
03889
03890
03891 rowLeftNums.style.left = (bmpX - bmpBorderSize - axisPaddingMargin - bmpBorderSize - butttonSz + (- bmpBorderSize - axisPaddingMargin - axisPaddingExtra)) + "px";
03892 rowLeftNums.style.top = (bmpY - bmpBorderSize) + "px";
03893 rowRightNums.style.left = (bmpX + bmpW + axisPaddingMargin + bmpBorderSize) + "px";
03894 rowRightNums.style.top = (bmpY - bmpBorderSize) + "px";
03895 colTopNums.style.left = (bmpX - bmpBorderSize) + "px";
03896 colTopNums.style.top = (bmpY - bmpBorderSize*2 - numberDigitH) + "px";
03897 colBottomNums.style.left = (bmpX - bmpBorderSize) + "px";
03898 colBottomNums.style.top = (bmpY + bmpH + bmpBorderSize + axisPaddingMargin + bmpBorderSize + butttonSz + bmpBorderSize) + "px";
03899 rowLeftNums.innerHTML = "";
03900 rowRightNums.innerHTML = "";
03901 colTopNums.innerHTML = "";
03902 colBottomNums.innerHTML = "";
03903
03904 var thresholdNumberSpacing = 100;
03905 var numberLoc = [];
03906 var oldNumberLoc = [-thresholdNumberSpacing,-thresholdNumberSpacing];
03907 var numberEl;
03908 var translatedRC;
03909
03910
03911 bmpGridChildren[0].style.left = 0 + "px";
03912 bmpGridChildren[0].style.top = 0 + "px";
03913 bmpGridChildren[0].style.width = (bmpW) + "px";
03914 bmpGridChildren[0].style.height = (bmpH) + "px";
03915
03916
03917 for(var i=0;i<rows;++i)
03918 {
03919 if(i<rows-1)
03920 {
03921
03922 bmpGridChildren[1+i*2].style.left = bmpBorderSize + "px";
03923 bmpGridChildren[1+i*2].style.top = ((i+1)*cellH) + "px";
03924 bmpGridChildren[1+i*2].style.width = (bmpW) + "px";
03925 bmpGridChildren[1+i*2].style.height = (bmpGridThickness+bmpBorderSize*2) + "px";
03926
03927
03928 bmpGridChildren[1+i*2+1].style.left = 0 + "px";
03929 bmpGridChildren[1+i*2+1].style.top = ((i+1)*cellH + bmpBorderSize) + "px";
03930 bmpGridChildren[1+i*2+1].style.width = (bmpW + bmpBorderSize*2) + "px";
03931 bmpGridChildren[1+i*2+1].style.height = bmpGridThickness + "px";
03932
03933 bmpGridChildren[1+i*2+1].style.backgroundColor =
03934 (doSnakeRows && i%2 == 1)?"rgb(100,100,100)":"#efeaea";
03935 }
03936
03937
03938 allRowsChildren[i].style.left = 0 + "px";
03939 allRowsChildren[i].style.top = (i*cellH + (i?bmpGridThickness+bmpBorderSize*2-1:0)) + "px";
03940 allRowsChildren[i].style.width = (butttonSz) + "px";
03941 allRowsChildren[i].style.height = (cellH - 1 + (i?-bmpBorderSize*2:0)) + "px";
03942
03943
03944 {
03945 numberLoc[0] = (i*cellH - 1 + cellH/2 - numberDigitH/2 + (i?bmpGridThickness+bmpBorderSize*2:0));
03946
03947
03948 translatedRC = localConvertGridToRowCol(i,0);
03949 if(numberLoc[0] - oldNumberLoc[0] >= thresholdNumberSpacing &&
03950 translatedRC[0]%5 == 0)
03951 {
03952
03953 numberEl = document.createElement("div");
03954 numberEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-number");
03955 numberEl.innerHTML = translatedRC[0];
03956 numberEl.style.top = numberLoc[0] + "px";
03957 numberEl.style.width = axisPaddingExtra + "px";
03958 rowLeftNums.appendChild(numberEl);
03959 oldNumberLoc[0] = numberLoc[0];
03960 }
03961
03962
03963 translatedRC = localConvertGridToRowCol(i,cols>1?1:0);
03964 if(numberLoc[0] - oldNumberLoc[1] >= thresholdNumberSpacing &&
03965 translatedRC[0]%5 == 0)
03966 {
03967
03968 numberEl = document.createElement("div");
03969 numberEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-number");
03970 numberEl.innerHTML = translatedRC[0];
03971 numberEl.style.top = numberLoc[0] + "px";
03972 numberEl.style.width = axisPaddingExtra + "px";
03973 rowRightNums.appendChild(numberEl);
03974 oldNumberLoc[1] = numberLoc[0];
03975 }
03976 }
03977 }
03978
03979 oldNumberLoc = [-thresholdNumberSpacing,-thresholdNumberSpacing];
03980
03981 for(var i=0;i<cols;++i)
03982 {
03983 if(i<cols-1)
03984 {
03985
03986
03987
03988
03989 bmpGridChildren[1+(rows-1)*2+i*2].style.top = bmpBorderSize + "px";
03990 bmpGridChildren[1+(rows-1)*2+i*2].style.left = ((i+1)*cellW + bmpBorderSize) + "px";
03991 bmpGridChildren[1+(rows-1)*2+i*2].style.height = (bmpH) + "px";
03992 bmpGridChildren[1+(rows-1)*2+i*2].style.width = (bmpGridThickness+bmpBorderSize*2) + "px";
03993
03994
03995 bmpGridChildren[1+(rows-1)*2+i*2+1].style.top = 0 + "px";
03996 bmpGridChildren[1+(rows-1)*2+i*2+1].style.left = ((i+1)*cellW + bmpBorderSize*2) + "px";
03997 bmpGridChildren[1+(rows-1)*2+i*2+1].style.height = (bmpH + bmpBorderSize*2) + "px";
03998 bmpGridChildren[1+(rows-1)*2+i*2+1].style.width = bmpGridThickness + "px";
03999
04000 bmpGridChildren[1+(rows-1)*2+i*2+1].style.backgroundColor =
04001 (doSnakeColumns && i%2 == 1)?"rgb(100,100,100)":"#efeaea";
04002 }
04003
04004
04005 allColsChildren[i].style.left = (i*cellW - 1 + (i?bmpGridThickness+bmpBorderSize*2:0)) + "px";
04006 allColsChildren[i].style.top = 0 + "px";
04007 allColsChildren[i].style.width = (cellW + 1 - (i?bmpGridThickness+bmpBorderSize*2:0)) + "px";
04008 allColsChildren[i].style.height = (butttonSz) + "px";
04009
04010
04011 {
04012 numberLoc[0] = (i*cellW + cellW/2 - axisPaddingExtra/2 + (i?bmpGridThickness+bmpBorderSize*2:0));
04013
04014
04015 translatedRC = localConvertGridToRowCol(0,i);
04016 if(numberLoc[0] - oldNumberLoc[0] >= thresholdNumberSpacing &&
04017 translatedRC[1]%5 == 0)
04018 {
04019
04020 numberEl = document.createElement("div");
04021 numberEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-number");
04022 numberEl.innerHTML = translatedRC[1];
04023 numberEl.style.left = numberLoc[0] + "px";
04024 numberEl.style.width = axisPaddingExtra + "px";
04025 colTopNums.appendChild(numberEl);
04026 oldNumberLoc[0] = numberLoc[0];
04027 }
04028
04029
04030 translatedRC = localConvertGridToRowCol(rows>1?1:0,i);
04031 if(numberLoc[0] - oldNumberLoc[1] >= thresholdNumberSpacing &&
04032 translatedRC[1]%5 == 0)
04033 {
04034
04035 numberEl = document.createElement("div");
04036 numberEl.setAttribute("class", ConfigurationAPI._POP_UP_DIALOG_ID + "-bitmap-number");
04037 numberEl.innerHTML = translatedRC[1];
04038 numberEl.style.left = numberLoc[0] + "px";
04039 numberEl.style.width = axisPaddingExtra + "px";
04040 colBottomNums.appendChild(numberEl);
04041 oldNumberLoc[1] = numberLoc[0];
04042 }
04043 }
04044 }
04045 }
04046
04047
04048
04049
04050
04051
04052 }
04053
04054
04055
04056
04057
04058
04059
04060 function localOptimizeAspectRatio()
04061 {
04062 var cellSkew = (cellW>cellH)?cellW/cellH:cellH/cellW;
04063 var MAX_SKEW = 3;
04064
04065
04066 if(forcedAspectH !== undefined)
04067 {
04068 var offAspectH = forcedAspectH/cellH;
04069 var offAspectW = forcedAspectW/cellW;
04070
04071 Debug.log("Adjusting skew factor = " + forcedAspectH + "-" + forcedAspectW);
04072
04073 if(offAspectH < offAspectW)
04074 bmpH = bmpW/cols*forcedAspectH/forcedAspectW*rows;
04075 else
04076 bmpW = bmpH/rows*forcedAspectW/forcedAspectH*cols;
04077 }
04078 else if(cellSkew > MAX_SKEW)
04079 {
04080 var adj = cellSkew/MAX_SKEW;
04081
04082 Debug.log("Adjusting skew factor = " + adj);
04083 if(cellW > cellH)
04084 {
04085 bmpW /= adj;
04086 }
04087 else
04088 bmpH /= adj;
04089 }
04090
04091 cellW = bmpW/cols;
04092 cellH = bmpH/rows;
04093
04094
04095 bmpX = padding + (popSz.w-bmpW)/2;
04096 bmpY = bmpY + (popSz.h-bmpY-bmpH)/2;
04097 hdrY = bmpY - padding - hdrH;
04098 }
04099 }
04100
04101
04102
04103
04104
04105
04106 ConfigurationAPI.getDateString;
04107 {
04108 ConfigurationAPI.getDateStringDayArr_ = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
04109 ConfigurationAPI.getDateStringMonthArr_ = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
04110 ConfigurationAPI.getDateString = function(date)
04111 {
04112 var dateStr = "";
04113
04114 dateStr += ConfigurationAPI.getDateStringDayArr_[date.getDay()];
04115 dateStr += " ";
04116 dateStr += ConfigurationAPI.getDateStringMonthArr_[date.getMonth()];
04117 dateStr += " ";
04118 dateStr += date.getDate();
04119 dateStr += " ";
04120 dateStr += date.getHours();
04121 dateStr += ":";
04122 dateStr += ((date.getMinutes()<10)?"0":"") + date.getMinutes();
04123 dateStr += ":";
04124 dateStr += ((date.getSeconds()<10)?"0":"") + date.getSeconds();
04125 dateStr += " ";
04126 dateStr += date.getFullYear();
04127 dateStr += " ";
04128 dateStr += date.toLocaleTimeString([],{timeZoneName: "short"}).split(" ")[2];
04129 return dateStr;
04130 }
04131 }
04132
04133
04134
04135 ConfigurationAPI.setCaretPosition = function(elem, caretPos, endPos)
04136 {
04137 elem.focus();
04138 elem.setSelectionRange(caretPos, endPos);
04139 }
04140
04141
04142
04143
04144
04145
04146
04147
04148
04149 ConfigurationAPI.setPopUpPosition = function(el,w,h,padding,border,margin,doNotResize,offsetUp)
04150 {
04151 Debug.log("ConfigurationAPI.setPopUpPosition");
04152
04153 if(padding === undefined) padding = 10;
04154 if(border === undefined) border = 1;
04155 if(margin === undefined) margin = 0;
04156
04157 var x,y;
04158
04159
04160
04161
04162 ConfigurationAPI.setPopUpPosition.stopPropagation = function(event) {
04163
04164 event.stopPropagation();
04165 }
04166
04167
04168
04169
04170 ConfigurationAPI.setPopUpPosition.popupResize = function() {
04171
04172 try
04173 {
04174 if(!el)
04175 {
04176 window.removeEventListener("resize",ConfigurationAPI.setPopUpPosition.popupResize);
04177 window.removeEventListener("scroll",ConfigurationAPI.setPopUpPosition.popupResize);
04178 return;
04179 }
04180 }
04181 catch(err) {return;}
04182
04183
04184
04185
04186
04187 var ww = DesktopContent.getWindowWidth()-(padding+border)*2;
04188 var wh = DesktopContent.getWindowHeight()-(padding+border)*2;
04189
04190
04191
04192 var ah = el.offsetHeight;
04193
04194 if(w === undefined || h === undefined)
04195 {
04196 w = ww-(margin)*2;
04197 h = wh-(margin)*2;
04198 }
04199
04200
04201 x = (DesktopContent.getWindowScrollLeft() + ((ww-w)/2));
04202 y = (DesktopContent.getWindowScrollTop() + ((wh-h)/2)) - (offsetUp|0) - 100;
04203
04204 if(y<DesktopContent.getWindowScrollTop()+margin+padding)
04205 y = DesktopContent.getWindowScrollTop()+margin+padding;
04206
04207
04208 if(w > ww-margin-padding)
04209 x = -DesktopContent.getWindowScrollLeft();
04210 if(ah > wh-margin-padding)
04211 y = -DesktopContent.getWindowScrollTop();
04212
04213 el.style.left = x + "px";
04214 el.style.top = y + "px";
04215 };
04216 ConfigurationAPI.setPopUpPosition.popupResize();
04217
04218
04219 el.style.width = w + "px";
04220 el.style.height = h + "px";
04221
04222 if(!doNotResize)
04223 {
04224 window.addEventListener("resize",ConfigurationAPI.setPopUpPosition.popupResize);
04225 window.addEventListener("scroll",ConfigurationAPI.setPopUpPosition.popupResize);
04226 }
04227 el.addEventListener("keydown",ConfigurationAPI.setPopUpPosition.stopPropagation);
04228 el.addEventListener("mousemove",ConfigurationAPI.setPopUpPosition.stopPropagation);
04229 el.addEventListener("mousemove",DesktopContent.mouseMove);
04230
04231 el.style.overflow = "auto";
04232
04233 return {"w" : w, "h" : h, "x" : x, "y" : y};
04234 }
04235
04236
04237
04238
04239
04240 ConfigurationAPI.getOnePixelPngData = function(rgba)
04241 {
04242 if(ConfigurationAPI.getOnePixelPngData.canvas === undefined)
04243 {
04244
04245 ConfigurationAPI.getOnePixelPngData.canvas = document.createElement("canvas");
04246 ConfigurationAPI.getOnePixelPngData.canvas.width = 1;
04247 ConfigurationAPI.getOnePixelPngData.canvas.height = 1;
04248 ConfigurationAPI.getOnePixelPngData.ctx = ConfigurationAPI.getOnePixelPngData.canvas.getContext("2d");
04249 ConfigurationAPI.getOnePixelPngData.bmpOverlayData = ConfigurationAPI.getOnePixelPngData.ctx.createImageData(1,1);
04250 }
04251
04252 ConfigurationAPI.getOnePixelPngData.bmpOverlayData.data[0]=rgba[0];
04253 ConfigurationAPI.getOnePixelPngData.bmpOverlayData.data[1]=rgba[1];
04254 ConfigurationAPI.getOnePixelPngData.bmpOverlayData.data[2]=rgba[2];
04255 ConfigurationAPI.getOnePixelPngData.bmpOverlayData.data[3]=rgba[3]!==undefined?rgba[3]:255;
04256
04257 ConfigurationAPI.getOnePixelPngData.ctx.putImageData(
04258 ConfigurationAPI.getOnePixelPngData.bmpOverlayData,0,0);
04259 return ConfigurationAPI.getOnePixelPngData.canvas.toDataURL();
04260 }
04261
04262
04263
04264
04265
04266
04267
04268
04269
04270
04271
04272
04273
04274
04275
04276
04277
04278
04279
04280
04281
04282
04283
04284
04285 ConfigurationAPI.editableFieldEditingCell_ = 0;
04286 ConfigurationAPI.editableFieldEditingIdString_;
04287 ConfigurationAPI.editableFieldEditingNodeType_;
04288 ConfigurationAPI.editableFieldEditingOldValue_;
04289 ConfigurationAPI.editableFieldEditingInitValue_;
04290 ConfigurationAPI.editableFieldHoveringCell_ = 0;
04291 ConfigurationAPI.editableFieldHoveringIdString_;
04292 ConfigurationAPI.editableFieldSelectedIdString_ = 0;
04293 ConfigurationAPI.editableFieldHandlersSubscribed_ = false;
04294 ConfigurationAPI.editableFieldMouseIsSelecting_ = false;
04295 ConfigurationAPI.editableField_SELECTED_COLOR_ = "rgb(251, 245, 53)";
04296 ConfigurationAPI.createEditableFieldElement = function(fieldObj,fieldIndex,
04297 depthIndex )
04298 {
04299 var str = "";
04300 var depth = depthIndex|0;
04301 var uid = fieldIndex|0;
04302
04303 if(!ConfigurationAPI.editableFieldHandlersSubscribed_)
04304 {
04305 ConfigurationAPI.editableFieldHandlersSubscribed_ = true;
04306
04307
04308 DesktopContent.mouseMoveSubscriber(ConfigurationAPI.handleEditableFieldBodyMouseMove);
04309 }
04310
04311 var fieldEl = document.createElement("div");
04312 fieldEl.setAttribute("class", "ConfigurationAPI-EditableField");
04313 fieldEl.setAttribute("id", "ConfigurationAPI-EditableField-" +
04314 ( depth + "-" + uid ));
04315
04316 Debug.log("Field type " + fieldObj.fieldColumnType);
04317
04318
04319 var valueType = fieldObj.fieldColumnType;
04320 var choices = fieldObj.fieldColumnDataChoicesArr;
04321 var value = fieldObj.fieldColumnDefaultValue;
04322 var path = fieldObj.fieldRelativePath;
04323 var nodeName = fieldObj.fieldColumnName;
04324
04325 return ConfigurationAPI.fillEditableFieldElement(fieldEl,uid,
04326 depth,nodeName,value,valueType,choices,path);
04327 }
04328
04329
04330
04331
04332
04333 ConfigurationAPI.getEditableFieldValue = function(fieldObj,fieldIndex,depthIndex )
04334 {
04335
04336
04337
04338 ConfigurationAPI.handleEditableFieldEditOK();
04339
04340 var depth = depthIndex|0;
04341 var uid = fieldIndex|0;
04342 var fieldEl = document.getElementById("editableFieldNode-Value-leafNode-" +
04343 ( depth + "-" + uid ));
04344 if(!fieldEl)
04345 {
04346 Debug.log("getEditableFieldValue Error! Invalid target field element '" +
04347 ( depth + "-" + uid ), Debug.HIGH_PRIORITY);
04348 return;
04349 }
04350
04351 var valueType = fieldObj.fieldColumnType;
04352 var value = fieldEl.textContent;
04353
04354
04355 return value;
04356 }
04357
04358
04359
04360
04361
04362
04363
04364
04365
04366 ConfigurationAPI.setEditableFieldValue = function(fieldObj,value,fieldIndex,depthIndex )
04367 {
04368
04369
04370 var depth = depthIndex|0;
04371 var uid = fieldIndex|0;
04372 var fieldEl = document.getElementById("ConfigurationAPI-EditableField-" +
04373 ( depth + "-" + uid ));
04374 if(!fieldEl)
04375 {
04376 Debug.log("setEditableFieldValue Error! Invalid target field element '" +
04377 ( depth + "-" + uid ), Debug.HIGH_PRIORITY);
04378 return;
04379 }
04380 var valueType = fieldObj.fieldColumnType;
04381 var choices = fieldObj.fieldColumnDataChoicesArr;
04382 var path = fieldObj.fieldRelativePath;
04383 var nodeName = fieldObj.fieldColumnName;
04384
04385 return ConfigurationAPI.fillEditableFieldElement(fieldEl,uid,
04386 depth,nodeName,value,valueType,choices,path);
04387 }
04388
04389
04390
04391
04392 ConfigurationAPI.fillEditableFieldElement = function(fieldEl,uid,
04393 depth,nodeName,value,valueType,choices,path)
04394 {
04395 var str = "";
04396
04397 var pathHTML = path;
04398
04399 pathHTML = pathHTML.replace(/</g, "<");
04400 pathHTML = pathHTML.replace(/>/g, ">");
04401
04402 str += "<div class='editableFieldNode-Path' style='display:none' id='editableFieldNode-path-" +
04403 ( depth + "-" + uid ) + "'>" +
04404 pathHTML +
04405 "</div>";
04406
04407 if(valueType == "FixedChoiceData")
04408 {
04409
04410 str +=
04411 "<div class='editableFieldNode-FixedChoice-CSV' style='display:none' " +
04412 "id='editableFieldNode-FixedChoice-CSV-" +
04413 ( depth + "-" + uid ) + "'>";
04414
04415 for(var j=0;j<choices.length;++j)
04416 {
04417 if(j) str += ",";
04418 str += choices[j];
04419 }
04420 str += "</div>";
04421 }
04422 else if(valueType == "BitMap")
04423 {
04424
04425 str +=
04426 "<div class='editableFieldNode-BitMap-Params' style='display:none' " +
04427 "id='editableFieldNode-BitMap-Params-" +
04428 ( depth + "-" + uid ) + "'>";
04429
04430 for(var j=1;j<choices.length;++j)
04431 {
04432 if(j-1) str += ";";
04433 str += choices[j].replace(/;/g,",");
04434 }
04435 str += "</div>";
04436 }
04437
04438
04439 {
04440
04441 str +=
04442 "<div class='editableFieldNode-Value editableFieldNode-ValueType-" + valueType +
04443 "' " +
04444 "id='editableFieldNode-Value-" +
04445 (depth + "-" + uid) + "' " +
04446
04447 "onclick='ConfigurationAPI.handleEditableFieldClick(" +
04448 depth + "," + uid + "," +
04449 "0,\"value\")' " +
04450
04451 "onmousemove='ConfigurationAPI.handleEditableFieldHover(" +
04452 depth + "," + uid + "," +
04453 "event)' " +
04454
04455 ">";
04456
04457 titleStr = "~ Leaf Value Node ~\n";
04458 titleStr += "Path: \t" + path + nodeName + "\n";
04459
04460
04461 str +=
04462 "<div style='float:left' title='" + titleStr + "'>" +
04463 "<b class='editableFieldNode-Value-leafNode-fieldName bold-header'>" +
04464 nodeName + "</b>" +
04465 "</div><div style='float:left'> :</div>";
04466
04467
04468 str +=
04469 "<div class='editableFieldNode-Value-editIcon' id='editableFieldNode-Value-editIcon-" +
04470 (depth + "-" + uid) + "' " +
04471 "onclick='ConfigurationAPI.handleEditableFieldClick(" +
04472 depth + "," + uid + "," +
04473 "1,\"value\"); event.stopPropagation();' " +
04474 "title='Edit the value of this node.' " +
04475 "></div>";
04476 }
04477
04478 str += "<div style='float:left; margin-left:9px;' id='editableFieldNode-Value-leafNode-" +
04479 (depth + "-" + uid) +
04480 "' class='" +
04481 "editableFieldNode-Value-leafNode-ColumnName-" + nodeName +
04482 "' " +
04483 ">";
04484
04485 if(valueType == "OnOff" ||
04486 valueType == "YesNo" ||
04487 valueType == "TrueFalse")
04488 {
04489
04490 str += "<div style='float:left'>";
04491 str += value;
04492 str += "</div>";
04493
04494 var color = (value == "On" || value == "Yes" || value == "True")?
04495 "rgb(16, 204, 16)":"rgb(255, 0, 0);";
04496 str += "<div style='width:10px;height:10px;" +
04497 "background-color:" + color + ";" +
04498 "float: left;" +
04499 "border-radius: 7px;" +
04500 "border: 2px solid white;" +
04501 "margin: 2px 0 0 6px;" +
04502 "'></div>";
04503 }
04504 else if(valueType == "Timestamp")
04505 str += ConfigurationAPI.getDateString(new Date((value|0)*1000));
04506 else
04507 str += value;
04508
04509
04510
04511
04512 fieldEl.innerHTML = str;
04513
04514
04515
04516 if(ConfigurationAPI.editableFieldSelectedIdString_ == (depth + "-" + uid))
04517 fieldEl.getElementsByClassName("editableFieldNode-Value")[0].style.backgroundColor =
04518 ConfigurationAPI.editableField_SELECTED_COLOR_;
04519
04520 return fieldEl;
04521 }
04522
04523
04524
04525
04526
04527
04528
04529 ConfigurationAPI.handleEditableFieldClick = function(depth,uid,editClick,type)
04530 {
04531 var idString = depth + "-" + uid;
04532 ConfigurationAPI.editableFieldEditingIdString_ = idString;
04533
04534 Debug.log("handleEditableFieldClick editClick " + editClick);
04535 Debug.log("handleEditableFieldClick idString " + idString);
04536
04537 var el = document.getElementById("editableFieldNode-Value-" + idString);
04538
04539 if(!el)
04540 {
04541 Debug.log("Invalid element pointed to by idString. Ignoring and exiting.");
04542 return;
04543 }
04544
04545 if(ConfigurationAPI.editableFieldHoveringCell_)
04546 {
04547
04548 ConfigurationAPI.handleEditableFieldBodyMouseMove();
04549 }
04550
04551 if(ConfigurationAPI.editableFieldEditingCell_)
04552 {
04553 if(ConfigurationAPI.editableFieldEditingCell_ == el)
04554 return true;
04555 ConfigurationAPI.handleEditableFieldEditOK();
04556 }
04557
04558 var path = document.getElementById("editableFieldNode-path-" + idString).textContent;
04559
04560
04561
04562
04563
04564 Debug.log("handleEditableFieldClick path " + path);
04565
04566 Debug.log("handleEditableFieldClick type " + type);
04567
04568
04569
04570
04571
04572
04573
04574
04575
04576
04577
04578
04579
04580
04581
04582
04583
04584
04585
04586
04587
04588
04589
04590
04591 if(editClick)
04592 {
04593
04594 if(type == "value")
04595 {
04596
04597 Debug.log("edit value mode");
04598
04599 selectThisTreeNode(idString,type);
04600 function selectThisTreeNode(idString,type)
04601 {
04602
04603
04604 var el = document.getElementById("editableFieldNode-Value-leafNode-" + idString);
04605 var vel = document.getElementById("editableFieldNode-Value-" + idString);
04606
04607
04608 var colType = vel.className.split(' ')[1].split('-');
04609 if(colType[1] == "ValueType")
04610 colType = colType[2];
04611
04612 var fieldName = el.className.substr(("editableFieldNode-Value-leafNode-ColumnName-").length);
04613
04614 Debug.log("fieldName=" + fieldName);
04615 Debug.log("colType=" + colType);
04616
04617 if(colType == "Author" ||
04618 colType == "Timestamp")
04619 {
04620 Debug.log("Can not edit Author or Timestamp fields.",
04621 Debug.WARN_PRIORITY);
04622 return false;
04623 }
04624
04625
04626 var str = "";
04627 var optionIndex = -1;
04628
04629
04630 if(colType == "YesNo" ||
04631 colType == "TrueFalse" ||
04632 colType == "OnOff")
04633 {
04634 type += "-bool";
04635 ConfigurationAPI.editableFieldEditingOldValue_ = el.innerHTML;
04636
04637 var initVal = el.childNodes[0].textContent;
04638 ConfigurationAPI.editableFieldEditingInitValue_ = initVal;
04639
04640 var boolVals = [];
04641 if(colType == "YesNo")
04642 boolVals = ["No","Yes"];
04643 else if(colType == "TrueFalse")
04644 boolVals = ["False","True"];
04645 else if(colType == "OnOff")
04646 boolVals = ["Off","On"];
04647
04648
04649 str += "<select onkeydown='ConfigurationAPI.handleEditableFieldKeyDown(event)' " +
04650 "onmousedown='ConfigurationAPI.editableFieldMouseIsSelecting_ = true; Debug.log(ConfigurationAPI.editableFieldMouseIsSelecting_);' " +
04651 "onmouseup='ConfigurationAPI.editableFieldMouseIsSelecting_ = false; Debug.log(ConfigurationAPI.editableFieldMouseIsSelecting_); event.stopPropagation();' " +
04652 "onclick='event.stopPropagation();'" +
04653 "style='margin:-8px -2px -2px -1px; height:" + (el.offsetHeight+6) + "px'>";
04654 for(var i=0;i<boolVals.length;++i)
04655 {
04656 str += "<option value='" + boolVals[i] + "'>";
04657 str += boolVals[i];
04658 str += "</option>";
04659 if(boolVals[i] == initVal)
04660 optionIndex = i;
04661 }
04662 str += "</select>";
04663 if(optionIndex == -1) optionIndex = 0;
04664 }
04665 else if(colType == "FixedChoiceData")
04666 {
04667 ConfigurationAPI.editableFieldEditingOldValue_ = el.textContent;
04668 ConfigurationAPI.editableFieldEditingInitValue_ = ConfigurationAPI.editableFieldEditingOldValue_;
04669
04670 var allowFixedChoiceArbitraryEdit = false;
04671 var optionCount = -1;
04672 optionIndex = 0;
04673
04674 str += "<div onkeydown='ConfigurationAPI.handleEditableFieldKeyDown(event)' " +
04675 "onmouseup='event.stopPropagation();' " +
04676 "onclick='event.stopPropagation();' " +
04677 "style='" +
04678 "white-space:nowrap;" +
04679 "margin:-3px -2px -2px -1px;" +
04680 "height:" + (el.offsetHeight+6) + "px'>";
04681
04682 str += "<select onkeydown='ConfigurationAPI.handleEditableFieldKeyDown(event)' " +
04683 "id='fixedChoice-editSelectBox' " +
04684 "onmouseup='event.stopPropagation();' " +
04685 "onclick='event.stopPropagation();' " +
04686 "style='" +
04687 "float:left;" +
04688 "margin:-2px -2px -2px -1px; height:" +
04689 (el.offsetHeight+6) + "px'>";
04690
04691
04692
04693 var vel = document.getElementById("editableFieldNode-FixedChoice-CSV-" +
04694 idString);
04695 var choices = vel.textContent.split(',');
04696
04697 for(var i=0;i<choices.length;++i)
04698 {
04699 if(i==1)
04700 {
04701 if(choices[i].indexOf("arbitraryBool=") == 0)
04702 {
04703
04704 allowFixedChoiceArbitraryEdit =
04705 choices[i][("arbitraryBool=").length] == "1"?
04706 true:false;
04707 Debug.log("allowFixedChoiceArbitraryEdit " + allowFixedChoiceArbitraryEdit);
04708 continue;
04709 }
04710 else
04711 {
04712
04713 ++optionCount;
04714 }
04715 }
04716 else
04717 ++optionCount;
04718
04719
04720 str += "<option>";
04721 str += decodeURIComponent(choices[i]);
04722 str += "</option>";
04723 if(decodeURIComponent(choices[i])
04724 == ConfigurationAPI.editableFieldEditingOldValue_)
04725 optionIndex = optionCount;
04726 }
04727 str += "</select>";
04728
04729 if(allowFixedChoiceArbitraryEdit)
04730 {
04731 var ww = (el.offsetWidth-6);
04732 if(ww < 150) ww = 150;
04733 str += "<input type='text' " +
04734 "id='fixedChoice-editTextBox' " +
04735 "style='display:none;" +
04736 "float:left;" +
04737 "margin:-2px 0 -" + (el.offsetHeight+6) + "px 0;" +
04738 "width:" +
04739 ww + "px; height:" + (el.offsetHeight+6) + "px" +
04740 "'>";
04741 str += "";
04742 str += "</input>";
04743
04744 str += "<div style='display:block;" +
04745 "margin: -2px 0 -7px 14px;" +
04746 "' " +
04747 "class='editableFieldNode-Value-editIcon' id='fixedChoice-editIcon" +
04748 "' " +
04749 "onclick='ConfigurationAPI.handleEditableFieldFixedChoiceEditToggle();' " +
04750 "title='Toggle free-form editing' " +
04751 "></div>";
04752 }
04753 str += "</div>";
04754 }
04755 else if(colType == "BitMap")
04756 {
04757 Debug.log("Handling bitmap select");
04758
04759 ConfigurationAPI.editableFieldEditingOldValue_ = el.textContent;
04760
04761
04762 ConfigurationAPI.bitMapDialog(
04763
04764 "Target Field: "" +
04765 fieldName_ + """,
04766 document.getElementById("editableFieldNode-BitMap-Params-" +
04767 idString).textContent.split(';'),
04768 ConfigurationAPI.editableFieldEditingOldValue_,
04769 function(val)
04770 {
04771 Debug.log("yes " + val);
04772 el.innerHTML = "";
04773 el.appendChild(document.createTextNode(val));
04774 ConfigurationAPI.editableFieldEditingCell_ = el;
04775
04776 type += "-bitmap";
04777 editTreeNodeOK();
04778
04779 },
04780 function()
04781 {
04782
04783 Debug.log("cancel bitmap");
04784 ConfigurationAPI.editableFieldEditingCell_ = 0;
04785 });
04786 return true;
04787 }
04788 else if(colType == "MultilineData")
04789 {
04790 ConfigurationAPI.editableFieldEditingOldValue_ = el.textContent;
04791 ConfigurationAPI.editableFieldEditingInitValue_ = ConfigurationAPI.editableFieldEditingOldValue_;
04792
04793 str += "<textarea rows='4' onkeydown='ConfigurationAPI.handleEditableFieldKeyDown(event)' cols='50' style='font-size: 14px; " +
04794 "margin:-8px -2px -2px -1px;width:" +
04795 (el.offsetWidth-6) + "px; height:" + (el.offsetHeight-8) + "px' ";
04796 str += " onmousedown='ConfigurationAPI.editableFieldMouseIsSelecting_ = true; Debug.log(ConfigurationAPI.editableFieldMouseIsSelecting_);' " +
04797 "onmouseup='ConfigurationAPI.editableFieldMouseIsSelecting_ = false; Debug.log(ConfigurationAPI.editableFieldMouseIsSelecting_);event.stopPropagation();' " +
04798 "onclick='event.stopPropagation();'" +
04799 ">";
04800 str += ConfigurationAPI.editableFieldEditingOldValue_;
04801 str += "</textarea>";
04802 }
04803 else
04804 {
04805 if(colType == "GroupID")
04806 type += "-groupid";
04807
04808 ConfigurationAPI.editableFieldEditingOldValue_ = el.textContent;
04809 ConfigurationAPI.editableFieldEditingInitValue_ = ConfigurationAPI.editableFieldEditingOldValue_;
04810
04811 var ow = el.offsetWidth+6;
04812 if(ow < 150)
04813 ow = 150;
04814 str += "<input type='text' onkeydown='ConfigurationAPI.handleEditableFieldKeyDown(event)' style='margin:-8px -2px -2px -1px;width:" +
04815 (ow) + "px; height:" + (el.offsetHeight>20?el.offsetHeight:20) + "px' value='";
04816 str += ConfigurationAPI.editableFieldEditingOldValue_;
04817 str += "' onmousedown='ConfigurationAPI.editableFieldMouseIsSelecting_ = true; Debug.log(ConfigurationAPI.editableFieldMouseIsSelecting_);' " +
04818 "onmouseup='ConfigurationAPI.editableFieldMouseIsSelecting_ = false; Debug.log(ConfigurationAPI.editableFieldMouseIsSelecting_);event.stopPropagation();' " +
04819 "onclick='event.stopPropagation();'" +
04820 ">";
04821 }
04822
04823
04824 str += ConfigurationAPI._OK_CANCEL_DIALOG_STR;
04825
04826 el.innerHTML = str;
04827
04828
04829 if(colType == "YesNo" ||
04830 colType == "TrueFalse" ||
04831 colType == "OnOff")
04832 {
04833 el.getElementsByTagName("select")[0].selectedIndex = optionIndex;
04834 el.getElementsByTagName("select")[0].focus();
04835 }
04836 else if(colType == "FixedChoiceData")
04837 {
04838 el.getElementsByTagName("select")[0].selectedIndex = optionIndex;
04839 el.getElementsByTagName("select")[0].focus();
04840 }
04841 else if(colType == "MultilineData")
04842 ConfigurationAPI.setCaretPosition(el.getElementsByTagName("textarea")[0],0,ConfigurationAPI.editableFieldEditingOldValue_.length);
04843 else
04844 ConfigurationAPI.setCaretPosition(el.getElementsByTagName("input")[0],0,ConfigurationAPI.editableFieldEditingOldValue_.length);
04845
04846
04847
04848 ConfigurationAPI.editableFieldEditingCell_ = el;
04849 ConfigurationAPI.editableFieldEditingNodeType_ = type;
04850 }
04851 }
04852 else
04853 {
04854 Debug.log("This should be impossible - tell a developer how you got here!", Debug.HIGH_PRIORITY);
04855 return;
04856 }
04857 }
04858 else
04859 {
04860 if(type == "value")
04861 {
04862
04863 Debug.log("Toggling selection of target field " + idString);
04864
04865
04866 var vel;
04867 if(ConfigurationAPI.editableFieldSelectedIdString_ &&
04868 (vel = document.getElementById("editableFieldNode-Value-" +
04869 ConfigurationAPI.editableFieldSelectedIdString_)))
04870 vel.style.backgroundColor = "transparent";
04871
04872
04873 vel = document.getElementById("editableFieldNode-Value-" +
04874 idString);
04875 if(ConfigurationAPI.editableFieldSelectedIdString_ == idString)
04876 {
04877
04878
04879 ConfigurationAPI.editableFieldSelectedIdString_ = undefined;
04880 return;
04881 }
04882 vel.style.backgroundColor = ConfigurationAPI.editableField_SELECTED_COLOR_;
04883 ConfigurationAPI.editableFieldSelectedIdString_ = idString;
04884 }
04885 else
04886 {
04887 Debug.log("This should be impossible - tell a developer how you got here!", Debug.HIGH_PRIORITY);
04888 return;
04889 }
04890 }
04891 }
04892
04893
04894
04895
04896
04897
04898 ConfigurationAPI.getSelectedEditableFieldIndex = function()
04899 {
04900 if(!ConfigurationAPI.editableFieldSelectedIdString_)
04901 return -1;
04902
04903 var idStr = ConfigurationAPI.editableFieldSelectedIdString_;
04904 return idStr.split('-')[1];
04905 }
04906
04907
04908
04909
04910 ConfigurationAPI.handleEditableFieldHover = function(depth,uid,event)
04911 {
04912 var idString = depth + "-" + uid;
04913
04914
04915
04916 event.stopPropagation();
04917 DesktopContent.mouseMove(event);
04918
04919
04920 if(ConfigurationAPI.editableFieldEditingCell_) return;
04921
04922 var el = document.getElementById("editableFieldNode-Value-editIcon-" + idString);
04923 if(ConfigurationAPI.editableFieldHoveringCell_ == el) return;
04924
04925 if(ConfigurationAPI.editableFieldHoveringCell_)
04926 {
04927
04928 bodyMouseMoveHandler();
04929 }
04930
04931
04932 ConfigurationAPI.editableFieldHoveringIdString_ = idString;
04933 ConfigurationAPI.editableFieldHoveringCell_ = el;
04934 ConfigurationAPI.editableFieldHoveringCell_.style.display = "block";
04935 var vel = document.getElementById("editableFieldNode-Value-" +
04936 ConfigurationAPI.editableFieldHoveringIdString_);
04937 vel.style.backgroundColor = "rgb(218, 194, 194)";
04938 }
04939
04940
04941
04942 ConfigurationAPI.handleEditableFieldFixedChoiceEditToggle = function()
04943 {
04944 Debug.log("handleEditableFieldFixedChoiceEditToggle");
04945
04946 var sel = document.getElementById("fixedChoice-editSelectBox");
04947 var tel = document.getElementById("fixedChoice-editTextBox");
04948
04949 Debug.log("sel.style.display " + sel.style.display);
04950 if(sel.style.display == "none")
04951 {
04952 sel.style.display = "block";
04953 tel.style.display = "none";
04954 }
04955 else
04956 {
04957 tel.style.width = (sel.offsetWidth-2) + "px";
04958 sel.style.display = "none";
04959 tel.style.display = "block";
04960 ConfigurationAPI.setCaretPosition(tel,0,tel.value.length);
04961 }
04962 }
04963
04964
04965
04966 ConfigurationAPI.handleEditableFieldBodyMouseMove = function(e)
04967 {
04968 if(ConfigurationAPI.editableFieldHoveringCell_)
04969 {
04970
04971 ConfigurationAPI.editableFieldHoveringCell_.style.display = "none";
04972 ConfigurationAPI.editableFieldHoveringCell_ = 0;
04973
04974 var vel = document.getElementById("editableFieldNode-Value-" +
04975 ConfigurationAPI.editableFieldHoveringIdString_);
04976 if(vel)
04977 {
04978 if(ConfigurationAPI.editableFieldHoveringIdString_ ==
04979 ConfigurationAPI.editableFieldSelectedIdString_)
04980 vel.style.backgroundColor = ConfigurationAPI.editableField_SELECTED_COLOR_;
04981 else
04982 vel.style.backgroundColor = "transparent";
04983 }
04984 }
04985 }
04986
04987
04988
04989
04990 ConfigurationAPI.handleEditableFieldKeyDown = function(e,keyEl)
04991 {
04992 var TABKEY = 9;
04993 var ENTERKEY = 13;
04994 var UPKEY = 38;
04995 var DNKEY = 40;
04996 var ESCKEY = 27;
04997
04998
04999 var shiftIsDown;
05000 if (window.event)
05001 {
05002 key = window.event.keyCode;
05003 shiftIsDown = !!window.event.shiftKey;
05004 }
05005 else
05006 {
05007 key = e.which;
05008 shiftIsDown = !!e.shiftKey;
05009 }
05010
05011
05012
05013
05014 if(!shiftIsDown)
05015 {
05016 var tel;
05017 if(ConfigurationAPI.editableFieldEditingCell_ &&
05018 (tel = ConfigurationAPI.editableFieldEditingCell_.getElementsByTagName("textarea")).length)
05019 {
05020 tel = tel[0];
05021
05022 if(e.keyCode == TABKEY)
05023 {
05024 Debug.log("tab.");
05025 if(e.preventDefault)
05026 e.preventDefault();
05027
05028 var i = tel.selectionStart;
05029 var j = tel.selectionEnd;
05030 tel.value = tel.value.substr(0,i) +
05031 '\t' + tel.value.substr(j);
05032 tel.selectionStart = tel.selectionEnd = j+1;
05033 }
05034 return false;
05035 }
05036 }
05037
05038
05039
05040
05041 if(e.keyCode == TABKEY || e.keyCode == ENTERKEY ||
05042 e.keyCode == UPKEY || e.keyCode == DNKEY)
05043 {
05044
05045 if(e.preventDefault)
05046 e.preventDefault();
05047
05048
05049 var idString = ConfigurationAPI.editableFieldEditingIdString_;
05050
05051 ConfigurationAPI.handleEditableFieldEditOK();
05052
05053
05054
05055
05056
05057
05058
05059 if(e.keyCode == ENTERKEY)
05060 return false;
05061
05062 var depth = idString.split('-')[0];
05063 var uid = idString.split('-')[1];
05064
05065 if((!shiftIsDown && e.keyCode == TABKEY) || e.keyCode == DNKEY)
05066 ++uid;
05067 else if((shiftIsDown && e.keyCode == TABKEY) || e.keyCode == UPKEY)
05068 --uid;
05069 if(uid < 0) return false;
05070
05071
05072 ConfigurationAPI.handleEditableFieldClick(depth,uid,1,"value");
05073 Debug.log("new uid=" + uid);
05074
05075 return false;
05076 }
05077 else if(e.keyCode == ESCKEY)
05078 {
05079 if(e.preventDefault)
05080 e.preventDefault();
05081 ConfigurationAPI.handleEditableFieldEditCancel();
05082 return false;
05083 }
05084 else if((e.keyCode >= 48 && e.keyCode <= 57) ||
05085 (e.keyCode >= 96 && e.keyCode <= 105))
05086 {
05087
05088 var sel;
05089 if((sel = ConfigurationAPI.editableFieldEditingCell_.getElementsByTagName("select")).length)
05090 {
05091 if(keyEl)
05092 sel = keyEl;
05093 else
05094 sel = sel[sel.length-1];
05095
05096
05097 var selNum;
05098 if(e.keyCode >= 96)
05099 selNum = e.keyCode - 96;
05100 else
05101 selNum = e.keyCode - 48;
05102
05103 sel.selectedIndex = selNum % (sel.options.length);
05104 sel.focus();
05105
05106 Debug.log("number select =" + sel.selectedIndex);
05107 if(sel.onchange)
05108 sel.onchange();
05109 }
05110 }
05111 }
05112
05113
05114
05115
05116 ConfigurationAPI.handleEditableFieldEditCancel = function()
05117 {
05118 if(!ConfigurationAPI.editableFieldEditingCell_) return;
05119 Debug.log("handleEditableFieldEditCancel type " + ConfigurationAPI.editableFieldEditingNodeType_);
05120
05121 if(ConfigurationAPI.editableFieldEditingNodeType_ == "value-bool")
05122 {
05123
05124 ConfigurationAPI.editableFieldEditingCell_.innerHTML = ConfigurationAPI.editableFieldEditingOldValue_;
05125 }
05126 else
05127 {
05128 ConfigurationAPI.editableFieldEditingCell_.innerHTML = "";
05129 ConfigurationAPI.editableFieldEditingCell_.appendChild(
05130 document.createTextNode(ConfigurationAPI.editableFieldEditingOldValue_));
05131 }
05132
05133 ConfigurationAPI.editableFieldEditingCell_ = 0;
05134 }
05135
05136
05137
05138
05139 ConfigurationAPI.handleEditableFieldEditOK = function()
05140 {
05141 if(!ConfigurationAPI.editableFieldEditingCell_) return;
05142 Debug.log("handleEditableFieldEditOK type " + ConfigurationAPI.editableFieldEditingNodeType_);
05143
05144
05145 var el = ConfigurationAPI.editableFieldEditingCell_;
05146 var type = ConfigurationAPI.editableFieldEditingNodeType_;
05147
05149
05150 function localEditTreeNodeOKRequestsComplete(newValue)
05151 {
05152
05153 el.innerHTML = "";
05154
05155
05156 if(type == "value" ||
05157 type == "value-bitmap")
05158 {
05159
05160
05161
05162
05163 el.appendChild(document.createTextNode(decodeURIComponent(newValue)));
05164
05165 }
05166 else if(type == "value-bool")
05167 {
05168 var str = "";
05169
05170
05171 str += "<div style='float:left'>";
05172 str += newValue;
05173 str += "</div>";
05174
05175 var color = (newValue == "On" || newValue == "Yes" || newValue == "True")?
05176 "rgb(16, 204, 16)":"rgb(255, 0, 0);";
05177 str += "<div style='width:10px;height:10px;" +
05178 "background-color:" + color + ";" +
05179 "float: left;" +
05180 "border-radius: 7px;" +
05181 "border: 2px solid white;" +
05182 "margin: 2px 0 0 6px;" +
05183 "'></div>";
05184 el.innerHTML = str;
05185 }
05186 else if(type == "value-groupid")
05187 {
05188 el.appendChild(document.createTextNode(newValue));
05189 }
05190 else
05191 {
05192 Debug.log("Unrecognizd tree edit type! Should be impossible!",Debug.HIGH_PRIORITY);
05193 ConfigurationAPI.handleEditableFieldEditCancel(); return;
05194 }
05195
05196
05197 ConfigurationAPI.editableFieldEditingCell_ = 0;
05198 }
05200
05201
05202 if(
05203 type == "value" ||
05204 type == "value-bool" ||
05205 type == "value-bitmap" ||
05206 type == "value-groupid")
05207
05208 {
05209 var newValue;
05210
05211 if(type == "value-bool")
05212 {
05213 var sel = el.getElementsByTagName("select")[0];
05214 newValue = sel.options[sel.selectedIndex].value;
05215 }
05216 else if(type == "value-bitmap")
05217 {
05218 newValue = encodeURIComponent(el.textContent);
05219 }
05220 else
05221 {
05222 var sel;
05223 if((sel = el.getElementsByTagName("textarea")).length)
05224 newValue = sel[0].value;
05225 else if((sel = el.getElementsByTagName("select")).length)
05226 {
05227
05228 if(sel[0].style.display == "none")
05229 {
05230
05231
05232 newValue = el.getElementsByTagName("input")[0].value;
05233 }
05234 else
05235 newValue = sel[0].options[sel[0].selectedIndex].value;
05236 }
05237 else
05238 newValue = el.getElementsByTagName("input")[0].value;
05239
05240 newValue = encodeURIComponent(newValue.trim());
05241 }
05242
05243 Debug.log("CfgGUI editTreeNodeOK editing " + type + " node = " +
05244 newValue);
05245
05246 if(ConfigurationAPI.editableFieldEditingInitValue_ == newValue)
05247 {
05248 Debug.log("No change. Do nothing.");
05249 ConfigurationAPI.handleEditableFieldEditCancel();
05250 return;
05251 }
05252
05253
05254
05255
05256
05257 localEditTreeNodeOKRequestsComplete(newValue);
05258
05259 }
05260 else
05261 {
05262 Debug.log("Unrecognizd tree edit type! Should be impossible!",Debug.HIGH_PRIORITY);
05263 editCellCancel(); return;
05264 }
05265 }
05266
05267
05268
05269
05270 ConfigurationAPI.hasClass = function(ele,cls)
05271 {
05272 return !!ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
05273 }
05274
05275
05276
05277 ConfigurationAPI.addClass = function(ele,cls)
05278 {
05279 if (!ConfigurationAPI.hasClass(ele,cls)) ele.className += " "+cls;
05280 }
05281
05282
05283
05284 ConfigurationAPI.removeClass = function(ele,cls)
05285 {
05286 if (ConfigurationAPI.hasClass(ele,cls))
05287 {
05288 var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
05289 ele.className=ele.className.replace(reg,'');
05290 }
05291 }
05292
05293
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304
05305
05306
05307
05308
05309 ConfigurationAPI.addSubsetRecords = function(subsetBasePath,
05310 recordArr,responseHandler,modifiedTablesIn,silenceErrors)
05311 {
05312 var modifiedTablesListStr = "";
05313 for(var i=0;modifiedTablesIn && i<modifiedTablesIn.length;++i)
05314 {
05315 if(i) modifiedTablesListStr += ",";
05316 modifiedTablesListStr += modifiedTablesIn[i].tableName + "," +
05317 modifiedTablesIn[i].tableVersion;
05318 }
05319
05320 var recordListStr = "";
05321 if(Array.isArray(recordArr))
05322 for(var i=0;i<recordArr.length;++i)
05323 {
05324 if(i) recordListStr += ",";
05325 recordListStr += encodeURIComponent(recordArr[i]);
05326 }
05327 else
05328 recordListStr = encodeURIComponent(recordArr);
05329
05330 DesktopContent.XMLHttpRequest("Request?RequestType=addTreeNodeRecords" +
05331 "&configGroup=" +
05332 "&configGroupKey=-1",
05333 "startPath=/" + subsetBasePath +
05334 "&recordList=" + recordListStr +
05335 "&modifiedTables=" + modifiedTablesListStr,
05336 function(req)
05337 {
05338 var modifiedTables = [];
05339
05340 var err = DesktopContent.getXMLValue(req,"Error");
05341 if(err)
05342 {
05343 if(!silenceErrors)
05344 Debug.log(err,Debug.HIGH_PRIORITY);
05345 responseHandler(modifiedTables,err);
05346 return;
05347 }
05348
05349
05350
05351
05352 var tableNames = req.responseXML.getElementsByTagName("NewActiveTableName");
05353 var tableVersions = req.responseXML.getElementsByTagName("NewActiveTableVersion");
05354 var tableComments = req.responseXML.getElementsByTagName("NewActiveTableComment");
05355 var tableVersion;
05356
05357
05358 for(var i=0;i<tableNames.length;++i)
05359 {
05360 tableVersion = DesktopContent.getXMLValue(tableVersions[i])|0;
05361 if(tableVersion >= -1) continue;
05362 var obj = {};
05363 obj.tableName = DesktopContent.getXMLValue(tableNames[i]);
05364 obj.tableVersion = DesktopContent.getXMLValue(tableVersions[i]);
05365 obj.tableComment = DesktopContent.getXMLValue(tableComments[i]);
05366 modifiedTables.push(obj);
05367 }
05368 responseHandler(modifiedTables);
05369
05370 },
05371 0,
05372 0,true);
05373
05374 }
05375
05376
05377
05378
05379
05380
05381
05382
05383
05384
05385
05386
05387
05388
05389
05390
05391
05392 ConfigurationAPI.deleteSubsetRecords = function(subsetBasePath,
05393 recordArr,responseHandler,modifiedTablesIn,silenceErrors)
05394 {
05395 var modifiedTablesListStr = "";
05396 for(var i=0;modifiedTablesIn && i<modifiedTablesIn.length;++i)
05397 {
05398 if(i) modifiedTablesListStr += ",";
05399 modifiedTablesListStr += modifiedTablesIn[i].tableName + "," +
05400 modifiedTablesIn[i].tableVersion;
05401 }
05402
05403 var recordListStr = "";
05404 var recordCount = 1;
05405 if(Array.isArray(recordArr))
05406 {
05407 for(var i=0;i<recordArr.length;++i)
05408 {
05409 if(i) recordListStr += ",";
05410 recordListStr += encodeURIComponent(recordArr[i]);
05411 }
05412 recordCount = recordArr.length;
05413 }
05414 else
05415 recordListStr = encodeURIComponent(recordArr);
05416
05417 DesktopContent.XMLHttpRequest("Request?RequestType=deleteTreeNodeRecords" +
05418 "&configGroup=" +
05419 "&configGroupKey=-1",
05420 "startPath=/" + subsetBasePath +
05421 "&recordList=" + recordListStr +
05422 "&modifiedTables=" + modifiedTablesListStr,
05423 function(req)
05424 {
05425
05426 var err = DesktopContent.getXMLValue(req,"Error");
05427 var modifiedTables = [];
05428 if(err)
05429 {
05430 if(!silenceErrors)
05431 Debug.log(err,Debug.HIGH_PRIORITY);
05432 responseHandler(modifiedTables,err);
05433 return;
05434 }
05435
05436
05437
05438
05439 var tableNames = req.responseXML.getElementsByTagName("NewActiveTableName");
05440 var tableVersions = req.responseXML.getElementsByTagName("NewActiveTableVersion");
05441 var tableComments = req.responseXML.getElementsByTagName("NewActiveTableComment");
05442 var tableVersion;
05443
05444
05445 for(var i=0;i<tableNames.length;++i)
05446 {
05447 tableVersion = DesktopContent.getXMLValue(tableVersions[i])|0;
05448 if(tableVersion >= -1) continue;
05449 var obj = {};
05450 obj.tableName = DesktopContent.getXMLValue(tableNames[i]);
05451 obj.tableVersion = DesktopContent.getXMLValue(tableVersions[i]);
05452 obj.tableComment = DesktopContent.getXMLValue(tableComments[i]);
05453 modifiedTables.push(obj);
05454 }
05455 responseHandler(modifiedTables,undefined,subsetBasePath,recordCount);
05456
05457 },
05458 0,
05459 0,true);
05460
05461 }
05462
05463
05464
05465 ConfigurationAPI.incrementName = function(name)
05466 {
05467
05468 for(var i=name.length-1;i>=0;--i)
05469 if(!(name[i] >= '0' && name[i] <= '9'))
05470 break;
05471
05472 var num = (name.substr(i+1)|0) + 1;
05473 name = name.substr(0,i+1);
05474 return name + num;
05475 }
05476
05477
05478
05479 ConfigurationAPI.createNewRecordName = function(startingName,existingArr)
05480 {
05481 var retVal = startingName;
05482 var found,i;
05483 try
05484 {
05485 var apps = existingArr;
05486 do
05487 {
05488 retVal = ConfigurationAPI.incrementName(retVal);
05489 found = false;
05490 for(i=0;i<apps.length;++i)
05491 if(apps[i] == retVal)
05492 {found = true; break;}
05493 } while(found);
05494 Debug.log("createNewRecordName " + retVal);
05495 }
05496 catch(e)
05497 {
05498
05499 return ConfigurationAPI.incrementName(retVal);
05500 }
05501
05502 return retVal;
05503 }
05504
05505
05506
05507
05508
05509
05510
05511
05512
05513
05514
05515
05516
05517
05518
05519
05520
05521
05522
05523
05524