return false unless reader_role_check(roles)
end
return true if self.own?(roles)
+ return true if self.new_record?
self.publish?
end
return false unless reader_role_check(roles)
end
return true if self.own?(roles)
+ return true if self.new_record?
self.visible > 0
end
Sheet.validate_elements_serial validate_serial_list
end
+ def boost
+ @new_element_index = 0
+ self.panel_elements.each do |elm|
+ if elm.new_record?
+ elm.new_index = @new_element_index
+ @new_element_index += 1
+ end
+ end
+ end
+
def store attr, au
if attr == false
self.errors.add :base, I18n.t('errors.invalid_json')
self.overwrite au
res = false
Sheet.transaction do
+ self.panel_elements.each do |elm|
+ elm.new_sheet = self
+ end
res = self.save
unless validate_child
res = false
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
def supply_default
- self.sheet_id = nil
- self.panel_id = nil
+# self.sheet_id = nil
+# self.panel_id = nil
self.x = 15
self.y = 15
if self.sheet
end
def tag_sheet_id
- self.get_sheet.new_record? ? '0' : self.get_sheet.id.to_s
+ self.get_sheet == nil or self.get_sheet.new_record? ? '0' : self.get_sheet.id.to_s
end
def tag_element_id
<%= l panel.updated_at %>
</td>
<td>
- <% @sheet_panel = SheetPanel.new -%>
+ <% @sheet_panel = SheetPanel.new :sheet_id => sheet.id, :panel_id => panel.id -%>
<% @sheet_panel.supply_default -%>
- <% @sheet_panel.attributes = {:sheet_id => sheet.id, :panel_id => panel.id} -%>
+ <% @sheet_panel.attributes = {} -%>
<%= form_for(@sheet_panel) do |f| %>
<%= f.hidden_field :sheet_id %>
<%= f.hidden_field :x %>
</td>
<td>
<% if sheet.own? author %>
- <% @sheet_panel = SheetPanel.new %>
+ <% @sheet_panel = SheetPanel.new:sheet_id => sheet.id, :panel_id => panel.id %>
<% @sheet_panel.supply_default -%>
- <% @sheet_panel.attributes = {:sheet_id => sheet.id, :panel_id => panel.id} -%>
+ <% @sheet_panel.attributes = {} -%>
<%= form_for(@sheet_panel) do |f| %>
<%= f.hidden_field :sheet_id %>
+ <%= f.hidden_field :z %>
<%= f.hidden_field :t %>
<%= f.hidden_field :panel_id %>
<div class="actions">
<%= render 'system/error_explanation', :obj => elm %>
<div class="field">
+ <%= f.label :sheet_id %>
+ <% if elm.new_record? %>
+ <%= f.number_field :sheet_id %>
+ <% else %>
+ <%= f.number_field :sheet_id, elm.field_tag_attributes(:sheet_id, no_attr) %>
+ <% end %>
+
+ <%= f.label :panel_id %>
+ <% if elm.new_record? %>
+ <%= f.number_field :panel_id %>
+ <% else %>
+ <%= f.number_field :panel_id, elm.field_tag_attributes(:panel_id, no_attr) %>
+ <% end %>
+ </div>
+ <div class="field">
<%= f.label :x %>
- <%= f.number_field :x, elm.field_tag_attributes(:x, no_attr, :size => 5) %>
+ <% if elm.new_record? %>
+ <%= f.number_field :x %>
+ <% else %>
+ <%= f.number_field :x, elm.field_tag_attributes(:x, no_attr, :size => 5) %>
+ <% end %>
<%= f.label :y %>
- <%= f.number_field :y, elm.field_tag_attributes(:y, no_attr, :size => 5) %>
+ <% if elm.new_record? %>
+ <%= f.number_field :y %>
+ <% else %>
+ <%= f.number_field :y, elm.field_tag_attributes(:y, no_attr, :size => 5) %>
+ <% end %>
</div>
<div class="row_break">
</div>
<div class="field">
<%= f.label :z %>
- <%= f.number_field :z, elm.field_tag_attributes(:z, no_attr, :size => 5) %>
+ <% if elm.new_record? %>
+ <%= f.number_field :z %>
+ <% else %>
+ <%= f.number_field :z, elm.field_tag_attributes(:z, no_attr, :size => 5) %>
+ <% end %>
<%= f.label :t %>
- <%= f.number_field :t, elm.field_tag_attributes(:t, no_attr, :size => 5) %>
+ <% if elm.new_record? %>
+ <%= f.number_field :t %>
+ <% else %>
+ <%= f.number_field :t, elm.field_tag_attributes(:t, no_attr, :size => 5) %>
+ <% end %>
</div>
<div class="row_break">
</div>
- <%= f.hidden_field :panel_id, elm.field_tag_attributes(:panel_id, no_attr) %>
- <%= f.hidden_field :sheet_id, elm.field_tag_attributes(:sheet_id, no_attr) %>
<% unless elm.new_record? %>
<%= f.hidden_field :id, elm.field_tag_attributes(:id, no_attr) %>
<% end %>
</div>
</div>
<%= form_for(@sheet, :html => {:jqform => 'pettanr-sheet-form'}) do |f| %>
- <%= render 'system/error_explanation', :obj => @sheet %>
-
<%= text_field_tag "json", '', :id => 'pettanr-sheet-json' %>
<div>
<%= submit_tag t('sheets.create_from_json'), :id => 'pettanr-sheet-submit' -%>
Dir.glob(dirname + '/*') do |fn|\r
ext = File.extname(fn).downcase\r
bn = File.basename(fn, ".*")\r
- s = bn.split('@')\r
- if s.size > 1\r
- caption = s[1]\r
- bn = s[0]\r
- end\r
case ext\r
when '.png', '.gif', '.jpeg'\r
puts fn\r
if ls\r
puts 'with license:' + ls\r
lsfn = d + '/' + File.basename(ls)\r
- if caption\r
- puts 'caption:' + caption\r
+ attrfn = d + '/attributes.json'\r
+ if File.exist?(attrfn) \r
+ puts 'get attributes.json'\r
+ attr = nil\r
+ File.open(attrfn, 'r') do |f|\r
+ attr = f.read\r
+ end\r
json = JSON.parse(open(ls).read)\r
- if json['attributes'] and json['attributes']['caption']\r
- json['attributes']['caption'] = caption\r
+ if json['attributes'] and attr\r
+ json['attributes'] = attr\r
end\r
File.open(lsfn, 'w') do |f|\r
f.write json.to_json.to_s\r