1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

fix redirect after training edition

This commit is contained in:
Sylvain 2016-06-23 12:46:14 +02:00
parent 7e1b05d339
commit 8bd4e6897d
5 changed files with 73 additions and 36 deletions

View File

@ -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()
]

View File

@ -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 @@
<div class="form-group m-b-lg" ng-class="{'has-error': trainingForm['training[name]'].$dirty && trainingForm['training[name]'].$invalid}">
<label for="name" class="col-sm-2 control-label">{{ 'name' | translate }} *</label>
<div class="col-sm-4">
<input ng-model="training.name"
type="text" name="training[name]"
<input name="training[name]"
ng-model="training.name"
type="text"
class="form-control"
id="training_name"
placeholder="{{'name' | translate}}"
required>
required/>
<span class="help-block" ng-show="trainingForm['training[name]'].$dirty && trainingForm['training[name]'].$error.required" translate>{{ 'name_is_required' }}</span>
</div>
</div>

View File

@ -1,25 +1,23 @@
<div>
<section class="heading b-b">
<div class="row no-gutter">
<div class="col-xs-2 col-sm-2 col-md-1">
<section class="heading-btn">
<a ng-click="backPrevLocation($event)"><i class="fa fa-long-arrow-left"></i></a>
</section>
</div>
<div class="col-xs-10 col-sm-10 col-md-8 b-l b-r-md">
<section class="heading-title">
<h1>{{ training.name }}</h1>
</section>
</div>
<div class="col-xs-12 col-sm-12 col-md-3 b-t hide-b-md">
<section class="heading-actions wrapper">
<div class="btn btn-lg btn-block btn-default rounded m-t-xs" ng-click="backPrevLocation($event)" translate>{{ 'cancel' }}</div>
</section>
</div>
<section class="heading b-b">
<div class="row no-gutter">
<div class="col-xs-2 col-sm-2 col-md-1">
<section class="heading-btn">
<a ng-click="cancel()"><i class="fa fa-long-arrow-left"></i></a>
</section>
</div>
</section>
<div class="col-xs-10 col-sm-10 col-md-8 b-l b-r-md">
<section class="heading-title">
<h1>{{ training.name }}</h1>
</section>
</div>
<div class="col-xs-12 col-sm-12 col-md-3 b-t hide-b-md">
<section class="heading-actions wrapper">
<div class="btn btn-lg btn-block btn-default rounded m-t-xs" ng-click="cancel()" translate>{{ 'cancel' }}</div>
</section>
</div>
</div>
</section>
<div class="row no-gutter">
@ -27,4 +25,3 @@
<ng-include src="'<%= asset_path 'admin/trainings/_form.html' %>'"></ng-include>
</div>
</div>
</div>

View File

@ -2,7 +2,7 @@
<div class="row no-gutter">
<div class="col-md-1 hidden-xs">
<section class="heading-btn">
<a href="#" ng-click="backPrevLocation($event)"><i class="fa fa-long-arrow-left "></i></a>
<a href="#" ng-click="cancel()"><i class="fa fa-long-arrow-left "></i></a>
</section>
</div>
<div class="col-md-8 b-l b-r">

View File

@ -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