@@ -17,6 +17,7 @@ import '@polymer/paper-fab/paper-fab.js';
17
17
import '@polymer/paper-input/paper-input.js' ;
18
18
import '@polymer/paper-spinner/paper-spinner.js' ;
19
19
import '@cwmr/paper-password-input/paper-password-input.js' ;
20
+ import '@cwmr/paper-tags-input/paper-tags-input.js' ;
20
21
import './shared-styles.js' ;
21
22
22
23
@customElement ( 'settings-view' )
@@ -63,55 +64,59 @@ export class SettingsView extends GompBaseElement {
63
64
}
64
65
@media screen and (max-width : 600px ) {
65
66
}
66
- </ style >
67
- < div class ="container ">
68
- < paper-card >
69
- < div class ="card-content ">
70
- < h3 > Security Settings</ h3 >
71
- < paper-input label ="Username " value ="[[currentUser.username]] " always-float-label ="" disabled =""> </ paper-input >
72
- < paper-input label ="Access Level " value ="[[currentUser.accessLevel]] " always-float-label ="" disabled =""> </ paper-input >
73
- < paper-password-input label ="Current Password " value ="{{currentPassword}} " always-float-label =""> </ paper-password-input >
74
- < paper-password-input label ="New Password " value ="{{newPassword}} " always-float-label =""> </ paper-password-input >
75
- < paper-password-input label ="Confirm Password " value ="{{repeatPassword}} " always-float-label =""> </ paper-password-input >
76
- </ div >
77
- < div class ="card-actions ">
78
- < paper-button on-click ="onUpdatePasswordClicked ">
79
- < iron-icon icon ="icons:lock-outline "> </ iron-icon >
80
- < span > Update Password</ span >
81
- < paper-button >
82
- </ div >
83
- </ paper-card >
84
- </ div >
85
- < div class ="container ">
86
- < paper-card >
87
- < div class ="card-content ">
88
- < h3 > Home Settings</ h3 >
89
- < paper-input label ="Title " always-float-label ="" value ="{{userSettings.homeTitle}} ">
90
- < paper-icon-button slot ="suffix " icon ="icons:save " on-click ="onSaveButtonClicked "> </ paper-icon-button >
91
- </ paper-input >
92
- < form id ="homeImageForm " enctype ="multipart/form-data ">
93
- < paper-input-container always-float-label ="">
94
- < label slot ="label "> Image</ label >
95
- < iron-input slot ="input ">
96
- < input id ="homeImageFile " name ="file_content " type ="file " accept =".jpg,.jpeg,.png ">
97
- </ iron-input >
98
- < paper-icon-button slot ="suffix " icon ="icons:file-upload " on-click ="onUploadButtonClicked "> </ paper-icon-button >
99
- </ paper-input-container >
100
- </ form >
101
- < img alt ="Home Image " src ="[[userSettings.homeImageUrl]] " class ="responsive " hidden \$="[[!userSettings.homeImageUrl]] ">
102
- </ div >
103
- </ paper-card >
104
- </ div >
105
- < paper-dialog id ="uploadingDialog " with-backdrop ="">
106
- < h3 > < paper-spinner active =""> </ paper-spinner > Uploading</ h3 >
107
- </ paper-dialog >
108
-
109
- < a href ="/create "> < paper-fab icon ="icons:add " class ="green "> </ paper-fab > </ a >
110
-
111
- < iron-ajax bubbles ="" id ="putPasswordAjax " url ="/api/v1/users/current/password " method ="PUT " on-response ="handlePutPasswordResponse " on-error ="handlePutPasswordError "> </ iron-ajax >
112
- < iron-ajax bubbles ="" id ="getSettingsAjax " url ="/api/v1/users/current/settings " on-response ="handleGetSettingsResponse "> </ iron-ajax >
113
- < iron-ajax bubbles ="" id ="putSettingsAjax " url ="/api/v1/users/current/settings " method ="PUT " on-response ="handlePutSettingsResponse " on-error ="handlePutSettingsError "> </ iron-ajax >
114
- < iron-ajax bubbles ="" id ="postImageAjax " url ="/api/v1/uploads " method ="POST " on-request ="handlePostImageRequest " on-response ="handlePostImageResponse " on-error ="handlePostImageError "> </ iron-ajax >
67
+ </ style >
68
+ < div class ="container ">
69
+ < paper-card >
70
+ < div class ="card-content ">
71
+ < h3 > Security Settings</ h3 >
72
+ < paper-input label ="Username " value ="[[currentUser.username]] " always-float-label ="" disabled =""> </ paper-input >
73
+ < paper-input label ="Access Level " value ="[[currentUser.accessLevel]] " always-float-label ="" disabled =""> </ paper-input >
74
+ < paper-password-input label ="Current Password " value ="{{currentPassword}} " always-float-label =""> </ paper-password-input >
75
+ < paper-password-input label ="New Password " value ="{{newPassword}} " always-float-label =""> </ paper-password-input >
76
+ < paper-password-input label ="Confirm Password " value ="{{repeatPassword}} " always-float-label =""> </ paper-password-input >
77
+ </ div >
78
+ < div class ="card-actions ">
79
+ < paper-button on-click ="onUpdatePasswordClicked ">
80
+ < iron-icon icon ="icons:lock-outline "> </ iron-icon >
81
+ < span > Update Password</ span >
82
+ < paper-button >
83
+ </ div >
84
+ </ paper-card >
85
+ </ div >
86
+ < div class ="container ">
87
+ < paper-card >
88
+ < div class ="card-content ">
89
+ < h3 > Settings</ h3 >
90
+ < paper-tags-input id ="tags " label ="Favorite Tags " tags ="{{userSettings.favoriteTags}} "> </ paper-tags-input >
91
+ < paper-input label ="Home Title " always-float-label ="" value ="{{userSettings.homeTitle}} "> </ paper-input >
92
+ < form id ="homeImageForm " enctype ="multipart/form-data ">
93
+ < paper-input-container always-float-label ="">
94
+ < label slot ="label "> Home Image</ label >
95
+ < iron-input slot ="input ">
96
+ < input id ="homeImageFile " name ="file_content " type ="file " accept =".jpg,.jpeg,.png ">
97
+ </ iron-input >
98
+ </ paper-input-container >
99
+ </ form >
100
+ < img alt ="Home Image " src ="[[userSettings.homeImageUrl]] " class ="responsive " hidden \$="[[!userSettings.homeImageUrl]] ">
101
+ </ div >
102
+ < div class ="card-actions ">
103
+ < paper-button on-click ="onSaveButtonClicked ">
104
+ < iron-icon icon ="icons:save "> </ iron-icon >
105
+ < span > Save</ span >
106
+ < paper-button >
107
+ </ div >
108
+ </ paper-card >
109
+ </ div >
110
+ < paper-dialog id ="uploadingDialog " with-backdrop ="">
111
+ < h3 > < paper-spinner active =""> </ paper-spinner > Uploading</ h3 >
112
+ </ paper-dialog >
113
+
114
+ < a href ="/create "> < paper-fab icon ="icons:add " class ="green "> </ paper-fab > </ a >
115
+
116
+ < iron-ajax bubbles ="" id ="putPasswordAjax " url ="/api/v1/users/current/password " method ="PUT " on-response ="handlePutPasswordResponse " on-error ="handlePutPasswordError "> </ iron-ajax >
117
+ < iron-ajax bubbles ="" id ="getSettingsAjax " url ="/api/v1/users/current/settings " on-response ="handleGetSettingsResponse "> </ iron-ajax >
118
+ < iron-ajax bubbles ="" id ="putSettingsAjax " url ="/api/v1/users/current/settings " method ="PUT " on-response ="handlePutSettingsResponse " on-error ="handlePutSettingsError "> </ iron-ajax >
119
+ < iron-ajax bubbles ="" id ="postImageAjax " url ="/api/v1/uploads " method ="POST " on-request ="handlePostImageRequest " on-response ="handlePostImageResponse " on-error ="handlePostImageError "> </ iron-ajax >
115
120
` ;
116
121
}
117
122
@@ -167,12 +172,14 @@ export class SettingsView extends GompBaseElement {
167
172
this . putPasswordAjax . generateRequest ( ) ;
168
173
}
169
174
protected onSaveButtonClicked ( ) {
170
- this . putSettingsAjax . body = JSON . stringify ( this . userSettings ) as any ;
171
- this . putSettingsAjax . generateRequest ( ) ;
172
- }
173
- protected onUploadButtonClicked ( ) {
174
- this . postImageAjax . body = new FormData ( this . homeImageForm ) ;
175
- this . postImageAjax . generateRequest ( ) ;
175
+ // If there's no image to upload, go directly to saving
176
+ if ( ! this . homeImageFile . value ) {
177
+ this . saveSettings ( ) ;
178
+ } else {
179
+ // We start by uploading the image, after which the rest of the settings will be saved
180
+ this . postImageAjax . body = new FormData ( this . homeImageForm ) ;
181
+ this . postImageAjax . generateRequest ( ) ;
182
+ }
176
183
}
177
184
178
185
protected isActiveChanged ( isActive : boolean ) {
@@ -212,13 +219,18 @@ export class SettingsView extends GompBaseElement {
212
219
213
220
const location = req . xhr . getResponseHeader ( 'Location' ) ;
214
221
this . userSettings . homeImageUrl = location ;
215
- this . onSaveButtonClicked ( ) ;
222
+ this . saveSettings ( ) ;
216
223
}
217
224
protected handlePostImageError ( ) {
218
225
this . uploadingDialog . close ( ) ;
219
226
this . showToast ( 'Upload failed!' ) ;
220
227
}
221
228
229
+ private saveSettings ( ) {
230
+ this . putSettingsAjax . body = JSON . stringify ( this . userSettings ) as any ;
231
+ this . putSettingsAjax . generateRequest ( ) ;
232
+ }
233
+
222
234
protected refresh ( ) {
223
235
this . getSettingsAjax . generateRequest ( ) ;
224
236
}
0 commit comments