OSDN Git Service

Merge branch 'v06sheet' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06sheet v06sheet
authoryasushiito <yas@pen-chan.jp>
Mon, 28 Oct 2013 01:43:03 +0000 (10:43 +0900)
committeryasushiito <yas@pen-chan.jp>
Mon, 28 Oct 2013 01:43:03 +0000 (10:43 +0900)
app/models/panel.rb
app/models/sheet.rb
app/models/sheet_panel.rb
app/views/sheet_panels/_append_panel.html.erb
app/views/sheet_panels/_append_sheet.html.erb
app/views/sheet_panels/_form.html.erb
app/views/sheets/_form.html.erb
script/preup.rb

index 0563f22..cc1dc82 100644 (file)
@@ -71,6 +71,7 @@ class Panel < ActiveRecord::Base
       return false unless reader_role_check(roles)
     end
     return true if self.own?(roles)
+    return true if self.new_record?
     self.publish?
   end
   
index 15991b1..69930be 100644 (file)
@@ -61,6 +61,7 @@ class Sheet < ActiveRecord::Base
       return false unless reader_role_check(roles)
     end
     return true if self.own?(roles)
+    return true if self.new_record?
     self.visible > 0
   end
   
@@ -261,6 +262,16 @@ class Sheet < ActiveRecord::Base
     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')
@@ -270,6 +281,9 @@ class Sheet < ActiveRecord::Base
     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
index 8d6ea69..b2e15dd 100644 (file)
@@ -12,8 +12,8 @@ class SheetPanel < ActiveRecord::Base
   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
@@ -366,7 +366,7 @@ class SheetPanel < ActiveRecord::Base
     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
index 64f7a00..2a64ce4 100644 (file)
@@ -10,9 +10,9 @@
     <%= 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 %>
index 7bbc797..4144f5a 100644 (file)
   </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">
index e534ca6..25dbd02 100644 (file)
@@ -2,26 +2,55 @@
   <%= 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 %>
index 4975a23..fd3c9ef 100644 (file)
@@ -96,8 +96,6 @@
   </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' -%>
index bccf649..cc55dcc 100644 (file)
@@ -18,11 +18,6 @@ end
 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
@@ -32,11 +27,16 @@ Dir.glob(dirname + '/*') do |fn|
     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