Fix mongoid deeply nested polimorphic
Got the commit from github. The roles and sub_roles save.
This commit is contained in:
1 parent
d27d7a623c
commit
4108ebf06d
11 files changed
+45
-41
No files matched your search
@@ -2,12 +2,12 @@ $('.attributes_block a.delete').live('click', function(){
|
||||
$(this).parents('.list_item').remove();
|
||||
});
|
||||
|
||||
$('#attributes a.remove_existing_record').live('click', function(){
|
||||
$('.action a.remove_existing_record').live('click', function(){
|
||||
$(this).next('.should_destroy').attr('value', 1);
|
||||
$("#attribute_" + $(this).prev().attr('value')).hide();
|
||||
});
|
||||
|
||||
$('#attributes_block a.switch').live('click', function(){
|
||||
$('.action a.switch').live('click', function(){
|
||||
$(this).parent().toggleClass('disable');
|
||||
var $am = $(this).next('.built_in_state')
|
||||
$am.attr('value', ($am.attr('value') == "false") ? "true" : "false");
|
||||
|
||||
@@ -26,12 +26,14 @@ class Admin::RolesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
puts params.to_yaml
|
||||
@attribute = Role.new(params[:role])
|
||||
@attribute.save
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
||||
def update
|
||||
puts params.to_yaml
|
||||
@attribute = Role.find(params[:id])
|
||||
@attribute.update_attributes(params[:role])
|
||||
respond_to do |format|
|
||||
|
||||
@@ -9,7 +9,6 @@ class Attribute
|
||||
|
||||
has_many :attribute_fields, :autosave => true, :dependent => :destroy
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
|
||||
|
||||
def is_built_in?
|
||||
|
||||
@@ -13,8 +13,8 @@ class AttributeField
|
||||
belongs_to :attribute
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_many :attribute_values
|
||||
|
||||
validates_uniqueness_of :key
|
||||
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||
|
||||
# Convert the string list_options into an array
|
||||
def select_list_options=(var)
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
<td class='select_mulitlingual' style='text-align:center'>
|
||||
<%= f.check_box :locale %>
|
||||
</td>
|
||||
<%= f.fields_for :i18n_variable, (attribute_field.i18n_variable.nil? ? attribute_field.build_i18n_variable : attribute_field.i18n_variable) do |f| %>
|
||||
<%= f.fields_for :i18n_variable, (attribute_field.new_record? ? attribute_field.build_i18n_variable : attribute_field.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td><%= f.text_field locale, :style => "width:130px" %></td>
|
||||
<% end %>
|
||||
<%= f.hidden_field :id %>
|
||||
<% end %>
|
||||
<td class='select_type'>
|
||||
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
<tbody>
|
||||
<tr class="list_item">
|
||||
<td><%= is_new ? (f.text_field :key, {:style => "width:150px"}) : @attribute.key %></td>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td>
|
||||
<%= text_field_tag "#{@attribute_type}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||
</td>
|
||||
<% end %>
|
||||
<%= f.fields_for :i18n_variable, (@attribute.new_record? ? @attribute.build_i18n_variable : @attribute.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td><%= f.text_field locale, :style => "width:150px" %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
<tbody>
|
||||
<tr class="list_item">
|
||||
<td><%= is_new ? (f.text_field :key, {:style => "width:150px"}) : @attribute.key %></td>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td>
|
||||
<%= text_field_tag "#{@attribute_type}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||
</td>
|
||||
<% end %>
|
||||
<%= f.fields_for :i18n_variable, (@attribute.new_record? ? @attribute.build_i18n_variable : @attribute.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td><%= f.text_field locale, :style => "width:150px" %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<div id='sub_roles' class="attributes_block <%= @class %>">
|
||||
<h2>Sub roles</h2>
|
||||
<% @attribute.sub_roles.each do |sub_role| %>
|
||||
<%= render :partial => 'form_sub', :object => sub_role, :locals => {:f => f} %>
|
||||
<% @attribute.sub_roles.each_with_index do |sub_role, i| %>
|
||||
<%= render :partial => 'form_sub', :object => sub_role, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -38,12 +38,12 @@
|
||||
</div>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "attribute_form" %>
|
||||
<script>
|
||||
$('#add_sub_role a.add').live('click', function(){
|
||||
var new_id = $(this).prev().attr('value');
|
||||
var old_id = new RegExp("new_sub_roles", "g");
|
||||
$(this).prev().attr('value', parseInt(new_id) + 1);
|
||||
$('#sub_role_temp_id').attr('value', new_id);
|
||||
$('#sub_roles').append(("<%= escape_javascript(add_attribute 'admin/roles/sub_role', f, :sub_roles) %>").replace(old_id, new_id));
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<%= f.fields_for :sub_roles, form_sub do |f| %>
|
||||
<%= render :partial => 'sub_role', :object => form_sub, :locals => {:f => f} %>
|
||||
<%= render :partial => 'sub_role', :object => form_sub, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
||||
@@ -12,11 +12,11 @@
|
||||
<tbody>
|
||||
<tr class="list_item">
|
||||
<td><%= sub_role.new_record? ? (f.text_field :key, {:style => "width:150px"}) : sub_role.key %></td>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td>
|
||||
<%= f.text_field "i18n_variable[#{locale}]", :value => (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||
</td>
|
||||
<% end %>
|
||||
<%= f.fields_for :i18n_variable, (sub_role.new_record? ? sub_role.build_i18n_variable : sub_role.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td><%= f.text_field locale, :style => "width:150px" %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -37,10 +37,10 @@
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<td id='add_attribute' colspan="5">
|
||||
<%= hidden_field_tag 'attribute_field_count', sub_role.attribute_fields.count %>
|
||||
<a href="#" class="add"><%= t(:add) %></a>
|
||||
<%= hidden_field_tag 'sub_role_temp_id', 'new_sub_roles' %>
|
||||
<%= hidden_field_tag 'sub_role_temp_id', (i rescue 'new_sub_roles') %>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
@@ -55,16 +55,14 @@
|
||||
</div>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "attribute_form" %>
|
||||
<script>
|
||||
$('.attributes_block a.add').live('click', function(){
|
||||
$('#add_attribute a.add').live('click', function(){
|
||||
var new_parent_id = $(this).next().attr('value');
|
||||
var old_parent_id = new RegExp("new_sub_roles", "g");
|
||||
var new_id = $(this).prev().attr('value');
|
||||
var old_id = new RegExp("new_attribute_fields", "g");
|
||||
$(this).prev().attr('value', parseInt(new_id) + 1);
|
||||
$(this).next().attr('value', parseInt(new_parent_id) + 1);
|
||||
$(this).parents('.sub_role_attributes').append(("<%= escape_javascript(add_attribute 'admin/attributes/attribute_field', f, :attribute_fields) %>").replace(old_id, new_id).replace(old_parent_id, new_parent_id));
|
||||
$(this).parents('table').append(("<%= escape_javascript(add_attribute 'admin/attributes/attribute_field', f, :attribute_fields) %>").replace(old_id, new_id).replace(old_parent_id, new_parent_id));
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
<% end unless !sub_role.new_record? %>
|
||||
Reference in new issue
Block a user