UNPKG

wejsv2old-plugin-cdp-profile

Version:
172 lines (155 loc) 5.71 kB
(function($, we, Ember, App){ App.ProfileEditController = Ember.ObjectController.extend(App.BasicInvalidMixin, App.PasswordInvalidMixin, App.MoreAboutYouMixin, App.AccountMixin, { init: function (){ this._super.apply(this, arguments); this.set('changePasswordUrl', we.configs.server.providers.accounts + '/change-password'); this.set('i18n', Ember.I18n.translations); }, majorVocabularyId: Ember.computed.alias('WeConfigs.client.publicVars.vocabularies.major'), interestsVocabularyId: Ember.computed.alias('WeConfigs.client.publicVars.vocabularies.interests'), profileName: function (){ if (!this.get('model.displayName')) return '@' + this.get('model.username'); return this.get('model.displayName'); }.property('model.displayName'), formacao: ['Nenhum', 'Médio incompleto', 'Médio completo', 'Técnico incompleto', 'Técnico completo', 'Graduação incompleta', 'Graduação completa','Especialização incompleta','Especialização completa','Mestrado incompleto','Mestrado completo','Doutorado incompleto','Doutorado completo'], generos: ['Feminino', 'Masculino'], isDirty: function (){ return !this.get('model.isDirty'); }.property('model.isDirty'), openNavegationModal: function (){ if (this.get('aboutMe') ){ $('html,body').animate({ scrollTop: 0 }, 1000); if (this.get('redirectToServiceUrl.message')) { Ember.run.later(function (){ $('#redirectModal').modal('show'); }, 1500); } } }.observes('aboutMe'), actions: { updateUser: function (){ var self = this; $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .5, color: '#fff' }, message: 'Salvando...' }); self.get('model').save().then(function (success){ $.unblockUI(); // $.growlUI('Informações salvas com sucesso!'); $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .5, color: '#fff' }, message: 'Informações salvas com sucesso!' ,showOverlay: false }); setTimeout($.unblockUI, 1000); // can edit cpf? if (self.get('model.cpf')) { self.get('model').set('canEditCPF', false); } else { self.get('model').set('canEditCPF', true); } return self.set('model', success); }, function (data){ $.unblockUI(); if (data.responseJSON.messages){ // $.growlUI(data.responseJSON.messages); $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .5, color: '#fff' }, message: data.responseJSON.messages[0].message ,showOverlay: false }); setTimeout($.unblockUI, 2000); } else { Ember.Logger.error('Unknow error on update user:', data.responseJSON); } }); }, changePassword: function (){ var self = this; $.post(this.get('changePasswordUrl'), { password: this.get('currPassword'), newPassword: this.get('newPassword'), rNewPassword: this.get('rNewPassword') }) .done(function (data){ $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .5, color: '#fff' }, message: 'Senha alterada com sucesso!' ,showOverlay: false }); setTimeout($.unblockUI, 1000); self.setProperties({ currPassword: '', newPassword: '', rNewPassword: '' }); }) .fail(function (data){ if (data.responseJSON.messages){ // $.growlUI(data.responseJSON.messages); $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .5, color: '#fff' }, message: data.responseJSON.messages[0].message ,showOverlay: false }); setTimeout($.unblockUI, 2000); } else { Ember.Logger.error('Unknow error on change password:', data.responseJSON); } }) }, showAvatarChangeModal: function(){ we.events.trigger('showAvatarChangeModal', { user: App.get('currentUser') }); }, weTermIntGetSelection: function (data){ this.set('isDirty', false); }, weTermIntHlpGetSelection: function (data){ this.set('isDirty', false); }, handleClick: function (){ // $.growlUI('É necessário o preenchimento de todos os campos do formulário `Informações Básicas` para continuar a navegação'); $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .5, color: '#fff' }, message: 'É necessário o preenchimento de todos os campos do formulário `Informações Básicas` para continuar a navegação!' ,showOverlay: false }); setTimeout($.unblockUI, 2000); } } }); })(jQuery, we, Ember, App);