def update_property_sets(resource_id)
(params[:property_sets] || []).each do |key, set_keys|
- if params[key][:auto_generate]
- set_keys = Array.new(set_keys.size - 1) { |i| i.to_s }
- end
-
- update_property_set(key, set_keys, params[key], resource_id)
+ update_property_set(key, set_keys, params[key], resource_id, params[:auto_generate][key])
end
end
- def update_property_set(key, set_keys, fields_hash, resource_id)
+ def update_property_set(key, set_keys, fields_hash, resource_id, auto_generate)
+ set_keys = Array.new(set_keys.size) { |i| i.to_s } if auto_generate
+
+ set_key_values = {}
+ fields_hash.each do |field_key, field_values|
+ field_values.zip(set_keys).each do |field_value, set_key|
+ set_key_values[set_key] ||= {}
+ set_key_values[set_key][field_key] = field_value
+ end
+ end
+
+ set_keys.reject! { |set_key| set_key.blank? || (auto_generate && set_key_values[set_key].values.all?(&:blank?)) }
+
Property.transaction do
Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all
update_property(key, set_keys, resource_id)
set_keys.each do |set_key|
- update_property("#{key}.#{set_key}.key", set_key, resource_id)
- end
+ update_property("#{key}.#{set_key}.key", set_key, resource_id) unless auto_generate
- fields_hash.each do |field_key, field_values|
- field_values.zip(set_keys).each do |field_value, set_key|
- update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id) if set_key
+ set_key_values[set_key].each do |field, value|
+ update_property("#{key}.#{set_key}.#{field}", value, resource_id)
end
end
end
<% value = property_value(property) -%>
<% if property.multi_values -%>
<% value.each_with_index do |sub_value, index| -%>
- <%= render "settings/multi_value", :property => property, :value => sub_value, :hide_delete => ((index == 0) || (value == 1)) -%>
+ <%= render "settings/multi_value", :property => property, :value => sub_value, :hide_delete => index == 0 -%>
<% end -%>
<div class="template" style="display:none;">
<%= render "settings/multi_value", :property => property, :value => nil, :hide_delete => false -%>
<script>
$j('.delete').live('click', function () {
+ var value_count = $j(this).parents('.property').find('.delete').size() - 2;
+ //if (0 == value_count) {
+ // var template = $j(this).parents('.property').find('.template').last();
+ // template.clone().insertBefore(template).show();
+ //}
$j(this).parents('.multi_value').remove();
return false;
});
$j('.add_value').live('click', function () {
- $j('.delete').show();
+ //$j(this).parents('.property').find('.delete').show();
var template = $j(this).parents('.property').find('.template').last();
template.clone().insertBefore(template).show();
<% errors = [] -%>
<% key_field = key_field(property) -%>
-<tr class="top multi_value <%= 'template' unless set_key -%>" style="<%= 'display:none' unless set_key -%>">
+<tr class="top multi_value <%= 'template' unless set_key -%> odd" style="<%= 'display:none' unless set_key -%>">
<% if key_field -%>
<td><%= render "settings/type_#{key_field.type}", :property => key_field, :field => key_field, :value => set_key, :name => "property_sets[#{property.key}][]", :id => "input_#{h key_field.key}", :size => key_field.indicativeSize -%></td>
<% else -%>
<td><%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%></td>
<% end -%>
- <td><a href="#" class="delete link-action"><%= message('delete') -%></a></td>
+ <td style="width: 60px;">
+ <% unless hide_delete -%>
+ <a href="#" class="delete link-action"><%= message('delete') -%></a>
+ <% end -%>
+ </td>
</tr>
<% unless errors.all?(&:blank?) -%>
<% if key_field(property) -%>
<th><%= message('key') -%></th>
<% else %>
- <%= hidden_field_tag "#{property.key}[auto_generate]", true -%>
+ <%= hidden_field_tag "auto_generate[#{property.key}]", true -%>
<% end -%>
<% property.fields.reject { |field| field.key == 'key' }.each do |field| -%>
<th>
</thead>
<tbody>
- <% Property.values(property.key, resource_id).reject(&:blank?).each do |set_key| -%>
- <%= render 'settings/set_instance', :property => property, :set_key => set_key, :resource_id => resource_id %>
+ <% set_keys = Property.values(property.key, resource_id) -%>
+ <% set_keys = [''] if set_keys.all?(&:blank?) -%>
+ <% set_keys.each_with_index do |set_key, index| -%>
+ <%= render 'settings/set_instance', :property => property, :set_key => set_key, :resource_id => resource_id, :hide_delete => (index == 0) %>
<% end -%>
- <%= render 'settings/set_instance', :property => property, :set_key => nil, :resource_id => resource_id %>
+ <%= render 'settings/set_instance', :property => property, :set_key => nil, :resource_id => resource_id, :hide_delete => false %>
</tbody>
<tfoot>