diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index 93312f8a6..1eb8526fc 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -37,10 +37,11 @@ class App.ControllerForm extends App.Controller attribute.value = @params[attribute.name] # rename display and name to _confirm - attribute.display = attribute.display + ' (confirm)' - attribute.name = attribute.name + '_confirm'; - item = @formGenItem( attribute, @model.className, fieldset ) - item.appendTo(fieldset) + if !attribute.single + attribute.display = attribute.display + ' (confirm)' + attribute.name = attribute.name + '_confirm'; + item = @formGenItem( attribute, @model.className, fieldset ) + item.appendTo(fieldset) # return form return fieldset diff --git a/app/assets/javascripts/app/controllers/_profile/password.js.coffee b/app/assets/javascripts/app/controllers/_profile/password.js.coffee new file mode 100644 index 000000000..1c12a4abb --- /dev/null +++ b/app/assets/javascripts/app/controllers/_profile/password.js.coffee @@ -0,0 +1,61 @@ +class App.ProfilePassword extends App.Controller + events: + 'submit form': 'update' + + constructor: -> + super + return if !@authenticate() + @render() + + render: => + + # item + html = $( App.view('profile/password')() ) + + configure_attributes = [ + { name: 'password_old', display: 'Current Password', tag: 'input', type: 'password', limit: 100, null: false, class: 'input span4', single: true }, + { name: 'password_new', display: 'New Password', tag: 'input', type: 'password', limit: 100, null: false, class: 'input span4', }, + ] + + @form = new App.ControllerForm( + el: html.find('.password_item') + model: { configure_attributes: configure_attributes } + autofocus: false + ) + @html html + + 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 + App.Com.ajax( + id: 'password_reset' + type: 'POST' + url: 'api/users/password_change' + data: JSON.stringify(params) + processData: true + success: @success + error: @error + ) + + success: (data, status, xhr) => + @render() + @notify( + type: 'success' + msg: App.i18n.translateContent( 'Password changed successfully!' ) + ) + + error: (xhr, status, error) => + @render() + data = JSON.parse( xhr.responseText ) + @notify( + type: 'error' + msg: App.i18n.translateContent( data.message ) + ) diff --git a/app/assets/javascripts/app/controllers/_settings/area.js.coffee b/app/assets/javascripts/app/controllers/_settings/area.js.coffee index cff6083ab..154c16528 100644 --- a/app/assets/javascripts/app/controllers/_settings/area.js.coffee +++ b/app/assets/javascripts/app/controllers/_settings/area.js.coffee @@ -1,5 +1,3 @@ -$ = jQuery.sub() - class App.SettingsArea extends App.Controller constructor: -> super @@ -23,7 +21,7 @@ class App.SettingsArea extends App.Controller class App.SettingsAreaItem extends App.Controller events: - 'submit form': 'update', + 'submit form': 'update' constructor: -> super diff --git a/app/assets/javascripts/app/controllers/profile.js.coffee b/app/assets/javascripts/app/controllers/profile.js.coffee index e6cc60cd8..11e04369a 100644 --- a/app/assets/javascripts/app/controllers/profile.js.coffee +++ b/app/assets/javascripts/app/controllers/profile.js.coffee @@ -1,21 +1,32 @@ -class Index extends App.Controller -# events: -# 'focusin [data-type=edit]': 'edit_in' +class Index extends App.ControllerLevel2 + toggleable: false +# toggleable: true constructor: -> super - - # set title - @title 'Profile' + return if !@authenticate() + + @menu = [ + { name: 'Password', 'target': 'password', controller: App.ProfilePassword, params: {} }, + { name: 'Language', 'target': 'language', controller: App.ProfileLinkedAccounts, params: { area: 'Ticket::Number' } }, + { name: 'Link Accounts', 'target': 'accounts', controller: App.ProfileLinkedAccounts, params: { area: 'Ticket::Number' } }, +# { name: 'Notifications', 'target': 'notify', controller: App.SettingsArea, params: { area: 'Ticket::Number' } }, + ] + @page = { + title: 'Profile', + head: 'Profile', + sub_title: 'Settings' + nav: '#profile', + } + + # render page @render() - - @navupdate '#profile' - - render: -> - @html App.view('profile')() +# render: -> +# @html App.view('profile')() +App.Config.set( 'profile/:target', Index, 'Routes' ) App.Config.set( 'profile', Index, 'Routes' ) App.Config.set( 'Profile', { prio: 1700, parent: '#current_user', name: 'Profile', target: '#profile', role: [ 'Agent', 'Customer' ] }, 'NavBarRight' ) diff --git a/app/assets/javascripts/app/controllers/reset_password.js.coffee b/app/assets/javascripts/app/controllers/reset_password.js.coffee index 0f0cf7a8e..03b9dd2e2 100644 --- a/app/assets/javascripts/app/controllers/reset_password.js.coffee +++ b/app/assets/javascripts/app/controllers/reset_password.js.coffee @@ -1,5 +1,3 @@ -$ = jQuery.sub() - class Index extends App.Controller className: 'container' diff --git a/app/assets/javascripts/app/controllers/settings.js.coffee b/app/assets/javascripts/app/controllers/settings.js.coffee index 6fb46a34a..b4f51c0b0 100644 --- a/app/assets/javascripts/app/controllers/settings.js.coffee +++ b/app/assets/javascripts/app/controllers/settings.js.coffee @@ -1,5 +1,3 @@ -$ = jQuery.sub() - class Index extends App.ControllerLevel2 toggleable: false # toggleable: true diff --git a/app/assets/javascripts/app/views/profile.jst.eco b/app/assets/javascripts/app/views/profile.jst.eco index a6fb0afd4..64cd44a11 100644 --- a/app/assets/javascripts/app/views/profile.jst.eco +++ b/app/assets/javascripts/app/views/profile.jst.eco @@ -1,14 +1,12 @@