diff options
author | Camil Staps | 2016-09-05 23:57:25 +0200 |
---|---|---|
committer | Camil Staps | 2016-09-05 23:57:25 +0200 |
commit | f0821c85800be8c98c465491c131a65392af050c (patch) | |
tree | 37083d36ca6e72610bfa16c798219f10b77d9988 | |
parent | Suggest new verbs (diff) |
Add roots
-rw-r--r-- | app/Http/Controllers/RootController.php | 41 | ||||
-rw-r--r-- | app/Http/routes.php | 3 | ||||
-rw-r--r-- | public/js/moderators.js | 28 | ||||
-rw-r--r-- | resources/views/add_root.php | 21 | ||||
-rw-r--r-- | resources/views/contribute.blade.php | 3 |
5 files changed, 94 insertions, 2 deletions
diff --git a/app/Http/Controllers/RootController.php b/app/Http/Controllers/RootController.php new file mode 100644 index 0000000..e3cf3e1 --- /dev/null +++ b/app/Http/Controllers/RootController.php @@ -0,0 +1,41 @@ +<?php +/** + * HebrewParseTrainer - practice Hebrew verbs + * Copyright (C) 2015 Camil Staps <info@camilstaps.nl> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +namespace App\Http\Controllers; + +use HebrewParseTrainer\Root; + +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Validator; +use Laravel\Lumen\Routing\Controller as BaseController; + +class RootController extends BaseController { + + public function create(Request $request) { + $root = new Root; + $root->root = $request->input('root'); + $root->strong = 1; + $root->save(); + + return [ + 'success' => true, + ]; + } + +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 8313029..b233efa 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -80,6 +80,9 @@ $app->group( $app->post('/verb/suggest', 'App\Http\Controllers\VerbController@suggest'); + $app->post('/root/create', + 'App\Http\Controllers\RootController@create'); + }); }); diff --git a/public/js/moderators.js b/public/js/moderators.js index 1a61075..10dd2a0 100644 --- a/public/js/moderators.js +++ b/public/js/moderators.js @@ -63,7 +63,6 @@ $(document).ready(function(){ }); $('form#suggest').submit(function(){ - var data = $(this).serialize(); var form = $(this); form.clearAlerts(); @@ -71,7 +70,7 @@ $(document).ready(function(){ $.ajax({ url: app_url + 'verb/suggest', method: 'post', - data: data, + data: form.serialize(), error: function(jqxhr, stat, error) { form.addAlert('danger', stat); }, @@ -91,4 +90,29 @@ $(document).ready(function(){ return false; }); + + $('form#add-root').submit(function(){ + var form = $(this); + + form.clearAlerts(); + + $.ajax({ + url: app_url + 'root/create', + method: 'post', + data: form.serialize(), + error: function(jqxhr, stat, error) { + form.addAlert('danger', stat); + }, + success: function(data) { + if (!data.success) { + form.addAlert('danger', data.message); + return; + } + + window.location = window.location; + } + }); + + return false; + }); }); diff --git a/resources/views/add_root.php b/resources/views/add_root.php new file mode 100644 index 0000000..da5cb1c --- /dev/null +++ b/resources/views/add_root.php @@ -0,0 +1,21 @@ +<div class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title">Add a new root</h3> + </div> + <div class="panel-body"> + <form class="form-horizontal" id="add-root"> + <div class="alerts"></div> + <div class="form-group"> + <label for="add-root-root" class="col-sm-2 control-label">Root</label> + <div class="col-sm-10"> + <input type="text" class="form-control" id="add-root-root" name="root" placeholder="קטל"/> + </div> + </div> + <div class="form-group"> + <div class="col-sm-offset-2 col-sm-10"> + <button type="submit" class="btn btn-primary">Add</button> + </div> + </div> + </form> + </div> +</div> diff --git a/resources/views/contribute.blade.php b/resources/views/contribute.blade.php index 4c3b6de..dd90e77 100644 --- a/resources/views/contribute.blade.php +++ b/resources/views/contribute.blade.php @@ -29,6 +29,9 @@ <div class="col-lg-6"> @include('suggest') </div> + <div class="col-lg-6"> + @include('add_root') + </div> </div> @endif |