Add user edit view

This commit is contained in:
Susmitha Girumala committed 2020-06-23 15:21:00 -04:00
1 parent 8cb1d81d71
commit d53f0aeae8
3 files changed
+89

No files matched your search

+60
View File
@@ -1,4 +1,64 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class OrgsOrgUsersUserRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
* Returns a user by id.
* @param {object} params
* @return {Promise{UserModel}}
*/
model({ user_id: id }) {
return this.store.findRecord('user', id);
}
// =actions
/**
* Rollback changes on user.
* @param {UserModel} user
*/
@action
cancel(user) {
user.rollbackAttributes();
}
/**
* Handle save user.
* @param {UserModel} user
* @param {Event} e
*/
@action
async save(user) {
try {
await user.save();
this.notify.success(this.intl.t('notify.save-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
/**
* Deletes the user and redirects to index.
* @param {UserModel} user
*/
@action
async delete(user) {
try {
await user.destroyRecord();
this.transitionTo('orgs.org.users');
this.notify.success(this.intl.t('notify.user.delete-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -1 +1,3 @@
{{title @model.name}}
{{outlet}}
@@ -0,0 +1,27 @@
<Rose::Layout::Page as |page|>
<page.breadcrumbs>
<BreadCrumbs />
</page.breadcrumbs>
<page.header>
<h2>{{t "resources.user"}}</h2>
</page.header>
<page.body>
<Form::User
@model={{@model}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>
<Rose::Separator />
<Rose::Button
@style="warning"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
>
{{t 'actions.delete'}}
</Rose::Button>
</page.body>
</Rose::Layout::Page>