1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

ability to edit price category

This commit is contained in:
Sylvain 2016-08-24 16:52:37 +02:00
parent 500a466371
commit 77db2b2326
5 changed files with 40 additions and 4 deletions

View File

@ -256,11 +256,37 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state",
$scope.priceCategories.push(cat)
growl.success(_t('price_category_successfully_created'))
, (err)->
growl.error(_t('unable_to_add_the_price_category_an_error_occurred'))
growl.error(_t('unable_to_add_the_price_category_check_name_already_used'))
console.error(err)
##
# Update the given price category with the new properties
# to specify in a modal dialog
# @param index {number} index of the caterory in the $scope.priceCategories array
# @param id {number} price category ID, must match the ID of the category at the index specified above
##
$scope.editPriceCategory = (id, index) ->
if $scope.priceCategories[index].id != id
growl.error(_t('unexpected_error_occurred_please_refresh'))
else
$uibModal.open
templateUrl: '<%= asset_path "admin/events/price_form.html" %>'
size: 'md'
resolve:
category: -> $scope.priceCategories[index]
controller: 'PriceCategoryController'
.result['finally'](null).then (p_cat) ->
# update the price category to the API
PriceCategory.update {id: id}, {price_category: p_cat}, (cat) ->
$scope.priceCategories[index] = cat
growl.success(_t('price_category_successfully_updated'))
, (err)->
growl.error(_t('unable_to_update_the_price_category'))
console.error(err)
### PRIVATE SCOPE ###

View File

@ -16,7 +16,7 @@
<td>{{ category.events }}</td>
<td>
<div class="buttons">
<button class="btn btn-default" ng-click="editPriceCategory(category.id)">
<button class="btn btn-default" ng-click="editPriceCategory(category.id, $index)">
<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)">

View File

@ -2,6 +2,10 @@ class PriceCategory < ActiveRecord::Base
has_many :event_price_category
has_many :events, through: :event_price_categories
validates :name, :presence => true
validates :name, uniqueness: {case_sensitive: false}
validates :conditions, :presence => true
def safe_destroy
if event_price_category.count == 0
destroy

View File

@ -100,7 +100,10 @@ en:
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."
unable_to_add_the_price_category_check_name_already_used: "Unable to add the price category, check that the name is not already used."
unexpected_error_occurred_please_refresh: "An unexpected error occurred, please refresh the page."
price_category_successfully_updated: "Price category successfully updated."
unable_to_update_the_price_category: "Unable to update the price category."
events_new:
# add a new event

View File

@ -100,7 +100,10 @@ fr:
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."
unable_to_add_the_price_category_check_name_already_used: "Impossible d'ajouter la catégorie tarifaire, vérifiez que le nom n'est pas déjà utilisé."
unexpected_error_occurred_please_refresh: "Une erreur inattendue est survenue, merci de rafraîchir la page."
price_category_successfully_updated: "La catégorie tarifaire a bien été mise à jour."
unable_to_update_the_price_category: "Impossible de mettre à jour la catégorie tarifaire."
events_new:
# ajouter un nouvel évènement