mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
ability to disabled training
This commit is contained in:
parent
14592c1e18
commit
05d9e62dd2
@ -9,9 +9,11 @@
|
||||
# Provides :
|
||||
# - $scope.submited(content)
|
||||
# - $scope.fileinputClass(v)
|
||||
# - $scope.onDisableToggled
|
||||
#
|
||||
# Requires :
|
||||
# - $state (Ui-Router) [ 'app.admin.trainings' ]
|
||||
# - $scope.training
|
||||
##
|
||||
class TrainingsController
|
||||
constructor: ($scope, $state) ->
|
||||
@ -43,6 +45,14 @@ class TrainingsController
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Force the 'public_page' attribute to false when the current training is disabled
|
||||
##
|
||||
$scope.onDisableToggled = ->
|
||||
$scope.training.public_page = !$scope.training.disabled
|
||||
|
||||
|
||||
|
||||
##
|
||||
# For use with 'ng-class', returns the CSS class name for the uploads previews.
|
||||
# The preview may show a placeholder or the content of the file depending on the upload state.
|
||||
|
@ -15,21 +15,21 @@
|
||||
<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</uib-alert>
|
||||
|
||||
<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>
|
||||
<label for="name" class="col-sm-2 control-label">{{ 'trainings_form.name' | translate }} *</label>
|
||||
<div class="col-sm-4">
|
||||
<input name="training[name]"
|
||||
ng-model="training.name"
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="training_name"
|
||||
placeholder="{{'name' | translate}}"
|
||||
placeholder="{{'trainings_form.name' | translate}}"
|
||||
required/>
|
||||
<span class="help-block" ng-show="trainingForm['training[name]'].$dirty && trainingForm['training[name]'].$error.required" translate>{{ 'name_is_required' }}</span>
|
||||
<span class="help-block" ng-show="trainingForm['training[name]'].$dirty && trainingForm['training[name]'].$error.required" translate>{{ 'trainings_form.name_is_required' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group m-b-lg">
|
||||
<label for="training_image" class="col-sm-2 control-label">{{ 'illustration' | translate }} *</label>
|
||||
<label for="training_image" class="col-sm-2 control-label">{{ 'trainings_form.illustration' | translate }} *</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="fileinput" data-provides="fileinput" ng-class="fileinputClass(training.training_image)">
|
||||
<div class="fileinput-new thumbnail" style="width: 334px; height: 250px;">
|
||||
@ -40,7 +40,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<span class="btn btn-default btn-file">
|
||||
<span class="fileinput-new">{{ 'add_an_illustration' | translate }} <i class="fa fa-upload fa-fw"></i></span>
|
||||
<span class="fileinput-new">{{ 'trainings_form.add_an_illustration' | translate }} <i class="fa fa-upload fa-fw"></i></span>
|
||||
<span class="fileinput-exists" translate>{{ 'change' }}</span>
|
||||
<input type="file"
|
||||
ng-model="training.training_image"
|
||||
@ -57,16 +57,16 @@
|
||||
|
||||
|
||||
<div class="form-group m-b-xl" ng-class="{'has-error': trainingForm['training[description]'].$dirty && trainingForm['training[description]'].$invalid}">
|
||||
<label for="training_description" class="col-sm-2 control-label">{{ 'description' | translate }} *</label>
|
||||
<label for="training_description" class="col-sm-2 control-label">{{ 'trainings_form.description' | translate }} *</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="hidden" name="training[description]" ng-value="training.description" />
|
||||
<summernote ng-model="training.description" id="training_description" placeholder="" config="summernoteOpts" name="training[description]" required></summernote>
|
||||
<span class="help-block" ng-show="trainingForm['training[description]'].$dirty && trainingForm['training[description]'].$error.required" translate>{{ 'description_is_required' }}</span>
|
||||
<span class="help-block" ng-show="trainingForm['training[description]'].$dirty && trainingForm['training[description]'].$error.required" translate>{{ 'trainings_form.description_is_required' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group m-b-lg" ng-class="{'has-error': trainingForm['training[machine_ids]'].$dirty && trainingForm['training[machine_ids]'].$invalid}">
|
||||
<label for="training_machines" class="col-sm-2 control-label">{{ 'associated_machines' | translate }}</label>
|
||||
<label for="training_machines" class="col-sm-2 control-label">{{ 'trainings_form.associated_machines' | translate }}</label>
|
||||
<div class="col-sm-4">
|
||||
<ui-select multiple ng-model="training.machine_ids" class="form-control" id="training_machines">
|
||||
<ui-select-match>
|
||||
@ -81,7 +81,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group m-b-lg" ng-class="{'has-error': trainingForm['training[nb_total_places]'].$dirty && trainingForm['training[nb_total_places]'].$invalid}">
|
||||
<label for="training_nb_total_places" class="col-sm-2 control-label">{{ 'number_of_tickets' | translate }}</label>
|
||||
<label for="training_nb_total_places" class="col-sm-2 control-label">{{ 'trainings_form.number_of_tickets' | translate }}</label>
|
||||
<div class="col-sm-4">
|
||||
<input ng-model="training.nb_total_places"
|
||||
type="number"
|
||||
@ -95,7 +95,7 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label for="training[public_page]" class="control-label col-sm-2" translate>
|
||||
{{ 'public_page' }}
|
||||
{{ 'trainings_form.public_page' }}
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input bs-switch
|
||||
@ -105,16 +105,35 @@
|
||||
class="form-control"
|
||||
switch-on-text="{{ 'yes' | translate }}"
|
||||
switch-off-text="{{ 'no' | translate }}"
|
||||
switch-active="{{!training.disabled}}"
|
||||
switch-animate="true"/>
|
||||
<input type="hidden" name="training[public_page]" value="{{training.public_page}}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="training[public_page]" class="control-label col-sm-2" translate>
|
||||
{{ 'trainings_form.disable_training' }}
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input bs-switch
|
||||
ng-model="training.disabled"
|
||||
name="training[disabled]"
|
||||
type="checkbox"
|
||||
class="form-control"
|
||||
switch-on-text="{{ 'yes' | translate }}"
|
||||
switch-off-text="{{ 'no' | translate }}"
|
||||
ng-change="onDisableToggled()"
|
||||
switch-animate="true"/>
|
||||
<input type="hidden" name="training[disabled]" value="{{training.disabled}}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- ./panel-body -->
|
||||
|
||||
<div class="panel-footer no-padder">
|
||||
<input type="submit"
|
||||
value="{{ 'validate_your_training' | translate }}"
|
||||
value="{{ 'trainings_form.validate_your_training' | translate }}"
|
||||
class="r-b btn-valid btn btn-warning btn-block p-lg btn-lg text-u-c"
|
||||
ng-disabled="trainingForm.$invalid"/>
|
||||
</div>
|
||||
|
@ -70,6 +70,6 @@ class API::TrainingsController < API::ApiController
|
||||
end
|
||||
|
||||
def training_params
|
||||
params.require(:training).permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, training_image_attributes: [:attachment], machine_ids: [], plan_ids: [])
|
||||
params.require(:training).permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, :disabled, training_image_attributes: [:attachment], machine_ids: [], plan_ids: [])
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
role = (current_user and current_user.is_admin?) ? 'admin' : 'user'
|
||||
|
||||
json.array!(@trainings) do |training|
|
||||
json.extract! training, :id, :name, :description, :machine_ids, :nb_total_places, :slug
|
||||
json.extract! training, :id, :name, :description, :machine_ids, :nb_total_places, :slug, :disabled
|
||||
json.training_image training.training_image.attachment.large.url if training.training_image
|
||||
json.plan_ids training.plan_ids if role === 'admin'
|
||||
end
|
||||
|
@ -1,2 +1,2 @@
|
||||
json.extract! @training, :id, :name, :description, :machine_ids, :nb_total_places, :public_page
|
||||
json.extract! @training, :id, :name, :description, :machine_ids, :nb_total_places, :public_page, :disabled
|
||||
json.training_image @training.training_image.attachment.large.url if @training.training_image
|
||||
|
@ -235,11 +235,19 @@ en:
|
||||
|
||||
trainings:
|
||||
# training edition form
|
||||
add_a_new_training: "Add a new training"
|
||||
validate_your_training: "Validate your training"
|
||||
associated_machines: "Associated machines"
|
||||
number_of_tickets: "Number of tickets"
|
||||
public_page: "Show in training lists"
|
||||
trainings_form:
|
||||
name: "Name"
|
||||
name_is_required: "Name is required."
|
||||
illustration: "Illustration"
|
||||
add_an_illustration: "Add an illustration"
|
||||
description: "Description"
|
||||
description_is_required: "Description is required."
|
||||
add_a_new_training: "Add a new training"
|
||||
validate_your_training: "Validate your training"
|
||||
associated_machines: "Associated machines"
|
||||
number_of_tickets: "Number of tickets"
|
||||
public_page: "Show in training lists"
|
||||
disable_training: "Disable the training"
|
||||
|
||||
user_admin:
|
||||
# partial form to edit/create an user (admin view)
|
||||
|
@ -235,11 +235,19 @@ fr:
|
||||
|
||||
trainings:
|
||||
# formulaire d'édition d'une formation
|
||||
add_a_new_training: "Ajouter une nouvelle formation"
|
||||
validate_your_training: "Valider votre formation"
|
||||
associated_machines: "Machines associées"
|
||||
number_of_tickets: "Nombre de places"
|
||||
public_page: "Afficher dans la liste de formation"
|
||||
trainings_form:
|
||||
name: "Nom"
|
||||
name_is_required: "Le nom est requis."
|
||||
illustration: "Visuel"
|
||||
add_an_illustration: "Ajouter un visuel"
|
||||
description: "Description"
|
||||
description_is_required: "La description est requise."
|
||||
add_a_new_training: "Ajouter une nouvelle formation"
|
||||
validate_your_training: "Valider votre formation"
|
||||
associated_machines: "Machines associées"
|
||||
number_of_tickets: "Nombre de places"
|
||||
public_page: "Afficher dans la liste de formation"
|
||||
disable_training: "Désactiver la formation"
|
||||
|
||||
user_admin:
|
||||
# formulaire partiel d'édition/création utilisateur (vue admin)
|
||||
|
@ -235,11 +235,19 @@ pt:
|
||||
|
||||
trainings:
|
||||
# training edition form
|
||||
add_a_new_training: "Adicionar um novo treinamento"
|
||||
validate_your_training: "Validar seu treinamento"
|
||||
associated_machines: "Máquinas associadas"
|
||||
number_of_tickets: "Número de vagas"
|
||||
public_page: "Mostrar na lista de treinamentos"
|
||||
trainings_form:
|
||||
name: "Nome"
|
||||
name_is_required: "Nome é obrigatório."
|
||||
illustration: "Ilustração"
|
||||
add_an_illustration: "Adicionar ilustração"
|
||||
description: "Descrição"
|
||||
description_is_required: "Descrição é obrigatório."
|
||||
add_a_new_training: "Adicionar um novo treinamento"
|
||||
validate_your_training: "Validar seu treinamento"
|
||||
associated_machines: "Máquinas associadas"
|
||||
number_of_tickets: "Número de vagas"
|
||||
public_page: "Mostrar na lista de treinamentos"
|
||||
disable_training: "Disable the training" # TODO
|
||||
|
||||
user_admin:
|
||||
# partial form to edit/create an user (admin view)
|
||||
|
5
db/migrate/20171010143708_add_disabled_to_training.rb
Normal file
5
db/migrate/20171010143708_add_disabled_to_training.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddDisabledToTraining < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :trainings, :disabled, :boolean
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20171005141522) do
|
||||
ActiveRecord::Schema.define(version: 20171010143708) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -703,6 +703,7 @@ ActiveRecord::Schema.define(version: 20171005141522) do
|
||||
t.string "slug", limit: 255
|
||||
t.text "description"
|
||||
t.boolean "public_page", default: true
|
||||
t.boolean "disabled"
|
||||
end
|
||||
|
||||
add_index "trainings", ["slug"], name: "index_trainings_on_slug", unique: true, using: :btree
|
||||
|
Loading…
x
Reference in New Issue
Block a user