-
Notifications
You must be signed in to change notification settings - Fork 191
/
ui.js
2026 lines (1648 loc) · 60.9 KB
/
ui.js
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
/**
* $3Dmol.UI - UI creates panels in the viewer to assist control of the viewport
* @constructor
* @param {$3Dmol.StateManager} stateManager StateManager is required to have interaction between glviewer and the ui.
* @param {Object} config Loads the user defined parameters to generate the ui
* @param {Object} parentElement Refers the parent division used to hold the canvas for 3Dmol.js
*/
$3Dmol.UI = (function(){
function UI(stateManager, config, parentElement){
config = config || {}
// Extract the viewer and then render it
var icons =new $3Dmol.UI.Icons();
var body = $('body');
var mainParent = $(parentElement[0]);
// Generates the necessary UI elements
var HEIGHT = config.height;
var WIDTH = config.width;
var uiElements = this.tools = generateUI(config);
/**
* Creates all the jquery object of different UI features
* @param {Object} config
*/
function generateUI(config){
var modelToolBar = new ModelToolbar();
mainParent.append(modelToolBar.ui);
setLocation(mainParent, modelToolBar.ui, 'left', 'top');
// modelToolBar.updateInputLength();
var contextMenu = new ContextMenu();
mainParent.append(contextMenu.ui);
setPosition(contextMenu.ui, 100, 100)
var surfaceMenu = new SurfaceMenu();
mainParent.append(surfaceMenu.ui);
setLocation(mainParent, surfaceMenu.ui, 'right', 'top', 0, modelToolBar.ui.height() + 5 );
var selectionBox = new SelectionBox(icons.select);
mainParent.append(selectionBox.ui);
setLocation(mainParent, selectionBox.ui, 'left', 'top', 0, modelToolBar.ui.height() + 5);
// Fixing Context Menu Behaviour
selectionBox.ui.on('mousedown', ()=>{
stateManager.exitContextMenu();
});
surfaceMenu.ui.on('mousedown', ()=>{
stateManager.exitContextMenu();
});
return {
modelToolBar : modelToolBar,
selectionBox : selectionBox,
contextMenu : contextMenu,
surfaceMenu : surfaceMenu
}
}
/**
* Resize the panel with respect to the new viewport
*
* @function $3Dmol.UI#resize
*/
this.resize = function(){
var selectionBox = this.tools.selectionBox;
var surfaceMenu = this.tools.surfaceMenu;
var modelToolBar = this.tools.modelToolBar;
var HEIGHT = mainParent.height();
setLocation(mainParent, modelToolBar.ui, 'left', 'top');
// modelToolBar.updateInputLength();
setLocation(mainParent, selectionBox.ui, 'left', 'top', 0, modelToolBar.ui.height() + 5);
selectionBox.updateScrollBox(HEIGHT);
setLocation(mainParent, surfaceMenu.ui, 'right', 'top', 0, modelToolBar.ui.height() + 5);
surfaceMenu.updateScrollBox(HEIGHT);
}
/**
* ModelToolbar is part of $3Dmol.UI to edit or change the model loaded into the viewer
*
* @function ModelToolbar
*/
function ModelToolbar(){
var boundingBox = this.ui = $('<div></div>');
boundingBox.css({
'position' : 'relative',
'min-width' : '150px'
});
var modelButton = new button(icons.molecule, 20, {tooltip : 'Toggle Model Selection Bar'} );
boundingBox.append(modelButton.ui);
modelButton.ui.css({
'display' : 'inline-block',
'top':'3px',
});
var control = {
urlType : {
active : true,
value : null,
key : 'Model type'
},
url : {
active : true,
value : null,
key : 'Url'
},
};
var surroundingBox = $('<div></div>');
surroundingBox.css({
'display' : 'inline-block',
'background' : '#e4e4e4',
'padding' : '2px',
'border-radius' : '3px',
// 'width' : '90%'
});
boundingBox.append(surroundingBox);
var currentModelBox = $('<div></div>');
currentModelBox.css({
});
var currentModel = $('<div></div>');
currentModel.css({
'display' : 'inline-block',
'font-family':'Arial',
'font-size':'12px',
'font-weight': 'bold',
// 'padding' : '3px'
});
currentModelBox.append(currentModel);
var changeButton = new button(icons.change, 16, { tooltip : 'Change Model', backgroundColor : 'white', bfr : 0.5});
changeButton.ui.css({
'display' : 'inline-block',
'margin-left' : '4px',
});
currentModelBox.append(changeButton.ui);
currentModelBox.hide();
surroundingBox.append(currentModelBox);
var formBox = $('<div></div>');
surroundingBox.append(formBox);
var dbs = 'pdb,mmtf,cid'.split(',');
var list = this.list = new $3Dmol.UI.Form.ListInput(control.urlType, dbs);
list.showAlertBox = false;
list.ui.css({
'display' : 'inline-block',
})
formBox.append(list.ui);
var input = this.url = new $3Dmol.UI.Form.Input(control.url);
formBox.append(input.ui);
input.ui.css({
'display' : 'inline-block',
'width' : '125px'
});
// input.setWidth(125);
var submitButton = new button(icons.tick, 16, { bfr : 0.5, backgroundColor : 'lightgreen', tooltip : 'Add Model'});
submitButton.ui.css({
'margin' : '0px'
})
formBox.append(submitButton.ui);
this.updateInputLength = function(){
// var width = parentElement.width()*0.3;
// boundingBox.width(width);
// input.setWidth(width - 12);
}
modelButton.ui.on('click', ()=>{
surroundingBox.toggle();
});
submitButton.ui.on('click', function(){
var validateDb = list.validate();
var validateId = input.validate();
if(validateId && validateDb){
stateManager.addModel(control);
}
else {
}
});
/**
* Sets the title in the ui with specified value
*
* @function ModelToolbar#setModel
* @param {String} heading Name of the molecule that is to be displayed on the title
*/
this.setModel = function(heading){
currentModel.text(heading);
currentModelBox.show();
formBox.hide();
}
changeButton.ui.on('click', function(){
currentModelBox.hide();
formBox.show();
input.setValue('');
});
boundingBox.on('keypress', function(e){
if(e.key == 'Enter' || e.key == 'Return'){
submitButton.ui.trigger('click')
}
});
}
/**
* Selection box creates the UI panel to manipulate selections and style that are drawn
* on the viewport
*
* @function SelectionBox
* @param {$3Dmol.UI.Icons} icon takes the svg code for the icon that is to be used to display
* selection box
* @return {Object} Jquery element of div
*/
function SelectionBox(icon, side='left') {
var selectionBox = this.ui = $('<div></div>');
_editingForm = false;
var selectionObjects = [];
var selections = $('<div></div>');
var scrollBox = $('<div></div>');
selections.css('opacity', '0.9');
var showArea = $('<div></div>');
var addArea = $('<div></div>');
var plusButton = new button(icons.plus, 20, { tooltip : 'Add New Selection'});
plusButton.ui.css('margin','0px');
var hideButton = new button(icon, 20, { tooltip : 'Toggle Selection Menu'});
this.selectionObjects = [];
// Content
selectionBox.append(hideButton.ui);
selectionBox.append(showArea);
selectionBox.css('position', 'absolute');
scrollBox.append(selections);
showArea.append(scrollBox);
addArea.append(plusButton.ui);
var alertBox = new AlertBox();
showArea.append(alertBox.ui);
showArea.append(addArea);
alertBox.ui.css('width', 162);
// CSS
if(side == 'left'){
selectionBox.css('text-align', 'left');
}
else if(side == 'right') {
selectionBox.css('text-align', 'right');
}
else {
// Add alert box code
selectionBox.css('text-align', 'right');
}
showArea.css('box-sizing', 'border-box');
showArea.css('padding', '3px');
// showArea.css('width', '162px');
scrollBox.css('max-height', HEIGHT*0.8);
scrollBox.css('overflow-y', 'auto');
scrollBox.css('overflow-x', 'visible');
selections.css('box-sizing', 'content-box');
this.updateScrollBox = function(height){
scrollBox.css('max-height', height*0.8);
}
// Action
var hidden = true;
showArea.hide();
hideButton.ui.click(toggleHide);
function toggleHide(){
if(hidden){
showArea.show(100);
}
else {
showArea.hide(100);
}
hidden = !hidden;
}
/**
* Card for manipulation of a selection form and related styles
*
* @function Selection
*/
function Selection(){
var boundingBox = this.ui = $('<div></div>');
var sid = this.id = null;
selectionObjects.push(this);
boundingBox.css({
'background' : '#e8e8e8',
'padding' : '4px 4px 2px 4px',
'border-radius' : '6px',
'margin-bottom' : '3px',
'position':'relative',
'width':'156px'
});
var header = $('<div></div>');
boundingBox.append(header);
var heading = $('<div></div>');
var controls = $('<div></div>');
header.append(heading, controls);
heading.css({
'font-family' : 'Arial',
'font-weight': 'bold',
'font-size':'12px',
'display':'inline-block',
'width' : '60px'
});
controls.css({
'display' : 'inline-block'
});
header.hide();
controls.editMode = false;
var removeButton = new button(icons.minus, 16, { bfr:0.5, backgroundColor:'#f06f6f', tooltip : 'Remove Selection'});
var editButton = new button(icons.pencil, 16, { tooltip : 'Edit Selection'});
var visibleButton = new button(icons.visible, 16, { tooltip : 'Show / Hide Selection'});
controls.append(removeButton.ui)
controls.append(editButton.ui);
controls.append(visibleButton.ui);
var parameters = $('<div></div>');
boundingBox.append(parameters);
var styleHolder = $('<div></div>');
removeButton.ui.on('click', function(){
stateManager.removeSelection(sid);
boundingBox.detach();
//delete this;
});
editButton.ui.on('click', function(){
parameters.toggle();
});
var hidden = false;
visibleButton.ui.on('click', ()=>{
stateManager.toggleHide(sid);
if(hidden){
hidden = false;
visibleButton.setSVG(icons.visible);
}
else {
hidden = true;
visibleButton.setSVG(icons.invisible);
}
});
var styleBox = new StyleBox();
var showStyle = false;
styleHolder.append(styleBox.ui);
styleBox.ui.css({
'position' : 'static',
// 'left' : '0',
'width' : 'px',
'border-radius' : '4px'
});
styleBox.ui.hide();
var allControl = this.allSelector = {
key : 'Select All Atom',
value : null,
active : true
}
var allCheckBox = new $3Dmol.UI.Form.Checkbox(allControl);
parameters.append(allCheckBox.ui);
var selectionFormControl = this.selectionValue = {
key : 'Selection Spec',
value : null,
active : true
}
var selectionSpecForm = new $3Dmol.UI.Form($3Dmol.GLModel.validAtomSelectionSpecs, selectionFormControl);
parameters.append(selectionSpecForm.ui);
var submitControls = $('<div></div>');
var submit = new button(icons.tick, 16, { backgroundColor : 'lightgreen', tooltip : 'Submit'});
var cancel = new button(icons.cross, 16, { backgroundColor : 'lightcoral', tooltip : 'Cancel'});
submitControls.append(submit.ui, cancel.ui);
var alertBox = new AlertBox();
parameters.append(alertBox.ui);
parameters.append(submitControls);
boundingBox.append(styleHolder);
allCheckBox.update = function(){
selectionSpecForm.ui.toggle();
}
function finalizeSelection(id){
header.show();
controls.editMode = true;
sid = this.id = id;
heading.text('Sel#' + id);
boundingBox.attr('data-id', id);
parameters.hide();
showStyle = true;
styleBox.setSid(id);
styleBox.ui.show();
}
function checkAndAddSelection(sid = null){
var validate = selectionSpecForm.validate();
if(validate){
selectionSpecForm.getValue();
var checkAtoms = stateManager.checkAtoms(selectionFormControl.value);
if(Object.keys(selectionFormControl.value).length == 0){
alertBox.error('Please enter some input');
}
else{
if(checkAtoms){
var id = stateManager.addSelection(selectionFormControl.value, sid);
finalizeSelection(id);
if(sid == null ) _editingForm = false;
}
else {
alertBox.error('No atom selected');
}
}
}
else {
alertBox.error('Invalid Input');
}
}
function removeSelf(selection){
var selectionToRemove = selectionObjects.find((sel)=>{
if(selection == sel){
console.log('Selection found', selection);
return true;
}
});
// delete selectionToRemove;
}
submit.ui.on('click', ()=>{
if(controls.editMode == false){
if(allControl.value){
var id = stateManager.addSelection({});
finalizeSelection(id);
_editingForm = false;
}
else{
checkAndAddSelection();
}
}
else {
if(allControl.value){
var id = sid
stateManager.addSelection({}, id);
finalizeSelection(id);
}
else{
var id = sid;
checkAndAddSelection(id);
}
}
});
var self = this;
cancel.ui.on('click', ()=>{
if(controls.editMode){
parameters.hide();
}
else {
boundingBox.detach();
removeSelf(self);
_editingForm = false;
}
});
boundingBox.on('keyup', (e)=>{
if(e.key == 'Enter'){
submit.ui.trigger('click');
}
});
/**
* @function Selection#setProperty
* @param {string} id Id of the selection created in StateManager
* @param {Object} specs Defination of the selection that will be used to set default
* values in the form
*/
this.setProperty = function(id, specs){
// check for all selection
if(Object.keys(specs).length == 0){
allCheckBox.setValue(true)
}else{
selectionSpecForm.setValue(specs);
}
// finalize the selection
finalizeSelection(id);
}
/**
* Adds style to the given selection
*
* @function Selection#addStyle
* @param {String} selId Id of the selection to inititate the StyleBox
* @param {String} styleId Id of the style that is created through StateManager
* @param {AtomStyleSpecs} styleSpecs
*/
this.addStyle = function(selId, styleId, styleSpecs){
styleBox.addStyle(selId, styleId, styleSpecs);
}
}
plusButton.ui.on('click', ()=>{
if(!_editingForm){
var newSelection = new Selection();
selections.append(newSelection.ui);
_editingForm = true;
}else {
alertBox.warning('Please complete the previous form');
}
});
/**
* Remove all the selection card from the ui
*/
this.empty = function(){
selections.empty();
_editingForm = false;
}
/**
* Adds or create new selection card
*
* @function SelectionBox#editSelection
* @param {String} id Id created in StateManager and passed down to this function during call
* @param {AtomSelectionSpec} selSpec Selection spec that is used to generate the selection form
* @param {String} styleId Id of style created in StateManager
* @param {AtomStyleSpecs} styleSpec Style spec if specified add the selection to the current selection
*/
this.editSelection = function(id, selSpec, styleId, styleSpec){
// if selection does not exist create new
// This thing works but I am not sure how!
// Search selection with id
var selectionUI = selections.children('[data-id='+ id +']');
if(selectionUI.length != 0) {
}
else {
selection = new Selection();
selection.setProperty(id, selSpec);
selections.append(selection.ui);
}
if(styleId != null){
selection.addStyle(id, styleId, styleSpec);
}
}
}
/**
*
* @param {Object} Jquery dom object
*/
/**
* Creates StyleBox for listing out different styles inside the selection
*
* @function StyleBox
* @param {String} selId Id of the selection for which the style box is created
* @param {String} side Alignment of text inside the box
*/
function StyleBox(selId, side='left') {
var styleBox = this.ui = $('<div></div>');
_editingForm = false;
var sid = this.sid = selId; // selection id
this.setSid = function(id){
sid = this.sid = id;
}
var styles = $('<div></div>');
var scrollBox = $('<div></div>');
styles.css('opacity', '0.9');
var showArea = $('<div></div>');
var addArea = $('<div></div>');
addArea.css('text-align' , 'center');
var plusButton = new button(icons.plus, 20, { tooltip : 'Add New Style'});
plusButton.ui.css('margin','0px');
this.selectionObjects = [];
// Content
styleBox.append(showArea);
styleBox.css('position', 'absolute');
scrollBox.append(styles);
showArea.append(scrollBox);
var alertBox = new AlertBox();
showArea.append(alertBox.ui);
addArea.append(plusButton.ui);
showArea.append(addArea);
// CSS
if(side == 'left'){
styleBox.css('text-align', 'left');
}
else if(side == 'right') {
styleBox.css('text-align', 'right');
}
else {
// Add alert box code
styleBox.css('text-align', 'right');
}
showArea.css('box-sizing', 'border-box');
showArea.css('padding', '3px');
// showArea.css('width', '162px');
showArea.css('background-color', '#a4a4a4')
showArea.css('border-radius', '4px');
// scrollBox.css('max-height', HEIGHT*0.8);
scrollBox.css('overflow', 'hidden');
// styles.css('max-height', HEIGHT*0.8);
// styles.css('overflow', 'auto');
styles.css('box-sizing', 'content-box');
/**
* Style card to define the value of the style
*
* @param {string} sid Id of the selction for which the style box is created
* and this stye will be added under that selection
*/
function Style(sid){
var boundingBox = this.ui = $('<div></div>');
var stid = this.id = null; // style id
boundingBox.css({
'background' : '#e8e8e8',
'padding' : '4px 4px 2px 4px',
'border-radius' : '6px',
'margin-bottom' : '3px',
'position':'relative'
});
var header = $('<div></div>');
boundingBox.append(header);
var heading = $('<div></div>');
var controls = $('<div></div>');
header.append(heading, controls);
heading.css({
'font-family' : 'Arial',
'font-weight': 'bold',
'font-size':'12px',
'display':'inline-block',
'width' : '60px'
});
controls.css({
'display' : 'inline-block'
});
header.hide();
controls.editMode = false;
var removeButton = new button(icons.minus, 16, { bfr:0.5, backgroundColor:'#f06f6f', tooltip : 'Remove Style'});
var editButton = new button(icons.pencil, 16, { tooltip : 'Edit Style'});
var visibleButton = new button(icons.visible, 16, { tooltip : 'Show / Hide Style'});
controls.append(removeButton.ui)
controls.append(editButton.ui);
controls.append(visibleButton.ui);
var parameters = $('<div></div>');
boundingBox.append(parameters);
removeButton.ui.on('click', { parent: this, stid : stid }, function(e){
stateManager.removeStyle(sid, stid);
boundingBox.detach();
//delete this;
});
editButton.ui.on('click', function(){
parameters.toggle();
});
var hidden = false;
visibleButton.ui.on('click', ()=>{
stateManager.toggleHideStyle(sid, stid);
if(hidden){
hidden = false;
visibleButton.setSVG(icons.visible);
}
else {
hidden = true;
visibleButton.setSVG(icons.invisible);
}
});
var styleFormControl = this.selectionValue = {
key : 'Style Spec',
value : null,
active : true
}
var styleSpecForm = new $3Dmol.UI.Form($3Dmol.GLModel.validAtomStyleSpecs, styleFormControl);
parameters.append(styleSpecForm.ui);
var submitControls = $('<div></div>');
var submit = new button(icons.tick, 16, { backgroundColor : 'lightgreen', tooltip : 'Submit'});
var cancel = new button(icons.cross, 16, { backgroundColor : 'lightcoral', tooltip : 'Cancel'});
submitControls.append(submit.ui, cancel.ui);
var alertBox = new AlertBox();
parameters.append(alertBox.ui);
parameters.append(submitControls);
function finalizeStyle(id){
header.show();
controls.editMode = true;
stid = id;
heading.text('Sty#' + id);
parameters.hide();
}
function checkAndAddStyle(stid = null){
var validate = styleSpecForm.validate();
if(validate){
styleSpecForm.getValue();
if(Object.keys(styleFormControl.value).length == 0){
alertBox.error('Please enter some value');
}
else{
var id = stateManager.addStyle(styleFormControl.value, sid, stid);
finalizeStyle(id);
if(stid == null) _editingForm = false;
}
}
else {
alertBox.error('Invalid Input');
}
}
submit.ui.on('click', ()=>{
if(controls.editMode == false){
checkAndAddStyle();
}
else {
var id = stid
styleSpecForm.getValue();
if(Object.keys(styleFormControl.value).length == 0){
alertBox.error('Please enter some value');
}
else{
checkAndAddStyle(id);
}
}
});
cancel.ui.on('click', ()=>{
if(controls.editMode){
parameters.hide();
}
else {
boundingBox.detach();
//delete this;
}
});
boundingBox.on('keyup', (e)=>{
if(e.key == 'Enter'){
submit.ui.trigger('click');
}
});
/**
* @function Style#updateStyle
* @param {String} styleId Id of the style created by StateManager
* @param {AtomStyleSpecs} styleSpec Specs for defining the style and setting default values
*/
this.updateStyle = function(styleId, styleSpec){
styleSpecForm.setValue(styleSpec);
finalizeStyle(styleId);
}
}
plusButton.ui.on('click', ()=>{
if( !_editingForm){
var newStyle = new Style(sid);
styles.append(newStyle.ui);
_editingForm = true;
}
else {
alertBox.warning('Please complete editing the current form');
}
});
/**
* @function StyleBox#addStyle
* @param {String} selectionId Id of the selection for which styles will be created
* @param {String} styleId Id of the style part of the selection
* @param {AtomStyleSpecs} styleSpecs Style specs that will be used to create
* style for the specified selection and set default values in the Style card
*/
this.addStyle = function(selectionId, styleId, styleSpecs){
var style = new Style(selectionId);
styles.append(style.ui);
style.updateStyle(styleId, styleSpecs);
}
}
/**
* Add alert messages to different panels
*
* @function AlertBox
* @param {Object} config Configuraiton for alert box display
*/
function AlertBox(config){
var boundingBox = this.ui = $('<div></div>');
config = config || {}
var delay = config.delay || 5000;
var autohide = (config.autohide == undefined )? true : config.autohide;
boundingBox.css({
'font-family' : 'Arial',
'font-size' : '14px',
'padding' : '3px',
'border-radius' : '4px',
'margin-top' : '2px',
'margin-bottm' : '2px',
'font-weight' : 'bold',
'text-align' : 'center',
});
boundingBox.hide();
function hide(){
if(autohide){
setTimeout(()=>{
boundingBox.hide();
}, delay);
}
}
/**
* Generate Internal alert message
* @param {String} msg Error Message
*/
this.error = function(msg){
boundingBox.css({
'background' : 'lightcoral',
'color' : 'darkred',
'border' : '1px solid darkred'
});
boundingBox.text(msg);
boundingBox.show();
hide();
}
/**
* Generates Internal warning message
* @param {String} msg Warming message
*/
this.warning = function(msg){
boundingBox.css({
'background' : '#fff3cd',
'color' : '#856409',
'border' : '1px solid #856409'
});
boundingBox.text(msg);
boundingBox.show();
hide();
}
/**
* Generates Internal Info message
* @param {String} msg Info message
*/
this.message = function(msg){
boundingBox.css({
'background' : 'lightgreen',
'color' : 'green',
'border' : '1px solid green'
});
boundingBox.text(msg);
boundingBox.show();
hide();
}
}
/**
* Creates the panel for manipulation of labels on the viewport
*
* @function ContextMenu
*/
function ContextMenu(){
var boundingBox = this.ui = $('<div></div>');
boundingBox.css('position', 'absolute');
// boundingBox.css('border', '1px solid black');
boundingBox.css('border-radius', '3px');
boundingBox.css('background', '#f1f1f1');
boundingBox.css('z-index', 99);
var contentBox = $('<div></div>');
contentBox.css('position', 'relative');
boundingBox.css('opacity', '0.85');
boundingBox.append(contentBox);
contentBox.css({
'background': '#f1f1f1',
'border-radius': '4px',
'padding': '4px',
'width':'140px'
});
// Context Box
// Remove Label Button
var labelMenuStyle = {
'background' : '#d3e2ee',
'padding' : '2px',
'font-family':'Arial',
'font-weight':'bold',
'font-size':'12px',
'border-radius':'2px',
// 'margin-top':'3px'
}