1
- import Ember from ' ember' ;
2
- import RSVP from ' rsvp' ;
3
- import _ from ' lodash' ;
1
+ import Ember from " ember" ;
2
+ import RSVP from " rsvp" ;
3
+ import _ from " lodash" ;
4
4
5
5
/**
6
- * Generic controller base. Should hopefully help avoid re-writing code in the future
7
- * Has:
8
- * - Message box
9
- * - Loading spinner
10
- * - CRUD methods for controlling records
11
- *
6
+ * @module Controllers/GoodcityController
7
+ * @augments ember/Controller
8
+ * @description Generic controller base. Should hopefully help avoid re-writing code in the future
9
+ * <br> Has:
10
+ * <br> - Message box
11
+ * <br> - Loading spinner
12
+ * <br> - CRUD methods for controlling records
12
13
*/
13
14
export default Ember . Controller . extend ( {
14
-
15
15
// ---- Services
16
16
17
17
messageBox : Ember . inject . service ( ) ,
@@ -23,15 +23,25 @@ export default Ember.Controller.extend({
23
23
24
24
// ---- Generic Helpers
25
25
26
+ /**
27
+ * @instance
28
+ * @description displays the loading spinner on the screen
29
+ */
26
30
showLoadingSpinner ( ) {
27
31
if ( Ember . testing ) {
28
32
return ;
29
33
}
30
34
if ( ! this . loadingView ) {
31
- this . loadingView = Ember . getOwner ( this ) . lookup ( 'component:loading' ) . append ( ) ;
35
+ this . loadingView = Ember . getOwner ( this )
36
+ . lookup ( "component:loading" )
37
+ . append ( ) ;
32
38
}
33
39
} ,
34
40
41
+ /**
42
+ * @instance
43
+ * @description hides the loading spinner off the screen
44
+ */
35
45
hideLoadingSpinner ( ) {
36
46
if ( Ember . testing ) {
37
47
return ;
@@ -43,38 +53,45 @@ export default Ember.Controller.extend({
43
53
} ,
44
54
45
55
showError ( message , cb ) {
46
- this . get ( "messageBox" ) . alert ( message || this . get ( "i18n" ) . t ( "unexpected_error" ) , cb ) ;
56
+ this . get ( "messageBox" ) . alert (
57
+ message || this . get ( "i18n" ) . t ( "unexpected_error" ) ,
58
+ cb
59
+ ) ;
47
60
} ,
48
61
49
62
onError ( response = { } ) {
50
- const errors = _ . map ( response . errors , ( err ) => _ . isString ( err ) ? err : err . detail ) ;
63
+ const errors = _ . map ( response . errors , err =>
64
+ _ . isString ( err ) ? err : err . detail
65
+ ) ;
51
66
this . showError ( errors [ 0 ] ) ;
52
67
} ,
53
68
54
69
// ---- CRUD
55
70
56
71
createRecord ( modelName , payload ) {
57
- const newRecord = this . get ( ' store' ) . createRecord ( modelName , payload ) ;
72
+ const newRecord = this . get ( " store" ) . createRecord ( modelName , payload ) ;
58
73
this . showLoadingSpinner ( ) ;
59
- return newRecord . save ( )
74
+ return newRecord
75
+ . save ( )
60
76
. catch ( r => {
61
77
this . onError ( r ) ;
62
78
} )
63
- . then ( ( ) => this . hideLoadingSpinner ( ) ) ;
79
+ . then ( ( ) => this . hideLoadingSpinner ( ) ) ;
64
80
} ,
65
81
66
82
updateRecord ( record , updates = { } , opts = { } ) {
67
83
_ . each ( updates , ( v , k ) => record . set ( k , v ) ) ;
68
84
this . showLoadingSpinner ( ) ;
69
- return record . save ( )
85
+ return record
86
+ . save ( )
70
87
. then ( ( ) => {
71
- _ . get ( opts , ' onSuccess' , _ . noop ) ( ) ;
88
+ _ . get ( opts , " onSuccess" , _ . noop ) ( ) ;
72
89
} )
73
90
. catch ( e => {
74
91
if ( ! opts . noRollback ) {
75
92
record . rollbackAttributes ( ) ;
76
93
}
77
- _ . get ( opts , ' onFailure' , _ . noop ) ( e ) ;
94
+ _ . get ( opts , " onFailure" , _ . noop ) ( e ) ;
78
95
this . onError ( e ) ;
79
96
} )
80
97
. finally ( ( ) => this . hideLoadingSpinner ( ) ) ;
@@ -90,5 +107,4 @@ export default Ember.Controller.extend({
90
107
back ( ) {
91
108
history . back ( ) ;
92
109
}
93
-
94
110
} ) ;
0 commit comments