mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
full ability to create price categories
This commit is contained in:
parent
6c3dfab0a9
commit
500a466371
@ -129,8 +129,8 @@ class EventsController
|
||||
##
|
||||
# Controller used in the events listing page (admin view)
|
||||
##
|
||||
Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'dialogs', 'growl', 'Event', 'Category', 'EventTheme', 'AgeRange', 'eventsPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', '_t'
|
||||
, ($scope, $state, dialogs, growl, Event, Category, EventTheme, AgeRange, eventsPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise, _t) ->
|
||||
Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'dialogs', '$uibModal', 'growl', 'Event', 'Category', 'EventTheme', 'AgeRange', 'PriceCategory', 'eventsPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', '_t'
|
||||
, ($scope, $state, dialogs, $uibModal, growl, Event, Category, EventTheme, AgeRange, PriceCategory, eventsPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise, _t) ->
|
||||
|
||||
|
||||
|
||||
@ -239,6 +239,29 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state",
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Open a modal dialog allowing the definition of a new price category.
|
||||
# Save it once filled and handle the result.
|
||||
##
|
||||
$scope.newPriceCategory = ->
|
||||
$uibModal.open
|
||||
templateUrl: '<%= asset_path "admin/events/price_form.html" %>'
|
||||
size: 'md'
|
||||
resolve:
|
||||
category: -> {}
|
||||
controller: 'PriceCategoryController'
|
||||
.result['finally'](null).then (p_cat) ->
|
||||
# save the price category to the API
|
||||
PriceCategory.save p_cat, (cat) ->
|
||||
$scope.priceCategories.push(cat)
|
||||
growl.success(_t('price_category_successfully_created'))
|
||||
, (err)->
|
||||
growl.error(_t('unable_to_add_the_price_category_an_error_occurred'))
|
||||
console.error(err)
|
||||
|
||||
|
||||
|
||||
|
||||
### PRIVATE SCOPE ###
|
||||
|
||||
##
|
@ -0,0 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
##
|
||||
# Controller used in price category creation/edition form dialog
|
||||
##
|
||||
Application.Controllers.controller "PriceCategoryController", ["$scope", "$uibModalInstance", "category"
|
||||
, ($scope, $uibModalInstance, category) ->
|
||||
|
||||
## Price category to edit/empty object for new category
|
||||
$scope.category = category
|
||||
|
||||
##
|
||||
# Callback for form validation
|
||||
##
|
||||
$scope.ok = ->
|
||||
$uibModalInstance.close($scope.category)
|
||||
|
||||
##
|
||||
# Do not validate the modifications, hide the modal
|
||||
##
|
||||
$scope.cancel = ->
|
||||
$uibModalInstance.dismiss('cancel')
|
||||
]
|
40
app/assets/templates/admin/events/price_form.html
Normal file
40
app/assets/templates/admin/events/price_form.html
Normal file
@ -0,0 +1,40 @@
|
||||
<div class="modal-header">
|
||||
<img ng-src="{{logoBlack.custom_asset_file_attributes.attachment_url}}" alt="{{logo.custom_asset_file_attributes.attachment}}" class="modal-logo"/>
|
||||
<h1 translate>{{ 'price_category' }}</h1>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form role="form" name="priceCategoryForm" class="form-horizontal" novalidate autocomplete="off" ng-keydown="priceCategoryForm.$valid && $event.which == 13 && ok()">
|
||||
<div class="form-group" ng-class="{'has-error': priceCategoryForm.name.$dirty && priceCategoryForm.name.$invalid}">
|
||||
<div class="col-sm-12">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon"><i class="fa fa-tag"></i></span>
|
||||
<input type="text"
|
||||
name="name"
|
||||
ng-model="category.name"
|
||||
class="form-control"
|
||||
placeholder="{{ 'category_name' | translate }}"
|
||||
required />
|
||||
</div>
|
||||
<span class="help-block" ng-show="priceCategoryForm.name.$dirty && priceCategoryForm.name.$error.required" translate>{{ 'category_name_is_required' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" ng-class="{'has-error': priceCategoryForm.conditions.$dirty && priceCategoryForm.conditions.$invalid}">
|
||||
<div class="col-sm-12">
|
||||
<textarea ng-model="category.conditions"
|
||||
rows="10"
|
||||
class="form-control"
|
||||
id="conditions"
|
||||
placeholder="{{ 'enter_here_the_conditions_under_which_this_price_is_applicable' | translate }}"
|
||||
name="conditions"
|
||||
required>
|
||||
</textarea>
|
||||
<span class="help-block" ng-show="priceCategoryForm.conditions.$dirty && priceCategoryForm.conditions.$error.required" translate>{{ 'conditions_are_required' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-info" ng-click="ok()" ng-disabled="priceCategoryForm.$invalid" translate>{{ 'confirm' }}</button>
|
||||
<button class="btn btn-default" ng-click="cancel()" translate>{{ 'cancel' }}</button>
|
||||
</div>
|
@ -1,4 +1,31 @@
|
||||
<div class="m-t">
|
||||
<h3 translate>{{ 'prices_categories' }}</h3>
|
||||
|
||||
<button type="button" class="btn btn-warning m-b m-t" ng-click="newPriceCategory()" translate>{{ 'add_a_price_category' }}</button>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:40%" translate>{{ 'name' }}</th>
|
||||
<th style="width:40%" translate>{{ 'usages_count' }}</th>
|
||||
<th style="width:20%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="category in priceCategories">
|
||||
<td>{{ category.name }}</td>
|
||||
<td>{{ category.events }}</td>
|
||||
<td>
|
||||
<div class="buttons">
|
||||
<button class="btn btn-default" ng-click="editPriceCategory(category.id)">
|
||||
<i class="fa fa-edit"></i> <span class="hidden-xs hidden-sm" translate>{{ 'edit' }}</span>
|
||||
</button>
|
||||
<button class="btn btn-danger" ng-click="removePriceCategory(category.id, $index)">
|
||||
<i class="fa fa-trash-o"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
@ -1,4 +1,4 @@
|
||||
class PriceCategoriesController < API::ApiController
|
||||
class API::PriceCategoriesController < API::ApiController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_price_category, only: [:show, :update, :destroy]
|
||||
|
||||
@ -43,6 +43,6 @@ class PriceCategoriesController < API::ApiController
|
||||
end
|
||||
|
||||
def price_category_params
|
||||
params.require(:price_category).permit(:name, :description)
|
||||
params.require(:price_category).permit(:name, :conditions)
|
||||
end
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
class GroupPolicy < ApplicationPolicy
|
||||
class PriceCategoryPolicy < ApplicationPolicy
|
||||
%w(index show create update destroy).each do |action|
|
||||
define_method "#{action}?" do
|
||||
user.is_admin?
|
||||
|
@ -1,4 +1,4 @@
|
||||
json.array!(@price_categories) do |category|
|
||||
json.extract! category, :id, :name
|
||||
json.extract! category, :id, :name, :conditions
|
||||
json.events category.event_price_category.count
|
||||
end
|
||||
|
@ -1 +1,2 @@
|
||||
json.extract! @price_category, :id, :name, :description, :created_at
|
||||
json.extract! @price_category, :id, :name, :conditions, :created_at
|
||||
json.events @price_category.event_price_category.count
|
@ -92,6 +92,15 @@ en:
|
||||
unable_to_delete_an_error_occured: "Unable to delete: an error occurred."
|
||||
manage_prices_categories: "Manage prices' categories"
|
||||
prices_categories: "Prices' categories"
|
||||
add_a_price_category: "Add a price's category"
|
||||
usages_count: "Usages count"
|
||||
price_category: "Price category"
|
||||
category_name: "Category's name"
|
||||
category_name_is_required: "Category's name is required."
|
||||
enter_here_the_conditions_under_which_this_price_is_applicable: "Enter here the conditions under which this price is applicable"
|
||||
conditions_are_required: "Conditions are required."
|
||||
price_category_successfully_created: "Price category successfully created."
|
||||
unable_to_add_the_price_category_an_error_occurred: "Unable to add the price category because of an unexpected error occurred."
|
||||
|
||||
events_new:
|
||||
# add a new event
|
||||
|
@ -90,8 +90,17 @@ fr:
|
||||
at_least_one_category_is_required: "Au moins une catégorie est requise."
|
||||
unable_to_delete_the_last_one: "Impossible de supprimer la dernière."
|
||||
unable_to_delete_an_error_occured: "Impossible de supprimer : une erreur est survenue."
|
||||
manage_prices_categories: "Gérer les catégories de tarifs"
|
||||
prices_categories: "Catégories de tarifs"
|
||||
manage_prices_categories: "Gérer les catégories tarifaires"
|
||||
prices_categories: "Catégories tarifaires"
|
||||
add_a_price_category: "Ajouter une catégorie tarifaire"
|
||||
usages_count: "Nombre d'utilisations"
|
||||
price_category: "Catégorie tarifaire"
|
||||
category_name: "Nom de la catégorie"
|
||||
category_name_is_required: "Le nom de la catégorie est requis."
|
||||
enter_here_the_conditions_under_which_this_price_is_applicable: "Saisissez ici les conditions d'application du tarif"
|
||||
conditions_are_required: "Les conditions sont requises."
|
||||
price_category_successfully_created: "La catégorie tarifaire a bien été créée."
|
||||
unable_to_add_the_price_category_an_error_occurred: "Impossible d'ajouter la catégorie tarifaire car une erreur inattendue est survenue."
|
||||
|
||||
events_new:
|
||||
# ajouter un nouvel évènement
|
||||
|
@ -2,7 +2,7 @@ class CreatePriceCategories < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :price_categories do |t|
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.text :conditions
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
@ -379,9 +379,9 @@ ActiveRecord::Schema.define(version: 20160824084111) do
|
||||
|
||||
create_table "price_categories", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.text "description"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "conditions"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "prices", force: :cascade do |t|
|
||||
|
Loading…
x
Reference in New Issue
Block a user