Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kevynlebouille/Whbab
base: 482e9c4395
...
head fork: kevynlebouille/Whbab
compare: ac393d309c
  • 2 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
8 app/assets/javascripts/application.js
@@ -27,7 +27,13 @@ jQuery(function($) {
$('button[data-url]:not([data-popin])').live('click', function(evt) {
evt.preventDefault();
- window.location = $(this).data('url');
+
+ if ($(this).data('target') == '_blank') {
+ window.open($(this).data('url'));
+ }
+ else {
+ window.location = $(this).data('url');
+ }
});
$('[data-popin]').live('click', function(evt) {
View
4 app/assets/stylesheets/application.css.scss
@@ -280,6 +280,10 @@
font-weight: bold;
}
+.army_list_unit_details h4 {;
+ margin-top: 10px;
+}
+
.army_list_unit_details .options {
float: right;
width: 300px;
View
16 app/controllers/army_list_units_controller.rb
@@ -17,6 +17,9 @@ def new
def edit
@army_list = current_user.army_lists.find(params[:army_list_id])
@army_list_unit = @army_list.army_list_units.find(params[:id])
+ @available_unit_options = @army_list_unit.unit.unit_options.without_magics
+ @magic_items_option = @army_list_unit.unit.unit_options.only_magic_items.first
+ @magic_standards_option = @army_list_unit.unit.unit_options.only_magic_standards.first
end
# POST /army_list/1/army_list_units
@@ -27,7 +30,7 @@ def create
respond_to do |format|
if @army_list_unit.save
- format.html { redirect_to(@army_list, :notice => 'Army list unit was successfully created.') }
+ format.html { redirect_to @army_list }
format.xml { render :xml => @army_list_unit, :status => :created, :location => @army_list_unit }
else
format.html { render :action => "new" }
@@ -39,14 +42,21 @@ def create
# PUT /army_list/1/army_list_units/1
# PUT /army_list/1/army_list_units/1.xml
def update
+ params[:army_list_unit][:unit_option_ids] ||= []
+ params[:army_list_unit][:magic_item_ids] ||= []
+
@army_list = current_user.army_lists.find(params[:army_list_id])
@army_list_unit = @army_list.army_list_units.find(params[:id])
respond_to do |format|
if @army_list_unit.update_attributes(params[:army_list_unit])
- format.html { redirect_to(@army_list, :notice => 'Army list unit was successfully updated.') }
+ format.html { redirect_to @army_list }
format.xml { head :ok }
else
+ @available_unit_options = @army_list_unit.unit.unit_options.without_magics
+ @magic_items_option = @army_list_unit.unit.unit_options.only_magic_items.first
+ @magic_standards_option = @army_list_unit.unit.unit_options.only_magic_standards.first
+
format.html { render :action => "edit" }
format.xml { render :xml => @army_list_unit.errors, :status => :unprocessable_entity }
end
@@ -61,7 +71,7 @@ def destroy
@army_list_unit.destroy
respond_to do |format|
- format.html { redirect_to(@army_list) }
+ format.html { redirect_to @army_list }
format.xml { head :ok }
end
end
View
6 app/controllers/army_lists_controller.rb
@@ -55,7 +55,7 @@ def create
respond_to do |format|
if @army_list.save
- format.html { redirect_to(@army_list, :notice => 'Army list was successfully created.') }
+ format.html { redirect_to @army_list }
format.xml { render :xml => @army_list, :status => :created, :location => @army_list }
else
format.html { render :action => "new", :layout => nil }
@@ -71,7 +71,7 @@ def update
respond_to do |format|
if @army_list.update_attributes(params[:army_list])
- format.html { redirect_to(@army_list, :notice => 'Army list was successfully updated.') }
+ format.html { redirect_to @army_list }
format.xml { head :ok }
else
format.html { render :action => "edit" }
@@ -87,7 +87,7 @@ def destroy
@army_list.destroy
respond_to do |format|
- format.html { redirect_to(army_lists_url) }
+ format.html { redirect_to army_lists_url }
format.xml { head :ok }
end
end
View
1  app/models/army_list_unit.rb
@@ -11,6 +11,7 @@ class ArmyListUnit < ActiveRecord::Base
validates_numericality_of :position, :greater_than_or_equal_to => 1, :only_integer => true, :allow_nil => true
before_validation :on => :create do
+ self.name = unit.name if unit.is_unique
self.name = unit.name + " \#" + (army_list.army_list_units.where(:unit_id => unit).count() + 1).to_s unless name?
self.size = unit.min_size
self.unit_category = unit.unit_category
View
3  app/models/magic_item.rb
@@ -6,9 +6,8 @@ class MagicItem < ActiveRecord::Base
validates_presence_of :magic_item_category_id, :name, :value_points
validates_numericality_of :value_points, :greater_than_or_equal_to => 0
- scope :by_category_and_army, lambda { |category, army| category.magic_items.where(:army_id => army).order("value_points DESC", "name") }
scope :magic_standards, where(:magic_item_category_id => 4)
- scope :by_army, lambda { |army| where(:army_id => army) }
+ scope :available_for, lambda { |army| where(:army_id => army).order("value_points DESC", "name") }
# def self.for_select(army)
# MagicItemCategory.all.map do |magic_item_category|
View
13 app/models/unit.rb
@@ -13,9 +13,18 @@ class Unit < ActiveRecord::Base
validates_numericality_of :value_points, :greater_than_or_equal_to => 0, :allow_nil => true
validates_inclusion_of :is_unique, :in => [true, false]
- def self.for_select(army)
+ def self.for_select(army_list)
+ used_units = army_list.army_list_units.collect { |alu| alu.unit }
+
UnitCategory.all.map do |unit_category|
- [unit_category.name, unit_category.units.where(:army_id => army).order("is_unique", "name").map { |u| [u.name, u.id] }]
+ [
+ unit_category.name,
+ unit_category.units
+ .where(:army_id => army_list.army)
+ .order("is_unique", "name")
+ .reject { |unit| unit.in?(used_units) if unit.is_unique }
+ .map { |u| [u.name, u.id] }
+ ]
end
end
end
View
4 app/models/unit_option.rb
@@ -12,4 +12,8 @@ class UnitOption < ActiveRecord::Base
validates_inclusion_of :is_magic_standards, :in => [true, false]
acts_as_list :scope => 'unit_id = #{unit_id} AND COALESCE(parent_id, \'\') = \'#{parent_id}\''
+
+ scope :without_magics, where(:is_magic_items => false, :is_magic_standards => false)
+ scope :only_magic_items, where(:is_magic_items => true, :is_magic_standards => false)
+ scope :only_magic_standards, where(:is_magic_items => false, :is_magic_standards => true)
end
View
82 app/views/army_list_units/_form.html.erb
@@ -1,82 +0,0 @@
-<%= form_for [@army_list, @army_list_unit] do |f| %>
- <%= render "shared/form_errors", :object => @army_list_unit %>
-
- <% if @army_list_unit.persisted? %>
- <p>
- <%= f.text_field :name, :placeholder => "Nom" %>
- <%= f.collection_select :unit_category_id, UnitCategory.all, :id, :name %><br />
- </p>
-
- <% if @army_list_unit.unit.min_size != @army_list_unit.unit.max_size %>
- <p>
- <%= f.label :size, @army_list_unit.unit.troops.first.name %> x
- <%= f.text_field :size, :placeholder => "Taille" %>
- </p>
- <% end %>
-
- <% magic_items_option = @army_list_unit.unit.unit_options.where(:parent_id => nil, :is_magic_items => 1).first %>
- <% magic_standards_option = @army_list_unit.unit.unit_options.where(:parent_id => nil, :is_magic_standards => 1).first %>
- <% if magic_items_option %>
- <div id="army_list_unit_magic_items">
- <h3>Objets magiques (<%= value_points(@army_list_unit.magic_items.sum('value_points')) %>/<%= value_points(magic_items_option.value_points) %>pts)</h3>
- <ul>
- <% MagicItemCategory.all.each do |magic_item_category| %>
- <li>
- <%= magic_item_category.name %>
- <ul>
- <% MagicItem.by_category_and_army(magic_item_category, @army_list.army).each do |magic_item| %>
- <li>
- <em><%= value_points(magic_item.value_points) %>pts</em>
- <label><%= check_box_tag "army_list_unit[magic_item_ids][]", magic_item.id, magic_item.in?(@army_list_unit.magic_items), "id" => "army_list_unit_magic_item_ids_#{magic_item.id}" %> <%= magic_item.name %></label>
- </li>
- <% end %>
- </ul>
- </li>
- <% end %>
- </ul>
- </div>
- <% elsif magic_standards_option %>
- <div id="army_list_unit_magic_items">
- <h3>Bannière magique (<%= value_points(@army_list_unit.magic_items.magic_standards.sum('value_points')) %>/<%= value_points(magic_standards_option.value_points) %>pts)</h3>
- <ul>
- <% MagicItem.magic_standards.by_army(@army_list.army).each do |magic_item| %>
- <li>
- <em><%= value_points(magic_item.value_points) %>pts</em>
- <label><%= check_box_tag "army_list_unit[magic_item_ids][]", magic_item.id, magic_item.in?(@army_list_unit.magic_items), "id" => "army_list_unit_magic_item_ids_#{magic_item.id}" %> <%= magic_item.name %></label>
- </li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div id="army_list_unit_unit_options">
- <h3>Options</h3>
- <ul>
- <!-- IGNORE MAGIC ITEMS/STANTARDS -->
- <% @army_list_unit.unit.unit_options.where(:parent_id => nil, :is_magic_items => 0, :is_magic_standards => 0).each do |option| %>
- <li>
- <% if option.children.any? %>
- <%= option.name %>
- <ul>
- <% option.children.each do |child| %>
- <li>
- <em><%= value_points(child.is_per_model ? child.value_points * @army_list_unit.size : child.value_points) %>pts</em>
- <label><%= check_box_tag "army_list_unit[unit_option_ids][]", child.id, child.in?(@army_list_unit.unit_options), "data-radio" => true, "data-depend" => child.depend.try(:id), "id" => "army_list_unit_unit_option_ids_#{child.id}" %> <%= child.name %></label></li>
- <% end %>
- </ul>
- <% else %>
- <em><%= value_points(option.is_per_model ? option.value_points * @army_list_unit.size : option.value_points) %>pts</em>
- <label><%= check_box_tag "army_list_unit[unit_option_ids][]", option.id, option.in?(@army_list_unit.unit_options), "data-depend" => option.depend.try(:id), "id" => "army_list_unit_unit_option_ids_#{option.id}" %> <%= option.name %></label>
- <% end %>
- </li>
- <% end %>
- </ul>
- </div>
- <% else %>
- <p><%= f.select :unit_id, grouped_options_for_select(Unit.for_select(@army_list.army), @army_list_unit.unit_id) %></p>
-
- <p><%= f.text_field :name, :placeholder => "Nom" %></p>
- <% end %>
-
- <p><%= f.submit "Valider" %></p>
-<% end %>
View
47 app/views/army_list_units/_show.html.erb
@@ -2,7 +2,8 @@
<div class="army_list_unit_overview">
<div class="name">
<strong><%= army_list_unit.name %></strong>
- <%= army_list_unit.unit.name %> <% if army_list_unit.size > 1 %><em>x<%= army_list_unit.size %></em><% end %>
+ <%= army_list_unit.unit.is_unique ? "<i>Unique</i>".html_safe : army_list_unit.unit.name %>
+ <%= "<em>x#{army_list_unit.size}</em>".html_safe if army_list_unit.size > 1 %>
</div>
<div class="value_points">
<strong><%= value_points army_list_unit.value_points %></strong> points
@@ -58,43 +59,45 @@
</tbody>
</table>
- <br />
-
- <div class="options">
- <strong>Options</strong><br />
- <% army_list_unit.unit_options.each do |option| %>
- <em><%= value_points(option.value_points) %>pts<%= '/fig.' if option.is_per_model %></em>
- • <%= option.name %><br />
- <% end %>
+ <% if army_list_unit.unit_options.any? %>
+ <div class="options">
+ <h4>Options</h4>
+ <% army_list_unit.unit_options.each do |option| %>
+ <em><%= value_points(option.value_points) %>pts<%= '/fig.' if option.is_per_model %></em>
+ • <%= option.name %><br />
+ <% end %>
- <% if army_list_unit.magic_items.any? %>
- <br /><strong>Objets magiques</strong><br />
- <% army_list_unit.magic_items.each do |magic_item| %>
- <em><%= value_points(magic_item.value_points) %>pts</em>
- • <%= magic_item.name %><br />
+ <% if army_list_unit.magic_items.any? %>
+ <br /><strong>Objets magiques</strong><br />
+ <% army_list_unit.magic_items.each do |magic_item| %>
+ <em><%= value_points(magic_item.value_points) %>pts</em>
+ • <%= magic_item.name %><br />
+ <% end %>
<% end %>
- <% end %>
- </div>
+ </div>
+ <% end %>
- <strong>Equipement</strong><br />
- <% army_list_unit.unit.equipments.each do |equipment| %>
- • <%= equipment.name %><br />
+ <% if army_list_unit.unit.equipments.any? %>
+ <h4>Equipement</h4>
+ <% army_list_unit.unit.equipments.each do |equipment| %>
+ • <%= equipment.name %><br />
+ <% end %>
<% end %>
<% if army_list_unit.unit.special_rules.any? %>
- <br /><strong>Règles Spéciales</strong><br />
+ <h4>Règles Spéciales</h4>
<% army_list_unit.unit.special_rules.each do |special_rule| %>
<%= special_rule.name %><br />
<% end %>
<% end %>
<% if army_list_unit.unit.magic? %>
- <br /><strong>Magie</strong><br />
+ <h4>Magie</h4>
<%= army_list_unit.unit.magic %><br />
<% end %>
<% if army_list_unit.unit.notes? %>
- <br /><strong>Remarques</strong><br />
+ <h4>Remarques</h4>
<%= army_list_unit.unit.notes %>
<% end %>
View
47 app/views/army_list_units/_show.pdf.erb
@@ -2,7 +2,8 @@
<div class="army_list_unit_overview">
<div class="name">
<strong><%= army_list_unit.name %></strong>
- <%= army_list_unit.unit.name %> <% if army_list_unit.size > 1 %><em>x<%= army_list_unit.size %></em><% end %>
+ <%= army_list_unit.unit.is_unique ? "<i>Unique</i>".html_safe : army_list_unit.unit.name %>
+ <%= "<em>x#{army_list_unit.size}</em>".html_safe if army_list_unit.size > 1 %>
</div>
<div class="value_points">
<strong><%= value_points army_list_unit.value_points %></strong> points
@@ -55,43 +56,45 @@
</tbody>
</table>
- <br />
-
- <div class="options">
- <strong>Options</strong><br />
- <% army_list_unit.unit_options.each do |option| %>
- <em><%= value_points(option.value_points) %>pts<%= '/fig.' if option.is_per_model %></em>
- • <%= option.name %><br />
- <% end %>
+ <% if army_list_unit.unit_options.any? %>
+ <div class="options">
+ <h4>Options</h4>
+ <% army_list_unit.unit_options.each do |option| %>
+ <em><%= value_points(option.value_points) %>pts<%= '/fig.' if option.is_per_model %></em>
+ • <%= option.name %><br />
+ <% end %>
- <% if army_list_unit.magic_items.any? %>
- <br /><strong>Objets magiques</strong><br />
- <% army_list_unit.magic_items.each do |magic_item| %>
- <em><%= value_points(magic_item.value_points) %>pts</em>
- • <%= magic_item.name %><br />
+ <% if army_list_unit.magic_items.any? %>
+ <br /><strong>Objets magiques</strong><br />
+ <% army_list_unit.magic_items.each do |magic_item| %>
+ <em><%= value_points(magic_item.value_points) %>pts</em>
+ • <%= magic_item.name %><br />
+ <% end %>
<% end %>
- <% end %>
- </div>
+ </div>
+ <% end %>
- <strong>Equipement</strong><br />
- <% army_list_unit.unit.equipments.each do |equipment| %>
- • <%= equipment.name %><br />
+ <% if army_list_unit.unit.equipments.any? %>
+ <h4>Equipement</h4>
+ <% army_list_unit.unit.equipments.each do |equipment| %>
+ • <%= equipment.name %><br />
+ <% end %>
<% end %>
<% if army_list_unit.unit.special_rules.any? %>
- <br /><strong>Règles Spéciales</strong><br />
+ <h4>Règles Spéciales</h4>
<% army_list_unit.unit.special_rules.each do |special_rule| %>
<%= special_rule.name %><br />
<% end %>
<% end %>
<% if army_list_unit.unit.magic? %>
- <br /><strong>Magie</strong><br />
+ <h4>Magie</h4>
<%= army_list_unit.unit.magic %><br />
<% end %>
<% if army_list_unit.unit.notes? %>
- <br /><strong>Remarques</strong><br />
+ <h4>Remarques</h4>
<%= army_list_unit.unit.notes %>
<% end %>
View
77 app/views/army_list_units/edit.html.erb
@@ -2,6 +2,81 @@
<h1>Editer <%= @army_list_unit.unit.name %></h1>
- <%= render 'form' %>
+ <%= form_for [@army_list, @army_list_unit] do |f| %>
+ <%= render "shared/form_errors", :object => @army_list_unit %>
+
+ <p>
+ <%= f.text_field :name, :placeholder => "Nom" unless @army_list_unit.unit.is_unique %>
+ <%= f.collection_select :unit_category_id, UnitCategory.all, :id, :name %><br />
+ </p>
+
+ <% if @army_list_unit.unit.min_size != @army_list_unit.unit.max_size %>
+ <p>
+ <%= f.label :size, @army_list_unit.unit.troops.first.name %> x
+ <%= f.text_field :size, :placeholder => "Taille" %>
+ </p>
+ <% end %>
+
+ <% if @magic_items_option %>
+ <div id="army_list_unit_magic_items">
+ <h3>Objets magiques (<%= value_points(@army_list_unit.magic_items.sum('value_points')) %>/<%= value_points(@magic_items_option.value_points) %>pts)</h3>
+ <ul>
+ <% MagicItemCategory.all.each do |magic_item_category| %>
+ <li>
+ <%= magic_item_category.name %>
+ <ul>
+ <% magic_item_category.magic_items.available_for(@army_list.army).each do |magic_item| %>
+ <li>
+ <em><%= value_points(magic_item.value_points) %>pts</em>
+ <label><%= check_box_tag "army_list_unit[magic_item_ids][]", magic_item.id, @army_list_unit.magic_items.all.include?(magic_item), "id" => "army_list_unit_magic_item_ids_#{magic_item.id}" %> <%= magic_item.name %></label>
+ </li>
+ <% end %>
+ </ul>
+ </li>
+ <% end %>
+ </ul>
+ </div>
+ <% elsif @magic_standards_option %>
+ <div id="army_list_unit_magic_items">
+ <h3>Bannière magique (<%= value_points(@army_list_unit.magic_items.magic_standards.sum('value_points')) %>/<%= value_points(@magic_standards_option.value_points) %>pts)</h3>
+ <ul>
+ <% MagicItem.magic_standards.available_for(@army_list.army).each do |magic_item| %>
+ <li>
+ <em><%= value_points(magic_item.value_points) %>pts</em>
+ <label><%= check_box_tag "army_list_unit[magic_item_ids][]", magic_item.id, @army_list_unit.magic_items.all.include?(magic_item), "id" => "army_list_unit_magic_item_ids_#{magic_item.id}" %> <%= magic_item.name %></label>
+ </li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <% if @available_unit_options.any? %>
+ <div id="army_list_unit_unit_options">
+ <h3>Options</h3>
+ <ul>
+ <!-- IGNORE MAGIC ITEMS/STANTARDS -->
+ <% @available_unit_options.each do |option| %>
+ <li>
+ <% if option.children.any? %>
+ <%= option.name %>
+ <ul>
+ <% option.children.each do |child| %>
+ <li>
+ <em><%= value_points(child.is_per_model ? child.value_points * @army_list_unit.size : child.value_points) %>pts</em>
+ <label><%= check_box_tag "army_list_unit[unit_option_ids][]", child.id, child.in?(@army_list_unit.unit_options), "data-radio" => true, "data-depend" => child.depend.try(:id), "id" => "army_list_unit_unit_option_ids_#{child.id}" %> <%= child.name %></label></li>
+ <% end %>
+ </ul>
+ <% else %>
+ <em><%= value_points(option.is_per_model ? option.value_points * @army_list_unit.size : option.value_points) %>pts</em>
+ <label><%= check_box_tag "army_list_unit[unit_option_ids][]", option.id, option.in?(@army_list_unit.unit_options), "data-depend" => option.depend.try(:id), "id" => "army_list_unit_unit_option_ids_#{option.id}" %> <%= option.name %></label>
+ <% end %>
+ </li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <p><%= f.submit "Valider" %></p>
+ <% end %>
</div>
View
10 app/views/army_list_units/new.html.erb
@@ -2,6 +2,14 @@
<h1>Ajouter<br />une unite</h1>
- <%= render 'form' %>
+ <%= form_for [@army_list, @army_list_unit] do |f| %>
+ <%= render "shared/form_errors", :object => @army_list_unit %>
+
+ <p><%= f.select :unit_id, grouped_options_for_select(Unit.for_select(@army_list), @army_list_unit.unit_id) %></p>
+
+ <p><%= f.text_field :name, :placeholder => "Nom" %></p>
+
+ <p><%= f.submit "Valider" %></p>
+ <% end %>
</div>
View
2  app/views/army_lists/index.html.erb
@@ -18,7 +18,7 @@
<p class="thumb"><a href="<%= army_list_path(army_list) %>"><%= image_tag "/system/armies/#{army_list.army.id}/thumb.png", :size => "220x132" %></a></p>
<p class="value_points"><%= value_points army_list.value_points %><br /><small style="font-size:20px">points</small></p>
<p><%= army_list.name %></p>
- <p class="actions"><button data-url="<%= army_list_path(army_list, :format => 'pdf') %>">Imprimer</button></p>
+ <p class="actions"><button data-url="<%= army_list_path(army_list, :format => 'pdf') %>" data-target="_blank">Imprimer</button></p>
</div>
</div>
View
4 app/views/army_lists/show.html.erb
@@ -3,11 +3,11 @@
<div class="army_list_portrait">
<%= image_tag "/system/armies/#{@army_list.army.id}/portrait.png", :size => "65x64" %>
<h2><%= link_to @army_list.army.name, army_lists_path({'search[army_id_eq]' => @army_list.army}) %></h2>
- <h1><%= @army_list.name %></h1>
+ <h1 title="<%= @army_list.name %>"><%= @army_list.name.truncate 30 %></h1>
</div>
<div id="subheader" class="grid_14 army_list">
- <button data-url="<%= army_list_path(@army_list, :format => 'pdf') %>" class="left">Imprimer</button>
+ <button data-url="<%= army_list_path(@army_list, :format => 'pdf') %>" data-target="_blank" class="left">Imprimer</button>
<%= button_to "Suppr.", army_list_path(@army_list), :confirm => "Êtes-vous sûr(e) ?", :method => :delete %>
<button data-popin="true" data-url="<%= edit_army_list_path @army_list %>">Editer</button>
</div>
View
2  config/initializers/wisepdf.rb
@@ -3,6 +3,6 @@
config.options = {
:encoding => 'utf8',
:layout => "pdf.html",
- # :show_as_html => true,
+ :show_as_html => Rails.env.development?,
}
end

No commit comments for this range

Something went wrong with that request. Please try again.