From 8bd4e6897de9e65e4383d42c813d17f93f104962 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 23 Jun 2016 12:46:14 +0200 Subject: [PATCH] fix redirect after training edition --- .../controllers/admin/trainings.coffee.erb | 48 ++++++++++++++++--- .../templates/admin/trainings/_form.html.erb | 9 ++-- .../templates/admin/trainings/edit.html.erb | 41 ++++++++-------- .../templates/admin/trainings/new.html.erb | 2 +- app/controllers/api/trainings_controller.rb | 9 +++- 5 files changed, 73 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/controllers/admin/trainings.coffee.erb b/app/assets/javascripts/controllers/admin/trainings.coffee.erb index 89535625e..6818d7425 100644 --- a/app/assets/javascripts/controllers/admin/trainings.coffee.erb +++ b/app/assets/javascripts/controllers/admin/trainings.coffee.erb @@ -61,7 +61,10 @@ class TrainingsController ## Application.Controllers.controller "NewTrainingController", [ '$scope', '$state', 'machinesPromise', 'CSRF' , ($scope, $state, machinesPromise, CSRF) -> - CSRF.setMetaTags() + + + + ### PUBLIC SCOPE ### ## Form action on the following URL $scope.method = 'post' @@ -72,8 +75,22 @@ Application.Controllers.controller "NewTrainingController", [ '$scope', '$state' ## list of machines $scope.machines = machinesPromise - ## Using the TrainingsController - new TrainingsController($scope, $state) + + + ### PRIVATE SCOPE ### + + ## + # Kind of constructor: these actions will be realized first when the controller is loaded + ## + initialize = -> + CSRF.setMetaTags() + + ## Using the TrainingsController + new TrainingsController($scope, $state) + + + ## !!! MUST BE CALLED AT THE END of the controller + initialize() ] @@ -83,10 +100,13 @@ Application.Controllers.controller "NewTrainingController", [ '$scope', '$state' ## Application.Controllers.controller "EditTrainingController", [ '$scope', '$state', '$stateParams', 'trainingPromise', 'machinesPromise', 'CSRF' , ($scope, $state, $stateParams, trainingPromise, machinesPromise, CSRF) -> - CSRF.setMetaTags() + + + + ### PUBLIC SCOPE ### ## Form action on the following URL - $scope.method = 'put' + $scope.method = 'patch' ## API URL where the form will be posted $scope.actionUrl = '/api/trainings/' + $stateParams.id @@ -97,8 +117,22 @@ Application.Controllers.controller "EditTrainingController", [ '$scope', '$state ## list of machines $scope.machines = machinesPromise - ## Using the TrainingsController - new TrainingsController($scope, $state) + + + ### PRIVATE SCOPE ### + + ## + # Kind of constructor: these actions will be realized first when the controller is loaded + ## + initialize = -> + CSRF.setMetaTags() + + ## Using the TrainingsController + new TrainingsController($scope, $state) + + + ## !!! MUST BE CALLED AT THE END of the controller + initialize() ] diff --git a/app/assets/templates/admin/trainings/_form.html.erb b/app/assets/templates/admin/trainings/_form.html.erb index 513efd04d..b4715c238 100644 --- a/app/assets/templates/admin/trainings/_form.html.erb +++ b/app/assets/templates/admin/trainings/_form.html.erb @@ -2,7 +2,7 @@ name="trainingForm" class="form-horizontal" ng-attr-action="{{ actionUrl }}" - ng-upload="whatthefuck(content)" + ng-upload="submited(content)" upload-options-enable-rails-csrf="true" unsaved-warning-form novalidate> @@ -17,12 +17,13 @@
- + required/> {{ 'name_is_required' }}
diff --git a/app/assets/templates/admin/trainings/edit.html.erb b/app/assets/templates/admin/trainings/edit.html.erb index 55cd89b48..d02b1f22e 100644 --- a/app/assets/templates/admin/trainings/edit.html.erb +++ b/app/assets/templates/admin/trainings/edit.html.erb @@ -1,25 +1,23 @@ -
- -
-
-
-
- -
-
-
-
-

{{ training.name }}

-
-
- -
-
-
{{ 'cancel' }}
-
-
+
+
+
+
+ +
-
+
+
+

{{ training.name }}

+
+
+ +
+
+
{{ 'cancel' }}
+
+
+
+
@@ -27,4 +25,3 @@
- diff --git a/app/assets/templates/admin/trainings/new.html.erb b/app/assets/templates/admin/trainings/new.html.erb index 41dd344f8..7635f836d 100644 --- a/app/assets/templates/admin/trainings/new.html.erb +++ b/app/assets/templates/admin/trainings/new.html.erb @@ -2,7 +2,7 @@
diff --git a/app/controllers/api/trainings_controller.rb b/app/controllers/api/trainings_controller.rb index d2ee21706..f1b973b25 100644 --- a/app/controllers/api/trainings_controller.rb +++ b/app/controllers/api/trainings_controller.rb @@ -35,10 +35,15 @@ class API::TrainingsController < API::ApiController members.each do |m| m.trainings << @training end + + head :no_content else - @training.update(training_params) + if @training.update(training_params) + render :show, status: :ok, location: @training + else + render json: @training.errors, status: :unprocessable_entity + end end - head :no_content end def destroy