@@ -40,6 +40,7 @@ define([
40
40
41
41
initialize : function ( options ) {
42
42
this . subscription = options . subscription ;
43
+ this . user = options . user ;
43
44
this . render ( ) ;
44
45
} ,
45
46
@@ -97,44 +98,55 @@ define([
97
98
*/
98
99
// Name
99
100
onClickEditName : function ( e ) {
100
- var $el = $ ( e . currentTarget ) ;
101
- if ( ! $el . hasClass ( '-editing' ) ) {
102
- var value = this . subscription . get ( 'name' ) ;
103
-
104
- $el . addClass ( '-editing' ) .
105
- html ( '<input />' ) .
106
- find ( 'input' ) . val ( value ) .
107
- focus ( ) ;
108
-
109
- $el . on ( 'keyup.' + this . subscription . get ( 'id' ) , this . onKeyUpEditName . bind ( this ) ) ;
110
- }
101
+ this . user . checkLogged ( )
102
+ . then ( function ( response ) {
103
+ var $el = $ ( e . currentTarget ) ;
104
+ if ( ! $el . hasClass ( '-editing' ) ) {
105
+ var value = this . subscription . get ( 'name' ) ;
106
+
107
+ $el . addClass ( '-editing' ) .
108
+ html ( '<input />' ) .
109
+ find ( 'input' ) . val ( value ) .
110
+ focus ( ) ;
111
+
112
+ $el . on ( 'keyup.' + this . subscription . get ( 'id' ) , this . onKeyUpEditName . bind ( this ) ) ;
113
+ }
114
+ } . bind ( this ) )
115
+ . catch ( function ( e ) {
116
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
117
+ } . bind ( this ) ) ;
111
118
} ,
112
119
113
120
onBlurEditName : function ( e ) {
114
- var $el = $ ( e . currentTarget ) ;
115
- if ( $el . hasClass ( '-editing' ) ) {
116
- var old_value = this . subscription . get ( 'name' ) ,
117
- new_value = $el . find ( 'input' ) . val ( ) ;
118
-
119
- $el . off ( 'keyup.' + this . subscription . get ( 'id' ) ) ;
120
-
121
- // Check if the value has changed before save it
122
- if ( old_value != new_value ) {
123
- this . subscription . save ( 'name' , new_value , {
124
- patch : true ,
125
- wait : true ,
126
- silent : true ,
127
- success : this . resetName . bind ( this ) ,
128
- error : function ( ) {
129
- $el . find ( 'input' ) .
130
- addClass ( 'error' ) .
131
- val ( old_value ) .
132
- focus ( ) ;
121
+ this . user . checkLogged ( )
122
+ . then ( function ( response ) {
123
+ var $el = $ ( e . currentTarget ) ;
124
+ if ( $el . hasClass ( '-editing' ) ) {
125
+ var old_value = this . subscription . get ( 'name' ) ,
126
+ new_value = $el . find ( 'input' ) . val ( ) ;
127
+
128
+ $el . off ( 'keyup.' + this . subscription . get ( 'id' ) ) ;
129
+
130
+ // Check if the value has changed before save it
131
+ if ( old_value != new_value ) {
132
+ this . subscription . save ( 'name' , new_value , {
133
+ patch : true ,
134
+ wait : true ,
135
+ silent : true ,
136
+ success : this . resetName . bind ( this ) ,
137
+ error : function ( ) {
138
+ $el . find ( 'input' ) .
139
+ addClass ( 'error' ) .
140
+ val ( old_value ) .
141
+ focus ( ) ;
142
+ }
143
+ } ) ;
133
144
}
134
- } ) ;
135
- }
136
-
137
- }
145
+ }
146
+ } . bind ( this ) )
147
+ . catch ( function ( e ) {
148
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
149
+ } . bind ( this ) ) ;
138
150
} ,
139
151
140
152
onKeyUpEditName : function ( e ) {
@@ -149,45 +161,57 @@ define([
149
161
150
162
// Language
151
163
onChangeLanguage : function ( e ) {
152
- var $el = $ ( e . currentTarget ) ,
153
- old_value = this . subscription . get ( 'language' ) ,
154
- new_value = $el . val ( ) ;
155
-
156
- this . subscription . save ( 'language' , new_value , {
157
- wait : true ,
158
- silent : true ,
159
- patch : true ,
160
- success : function ( ) {
161
- $el . val ( new_value ) ;
162
- mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-correct' ] ) ;
163
- } ,
164
- error : function ( ) {
165
- $el . val ( old_value ) ;
166
- mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-incorrect' ] ) ;
167
- }
168
- } ) ;
164
+ this . user . checkLogged ( )
165
+ . then ( function ( response ) {
166
+ var $el = $ ( e . currentTarget ) ,
167
+ old_value = this . subscription . get ( 'language' ) ,
168
+ new_value = $el . val ( ) ;
169
+
170
+ this . subscription . save ( 'language' , new_value , {
171
+ wait : true ,
172
+ silent : true ,
173
+ patch : true ,
174
+ success : function ( ) {
175
+ $el . val ( new_value ) ;
176
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-correct' ] ) ;
177
+ } ,
178
+ error : function ( ) {
179
+ $el . val ( old_value ) ;
180
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-incorrect' ] ) ;
181
+ }
182
+ } ) ;
183
+ } . bind ( this ) )
184
+ . catch ( function ( e ) {
185
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
186
+ } . bind ( this ) ) ;
169
187
} ,
170
188
171
189
// Destroy
172
190
onClickDestroy : function ( e ) {
173
191
e . preventDefault ( ) ;
174
192
175
- this . subscription . set ( 'from' , 'your profile' ) ;
193
+ this . user . checkLogged ( )
194
+ . then ( function ( response ) {
195
+ this . subscription . set ( 'from' , 'your profile' ) ;
176
196
177
- // Create and append confirm view
178
- var confirmView = new ListItemDeleteConfirmView ( {
179
- model : this . subscription
180
- } ) ;
181
- this . $el . append ( confirmView . render ( ) . el ) ;
182
-
183
- // Listen to confirmed param of confirmView
184
- this . listenTo ( confirmView , 'confirmed' , function ( ) {
185
- this . subscription . destroy ( {
186
- success : this . remove . bind ( this )
187
- } ) ;
188
- mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-deleted' ] ) ;
189
- window . ga ( 'send' , 'event' , 'User Profile' , 'Delete Subscription' ) ;
190
- } . bind ( this ) ) ;
197
+ // Create and append confirm view
198
+ var confirmView = new ListItemDeleteConfirmView ( {
199
+ model : this . subscription
200
+ } ) ;
201
+ this . $el . append ( confirmView . render ( ) . el ) ;
202
+
203
+ // Listen to confirmed param of confirmView
204
+ this . listenTo ( confirmView , 'confirmed' , function ( ) {
205
+ this . subscription . destroy ( {
206
+ success : this . remove . bind ( this )
207
+ } ) ;
208
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-deleted' ] ) ;
209
+ window . ga ( 'send' , 'event' , 'User Profile' , 'Delete Subscription' ) ;
210
+ } . bind ( this ) ) ;
211
+ } . bind ( this ) )
212
+ . catch ( function ( e ) {
213
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
214
+ } . bind ( this ) ) ;
191
215
} ,
192
216
193
217
// View on map
@@ -197,40 +221,59 @@ define([
197
221
198
222
// Datasets
199
223
onClickDataset : function ( ) {
200
- var confirmView = new ListItemDatasetsConfirmView ( {
201
- model : this . subscription
202
- } ) ;
224
+ this . user . checkLogged ( )
225
+ . then ( function ( response ) {
226
+ var confirmView = new ListItemDatasetsConfirmView ( {
227
+ model : this . subscription
228
+ } ) ;
203
229
204
- this . $el . append ( confirmView . render ( ) . el ) ;
230
+ this . $el . append ( confirmView . render ( ) . el ) ;
205
231
206
- // Listen to confirmed param of confirmView
207
- this . listenTo ( confirmView , 'confirmed' , function ( datasets ) {
208
- this . saveDatasets ( datasets ) ;
209
- } . bind ( this ) ) ;
232
+ // Listen to confirmed param of confirmView
233
+ this . listenTo ( confirmView , 'confirmed' , function ( datasets ) {
234
+ this . saveDatasets ( datasets ) ;
235
+ } . bind ( this ) ) ;
236
+ } . bind ( this ) )
237
+ . catch ( function ( e ) {
238
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
239
+ } . bind ( this ) ) ;
210
240
} ,
211
241
212
242
onClickDatasetRemove : function ( e ) {
213
243
e && e . preventDefault ( ) ;
214
- var datasets = _ . without ( this . subscription . get ( 'datasets' ) , $ ( e . currentTarget ) . data ( 'dataset' ) ) ;
215
- this . saveDatasets ( datasets ) ;
244
+
245
+ this . user . checkLogged ( )
246
+ . then ( function ( response ) {
247
+ var datasets = _ . without ( this . subscription . get ( 'datasets' ) , $ ( e . currentTarget ) . data ( 'dataset' ) ) ;
248
+ this . saveDatasets ( datasets ) ;
249
+ } . bind ( this ) )
250
+ . catch ( function ( e ) {
251
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
252
+ } . bind ( this ) ) ;
216
253
} ,
217
254
218
255
/**
219
256
* HELPERS
220
257
* - resetName
221
258
*/
222
259
saveDatasets : function ( datasets ) {
223
- this . subscription . save ( 'datasets' , datasets , {
224
- wait : true ,
225
- silent : true ,
226
- patch : true ,
227
- success : function ( ) {
228
- mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-correct' ] ) ;
229
- } ,
230
- error : function ( ) {
231
- mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-incorrect' ] ) ;
232
- }
233
- } ) ;
260
+ this . user . checkLogged ( )
261
+ . then ( function ( response ) {
262
+ this . subscription . save ( 'datasets' , datasets , {
263
+ wait : true ,
264
+ silent : true ,
265
+ patch : true ,
266
+ success : function ( ) {
267
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-correct' ] ) ;
268
+ } ,
269
+ error : function ( ) {
270
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-subscription-incorrect' ] ) ;
271
+ }
272
+ } ) ;
273
+ } . bind ( this ) )
274
+ . catch ( function ( e ) {
275
+ mps . publish ( 'Notification/open' , [ 'notification-my-gfw-not-logged' ] ) ;
276
+ } . bind ( this ) ) ;
234
277
} ,
235
278
236
279
resetName : function ( ) {
0 commit comments