DataInventory
Changes
resources/views/organization_types/edit.edge 28(+28 -0)
Details
diff --git a/app/Controllers/Http/OrganizationTypeController.js b/app/Controllers/Http/OrganizationTypeController.js
index d8fa09b..6208eb0 100644
--- a/app/Controllers/Http/OrganizationTypeController.js
+++ b/app/Controllers/Http/OrganizationTypeController.js
@@ -4,7 +4,7 @@
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
/** @typedef {import('@adonisjs/framework/src/View')} View */
const OrganizationType = use('App/Models/OrganizationType')
-const { validate } = use('Validator')
+const { validate, validateAll } = use('Validator')
const Env = use('Env')
/**
@@ -90,6 +90,10 @@ class OrganizationTypeController {
* @param {View} ctx.view
*/
async edit ({ params, request, response, view }) {
+ const type = await OrganizationType.findOrFail(params.id)
+ return view.render('organization_types.edit', {
+ type: type.toJSON()
+ })
}
/**
@@ -100,7 +104,26 @@ class OrganizationTypeController {
* @param {Request} ctx.request
* @param {Response} ctx.response
*/
- async update ({ params, request, response }) {
+ async update ({ params, request, response, session }) {
+ const data = request.only(['type'])
+
+ const validation =await validateAll(data, {
+ type: 'required'
+ })
+
+ if (validation.fails()) {
+ session
+ .withErrors(validation.messages())
+ .flashAll()
+
+ return response.redirect('back')
+ }
+
+ const type = await OrganizationType.findOrFail(params.id)
+ type.merge(data)
+ await type.save()
+
+ return response.redirect(Env.get('APP_URL') + '/organization_types')
}
/**
resources/views/organization_types/edit.edge 28(+28 -0)
diff --git a/resources/views/organization_types/edit.edge b/resources/views/organization_types/edit.edge
new file mode 100644
index 0000000..534aa3a
--- /dev/null
+++ b/resources/views/organization_types/edit.edge
@@ -0,0 +1,28 @@
+@layout('layouts.main')
+
+@section('content')
+<form method="POST" action="{{ APP_URL() + route('/organization_types.update', {id: type.id}) + '?_method=PUT'}}">
+ {{ csrfField() }}
+ <div class="field">
+ <label class="label">Organization Type</label>
+ <input class="input" type="text" name="type" placeholder="Admin boundaries" value="{{ type.type }}" />
+ {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('type'), hasErrorFor('type')) }}
+ </div>
+
+ <div class="field is-grouped">
+ <div class="control">
+ <button class="button is-link ss-submit" type="submit">Submit</button>
+ </div>
+ <div class="control">
+ <button class="button is-text"><a href="{{ APP_URL() + route('/organization_types.index') }}">Cancel</a></button>
+ </div>
+ </div>
+ <!--
+ <div class="notification is-warning">
+ <button class="delete"></button>
+ Building Snapshots for some items may take a couple minutes. Please be patient!
+ </div>
+ -->
+</form>
+
+@endsection
\ No newline at end of file
diff --git a/resources/views/organization_types/index.edge b/resources/views/organization_types/index.edge
index 6d82388..19d9ab4 100644
--- a/resources/views/organization_types/index.edge
+++ b/resources/views/organization_types/index.edge
@@ -24,9 +24,11 @@
<tr>
<td>{{ type.type }}</td>
<td>
- <form action="{{ APP_URL() + route('/orgnization_types.destroy', { id: type.id }) + '?_method=DELETE'}}" method="post">
+ <form action="{{ APP_URL() + route('/organization_types.destroy', { id: type.id }) + '?_method=DELETE'}}" method="post">
{{ csrfField() }}
<button type="submit" name="button" class="is-small button is-danger" onclick="return confirm('Are you sure you want to delete this organization type?');">Delete</button>
+
+ <a href="{{APP_URL() + route('/organization_types.edit', { id: type.id })}}" class="button is-small is-warning">Edit</a>
</form>
</td>
</tr>