diff --git a/app/assets/javascripts/app/controllers/_profile/avatar.js.coffee b/app/assets/javascripts/app/controllers/_profile/avatar.js.coffee new file mode 100644 index 000000000..792772240 --- /dev/null +++ b/app/assets/javascripts/app/controllers/_profile/avatar.js.coffee @@ -0,0 +1,60 @@ +class Index extends App.Controller + events: + 'submit form': 'update' + + constructor: -> + super + return if !@authenticate() + @render() + + render: => + @html App.view('profile/avatar')() + + + update: (e) => + e.preventDefault() + params = @formParam(e.target) + error = @form.validate(params) + if error + @formValidate( form: e.target, errors: error ) + return false + + @formDisable(e) + + # get data + @locale = params['locale'] + @ajax( + id: 'preferences' + type: 'PUT' + url: @apiPath + '/users/preferences' + data: JSON.stringify(params) + processData: true + success: @success + error: @error + ) + + success: (data, status, xhr) => + App.User.retrieve( + App.Session.get( 'id' ), + => + App.i18n.set( @locale ) + App.Event.trigger( 'ui:rerender' ) + App.Event.trigger( 'ui:page:rerender' ) + @notify( + type: 'success' + msg: App.i18n.translateContent( 'Successfully!' ) + ) + , + true + ) + + error: (xhr, status, error) => + @render() + data = JSON.parse( xhr.responseText ) + @notify( + type: 'error' + msg: App.i18n.translateContent( data.message ) + ) + +App.Config.set( 'Avatar', { prio: 1100, name: 'Avatar', parent: '#profile', target: '#profile/avatar', controller: Index }, 'NavBarProfile' ) + diff --git a/app/assets/javascripts/app/views/profile/avatar.jst.eco b/app/assets/javascripts/app/views/profile/avatar.jst.eco new file mode 100644 index 000000000..074e9ad3e --- /dev/null +++ b/app/assets/javascripts/app/views/profile/avatar.jst.eco @@ -0,0 +1,5 @@ +
+

<%- @T( 'Avatar' ) %>

+
+ +