parent
12d3a9c117
commit
aff69e6053
@ -0,0 +1,49 @@ |
||||
# Place all the behaviors and hooks related to the matching controller here. |
||||
# All this logic will automatically be available in application.js. |
||||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
||||
|
||||
$(document).on 'keyup', "form", (event) -> |
||||
$("input:text[name='css']").each (index, event) -> |
||||
frominput = $(this).next().next() |
||||
toinput = $(frominput).next().next() |
||||
if $(this).val() |
||||
$(frominput).prop('disabled', true) |
||||
$(toinput).prop('disabled', true) |
||||
else |
||||
$(frominput).prop('disabled', false) |
||||
$(toinput).prop('disabled', false) |
||||
$("input:text[name='from']").each (index, event) -> |
||||
cssinput = $(this).prev().prev() |
||||
if $(this).val() |
||||
$(cssinput).prop('disabled', true) |
||||
else |
||||
$(cssinput).prop('disabled', false) |
||||
$("input:text[name='to']").each (index, event) -> |
||||
cssinput = $(this).prev().prev().prev().prev() |
||||
if $(this).val() |
||||
$(cssinput).prop('disabled', true) |
||||
else |
||||
$(cssinput).prop('disabled', false) |
||||
|
||||
$("form").ready -> |
||||
$("input:text[name='css']").each (index, event) -> |
||||
frominput = $(this).next().next() |
||||
toinput = $(frominput).next().next() |
||||
if $(this).val() |
||||
$(frominput).prop('disabled', true) |
||||
$(toinput).prop('disabled', true) |
||||
else |
||||
$(frominput).prop('disabled', false) |
||||
$(toinput).prop('disabled', false) |
||||
$("input:text[name='from']").each (index, event) -> |
||||
cssinput = $(this).prev().prev() |
||||
if $(this).val() |
||||
$(cssinput).prop('disabled', true) |
||||
else |
||||
$(cssinput).prop('disabled', false) |
||||
$("input:text[name='to']").each (index, event) -> |
||||
cssinput = $(this).prev().prev().prev().prev() |
||||
if $(this).val() |
||||
$(cssinput).prop('disabled', true) |
||||
else |
||||
$(cssinput).prop('disabled', false) |
@ -0,0 +1,3 @@ |
||||
// Place all the styles related to the groupe controller here. |
||||
// They will automatically be included in application.css. |
||||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
@ -0,0 +1,48 @@ |
||||
class GroupsController < ApplicationController |
||||
before_action :set_group, only: [:edit, :update, :destroy] |
||||
|
||||
def new |
||||
@group = Group.new |
||||
end |
||||
|
||||
def create |
||||
@group = Group.new(group_params) |
||||
if @group.save |
||||
redirect_to config_index_path, notice: 'Group has been successfully created.' |
||||
else |
||||
render :new |
||||
end |
||||
end |
||||
|
||||
def edit |
||||
@group = Group.find(params[:id]) |
||||
end |
||||
|
||||
def update |
||||
if @group.update(group_params) |
||||
redirect_to config_index_path, notice: 'Group has been successfully updated.' |
||||
else |
||||
render :edit |
||||
end |
||||
end |
||||
|
||||
|
||||
def destroy |
||||
@group.destroy |
||||
redirect_to config_index_path, notice: 'Group has been successfully removed.' |
||||
end |
||||
|
||||
private |
||||
def set_group |
||||
@group = Group.find(params[:id]) |
||||
end |
||||
|
||||
def group_params |
||||
params.require(:group).permit( |
||||
:id, :name, :template_id, |
||||
targets_attributes: [:id, :name, :css, :from, :to, :_destroy], |
||||
sites_attributes: [:id, :name, :url, :_destroy] |
||||
) |
||||
end |
||||
|
||||
end |
@ -0,0 +1,25 @@ |
||||
module ApplicationHelper |
||||
def link_to_add_fields_below(name, f, association) |
||||
new_object = f.object.send(association).klass.new |
||||
id = new_object.object_id |
||||
fields = f.fields_for(association, new_object, child_index: id) do |builder| |
||||
render(association.to_s.singularize + "_fields", f: builder) |
||||
end |
||||
|
||||
link_to(name, '#', class: "add_fields_below", data: {id: id, fields: fields.gsub("\n", "")}) |
||||
end |
||||
|
||||
def link_to_add_fields(name, f, association) |
||||
new_object = f.object.send(association).klass.new |
||||
id = new_object.object_id |
||||
fields = f.fields_for(association, new_object, child_index: id) do |builder| |
||||
render(association.to_s.singularize + "_fields", f: builder) |
||||
end |
||||
|
||||
link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")}) |
||||
end |
||||
|
||||
def link_to_remove_fields(name, f) |
||||
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") |
||||
end |
||||
end |
@ -0,0 +1,2 @@ |
||||
module GroupHelper |
||||
end |
@ -0,0 +1,52 @@ |
||||
<%= form_with(model: group, local: true, remote: true, class: "mts") do |form| %> |
||||
<% if group.errors.any? %> |
||||
<div id="alert--error"> |
||||
<h2><%= pluralize(group.errors.count, "error") %> prohibited this group from being saved:</h2> |
||||
|
||||
<ul> |
||||
<% group.errors.full_messages.each do |message| %> |
||||
<li><%= message %></li> |
||||
<% end %> |
||||
</ul> |
||||
</div> |
||||
<% end %> |
||||
|
||||
<fieldset class="mbs pas block"> |
||||
<legend class="h4-like"><%= :group %></legend> |
||||
<div class="auto-grid has-gutter mbs"> |
||||
<%= form.label :name, :name, class: 'txtright' %> |
||||
<%= form.text_field :name %> |
||||
|
||||
<%= form.label :template_id, :template_id, class: 'txtright' %> |
||||
<%= form.select :template_id, |
||||
::Template.all.collect {|t| [t.name, t.id]}, |
||||
{prompt: :select}, |
||||
{multiple: :true, size: 5} %> |
||||
</div> |
||||
</fieldset> |
||||
|
||||
<fieldset class="mbs pas block"> |
||||
<legend class="h4-like"><%= :targets %></legend> |
||||
<%= form.fields_for :targets do |builder| %> |
||||
<%= render 'target_fields', f: builder %> |
||||
<% end %> |
||||
|
||||
<%= link_to_add_fields :add_target, form, :targets %> |
||||
</fieldset> |
||||
|
||||
<fieldset class="mbs pas block"> |
||||
<legend class="h4-like"><%= :sites %></legend> |
||||
<%= link_to_add_fields_below :add_site, form, :sites %> |
||||
|
||||
<%= form.fields_for :sites do |builder| %> |
||||
<%= render 'site_fields', f: builder %> |
||||
<% end %> |
||||
|
||||
<%= link_to_add_fields :add_site, form, :sites %> |
||||
</fieldset> |
||||
|
||||
<div class="actions"> |
||||
<%= form.submit :submit %> |
||||
</div> |
||||
|
||||
<% end %> |
@ -0,0 +1,13 @@ |
||||
<fieldset class="pan mbs"> |
||||
<div class="auto-grid has-gutter"> |
||||
<%= f.label :name, :name %>: |
||||
<%= f.text_field :name %> |
||||
|
||||
<%= f.label :url, :url %>: |
||||
<%= f.url_field :url, size: 50 %> |
||||
|
||||
<%= f.hidden_field :_destroy %> |
||||
<%= link_to :delete, "#", class: "remove_fields" %> |
||||
|
||||
</div> |
||||
</fieldset> |
@ -0,0 +1,19 @@ |
||||
<fieldset class="pan mbs"> |
||||
<div class="auto-grid has-gutter"> |
||||
<%= f.label :name, :name %>: |
||||
<%= f.text_field :name %> |
||||
|
||||
<%= f.label :css, :css %>: |
||||
<%= f.text_field :css, name: :css %> |
||||
|
||||
<%= f.label :from, :from %>: |
||||
<%= f.text_field :from, name: :from %> |
||||
|
||||
<%= f.label :to, :to %>: |
||||
<%= f.text_field :to, name: :to %> |
||||
|
||||
<%= f.hidden_field :_destroy %> |
||||
<%= link_to :delete, "#", class: "remove_fields" %> |
||||
|
||||
</div> |
||||
</fieldset> |
@ -0,0 +1,5 @@ |
||||
<h1 class="txtcenter"><%= :edit %> <%= @group.name %></h1> |
||||
|
||||
<%= render 'form', group: @group %> |
||||
|
||||
<%= link_to :back, config_index_path %> |
@ -0,0 +1,5 @@ |
||||
<h1 class="txtcenter"><%= :new %></h1> |
||||
|
||||
<%= render 'form', group: @group %> |
||||
|
||||
<%= link_to :back, config_index_path %> |
@ -0,0 +1,5 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe GroupeController, type: :controller do |
||||
|
||||
end |
@ -0,0 +1,15 @@ |
||||
require 'rails_helper' |
||||
|
||||
# Specs in this file have access to a helper object that includes |
||||
# the GroupeHelper. For example: |
||||
# |
||||
# describe GroupeHelper do |
||||
# describe "string concat" do |
||||
# it "concats two strings with spaces" do |
||||
# expect(helper.concat_strings("this","that")).to eq("this that") |
||||
# end |
||||
# end |
||||
# end |
||||
RSpec.describe GroupeHelper, type: :helper do |
||||
pending "add some examples to (or delete) #{__FILE__}" |
||||
end |
Loading…
Reference in new issue