FEATURE: editable badge groups

This commit is contained in:
Sam
2014-07-27 18:22:01 +10:00
parent 0ab456b647
commit 1a6aa07611
12 changed files with 192 additions and 9 deletions

View File

@@ -2,8 +2,8 @@ class Admin::BadgesController < Admin::AdminController
def index
data = {
badge_types: BadgeType.all.to_a,
badge_groupings: BadgeGrouping.all.to_a,
badge_types: BadgeType.all.order(:id).to_a,
badge_groupings: BadgeGrouping.all.order(:position).to_a,
badges: Badge.all.to_a,
protected_system_fields: Badge.protected_system_fields,
triggers: Badge.trigger_hash
@@ -20,8 +20,24 @@ class Admin::BadgesController < Admin::AdminController
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
end
def badge_groupings
badge_groupings = BadgeGrouping.all.to_a
def save_badge_groupings
badge_groupings = BadgeGrouping.all.order(:position).to_a
ids = params[:ids].map(&:to_i)
params[:names].each_with_index do |name,index|
id = ids[index].to_i
group = badge_groupings.find{|b| b.id == id} || BadgeGrouping.new()
group.name = name
group.position = index
group.save
end
badge_groupings.each do |g|
g.destroy unless g.system? || ids.include?(g.id)
end
badge_groupings = BadgeGrouping.all.order(:position).to_a
render_serialized(badge_groupings, BadgeGroupingSerializer, root: "badge_groupings")
end