@@ -122,6 +122,7 @@ class Browser extends DashboardView {
122
122
this . handleShowAcl = this . handleShowAcl . bind ( this ) ;
123
123
this . onDialogToggle = this . onDialogToggle . bind ( this ) ;
124
124
this . abortAddRow = this . abortAddRow . bind ( this ) ;
125
+ this . saveNewRow = this . saveNewRow . bind ( this ) ;
125
126
}
126
127
127
128
componentWillMount ( ) {
@@ -303,6 +304,66 @@ class Browser extends DashboardView {
303
304
}
304
305
}
305
306
307
+ saveNewRow ( ) {
308
+ const obj = this . state . newObject ;
309
+ if ( ! obj ) {
310
+ return ;
311
+ }
312
+
313
+ obj . save ( null , { useMasterKey : true } ) . then (
314
+ objectSaved => {
315
+ let msg = objectSaved . className + ' with id \'' + objectSaved . id + '\' created' ;
316
+ this . showNote ( msg , false ) ;
317
+
318
+ const state = { data : this . state . data } ;
319
+ const relation = this . state . relation ;
320
+ if ( relation ) {
321
+ const parent = relation . parent ;
322
+ const parentRelation = parent . relation ( relation . key ) ;
323
+ parentRelation . add ( obj ) ;
324
+ const targetClassName = relation . targetClassName ;
325
+ parent . save ( null , { useMasterKey : true } ) . then (
326
+ ( ) => {
327
+ this . setState ( {
328
+ newObject : null ,
329
+ data : [ obj , ...this . state . data ] ,
330
+ relationCount : this . state . relationCount + 1 ,
331
+ counts : {
332
+ ...this . state . counts ,
333
+ [ targetClassName ] : this . state . counts [ targetClassName ] + 1
334
+ }
335
+ } ) ;
336
+ } ,
337
+ error => {
338
+ let msg = typeof error === "string" ? error : error . message ;
339
+ if ( msg ) {
340
+ msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
341
+ }
342
+ obj . set ( attr , prev ) ;
343
+ this . setState ( { data : this . state . data } ) ;
344
+ this . showNote ( msg , true ) ;
345
+ }
346
+ ) ;
347
+ } else {
348
+ state . newObject = null ;
349
+ if ( this . props . params . className === obj . className ) {
350
+ this . state . data . unshift ( obj ) ;
351
+ }
352
+ this . state . counts [ obj . className ] += 1 ;
353
+ }
354
+
355
+ this . setState ( state ) ;
356
+ } ,
357
+ error => {
358
+ let msg = typeof error === "string" ? error : error . message ;
359
+ if ( msg ) {
360
+ msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
361
+ }
362
+ this . showNote ( msg , true ) ;
363
+ }
364
+ ) ;
365
+ }
366
+
306
367
addRowWithModal ( ) {
307
368
this . addRow ( ) ;
308
369
this . selectRow ( undefined , true ) ;
@@ -573,60 +634,22 @@ class Browser extends DashboardView {
573
634
} else {
574
635
obj . set ( attr , value ) ;
575
636
}
637
+ if ( isNewObject ) {
638
+ this . setState ( {
639
+ isNewObject : obj
640
+ } ) ;
641
+ return ;
642
+ }
576
643
obj . save ( null , { useMasterKey : true } ) . then ( ( objectSaved ) => {
577
- const createdOrUpdated = isNewObject ? 'created' : 'updated' ;
578
- let msg = objectSaved . className + ' with id \'' + objectSaved . id + '\' ' + createdOrUpdated ;
644
+ let msg = objectSaved . className + ' with id \'' + objectSaved . id + '\' updated' ;
579
645
this . showNote ( msg , false ) ;
580
-
581
646
const state = { data : this . state . data } ;
582
-
583
- if ( isNewObject ) {
584
- const relation = this . state . relation ;
585
- if ( relation ) {
586
- const parent = relation . parent ;
587
- const parentRelation = parent . relation ( relation . key ) ;
588
- parentRelation . add ( obj ) ;
589
- const targetClassName = relation . targetClassName ;
590
- parent . save ( null , { useMasterKey : true } ) . then ( ( ) => {
591
- this . setState ( {
592
- newObject : null ,
593
- data : [
594
- obj ,
595
- ...this . state . data ,
596
- ] ,
597
- relationCount : this . state . relationCount + 1 ,
598
- counts : {
599
- ...this . state . counts ,
600
- [ targetClassName ] : this . state . counts [ targetClassName ] + 1 ,
601
- } ,
602
- } ) ;
603
- } , ( error ) => {
604
- let msg = typeof error === 'string' ? error : error . message ;
605
- if ( msg ) {
606
- msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
607
- }
608
- obj . set ( attr , prev ) ;
609
- this . setState ( { data : this . state . data } ) ;
610
- this . showNote ( msg , true ) ;
611
- } ) ;
612
- } else {
613
- state . newObject = null ;
614
- if ( this . props . params . className === obj . className ) {
615
- this . state . data . unshift ( obj ) ;
616
- }
617
- this . state . counts [ obj . className ] += 1 ;
618
- }
619
- }
620
647
this . setState ( state ) ;
621
648
} , ( error ) => {
622
649
let msg = typeof error === 'string' ? error : error . message ;
623
650
if ( msg ) {
624
651
msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
625
652
}
626
- if ( ! isNewObject ) {
627
- obj . set ( attr , prev ) ;
628
- this . setState ( { data : this . state . data } ) ;
629
- }
630
653
631
654
this . showNote ( msg , true ) ;
632
655
} ) ;
@@ -1048,6 +1071,7 @@ class Browser extends DashboardView {
1048
1071
onCloneSelectedRows = { this . showCloneSelectedRowsDialog }
1049
1072
onEditSelectedRow = { this . showEditRowDialog }
1050
1073
onEditPermissions = { this . onDialogToggle }
1074
+ onSaveNewRow = { this . saveNewRow }
1051
1075
onAbortAddRow = { this . abortAddRow }
1052
1076
1053
1077
columns = { columns }
@@ -1067,6 +1091,7 @@ class Browser extends DashboardView {
1067
1091
setRelation = { this . setRelation }
1068
1092
onAddColumn = { this . showAddColumn }
1069
1093
onAddRow = { this . addRow }
1094
+ onAbortAddRow = { this . abortAddRow }
1070
1095
onAddRowWithModal = { this . addRowWithModal }
1071
1096
onAddClass = { this . showCreateClass }
1072
1097
showNote = { this . showNote } />
0 commit comments