From 644a5a9d472f7ab64756069348aa10428d0dd675 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 21 Jun 2016 17:05:49 +0200 Subject: [PATCH] [ongoing][UI] advanced trainings management --- .../controllers/admin/trainings.coffee.erb | 113 +++++++++--------- app/assets/javascripts/router.coffee.erb | 24 +++- .../templates/admin/trainings/_form.html.erb | 60 ++++++++++ .../templates/admin/trainings/edit.html.erb | 30 +++++ .../templates/admin/trainings/index.html.erb | 39 +----- .../templates/admin/trainings/new.html.erb | 35 ++++++ app/assets/templates/machines/_form.html.erb | 2 +- 7 files changed, 213 insertions(+), 90 deletions(-) create mode 100644 app/assets/templates/admin/trainings/_form.html.erb create mode 100644 app/assets/templates/admin/trainings/edit.html.erb create mode 100644 app/assets/templates/admin/trainings/new.html.erb diff --git a/app/assets/javascripts/controllers/admin/trainings.coffee.erb b/app/assets/javascripts/controllers/admin/trainings.coffee.erb index 9672cc9d6..c782cd33e 100644 --- a/app/assets/javascripts/controllers/admin/trainings.coffee.erb +++ b/app/assets/javascripts/controllers/admin/trainings.coffee.erb @@ -1,7 +1,52 @@ 'use strict' -Application.Controllers.controller "TrainingsController", ["$scope", "$state", "$uibModal", 'Training', 'trainingsPromise', 'machinesPromise', '_t', 'growl' -, ($scope, $state, $uibModal, Training, trainingsPromise, machinesPromise, _t, growl) -> + + +## +# Controller used in the training creation page (admin) +## +Application.Controllers.controller "NewTrainingController", [ '$scope', ($scope) -> + + + + ### PUBLIC SCOPE ### + + ## Form action on the following URL + $scope.method = 'post' + + ## API URL where the form will be posted + $scope.actionUrl = '/api/trainings' +] + + + +## +# Controller used in the training edition page (admin) +## +Application.Controllers.controller "EditTrainingController", [ '$scope', '$stateParams', 'trainingPromise', ($scope, $stateParams, trainingPromise) -> + + + + ### PUBLIC SCOPE ### + + ## Form action on the following URL + $scope.method = 'put' + + ## API URL where the form will be posted + $scope.actionUrl = '/api/trainings' + $stateParams.id + + ## Details of the training to edit (id in URL) + $scope.training = trainingPromise +] + + + + +## +# Controller used in the public listing page, allowing logged users to see the list of trainings +## +Application.Controllers.controller "TrainingsController", ["$scope", "$state", "$uibModal", 'Training', 'trainingsPromise', 'machinesPromise', '_t', 'growl', 'dialogs' +, ($scope, $state, $uibModal, Training, trainingsPromise, machinesPromise, _t, growl, dialogs) -> @@ -40,35 +85,6 @@ Application.Controllers.controller "TrainingsController", ["$scope", "$state", " - ## - # Create a new empty training object and append it to the $scope.trainings list - ## - $scope.addTraining = -> - $scope.inserted = - name: '' - machine_ids: [] - $scope.trainings.push($scope.inserted) - - - - ## - # Saves a new training / Update an existing training to the server (form validation callback) - # @param data {Object} training name, associated machine(s) and default places number - # @param id {number} training id, in case of update - ## - $scope.saveTraining = (data, id) -> - if id? - Training.update {id: id}, - training: data - else - Training.save - training: data - , (resp) -> - $scope.trainings[$scope.trainings.length-1] = resp - console.log(resp) - - - ## # Removes the newly inserted but not saved training / Cancel the current training modification # @param rowform {Object} see http://vitalets.github.io/angular-xeditable/ @@ -138,30 +154,17 @@ Application.Controllers.controller "TrainingsController", ["$scope", "$state", " # @param training {Object} training to delete ## $scope.removeTraining = (index, training)-> - training.$delete -> - $scope.trainings.splice(index, 1) - growl.info(_t('training_successfully_deleted')) - , (error)-> - growl.warning(_t('unable_to_delete_the_training_because_some_users_alredy_booked_it')) - - - - ## - # Open the modal to edit description of the training - # @param training {Object} Training to edit description - ## - $scope.openModalToSetDescription = (training)-> - $uibModal.open( - templateUrl: "<%= asset_path 'admin/trainings/modal_edit.html' %>" - controller: ['$scope', '$uibModalInstance', 'Training', 'growl', ($scope, $uibModalInstance, Training, growl)-> - $scope.training = training - $scope.save = -> - Training.update id: training.id, { training: { description: $scope.training.description } }, (training)-> - $uibModalInstance.close() - growl.success(_t('description_was_successfully_saved')) - return - ] - ) + dialogs.confirm + resolve: + object: -> + title: _t('confirmation_required') + msg: _t('do_you_really_want_to_delete_this_traning') + , -> # deletion confirmed + training.$delete -> + $scope.trainings.splice(index, 1) + growl.info(_t('training_successfully_deleted')) + , (error)-> + growl.warning(_t('unable_to_delete_the_training_because_some_users_alredy_booked_it')) diff --git a/app/assets/javascripts/router.coffee.erb b/app/assets/javascripts/router.coffee.erb index 7f1416510..e088f9cea 100644 --- a/app/assets/javascripts/router.coffee.erb +++ b/app/assets/javascripts/router.coffee.erb @@ -523,7 +523,29 @@ angular.module('application.router', ['ui.router']). translations: [ 'Translations', (Translations) -> Translations.query('app.admin.trainings').$promise ] - + .state 'app.admin.trainings_new', + url: '/admin/trainings/new' + views: + 'main@': + templateUrl: '<%= asset_path "admin/trainings/new.html" %>' + controller: 'NewTrainingController' + resolve: + translations: [ 'Translations', (Translations) -> + Translations.query(['app.admin.trainings_new', 'app.shared.trainings']).$promise + ] + .state 'app.admin.trainings_edit', + url: '/admin/trainings/:id/edit' + views: + 'main@': + templateUrl: '<%= asset_path "admin/trainings/edit.html" %>' + controller: 'EditTrainingController' + resolve: + trainingPromise: ['Training', '$stateParams', (Training, $stateParams)-> + Training.get(id: $stateParams.id).$promise + ] + translations: [ 'Translations', (Translations) -> + Translations.query(['app.admin.trainings_edit', 'app.shared.trainings']).$promise + ] # events .state 'app.admin.events', url: '/admin/events' diff --git a/app/assets/templates/admin/trainings/_form.html.erb b/app/assets/templates/admin/trainings/_form.html.erb new file mode 100644 index 000000000..e47dff573 --- /dev/null +++ b/app/assets/templates/admin/trainings/_form.html.erb @@ -0,0 +1,60 @@ +
+ + + +
+
+ + {{alert.msg}} + +
+ +
+ + {{ 'name_is_required' }} +
+
+ +
+ +
+
+
+ +
+
+ +
+
+ + {{ 'add_an_illustration' | translate }} + {{ 'change' }} + + + {{ 'delete' }} +
+
+
+
+ + +
+ +
+ + {{ 'description_is_required' }} +
+
+ +
+ + +
+
diff --git a/app/assets/templates/admin/trainings/edit.html.erb b/app/assets/templates/admin/trainings/edit.html.erb new file mode 100644 index 000000000..b0ee69b4d --- /dev/null +++ b/app/assets/templates/admin/trainings/edit.html.erb @@ -0,0 +1,30 @@ +
+ +
+
+
+
+ +
+
+
+
+

{{ training.name }}

+
+
+ +
+
+
{{ 'cancel' }}
+
+
+
+
+ + +
+
+ +
+
+
diff --git a/app/assets/templates/admin/trainings/index.html.erb b/app/assets/templates/admin/trainings/index.html.erb index f70eb43c6..93f2cb190 100644 --- a/app/assets/templates/admin/trainings/index.html.erb +++ b/app/assets/templates/admin/trainings/index.html.erb @@ -21,11 +21,7 @@
- - + @@ -38,35 +34,12 @@ + + + - - -
{{ training.name }}{{ showMachines(training) }}{{ training.nb_total_places }} - - {{ training.name }} - - - - {{ showMachines(training) }} - - - - {{ training.nb_total_places }} - - -
- - -
-
- -