Added interface and methods for edit the name of a Budget::Group if the budget is still inthe drafting phase
This commit is contained in:
@@ -8,10 +8,22 @@ class Admin::BudgetGroupsController < Admin::BaseController
|
|||||||
@groups = @budget.groups.includes(:headings)
|
@groups = @budget.groups.includes(:headings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@group = Budget::Group.by_slug(params[:id]).first
|
||||||
|
if @group.generate_slug?
|
||||||
|
params[:id] = @group.generate_slug
|
||||||
|
end
|
||||||
|
@group.update(budget_group_params)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def budget_group_params
|
def budget_group_params
|
||||||
params.require(:budget_group).permit(:name)
|
params.require(:budget_group).permit(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_budget
|
||||||
|
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -72,6 +72,10 @@ module AdminHelper
|
|||||||
user_roles(user).join(", ")
|
user_roles(user).join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def display_budget_goup_form(group)
|
||||||
|
group.errors.messages.size > 0 ? "" : "display:none"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def namespace
|
def namespace
|
||||||
|
|||||||
@@ -10,14 +10,27 @@ class Budget
|
|||||||
validates :name, presence: true, uniqueness: { scope: :budget }
|
validates :name, presence: true, uniqueness: { scope: :budget }
|
||||||
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
||||||
|
|
||||||
|
scope :by_slug, ->(slug) { where(slug: slug) }
|
||||||
|
|
||||||
|
before_save :strip_name
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
slug
|
||||||
|
end
|
||||||
|
|
||||||
def single_heading_group?
|
def single_heading_group?
|
||||||
headings.count == 1
|
headings.count == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def generate_slug?
|
def generate_slug?
|
||||||
slug.nil? || budget.drafting?
|
slug.nil? || budget.drafting?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def strip_name
|
||||||
|
self.name = self.name.strip
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
6
app/views/admin/budget_groups/update.js.erb
Normal file
6
app/views/admin/budget_groups/update.js.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<% if @group.errors.any? %>
|
||||||
|
$("#group-form-<%= @group.id %>").html('<%= j render("admin/budgets/group_form", group: @group, budget: @group.budget, button_title: "admin.budgets.form.submit", id: "group-form-#{@group.id}", css_class: "group-toggle-#{@group.id}" ) %>');
|
||||||
|
<% else %>
|
||||||
|
$("#group-name-<%= @group.id %>").html('<%= @group.name %>')
|
||||||
|
$(".group-toggle-<%= @group.id %>").toggle()
|
||||||
|
<% end %>
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="4" class="with-button">
|
<th colspan="4" class="with-button">
|
||||||
<%= group.name %>
|
<%= content_tag(:span, group.name, class:"group-toggle-#{group.id}", id:"group-name-#{group.id}") %>
|
||||||
|
<%= render 'admin/budgets/group_form', budget: @budget, group: group, id: "group-form-#{group.id}", button_title: "admin.budgets.form.submit", css_class: "group-toggle-#{group.id}" %>
|
||||||
<%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %>
|
<%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %>
|
||||||
|
<%= link_to t("admin.budgets.form.edit_group"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => ".group-toggle-#{group.id}" } %>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|||||||
15
app/views/admin/budgets/_group_form.html.erb
Normal file
15
app/views/admin/budgets/_group_form.html.erb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<%= form_for [:admin, budget, group], html: {id: id, style: display_budget_goup_form(group), class: css_class}, remote: true do |f| %>
|
||||||
|
|
||||||
|
<%= f.label :name, t("admin.budgets.form.group") %>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<%= f.text_field :name,
|
||||||
|
label: false,
|
||||||
|
maxlength: 50,
|
||||||
|
placeholder: t("admin.budgets.form.group"),
|
||||||
|
class: "input-group-field" %>
|
||||||
|
<div class="input-group-button">
|
||||||
|
<%= f.submit t(button_title), class: "button success" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@@ -10,21 +10,7 @@
|
|||||||
<%= link_to t("admin.budgets.form.add_group"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#new-group-form" } %>
|
<%= link_to t("admin.budgets.form.add_group"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#new-group-form" } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= form_for [:admin, @budget, Budget::Group.new], html: {id: "new-group-form", style: "display:none"}, remote: true do |f| %>
|
<%= render 'admin/budgets/group_form', budget: @budget, group: Budget::Group.new, id: "new-group-form", button_title: "admin.budgets.form.create_group", css_class: '' %>
|
||||||
|
|
||||||
<%= f.label :name, t("admin.budgets.form.group") %>
|
|
||||||
|
|
||||||
<div class="input-group">
|
|
||||||
<%= f.text_field :name,
|
|
||||||
label: false,
|
|
||||||
maxlength: 50,
|
|
||||||
placeholder: t("admin.budgets.form.group"),
|
|
||||||
class: "input-group-field" %>
|
|
||||||
<div class="input-group-button">
|
|
||||||
<%= f.submit t("admin.budgets.form.create_group"), class: "button success" %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% groups.each do |group| %>
|
<% groups.each do |group| %>
|
||||||
<div id="<%= dom_id(group) %>">
|
<div id="<%= dom_id(group) %>">
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ en:
|
|||||||
no_groups: No groups created yet. Each user will be able to vote in only one heading per group.
|
no_groups: No groups created yet. Each user will be able to vote in only one heading per group.
|
||||||
add_group: Add new group
|
add_group: Add new group
|
||||||
create_group: Create group
|
create_group: Create group
|
||||||
|
edit_group: Edit group
|
||||||
|
submit: Save group
|
||||||
heading: Heading name
|
heading: Heading name
|
||||||
add_heading: Add heading
|
add_heading: Add heading
|
||||||
amount: Amount
|
amount: Amount
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ es:
|
|||||||
no_groups: No hay grupos creados todavía. Cada usuario podrá votar en una sola partida de cada grupo.
|
no_groups: No hay grupos creados todavía. Cada usuario podrá votar en una sola partida de cada grupo.
|
||||||
add_group: Añadir nuevo grupo
|
add_group: Añadir nuevo grupo
|
||||||
create_group: Crear grupo
|
create_group: Crear grupo
|
||||||
|
edit_group: Editar grupo
|
||||||
|
submit: Guardar grupo
|
||||||
heading: Nombre de la partida
|
heading: Nombre de la partida
|
||||||
add_heading: Añadir partida
|
add_heading: Añadir partida
|
||||||
amount: Cantidad
|
amount: Cantidad
|
||||||
|
|||||||
@@ -903,6 +903,7 @@ ActiveRecord::Schema.define(version: 20180220211105) do
|
|||||||
t.integer "related_content_id"
|
t.integer "related_content_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.integer "flags_count", default: 0
|
||||||
t.datetime "hidden_at"
|
t.datetime "hidden_at"
|
||||||
t.integer "related_content_scores_count", default: 0
|
t.integer "related_content_scores_count", default: 0
|
||||||
t.integer "author_id"
|
t.integer "author_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user