-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://gitlab.com/pasosdeJesus/sivel2_gen/-/issues/741 Combatientes ahora con turbo See merge request pasosdeJesus/sivel2_gen!523
- Loading branch information
Showing
7 changed files
with
152 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,10 @@ | ||
require 'date' | ||
|
||
require 'sivel2_gen/concerns/controllers/combatientes_controller' | ||
|
||
module Sivel2Gen | ||
class CombatientesController < ApplicationController | ||
load_and_authorize_resource class: Sivel2Gen::Combatiente | ||
|
||
# Crea un nuevo registro para el caso que recibe por parametro | ||
# params[:caso_id]. Pone valores simples en los campos requeridos | ||
def nuevo | ||
if params[:caso_id] | ||
@combatiente = Combatiente.new | ||
@combatiente.nombre = 'N' | ||
@combatiente.sexo = Msip::Persona.convencion_sexo[:sexo_masculino].to_s | ||
@combatiente.resagresion_id = 1 | ||
@combatiente.caso_id = params[:caso_id] | ||
if @combatiente.save | ||
respond_to do |format| | ||
format.js { render json: {'combatiente' => @combatiente.id.to_s } } | ||
format.json { render json: {'combatiente' => @combatiente.id.to_s }, | ||
status: :created } | ||
format.html { render json: {'combatiente' => @combatiente.id.to_s } } | ||
end | ||
else | ||
respond_to do |format| | ||
format.html { | ||
render inline: 'Error: ' + @combatiente.errors.messages.to_s | ||
} | ||
format.json { render json: @combatiente.errors.messages, | ||
status: :unprocessable_entity } | ||
end | ||
end | ||
else | ||
respond_to do |format| | ||
format.html { render inline: 'Falta identificacion del caso' } | ||
end | ||
end | ||
end | ||
|
||
include Sivel2Gen::Concerns::Controllers::CombatientesController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
<%= f.simple_fields_for :combatiente do |vc| %> | ||
<%= render 'combatiente_campos', f: vc %> | ||
<% end %> | ||
<div class="links"> | ||
<%= link_to_add_association 'Añadir Combatiente', f, | ||
:combatiente, | ||
partial: 'combatiente_campos', | ||
class: 'btn btn-sm btn-primary agrega-comb', | ||
"data-ajax": File.join( | ||
Rails.configuration.relative_url_root, | ||
"combatientes/nuevo" | ||
), | ||
"data-ajaxdata": "caso_id" | ||
%> | ||
<div id="combatientes_marco"> | ||
<%= f.simple_fields_for :combatiente, | ||
child_index: params[:index] do |com| %> | ||
<%= render '/sivel2_gen/casos/combatiente_campos', :f => com %> | ||
<% end %> | ||
</div> | ||
|
||
<%= f.submit "Agregar Combatiente", | ||
formaction: sivel2_gen.crear_combatiente_path(index: @caso.combatiente.size), | ||
formmethod: :post, | ||
formnovalidate: true, | ||
class: 'btn btn-sm btn-primary', | ||
name: "agregar-combatiente", | ||
id: "agregar-combatiente", | ||
input_html: {class: "tom-select"}, | ||
data: { | ||
disable_with: false } %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<%= simple_form_for @caso do |form| %> | ||
<%= form.simple_fields_for :combatiente, | ||
child_index: params[:index] do |com_form| %> | ||
<%= turbo_stream.replace "agregar-combatiente" do %> | ||
<%= form.submit "Agregar Combatiente", | ||
formaction: sivel2_gen.crear_combatiente_path(com_form.index.to_i + 1), | ||
formmethod: :post, | ||
formnovalidate: true, | ||
class: 'btn btn-sm btn-primary agregar-vic', | ||
id: "agregar-combatiente", | ||
data: { | ||
disable_with: false } %> | ||
<% end %> | ||
|
||
<%= turbo_stream.append "combatientes_marco" do %> | ||
<%= render "/sivel2_gen/casos/combatiente_campos", f: com_form %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= fields model: @caso do |form| %> | ||
<%= form.simple_fields_for :combatiente, | ||
child_index: params[:index] do |com_form| %> | ||
<%= turbo_frame_tag "combatiente_#{com_form.index}" do %> | ||
<%= com_form.hidden_field :id, value: params[:id] %> | ||
<%= com_form.hidden_field :_destroy, value: true %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
lib/sivel2_gen/concerns/controllers/combatientes_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'date' | ||
|
||
module Sivel2Gen | ||
module Concerns | ||
module Controllers | ||
module CombatientesController | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include ActionView::Helpers::AssetUrlHelper | ||
|
||
load_and_authorize_resource class: Sivel2Gen::Caso | ||
before_action :prepara_caso | ||
|
||
# Crea un nuevo registro para el caso que recibe por parametro | ||
# params[:caso_id]. Pone valores simples en los campos requeridos | ||
def nuevo | ||
if params[:caso_id] | ||
@combatiente = Combatiente.new | ||
@combatiente.nombre = 'N' | ||
@combatiente.sexo = Msip::Persona.convencion_sexo[:sexo_masculino].to_s | ||
@combatiente.resagresion_id = 1 | ||
@combatiente.caso_id = params[:caso_id] | ||
if @combatiente.save | ||
respond_to do |format| | ||
format.js { render json: {'combatiente' => @combatiente.id.to_s } } | ||
format.json { render json: {'combatiente' => @combatiente.id.to_s }, | ||
status: :created } | ||
format.html { render json: {'combatiente' => @combatiente.id.to_s } } | ||
end | ||
else | ||
respond_to do |format| | ||
format.html { | ||
render inline: 'Error: ' + @combatiente.errors.messages.to_s | ||
} | ||
format.json { render json: @combatiente.errors.messages, | ||
status: :unprocessable_entity } | ||
end | ||
end | ||
else | ||
respond_to do |format| | ||
format.html { render inline: 'Falta identificacion del caso' } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
end | ||
|
||
def create | ||
end | ||
|
||
def update | ||
end | ||
|
||
private | ||
|
||
def prepara_caso | ||
@caso = Sivel2Gen::Caso.new( | ||
combatiente: [Sivel2Gen::Combatiente.new]) | ||
end | ||
end # included | ||
|
||
end | ||
end | ||
end | ||
end |