@@ -90,30 +90,23 @@ define([
90
90
this . targetId = targetId ;
91
91
this . uuid = vpCommon . getUUID ( ) ;
92
92
93
- // state
94
- this . state = {
95
- originObj : '' ,
96
- tempObj : '_vp' ,
97
- selected : [ ] ,
98
- axis : 0 ,
99
- lines : TABLE_LINES ,
100
- steps : [ ] ,
101
- popup : FRAME_EDIT_TYPE . NONE
102
- }
103
-
104
- this . codepreview = undefined ;
93
+ this . renderButton ( ) ;
105
94
106
- this . bindEvent ( ) ;
107
- this . init ( ) ;
95
+ var that = this ;
96
+ // open popup
97
+ $ ( vpCommon . formatString ( '.{0}.{1}' , VP_FE_BTN , this . uuid ) ) . on ( 'click' , function ( event ) {
98
+ if ( ! $ ( this ) . hasClass ( 'disabled' ) ) {
99
+ that . open ( ) ;
100
+ }
101
+ } ) ;
108
102
}
109
103
110
104
FrameEditor . prototype . wrapSelector = function ( query = '' ) {
111
105
return vpCommon . formatString ( '.{0}.{1} {2}' , VP_FE , this . uuid , query ) ;
112
106
}
113
107
114
108
FrameEditor . prototype . open = function ( ) {
115
- this . loadVariableList ( ) ;
116
-
109
+ this . init ( ) ;
117
110
$ ( this . wrapSelector ( ) ) . show ( ) ;
118
111
119
112
if ( ! this . codepreview ) {
@@ -152,17 +145,33 @@ define([
152
145
}
153
146
154
147
FrameEditor . prototype . close = function ( ) {
155
- $ ( this . wrapSelector ( ) ) . hide ( ) ;
148
+ this . unbindEvent ( ) ;
149
+ $ ( this . wrapSelector ( ) ) . remove ( ) ;
156
150
}
157
151
158
152
FrameEditor . prototype . init = function ( ) {
159
- this . pageThis . loadCss ( Jupyter . notebook . base_url + vpConst . BASE_PATH + vpConst . STYLE_PATH + "common/frameEditor.css" ) ;
153
+ // state
154
+ this . state = {
155
+ originObj : '' ,
156
+ tempObj : '_vp' ,
157
+ selected : [ ] ,
158
+ axis : 0 ,
159
+ lines : TABLE_LINES ,
160
+ steps : [ ] ,
161
+ popup : FRAME_EDIT_TYPE . NONE
162
+ }
160
163
161
- this . renderButton ( ) ;
162
- this . renderThis ( ) ;
164
+ this . codepreview = undefined ;
165
+
166
+ vpCommon . loadCss ( Jupyter . notebook . base_url + vpConst . BASE_PATH + vpConst . STYLE_PATH + "common/frameEditor.css" ) ;
163
167
168
+ this . render ( ) ;
169
+ this . bindEvent ( ) ;
170
+
164
171
// this.setDraggableBox();
165
172
this . setDraggableColumns ( ) ;
173
+
174
+ this . loadVariableList ( ) ;
166
175
}
167
176
168
177
FrameEditor . prototype . initState = function ( ) {
@@ -177,7 +186,9 @@ define([
177
186
var buttonTag = new sb . StringBuilder ( ) ;
178
187
buttonTag . appendFormat ( '<button type="button" class="{0} {1} {2}">{3}</button>'
179
188
, VP_FE_BTN , this . uuid , 'vp-button' , 'Edit' ) ;
180
- $ ( this . pageThis . wrapSelector ( '#' + this . targetId ) ) . parent ( ) . append ( buttonTag . toString ( ) ) ;
189
+ if ( this . pageThis ) {
190
+ $ ( this . pageThis . wrapSelector ( '#' + this . targetId ) ) . parent ( ) . append ( buttonTag . toString ( ) ) ;
191
+ }
181
192
}
182
193
183
194
FrameEditor . prototype . setPreview = function ( previewCodeStr ) {
@@ -191,7 +202,7 @@ define([
191
202
}
192
203
}
193
204
194
- FrameEditor . prototype . renderThis = function ( ) {
205
+ FrameEditor . prototype . render = function ( ) {
195
206
var page = new sb . StringBuilder ( ) ;
196
207
page . appendFormatLine ( '<div class="{0} {1}">' , VP_FE , this . uuid ) ;
197
208
page . appendFormatLine ( '<div class="{0}">' , VP_FE_CONTAINER ) ;
@@ -338,6 +349,7 @@ define([
338
349
} ) ;
339
350
$ ( that . wrapSelector ( '#vp_feVariable' ) ) . trigger ( 'change' ) ;
340
351
} catch ( ex ) {
352
+ console . log ( 'FrameEditor:' , result ) ;
341
353
// console.log(ex);
342
354
}
343
355
} ) ;
@@ -515,7 +527,7 @@ define([
515
527
} ) ;
516
528
}
517
529
518
- FrameEditor . prototype . getCode = function ( type , content = { } ) {
530
+ FrameEditor . prototype . getTypeCode = function ( type , content = { } ) {
519
531
var tempObj = this . state . tempObj ;
520
532
var orgObj = this . state . originObj ;
521
533
@@ -668,15 +680,30 @@ define([
668
680
} ) ;
669
681
}
670
682
683
+ FrameEditor . prototype . unbindEvent = function ( ) {
684
+ $ ( document ) . off ( this . wrapSelector ( '*' ) ) ;
685
+
686
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_CLOSE ) ) ;
687
+ $ ( document ) . off ( 'change' , this . wrapSelector ( '#vp_feVariable' ) ) ;
688
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.vp-fe-df-refresh' ) ) ;
689
+ $ ( document ) . off ( 'contextmenu' , this . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN ) ) ;
690
+ $ ( document ) . off ( 'contextmenu' , this . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_ROW ) ) ;
691
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN ) ) ;
692
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_ROW ) ) ;
693
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_ADD_COLUMN ) ) ;
694
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_ADD_ROW ) ) ;
695
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE_MORE ) ) ;
696
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_MENU_ITEM ) ) ;
697
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_POPUP_OK ) ) ;
698
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_POPUP_CANCEL ) ) ;
699
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_POPUP_CLOSE ) ) ;
700
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_BUTTON_CANCEL ) ) ;
701
+ $ ( document ) . off ( 'click' , this . wrapSelector ( '.' + VP_FE_BUTTON_APPLY ) ) ;
702
+
703
+ }
671
704
672
705
FrameEditor . prototype . bindEvent = function ( ) {
673
706
var that = this ;
674
- // open popup
675
- $ ( document ) . on ( 'click' , vpCommon . formatString ( '.{0}.{1}' , VP_FE_BTN , this . uuid ) , function ( event ) {
676
- if ( ! $ ( this ) . hasClass ( 'disabled' ) ) {
677
- that . open ( ) ;
678
- }
679
- } ) ;
680
707
681
708
// close popup
682
709
$ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_CLOSE ) , function ( event ) {
@@ -697,7 +724,7 @@ define([
697
724
that . initState ( ) ;
698
725
699
726
// load code with temporary df
700
- that . loadCode ( that . getCode ( FRAME_EDIT_TYPE . INIT ) ) ;
727
+ that . loadCode ( that . getTypeCode ( FRAME_EDIT_TYPE . INIT ) ) ;
701
728
that . loadInfo ( ) ;
702
729
} ) ;
703
730
@@ -756,7 +783,8 @@ define([
756
783
} ) ;
757
784
758
785
// select column
759
- $ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN ) , function ( ) {
786
+ $ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN ) , function ( evt ) {
787
+ evt . stopPropagation ( ) ;
760
788
var hasSelected = $ ( this ) . hasClass ( 'selected' ) ;
761
789
$ ( that . wrapSelector ( '.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_ROW ) ) . removeClass ( 'selected' ) ;
762
790
if ( ! hasSelected ) {
@@ -800,7 +828,7 @@ define([
800
828
// more rows
801
829
$ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_TABLE_MORE ) , function ( ) {
802
830
that . state . lines += TABLE_LINES ;
803
- that . loadCode ( that . getCode ( FRAME_EDIT_TYPE . SHOW ) ) ;
831
+ that . loadCode ( that . getTypeCode ( FRAME_EDIT_TYPE . SHOW ) ) ;
804
832
} ) ;
805
833
806
834
// click menu item
@@ -814,13 +842,13 @@ define([
814
842
that . openInputPopup ( editType ) ;
815
843
return ;
816
844
}
817
- that . loadCode ( that . getCode ( editType ) ) ;
845
+ that . loadCode ( that . getTypeCode ( editType ) ) ;
818
846
} ) ;
819
847
820
848
// ok input popup
821
849
$ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_POPUP_OK ) , function ( ) {
822
850
// TODO: ok input popup
823
- that . loadCode ( that . getCode ( that . state . popup , that . getPopupContent ( ) ) ) ;
851
+ that . loadCode ( that . getTypeCode ( that . state . popup , that . getPopupContent ( ) ) ) ;
824
852
that . closeInputPopup ( ) ;
825
853
} ) ;
826
854
@@ -841,8 +869,20 @@ define([
841
869
842
870
// click apply
843
871
$ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_BUTTON_APPLY ) , function ( ) {
844
- $ ( that . pageThis . wrapSelector ( '#' + that . targetId ) ) . val ( that . state . steps . join ( '\n' ) ) ;
845
- $ ( that . pageThis . wrapSelector ( '#' + that . targetId ) ) . trigger ( 'frame_apply' ) ;
872
+ var code = that . state . steps . join ( '\n' ) ;
873
+ if ( that . pageThis ) {
874
+ $ ( that . pageThis . wrapSelector ( '#' + that . targetId ) ) . val ( code ) ;
875
+ $ ( that . pageThis . wrapSelector ( '#' + that . targetId ) ) . trigger ( {
876
+ type : 'frame_apply' ,
877
+ code : code
878
+ } ) ;
879
+ } else {
880
+ $ ( vpCommon . wrapSelector ( '#' + that . targetId ) ) . val ( code ) ;
881
+ $ ( vpCommon . wrapSelector ( '#' + that . targetId ) ) . trigger ( {
882
+ type : 'frame_apply' ,
883
+ code : code
884
+ } ) ;
885
+ }
846
886
that . close ( ) ;
847
887
} ) ;
848
888
}
0 commit comments