Commit 9ce17ecb authored by rdoerge's avatar rdoerge
Browse files

Added a "Change Password"-button & field

parent 2b949927
import m from 'mithril'; import m from 'mithril';
import { RadioGroup } from 'polythene-mithril'; import { RadioGroup, Button, Dialog } from 'polythene-mithril';
import { Form, textInput } from 'amiv-web-ui-components';
import { apiUrl } from 'networkConfig';
import EditView from '../views/editView'; import EditView from '../views/editView';
class passwordField {
view({ attrs: { form } }) {
return m(textInput, form.bind({
type: 'password',
name: 'password',
label: 'new password',
floatingLabel: true,
}));
}
}
export default class UserEdit extends EditView { export default class UserEdit extends EditView {
constructor(vnode) {
super(vnode);
this.pw = new Form();
}
oninit() {
// load schema
m.request(`${apiUrl}/docs/api-docs`).then((schema) => {
this.pw.setSchema(JSON.parse(JSON.stringify(schema.definitions.User)));
this.form.setSchema(schema.definitions.User);
}).catch((error) => { console.log(error); });
}
view() { view() {
const passwordButton = m(Button, {
label: 'submit',
disabled: !this.pw.valid,
events: {
onclick: () => {
this.controller.handler.patch(this.pw.data).then((data) => {
this.form.data._etag = data._etag;
Dialog.hide();
});
},
},
});
return this.layout([ return this.layout([
...this.form.renderPage({ ...this.form.renderPage({
lastname: { type: 'text', label: 'Last Name' }, lastname: { type: 'text', label: 'Last Name' },
...@@ -55,6 +93,33 @@ export default class UserEdit extends EditView { ...@@ -55,6 +93,33 @@ export default class UserEdit extends EditView {
], ],
onChange: ({ value }) => { this.form.data.department = value; }, onChange: ({ value }) => { this.form.data.department = value; },
}), }),
m(Button, {
label: 'Change Password',
border: true,
events: { onclick: () => this.resetpw() },
}),
]); ]);
} }
resetpw() {
this.pw.data._id = this.form.data._id;
this.pw.data._etag = this.form.data._etag;
Dialog.show({
body: [
'Enter the new password.',
m('div', m(passwordField, { form: this.pw })),
],
backdrop: true,
footerButtons: [
m(Button, {
label: 'Cancel',
events: {
onclick: () => {
Dialog.hide();
},
},
}),
],
});
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment