-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathjavascript-console.js
More file actions
2311 lines (1962 loc) · 97.3 KB
/
javascript-console.js
File metadata and controls
2311 lines (1962 loc) · 97.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Fme root namespace.
*
* @namespace Fme
*/
// Ensure Fme root object exists
if (typeof Fme == "undefined" || !Fme)
{
var Fme = {};
}
/**
* Array extension for indexOf if the browser does not support it.
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (obj, fromIndex) {
if (fromIndex == null) {
fromIndex = 0;
} else if (fromIndex < 0) {
fromIndex = Math.max(0, this.length + fromIndex);
}
for (var i = fromIndex, j = this.length; i < j; i++) {
if (this[i] === obj)
return i;
}
return -1;
};
}
if (typeof String.prototype.startsWith != 'function') {
// see below for better implementation!
String.prototype.startsWith = function (str){
return this.indexOf(str) == 0;
};
}
/**
* Admin Console Javascript Console
*
* @namespace Alfresco
* @class Fme.JavascriptConsole
*/
(function()
{
/**
* YUI Library aliases
*/
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Element = YAHOO.util.Element;
/**
* Alfresco Slingshot aliases
*/
var $html = Alfresco.util.encodeHTML,
$hasEventInterest = Alfresco.util.hasEventInterest;
/**
* JavascriptConsole constructor.
*
* @param {String}
* htmlId The HTML id of the parent element
* @return {Fme.JavascriptConsole} The new JavascriptConsole instance
* @constructor
*/
Fme.JavascriptConsole = function(htmlId)
{
this.name = "Fme.JavascriptConsole";
Fme.JavascriptConsole.superclass.constructor.call(this, htmlId);
/* Register this component */
Alfresco.util.ComponentManager.register(this);
/* Load YUI Components */
Alfresco.util.YUILoaderHelper.require(["button", "container", "datasource", "datatable", "paginator", "json", "history", "tabview"], this.onComponentsLoaded, this);
/* Define panel handlers */
var parent = this;
/* File List Panel Handler */
ListPanelHandler = function ListPanelHandler_constructor()
{
ListPanelHandler.superclass.constructor.call(this, "main");
};
YAHOO.extend(ListPanelHandler, Alfresco.ConsolePanelHandler,
{
/**
* Called by the ConsolePanelHandler when this panel shall be loaded
*
* @method onLoad
*/
onLoad: function onLoad()
{
parent.widgets.pathField = Dom.get(parent.id + "-pathField");
parent.widgets.documentField = Dom.get(parent.id + "-documentField");
parent.widgets.nodeField = Dom.get(parent.id + "-nodeRef");
parent.widgets.scriptInput = Dom.get(parent.id + "-jsinput");
parent.widgets.scriptOutput = Dom.get(parent.id + "-jsoutput");
parent.widgets.repoInfoOutput = Dom.get(parent.id + "-repoInfo");
parent.widgets.dumpInfoOutput = Dom.get(parent.id + "-dump");
parent.widgets.jsonOutput= Dom.get(parent.id + "-jsonOutput");
parent.widgets.templateInput = Dom.get(parent.id + "-templateinput");
parent.widgets.templateOutputHtml = Dom.get(parent.id + "-templateoutputhtml");
parent.widgets.templateOutputText = Dom.get(parent.id + "-templateoutputtext");
parent.widgets.config = {
runas : Dom.get(parent.id + "-runas"),
transaction : Dom.get(parent.id + "-transactions"),
urlargs : Dom.get(parent.id + "-urlarguments"),
runlikecrazy : Dom.get(parent.id + "-runlikecrazy")
};
// Buttons
parent.widgets.selectDestinationButton = Alfresco.util.createYUIButton(parent, "selectDestination-button", parent.onSelectDestinationClick);
parent.widgets.executeButton = Alfresco.util.createYUIButton(parent, "execute-button", parent.onExecuteClick);
parent.widgets.refreshButton = Alfresco.util.createYUIButton(parent, "refresh-button", parent.onRefreshServerInfoClick);
// Dom.addClass(parent.widgets.refreshButton, 'refresh-button');
Dom.addClass(parent.widgets.refreshButton._button.parentNode.parentNode, 'refresh-button-env');
}
});
new ListPanelHandler();
return this;
};
YAHOO.extend(Fme.JavascriptConsole, Alfresco.ConsoleTool,
{
clearOutput : function ACJC_clearOutput() {
this.widgets.scriptOutput.innerHTML = "";
this.widgets.templateOutputHtml.innerHTML = "";
this.widgets.templateOutputText.innerHTML = "";
},
template: '<div class="display-element"><span class="display-label">{name}</span><span class="display-field">{value}</span></div>',
appendLineArrayToOutput: function ACJC_appendLineArrayToOutput(lineArray) {
var newLines = "";
for (line in lineArray) {
newLines = newLines + lineArray[line] + "\n";
}
this.setOutputText(newLines);
},
setOutputText : function(text) {
var outputfield = this.widgets.scriptOutput;
outputfield.innerHTML = "";
outputfield.appendChild(document.createTextNode(text));
},
browserSupportsHtml5Storage: function ACJC_browserSupportsHtml5Storage() {
try {
var testString = "LSTEST12345";
localStorage.setItem(testString, testString );
localStorage.removeItem(testString);
return true;
} catch(e) {
return false;
}
},
createMenuButtons: function ACJC_createMenuButtons(listOfScripts) {
this.createThemeMenu();
this.createScriptsLoadMenu(listOfScripts);
this.createScriptsSaveMenu(listOfScripts);
this.createDocsMenu();
this.createDumpDisplayMenu();
this.widgets.exportResultsButton = Alfresco.util.createYUIButton(this,
"exportResults-button", this.exportResultTableAsCSV);
Dom.setStyle(this.widgets.exportResultsButton, "display", "none");
},
createDocsMenu: function ACJC_createDocsMenu(){
if(!this.widgets.docsMenuButton){
var docsMenuItems = [
[ { text : "Mozilla Javascript Reference", url : "https://developer.mozilla.org/en/JavaScript/Reference", target:"_blank"},
{ text : "W3Schools Javascript Reference", url : "http://www.w3schools.com/jsref/default.asp", target:"_blank"},
{ text : "Alfresco 3.4 Javascript API", url : "http://wiki.alfresco.com/wiki/3.4_JavaScript_API", target:"_blank" },
{ text : "Alfresco 3.4 Javascript Services API", url : "http://wiki.alfresco.com/wiki/3.4_JavaScript_Services_API", target:"_blank" },
{ text : "Alfresco 4.0 Javascript API", url : "http://docs.alfresco.com/4.0/topic/com.alfresco.enterprise.doc/references/API-JS-Scripting-API.html", target:"_blank" },
{ text : "Alfresco 4.0 Javascript Services API", url : "http://docs.alfresco.com/4.0/topic/com.alfresco.enterprise.doc/references/API-JS-Services.html", target:"_blank" },
{ text : "Alfresco 4.1 Javascript API", url : "http://docs.alfresco.com/4.1/topic/com.alfresco.enterprise.doc/references/API-JS-Scripting-API.html", target:"_blank" },
{ text : "Alfresco 4.1 Javascript Services API", url : "http://docs.alfresco.com/4.1/topic/com.alfresco.enterprise.doc/references/API-JS-Services.html", target:"_blank" },
{ text : "Alfresco 4.2 Javascript API", url : "http://docs.alfresco.com/4.2/topic/com.alfresco.enterprise.doc/references/API-JS-Scripting-API.html", target:"_blank" },
{ text : "Alfresco 4.2 Javascript Services API", url : "http://docs.alfresco.com/4.2/topic/com.alfresco.enterprise.doc/references/API-JS-Services.html", target:"_blank" },
{ text : "Alfresco 5.0 Javascript Scripting API", url : "http://docs.alfresco.com/5.0/references/API-JS-Scripting-API.html", target:"_blank" },
{ text : "Alfresco 5.0 Javascript Services API", url : "http://docs.alfresco.com/5.0/references/API-JS-Services.html", target:"_blank" },
{ text : "Alfresco 5.0 Javascript Root Objects", url : "http://docs.alfresco.com/5.0/references/API-JS-rootscoped.html", target:"_blank" },
{ text : "Alfresco Javascript Cookbook", url : "http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook", target:"_blank" }
],
[
{ text : "Alfresco Freemarker Template Guide", url : "http://wiki.alfresco.com/wiki/Template_Guide", target:"_blank"},
{ text : "Alfresco Freemarker Template Cookbook", url : "http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook", target:"_blank"},
{ text : "Alfresco 4.0 API Reference", url : "http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-FreeMarker-intro.html", target:"_blank"},
{ text : "Alfresco 4.1 API Reference", url : "http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-FreeMarker-intro.html", target:"_blank"},
{ text : "Alfresco 4.2 API Reference", url : "http://docs.alfresco.com/4.2/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-FreeMarker-intro.html", target:"_blank"},
{ text : "Alfresco 5.0 API Reference", url : "http://docs.alfresco.com/5.0/references/API-FreeMarker-intro.html", target:"_blank"},
{ text : "Freemarker Manual", url : "http://freemarker.sourceforge.net/docs/index.html", target:"_blank"}
],
[
{ text : "Fulltext Search Reference", url : "http://docs.alfresco.com/5.0/concepts/rm-searchsyntax-intro.html", target:"_blank" },
{ text : "Lucene Search Reference", url : "http://wiki.alfresco.com/wiki/Search", target:"_blank" },
{ text : "Alfresco XPath Search", url : "http://wiki.alfresco.com/wiki/Search_Documentation", target:"_blank" }
],
[
{ text : "Webscripts Reference", url : "http://wiki.alfresco.com/wiki/Web_Scripts", target:"_blank" },
{ text : "Webscripts Examples", url : "http://wiki.alfresco.com/wiki/Web_Scripts_Examples", target:"_blank" }
]
];
this.widgets.docsMenuButton = new YAHOO.widget.Button({
id: "docsButton",
name: "docsButton",
label: this.msg("button.docs") + (Alfresco.constants.MENU_ARROW_SYMBOL !== undefined ? (' ' + Alfresco.constants.MENU_ARROW_SYMBOL) : ''),
type: "menu",
menu: docsMenuItems,
container: this.id + "-documentation"
});
var menu = this.widgets.docsMenuButton.getMenu();
menu.cfg.setProperty("zindex", 10);
this.widgets.docsMenuButton.getMenu().setItemGroupTitle("Javascript", 0);
this.widgets.docsMenuButton.getMenu().setItemGroupTitle("Freemarker", 1);
this.widgets.docsMenuButton.getMenu().setItemGroupTitle("Lucene", 2);
this.widgets.docsMenuButton.getMenu().setItemGroupTitle("Webscripts", 3);
}
},
initSubmenuIds: function (entry, suffix) {
if (entry.submenu) {
entry.submenu.id = entry.submenu.id + suffix;
entry.submenu.itemdata.forEach(function (f) {
this.initSubmenuIds(f, suffix);
}.bind(this));
}
},
createScriptsSaveMenu: function(listOfScripts){
var saveMenuItems = [{
text : this.msg("button.save.create.new"),
value : "NEW"
}];
var scripts = JSON.parse(JSON.stringify(listOfScripts));//copy
scripts.forEach(function(e) {
this.initSubmenuIds.call(this, e, "-scriptsave");
}.bind(this));
saveMenuItems.push(scripts);
if(this.widgets.saveMenuButton){
this.widgets.saveMenuButton.getMenu().clearContent();
this.widgets.saveMenuButton.getMenu().addItems(saveMenuItems);
this.widgets.saveMenuButton.getMenu().render(this.id + "-scriptsave");
}else{
this.widgets.saveMenuButton = new YAHOO.widget.Button({
id: "saveButton",
name: "saveButton",
label: this.msg("button.save.script") + (Alfresco.constants.MENU_ARROW_SYMBOL !== undefined ? (' ' + Alfresco.constants.MENU_ARROW_SYMBOL) : ''),
type: "menu",
menu: saveMenuItems,
container: this.id + "-scriptsave"
});
var menu = this.widgets.saveMenuButton.getMenu();
menu.cfg.setProperty("zindex", 10);
menu.subscribe("click", this.onSaveScriptClick, this);
}
},
createScriptsLoadMenu: function(listOfScripts){
var loadMenuItems = [{
text : this.msg("button.load.create.new"),
value : "NEW"
}];
var scripts = JSON.parse(JSON.stringify(listOfScripts));//copy
scripts.forEach(function(e) {
this.initSubmenuIds.call(this, e, "-scriptload");
}.bind(this));
loadMenuItems.push(scripts);
if(this.widgets.loadMenuButton){
this.widgets.loadMenuButton.getMenu().clearContent();
this.widgets.loadMenuButton.getMenu().addItems(loadMenuItems);
this.widgets.loadMenuButton.getMenu().render(this.id + "-scriptload");
}else{
this.widgets.loadMenuButton = new YAHOO.widget.Button({
id: "loadButton",
name: "loadButton",
label: this.msg("button.load.script") + (Alfresco.constants.MENU_ARROW_SYMBOL !== undefined ? (' ' + Alfresco.constants.MENU_ARROW_SYMBOL) : ''),
type: "menu",
menu: loadMenuItems,
container: this.id + "-scriptload"
});
var menu = this.widgets.loadMenuButton.getMenu();
menu.cfg.setProperty("zindex", 10);
menu.subscribe("click", this.onLoadScriptClick, this);
}
},
createThemeMenu: function ACJC_createThemeMenu(){
if(!this.widgets.themeMenuButton){
var themeMenuItems = [ { text : "default", value : "default"},
{ text : "ambiance-mobile", value : "ambiance-mobile"},
{ text : "ambiance", value : "ambiance"},
{ text : "blackboard", value : "blackboard"},
{ text : "cobalt", value : "cobalt"},
{ text : "eclipse", value : "eclipse"},
{ text : "erlang-dark", value : "erlang-dark"},
{ text : "lesser-dark", value : "lesser-dark"},
{ text : "monokai", value : "monokai"},
{ text : "neat", value : "neat"},
{ text : "rubyblue", value : "rubyblue"},
{ text : "solarized", value : "solarized"},
{ text : "twilight", value : "twilight"},
{ text : "vibrant-ink", value : "vibrant-ink"},
{ text : "xq-dark", value : "xq-dark"}
];
this.widgets.themeMenuButton = new YAHOO.widget.Button({
id: "themeButton",
name: "themeButton",
label: this.msg("button.codemirror.theme") + (Alfresco.constants.MENU_ARROW_SYMBOL !== undefined ? (' ' + Alfresco.constants.MENU_ARROW_SYMBOL) : ''),
type: "menu",
menu: themeMenuItems,
container: this.id + "-theme"
});
if(this.browserSupportsHtml5Storage()){
// preselect item
var theme = window.localStorage["javascript.console.codemirror.theme"];
if(theme){
var menuItems = this.widgets.themeMenuButton.getMenu().getItems();
for ( var i = 0; i < menuItems.length; i++) {
var menuItem = menuItems[i];
if(theme==menuItem.cfg.getProperty('text')){
menuItem.cfg.setProperty("checked", true);
}
}
}
}
var menu = this.widgets.themeMenuButton.getMenu();
menu.cfg.setProperty("zindex", 10);
menu.subscribe("click", this.onThemeSelection, this);
}
},
/**
* create the display options menu for dumps
*/
createDumpDisplayMenu: function ACJC_createDumpDisplayMenu(){
if(!this.widgets.dumpDisplayMenu){
var displayMenu = new YAHOO.widget.Menu('nowhere');
displayMenu.addItem({text: "Hide equal values",value:"Differences"});
displayMenu.addItem({text: "Hide different values",value:"highlightDifferences"});
displayMenu.addItem({text: "Hide null values", value:"nullValues"});
this.widgets.dumpDisplayMenu = new YAHOO.widget.Button({
type: "split",
label: "Display options",
name: "dumpDisplayButton",
menu: displayMenu,
container: "splitButtonContainer",
disabled: false
});
this.widgets.dumpDisplayMenu.on("appendTo", function () {
menu = this.getMenu();
menu.subscribe("click", function onMenuClick(sType, oArgs) {
var oMenuItem = oArgs[1];
if (oMenuItem) {
dt.showColumn(dt.getColumn(oMenuItem.value));
menu.removeItem(oMenuItem.index);
refreshButton();
}
});
});
}
},
onEditorKeyEvent : function ACJC_onEditorKeyEvent(i, e) {
// Hook into ctrl-enter
if (e.type=="keyup" && e.keyCode == 13 && (e.ctrlKey || e.metaKey) && !e.altKey) {
e.stop();
i.owner.onExecuteClick(i.owner, e);
}
// Hook into ctrl+/ for Comment/Uncomment
if (e.type=="keydown" && e.keyCode == 55 && (e.ctrlKey || e.metaKey) && !e.altKey) {
e.stop();
var editor = i.owner.widgets.codeMirrorScript;
var code = editor.getSelection();
if (code.substr(0,2) == "//") {
code = code.replace(/^\/\//gm, ""); // add a // before each line
}
else {
code = code.replace(/^/gm, "//"); // remove // comment before
// each line
}
editor.replaceSelection(code);
}
// Hook into ctrl+shift+F for js code format
if (e.type=="keydown" && e.keyCode == 70 && (e.ctrlKey || e.metaKey) && !e.altKey) {
e.stop();
var editor = i.owner.widgets.codeMirrorScript;
editor.setValue(js_beautify(editor.getValue()));
}
},
/**
* Fired by YUI when parent element is available for scripting.
* Component initialisation, including instantiation of YUI widgets and
* event listener binding.
*
* @method onReady
*/
onReady: function ACJC_onReady()
{
// Call super-class onReady() method
Fme.JavascriptConsole.superclass.onReady.call(this);
var self = this;
this.javascriptCommands = new Object();
function passAndHint(cm) {
setTimeout(function() {cm.execCommand("autocomplete");}, 100);
return CodeMirror.Pass;
}
function myHint(cm) {
return CodeMirror.showHint(cm, CodeMirror.ternHint, {async: true});
}
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, myHint);
};
// Attach the CodeMirror highlighting
var uiMirrorScript = new CodeMirrorUI(this.widgets.scriptInput, {imagePath:Alfresco.constants.URL_RESCONTEXT+'fme/components/jsconsole/codemirror-ui/images', searchMode:'no'} ,{
mode : "javascript",
styleActiveLine: true,
showCursorWhenSelecting :true,
// gutters: ["CodeMirror-linenumbers", "CodeMirror-lint-markers"],
// lintWith: function(text){
// return CodeMirror.lint.javascript(text, self.javascriptCommands.globalMap);
// },
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
tabSize: 4,
indentUnit: 4,
indentWithTabs: true,
autofocus :true,
onKeyEvent: this.onEditorKeyEvent,
extraKeys: {
"'.'": passAndHint,
"Ctrl-I": function(cm) { CodeMirror.tern.showType(cm); },
"Ctrl-Space": "autocomplete",
"Ctrl-Enter": function(cm){
cm.owner.onExecuteClick(cm.owner);
}
}
});
this.widgets.codeMirrorScript = uiMirrorScript.getMirrorInstance();
this.widgets.codeMirrorScript.on("cursorActivity", function(cm){
var currentLine = cm.getCursor().line+1;
var column = cm.getCursor().ch;
//var results = CodeMirror.lint.javascript(cm.getDoc().getValue(), self.javascriptCommands.globalMap);
var results =[];
var info = "Line "+currentLine +" \t - Column "+column+" \t - Errors/Warnings " +results.length;
var text = YAHOO.util.Selector.query('.scriptStatusLine', null, true);
text.innerHTML=info;
// CodeMirror.tern.updateArgHints(cm);
});
this.widgets.codeMirrorScript.getInputField().blur();
var uiMirrorTemplate = new CodeMirrorUI(this.widgets.templateInput, {imagePath:Alfresco.constants.URL_RESCONTEXT+'fme/components/jsconsole/codemirror-ui/images', searchMode:'no'} , {
lineNumbers: true,
lineWrapping: true,
mode:"freemarker",
styleActiveLine: true,
highlightSelectionMatches : true,
showCursorWhenSelecting :true,
matchBrackets: true,
showTrailingSpace: true,
onKeyEvent: this.onEditorKeyEvent,
markParen: function(node, ok) {
node.style.backgroundColor = ok ? "#CCF" : "#FCC#";
if(!ok) {
node.style.color = "red";
}
},
unmarkParen: function(node) {
node.style.backgroundColor = "";
node.style.color = "";
},
indentUnit: 4
});
this.widgets.codeMirrorTemplate = uiMirrorTemplate.getMirrorInstance();
function showStatusInfo(cm, statusLineClass){
var currentLine = cm.getCursor().line+1;
var column = cm.getCursor().ch;
var info = "Line "+currentLine +" \t - Column "+column;
var text = YAHOO.util.Selector.query(statusLineClass, null, true);
text.innerHTML=info;
}
this.widgets.codeMirrorTemplate.on("cursorActivity", function(cm){
showStatusInfo(cm, '.templateStatusLine');
});
this.widgets.codeMirrorTemplate.getInputField().blur();
// Attach the CodeMirror highlighting
var uiMirrorJSON = new CodeMirrorUI(this.widgets.jsonOutput, {searchMode:'no', imagePath:Alfresco.constants.URL_RESCONTEXT+'fme/components/jsconsole/codemirror-ui/images'} , {
mode : "application/json",
styleActiveLine: true,
readOnly: true,
showCursorWhenSelecting :true,
highlightSelectionMatches : true,
gutters: ["CodeMirror-lint-markers"],
lintWith: CodeMirror.jsonValidator,
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
onKeyEvent: this.onEditorKeyEvent
});
this.widgets.codeMirrorJSON = uiMirrorJSON.getMirrorInstance();
this.widgets.codeMirrorJSON.on("cursorActivity", function(cm){
showStatusInfo(cm, '.jsonStatusLine');
});
// Store this for use in event
this.widgets.codeMirrorScript.owner = this;
this.widgets.codeMirrorTemplate.owner = this;
this.setupResizableEditor();
this.widgets.inputTabs = new YAHOO.widget.TabView(this.id + "-inputTabs");
this.widgets.outputTabs = new YAHOO.widget.TabView(this.id + "-outputTabs");
// enable correct initialisation when navigating to the json editor
// -> refresh when the tab changes to active.
var jsonView = this.widgets.codeMirrorJSON;
this.widgets.outputTabs.getTab(3).addListener("activeChange", function(event){
if(event.newValue){
YAHOO.lang.later(50, undefined, function(){
jsonView.refresh();
});
};
});
new YAHOO.widget.Tooltip("tooltip-urlargs", {
context: this.widgets.config.urlargs,
text: this.msg("tooltip.urlargs"),
showDelay: 200
});
new YAHOO.widget.Tooltip("tooltip-runas", {
context: this.widgets.config.runas,
text: this.msg("tooltip.runas"),
showDelay: 200
});
var tab0 = this.widgets.inputTabs.getTab(1); // 2nd tab
tab0.addListener('click', function handleClick(e) {
self.widgets.codeMirrorTemplate.refresh();
});
this.widgets.statsModule = new YAHOO.widget.Module("perfPanel", {visible:true, draggable:false, close:false } );
var noExecEl = YAHOO.lang.substitute(this.template, {
name:this.msg("label.stats.no.execution"),
value:''
});
this.widgets.statsModule.setBody(noExecEl);
this.widgets.statsModule.render(this.id + "-executionStats");
var stats = Dom.get(this.id + "-executionStatsSimple");
myTooltip = new YAHOO.widget.Tooltip("statsTooltip", {
context: stats,
text: "Please click for more details.",
showDelay: 500
});
YAHOO.Bubbling.on("folderSelected", this.onDestinationSelected, this);
// Store and Restore script content to and from local storage
if (self.browserSupportsHtml5Storage()) {
window.onbeforeunload = function(e) {
self.widgets.codeMirrorScript.save();
window.localStorage["javascript.console.script"] = self.widgets.scriptInput.value;
self.widgets.codeMirrorTemplate.save();
window.localStorage["javascript.console.template"] = self.widgets.templateInput.value;
if(self.widgets.config.runas){
window.localStorage["javascript.console.config.runas"] = self.widgets.config.runas.value;
}
if( self.widgets.config.transactions){
window.localStorage["javascript.console.config.transactions"] = self.widgets.config.transactions.value;
}
if( self.widgets.config.urlarguments){
window.localStorage["javascript.console.config.urlarguments"] = self.widgets.config.urlarguments.value;
}
if( self.widgets.config.runlikecrazy){
window.localStorage["javascript.console.config.runlikecrazy"] = self.widgets.config.runlikecrazy.value;
}
window.localStorage["javascript.console.codemirror.theme"] = self.widgets.codeMirrorScript.options.theme;
};
if (window.localStorage["javascript.console.config.runas"]) {
self.widgets.config.runas.value = window.localStorage["javascript.console.config.runas"];
}
if (window.localStorage["javascript.console.config.transactions"]) {
self.widgets.config.transactions.value = window.localStorage["javascript.console.config.transactions"];
}
if (window.localStorage["javascript.console.config.urlarguments"]) {
self.widgets.config.urlarguments.value = window.localStorage["javascript.console.config.urlarguments"];
}
if (window.localStorage["javascript.console.config.runlikecrazy"]) {
self.widgets.config.runlikecrazy.value = window.localStorage["javascript.console.config.runlikecrazy"];
}
if (window.localStorage["javascript.console.script"]) {
var javascriptText = window.localStorage["javascript.console.script"];
this.widgets.codeMirrorScript.setValue(javascriptText);
}
if (window.localStorage["javascript.console.template"]) {
this.widgets.codeMirrorTemplate.setValue(window.localStorage["javascript.console.template"]);
}
if (window.localStorage["javascript.console.codemirror.theme"]) {
var theme = window.localStorage["javascript.console.codemirror.theme"];
this.widgets.codeMirrorScript.setOption('theme',theme);
this.widgets.codeMirrorTemplate.setOption('theme',theme);
}
}
this.loadRepoScriptList();
// Read Javascript API Commands for code completion
Alfresco.util.Ajax.request(
{
url: Alfresco.constants.PROXY_URI + "de/fme/jsconsole/apicommands.json",
method: Alfresco.util.Ajax.GET,
requestContentType: Alfresco.util.Ajax.JSON,
successCallback: {
fn: function(res) {
this.javascriptCommands = res.json;
this.javascriptCommands.globalMap={};
for ( var i = 0; i < this.javascriptCommands.global.length; i++) {
this.javascriptCommands.globalMap[this.javascriptCommands.global[i]]=false;
}
},
scope: this
}
});
/**
* maps the alfresco specific type to a tern compatible type
*/
function getTernType(propertyDataType, isMultiValued){
if(propertyDataType==="d:text"){
if(isMultiValued){
type="[string]";
}else{
type="string";
}
}else if(propertyDataType ==="d:noderef"){
if(isMultiValued){
type ="[ScriptNode]";
}else{
type ="ScriptNode";
}
}else if(propertyDataType ==="d:category"){
if(isMultiValued){
type ="[CategoryNode]";
}else{
type ="CategoryNode";
}
}else if (propertyDataType === "d:boolean"){
if(isMultiValued){
type ="[bool]";
}else{
type ="bool";
}
}else if (propertyDataType === "d:date"||propertyDataType === "d:datetime"){
if(isMultiValued){
type ="[Date.prototype]";
}else{
type ="Date.prototype";
}
}else if (propertyDataType === "d:int"||propertyDataType === "d:float"||propertyDataType === "d:double"||propertyDataType === "d:long"){
if(isMultiValued){
type ="[number]";
}else{
type ="number";
}
}else if (propertyDataType === "d:content"){
if(isMultiValued){
type ="[ScriptContent]";
}else{
type ="ScriptContent";
}
}else{
if(isMultiValued){
type="[?]";
}else{
type="?";
}
}
return type;
}
// Read the Alfresco Data Dictionary for code completion (types and
// aspects)
Alfresco.util.Ajax.request(
{
url: Alfresco.constants.PROXY_URI + "api/classes",
method: Alfresco.util.Ajax.GET,
requestContentType: Alfresco.util.Ajax.JSON,
successCallback: {
fn: function(res) {
this.dictionary = res.json;
var templates= generateTemplates(this.dictionary);
var templateDefinitions = {
"name" : "alfresco_datatypes",
"context" : "javascript",
"templates" : templates
};
CodeMirror.templatesHint.addTemplates(templateDefinitions);
},
scope: this
}
});
/**
* generates the templates for properties, types and aspects. They
* are available for autocompletion in the codemirror editor.
*/
var generateTemplates = function generateTemplates(dictionary){
var templates = new Array();
var propertyNames = new Array();
var assocNames = new Array();
var ternProperties = new Object();
for(var t in dictionary) {
var type= dictionary[t].isAspect ? "ASPECT" : "TYPE";
var name = dictionary[t].name;
var template =name.replace(/:/g,'_');
var templDescription ;
var title= dictionary[t].title;
templDescription = "title:\t\t\t\t" + title;
var description= dictionary[t].title;
templDescription+="\ndescription:\t\t"+description;
var isContainer= dictionary[t].isContainer;
templDescription+="\nisContainer:\t\t"+isContainer;
var parent = dictionary[t].parent;
if(parent){
templDescription += "\nparent:\t\t\t"+parent.name +"("+parent.title+")";
}
var defaultAspects = dictionary[t].defaultAspects;
if(defaultAspects){
templDescription += "\ndefaultAspects:\n";
for(var aspect in dictionary[t].defaultAspects) {
var aspectName= dictionary[t].defaultAspects[aspect].name;
var aspectTitle= dictionary[t].defaultAspects[aspect].title;
templDescription+="\t\t\t\t"+aspectName + "("+aspectTitle+")\n";
}
}
var properties = dictionary[t].properties;
if(properties){
templDescription += "\nproperties:\n";
for(var property in dictionary[t].properties) {
var propertyName= dictionary[t].properties[property].name;
var propertyDataType= dictionary[t].properties[property].dataType;
templDescription+="\t\t\t\t"+propertyName +" ("+propertyDataType+")\n";
var propertyInfo = dictionary[t].properties[property];
var propDescription ="title:\t\t\t\t"+propertyInfo.title+"\ndescription:\t\t\t"+propertyInfo.description+"\ndataType:\t\t\t"
+propertyInfo.dataType+"\ndefaultValue:\t\t"+propertyInfo.defaultValue+"\nmultivalued:\t\t"
+propertyInfo.multiValued+"\nmandatory:\t\t\t"+propertyInfo.mandatory+"\nenforced:\t\t\t"
+propertyInfo.enforced+"\nprotected:\t\t\t"+propertyInfo["protected"]+"\nindexed:\t\t\t"+propertyInfo.indexed;
var propertyTemplate = {
"name" : "PROP_"+propertyInfo.name.replace(/:/g,'_').toUpperCase(),
"description" : propDescription,
"template" : propertyName,
"className": "CodeMirror-hint-alfresco"
}
if(propertyNames.indexOf(propertyName)==-1){
templates.push(propertyTemplate);
propertyNames.push(propertyName);
var type = getTernType(propertyDataType, propertyInfo.multiValued);
ternProperties[propertyName] ={"!type":type,"!doc":propDescription};
if(propertyName.startsWith("cm:")){
ternProperties[propertyName.replace(/^cm\:/,"")] ={"!type":type,"!doc":propDescription};
};
}
}
}
var associations = dictionary[t].associations;
if(associations){
templDescription += "\nassociations:\n";
for(var association in dictionary[t].associations) {
var assocName= dictionary[t].associations[association].name;
var assocTitle= dictionary[t].associations[association].title;
templDescription+="\t\t\t\t"+assocName + "("+assocTitle+")\n";
var assocInfo = dictionary[t].associations[assocName];
var sourceClass= dictionary[t].associations[assocName].source["class"];
var sourceMandatory= dictionary[t].associations[assocName].source["mandatory"];
var sourceMany= dictionary[t].associations[assocName].source["many"];
var targetClass= dictionary[t].associations[assocName].target["class"];
var targetMandatory= dictionary[t].associations[assocName].target["mandatory"];
var targetMany= dictionary[t].associations[assocName].target["many"];
var assocDescription ="isChildAssoc:\t\tfalse\ntitle:\t\t\t\t"+assocInfo.title+"\nsource:\t\t\t"+
"\n\tclass:\t\t"+sourceClass+"\n\tmandatory:\t"
+sourceMandatory+"\n\tmany:\t\t"+sourceMany+"\ntarget:\t\t"+
"\n\tclass:\t\t"+targetClass+"\n\tmandatory:\t"
+targetMandatory+"\n\tmany:\t\t"+targetMany;
var assocTemplate = {
"name" : "ASSOC_"+assocInfo.name.replace(/:/g,'_').toUpperCase(),
"description" : assocDescription,
"template" : assocName,
"className": "CodeMirror-hint-alfresco"
}
if(assocNames.indexOf(assocName)==-1){
templates.push(assocTemplate);
assocNames.push(assocName);
}
}
}
var childAssocs= dictionary[t].childassociations;
if(childAssocs){
templDescription += "\nchildassociations:\n";
for(var association in dictionary[t].childassociations) {
var assocName= dictionary[t].childassociations[association].name;
var assocTitle= dictionary[t].childassociations[association].title;
templDescription+="\t\t\t\t"+assocName + "("+assocTitle+")\n";
var assocInfo = dictionary[t].childassociations[assocName];
var sourceClass= dictionary[t].childassociations[assocName].source["class"];
var sourceMandatory= dictionary[t].childassociations[assocName].source["mandatory"];
var sourceMany= dictionary[t].childassociations[assocName].source["many"];
var targetClass= dictionary[t].childassociations[assocName].target["class"];
var targetMandatory= dictionary[t].childassociations[assocName].target["mandatory"];
var targetMany= dictionary[t].childassociations[assocName].target["many"];
var assocDescription ="isChildAssoc:\t\ttrue\ntitle:\t\t\t\t"+assocInfo.title+"\nsource:\t\t"+
"\n\tclass:\t\t"+sourceClass+"\n\tmandatory:\t"
+sourceMandatory+"\n\tmany:\t\t"+sourceMany+"\ntarget:\t\t\t"+
"\n\tclass:\t\t"+targetClass+"\n\tmandatory:\t"
+targetMandatory+"\n\tmany:\t\t"+targetMany;
var assocTemplate = {
"name" : "ASSOC_"+assocInfo.name.replace(/:/g,'_').toUpperCase(),
"description" : assocDescription,
"template" : assocName,
"className": "CodeMirror-hint-alfresco"
}
if(assocNames.indexOf(assocName)==-1){
templates.push(assocTemplate);
assocNames.push(assocName);
}
}
}
var templateName = type+"_"+template;
var template = {
"name" : templateName.toUpperCase(),
"description" : templDescription,
"template" : name,
"className": "CodeMirror-hint-alfresco"
}
templates.push(template);
};
var propertyMap = {
"!type": "fn()",
"prototype": ternProperties,
};
CodeMirror.tern.getDef()[1].Properties=propertyMap;
templates.sort(function(a,b){
var nameA=a.name.toLowerCase(), nameB=b.name.toLowerCase()
if (nameA < nameB) // sort string ascending
return -1
if (nameA > nameB)
return 1
return 0 // default return value (no sorting)
});
return templates;
}
// Read the Alfresco workflow definitions for code completion (types and
// aspects)
Alfresco.util.Ajax.request(
{
url: Alfresco.constants.PROXY_URI + "api/workflow-definitions",
method: Alfresco.util.Ajax.GET,
requestContentType: Alfresco.util.Ajax.JSON,
successCallback: {
fn: function(res) {
this.definitions= res.json.data;
var templates= generateWorkflowDefinitionTemplates(this.definitions);
var templateDefinitions = {
"name" : "alfresco_wfl_templates",
"context" : "javascript",
"templates" : templates
};
CodeMirror.templatesHint.addTemplates(templateDefinitions);
},
scope: this
}
});
/**
* generates the templates for properties, types and aspects. They are
* available for autocompletion in the codemirror editor.
*/
var generateWorkflowDefinitionTemplates = function generateWorkflowDefinitionTemplates(definitions){
var templates = new Array();
for(var t in definitions) {
var type= definitions[t].name.startsWith("activiti") ? "ACTIVITI" : "JBPM";
var name = definitions[t].name;
var template =name.replace(/\$/g,'_');
var id= definitions[t].id;
var templDescription ;
var title= definitions[t].title;