@@ -47,7 +47,7 @@ export class Editor extends Component {
47
47
availableUsersForPermission : [ ] ,
48
48
userIdsWithPermission : [ ] ,
49
49
firstTimeLoad : true ,
50
- mode : "javascript " ,
50
+ mode : "" ,
51
51
defaultValue : ""
52
52
}
53
53
@@ -80,6 +80,21 @@ export class Editor extends Component {
80
80
} ) ;
81
81
}
82
82
83
+ // Find the document on this editor page for updating title
84
+ Meteor . call ( 'findDocument' , id , ( error , result ) => {
85
+ if ( error ) {
86
+ console . log ( "Can't find Document" ) ;
87
+ } else {
88
+ console . log ( "result.mode" , result . mode )
89
+ this . setState ( {
90
+ title : result . title ,
91
+ documentCreatedBy : result . createdBy ,
92
+ mode : ( result . mode != "" ) ? result . mode : "javascript" //default mode is JS
93
+ } )
94
+ console . log ( "current mode" , this . state . mode )
95
+ }
96
+ } ) ;
97
+
83
98
// Get all users so that we can give permission
84
99
Meteor . call ( 'getAllUsers' , ( error , result ) => {
85
100
if ( error ) {
@@ -112,15 +127,6 @@ export class Editor extends Component {
112
127
}
113
128
} ) ;
114
129
115
- // Find the document on this editor page for updating title
116
- Meteor . call ( 'findDocument' , id , ( error , result ) => {
117
- if ( error ) {
118
- console . log ( "Can't find Document" ) ;
119
- } else {
120
- this . setState ( { title : result . title , documentCreatedBy : result . createdBy } )
121
- }
122
- } ) ;
123
-
124
130
}
125
131
126
132
// onChange Event of input, setState of title
@@ -238,14 +244,22 @@ export class Editor extends Component {
238
244
}
239
245
240
246
setMode ( e ) {
241
-
247
+ const { id , mode } = this . state ;
242
248
if ( this . state . mode = 'openedge' ) {
243
249
this . refs . aceEditor . editor . getSession ( ) . setMode ( customMode ) ;
244
250
}
245
251
246
252
this . setState ( {
247
253
mode : e . target . value
248
254
} )
255
+
256
+ Meteor . call ( 'updateMode' , id , e . target . value , ( error ) => {
257
+ if ( error ) {
258
+ console . log ( "Fail to update the document mode" , error . reason ) ;
259
+ } else {
260
+ console . log ( "Mode updated successfully" ) ;
261
+ }
262
+ } ) ;
249
263
}
250
264
251
265
onLoad ( editor ) {
@@ -298,7 +312,7 @@ export class Editor extends Component {
298
312
299
313
this . lastTimeInsert = DocumentContents . findOne ( { docId : id } , { sort : { createdAt : - 1 , limit : 1 } } ) . createdAt ;
300
314
this . prevValues = editor . getValue ( ) . split ( '\n' ) ;
301
-
315
+
302
316
this . setState ( { defaultValue : editor . getValue ( ) } )
303
317
}
304
318
}
0 commit comments