From f2f16e15a44782792cc63a02f9793f7672943c98 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 1 Oct 2015 07:13:36 -0700 Subject: [PATCH] Edit user --- app/pods/protected/users/edit/controller.js | 32 +++++++++++++++++++ app/pods/protected/users/edit/route.js | 8 +++++ app/pods/protected/users/edit/template.hbs | 6 ++++ .../protected/users/user-form/component.js | 13 ++++++++ .../protected/users/user-form/template.hbs | 32 +++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 app/pods/protected/users/edit/controller.js create mode 100644 app/pods/protected/users/edit/route.js create mode 100644 app/pods/protected/users/edit/template.hbs create mode 100644 app/pods/protected/users/user-form/component.js create mode 100644 app/pods/protected/users/user-form/template.hbs diff --git a/app/pods/protected/users/edit/controller.js b/app/pods/protected/users/edit/controller.js new file mode 100644 index 0000000..903eefd --- /dev/null +++ b/app/pods/protected/users/edit/controller.js @@ -0,0 +1,32 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions: { + save: function() { + let user = this.get('model'); + + if (user.get('hasDirtyAttributes')) { + user.save().then((user) => { + this.get('flashMessages').clearMessages(); + this.transitionToRoute('protected.users.show', user); + }, (err) => { + err.errors.forEach((error) => { + this.get('flashMessages').error(error.detail); + }); + }); + } else { + this.transitionToRoute('protected.users.show', user); + } + }, + + cancel: function() { + let user = this.get('model'); + + user.get('errors').clear(); + user.rollbackAttributes(); + + this.transitionToRoute('protected.users.show', user); + }, + + }, +}); diff --git a/app/pods/protected/users/edit/route.js b/app/pods/protected/users/edit/route.js new file mode 100644 index 0000000..bc22dc0 --- /dev/null +++ b/app/pods/protected/users/edit/route.js @@ -0,0 +1,8 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model: function(params) { + return this.store.findRecord('user', params.user_id, { reload: true }); + }, + +}); diff --git a/app/pods/protected/users/edit/template.hbs b/app/pods/protected/users/edit/template.hbs new file mode 100644 index 0000000..68d66b4 --- /dev/null +++ b/app/pods/protected/users/edit/template.hbs @@ -0,0 +1,6 @@ +{{ + protected/users/user-form + user=model + save="save" + cancel="cancel" +}} diff --git a/app/pods/protected/users/user-form/component.js b/app/pods/protected/users/user-form/component.js new file mode 100644 index 0000000..a53a469 --- /dev/null +++ b/app/pods/protected/users/user-form/component.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + actions: { + save: function() { + this.sendAction('save'); + }, + + cancel: function() { + this.sendAction('cancel'); + }, + } +}); diff --git a/app/pods/protected/users/user-form/template.hbs b/app/pods/protected/users/user-form/template.hbs new file mode 100644 index 0000000..60c2d77 --- /dev/null +++ b/app/pods/protected/users/user-form/template.hbs @@ -0,0 +1,32 @@ +
+
+ {{user.name}} +
+
+ + {{input value=user.name}} +
+
+
+
+ + {{input value=user.email}} +
+
+
+
+ + {{user.role}} +
+
+
+
+ + Cancel + + {{#if user.hasDirtyAttributes}} + + {{/if}} +