if confirm('destroy ?')
trace = editor.element_tag_id($(@))
$(trace + '_destroy').val('true')
- sheet_trace = editor.panel_tag_id($(@))
+ sheet_trace = editor.sheet_tag_id($(@))
update_t(sheet_trace + 'tsort')
update_z(sheet_trace + 'zsort')
# sync
$(trace + 'element_tab').css('display', 'none')
- $(trace + 'tab_panel').css('display', 'none')
+ $(trace + 'tab_sheet').css('display', 'none')
$(trace + 'zsort').css('display', 'none')
$(trace + 'tsort').css('display', 'none')
- switch $(@).attr('element_type')
- when 'panel_picture'
- trace = trace + 'div'
$(trace).css('display', 'none')
format.html {
if @author
@new_panels = Panel.mylist(@author, 1, 5)
+ @new_stories = Story.mylist(@author, 1, 5)
+ @fresh_stories = StorySheet.mylist(@author, 1, 5).map {|ss| ss.story}
end
}
format.json { render json: @sheet.to_json(Sheet.show_json_opt) }
r
end
+ def copy
+ attr = self.copy_attributes
+ Sheet.each_element_class_names do |n|
+ attr.merge! Sheet.class_name_to_class(n).panelize(self.elements_by_class_name(n).map {|elm| elm.copy_attributes})
+ end
+ attr
+ end
+
+ def copy_attributes
+ r = self.attributes
+ r.delete 'id'
+ r.delete 'author_id'
+ r.delete 'created_at'
+ r.delete 'updated_at'
+ r
+ end
+
+ def self.panelize sheet
+ attr = sheet.attributes
+ attr.delete 'id'
+ attr
+ end
+
end
belongs_to :panel
belongs_to :sheet
- validates :sheet_id, :presence => true, :numericality => true, :existence => {:both => false}
- validates :panel_id, :presence => true, :numericality => true, :existence => {:both => false}
+ validates :sheet_id, :numericality => {:allow_blank => true}
+ validates :panel_id, :numericality => {:allow_blank => true}
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :x, :presence => true, :numericality => true
validates :y, :presence => true, :numericality => true
if self.panel
self.panel.licensed_pictures
else
- []
+ {}
+ end
+ end
+
+ def self.panelize elements_attributes
+ elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array)
+ hash = {}
+ index = 0
+ elements_attributes.each do |element_attributes|
+ hash[self.to_s.tableize + '_attributes'] ||= {}
+ n = if element_attributes['id']
+ element_attributes['id'].to_s
+ else
+ index += 1
+ 'new' + index.to_s
+ end
+ hash[self.to_s.tableize + '_attributes'][n] = element_attributes
+ end
+ hash
end
- end
-
+
+ def copy_attributes
+ r = self.attributes
+ r.delete 'id'
+ r.delete 'sheet_id'
+ r.delete 'created_at'
+ r.delete 'updated_at'
+ r
+ end
+
def self.new_t sheet_id
r = SheetPanel.max_t(sheet_id)
r.blank? ? 0 : r.to_i + 1
<div <%= raw elm.any_tag_attr() -%> class="sheet_panel" style="top:<%= elm.y %>px; left:<%= elm.x %>px; z-index:<%= elm.z %>;">
- <% panel = Panel.show elm.panel, author -%>
- <% if panel -%>
+ <% if elm.panel -%>
+ <% panel = Panel.show elm.panel, author -%>
<%= render 'panels/body', :panel => panel, :author => author, :spot => nil %>
<% end %>
</div>
<%= panel_icon(:object => elm.panel, :size => 64) %>
</div>
<span class="elements-tab-face-caption">
- <%= h(truncate(elm.panel.caption, :length => 15)) -%>
+ <% if elm.panel -%>
+ <%= h(truncate(elm.panel.caption, :length => 15)) -%>
+ <% else %>
+ <%= t('deleted') -%>
+ <% end %>
</span>
<div class="elements-tab-face-end">
</div>
<%= link_to author_icon(:object => sheet_panel.author, :size => 17), author_path(sheet_panel.author) %>
</td>
<td>
- <% if sheet_panel.own? author %>
- <%= render 'sheet_panels/order', :sheet_panel => sheet_panel %>
- <% else %>
- No.<%= sheet_panel.t %>
- <% end %>
+ No.<%= sheet_panel.t %>
</td>
</tr>
</table>
<%= link_to t('link.edit'), edit_sheet_path(@sheet) %>
<%= link_to t('link.destroy'), sheet_path(@sheet), :method => :delete %>
+ <h2><%= t('sheets.show.copy') -%></h2>
+ <%= form_for(Sheet.new, :html => {:jqform => 'pettanr-sheet-form'}) do |f| %>
+
+ <%= hidden_field_tag "json", @sheet.copy().to_json %>
+ <div>
+ <%= submit_tag t('sheets.show.inspire') -%>
+ </div>
+ <% end %>
+
<h3><%= t('sheet_panels.append.new_panels') -%></h3>
<table>
<% @new_panels.each do |panel| %>
<%= render 'sheet_panels/append_panel', :sheet => @sheet, :panel => panel, :author => @author %>
<% end %>
</table>
+ <h3><%= t('story_sheets.append.new_stories') -%></h3>
+ <table>
+ <% @new_stories.each do |story| %>
+ <%= render 'story_sheets/append_story', :sheet => @sheet, :story => story, :author => @author %>
+ <% end %>
+ </table>
+ <h3><%= t('story_sheets.append.fresh_stories') -%></h3>
+ <table>
+ <% @fresh_stories.each do |story| %>
+ <%= render 'story_sheets/append_story', :sheet => @sheet, :story => story, :author => @author %>
+ <% end %>
+ </table>
<% end %>
<%= distance_of_time_in_words_to_now story.updated_at %>
</td>
<td>
- <%= link_to author_icon(:object => story.author, :size => 25), story_path(story.author) %>
- <%= link_to h(truncate(story.author.name, :length => 12)), author_path(story.author) %>
- </td>
- <td>
<% if story.own? author %>
<% @story_sheet = StorySheet.new :story_id => story.id, :sheet_id => sheet.id %>
<%= form_for(@story_sheet) do |f| %>
new: 新紙
show:
title: 用紙詳細
+ copy: 用紙をコピーしたい
+ inspire: インスパイヤ
play:
title: 用紙を読む
empty: 紙コマはありません
end
context 'sheet_idを検証するとき' do
- it 'nullなら失敗する' do
- @sheet_panel.sheet_id = nil
- @sheet_panel.should_not be_valid
- end
it '数値でなければ失敗する' do
@sheet_panel.sheet_id = 'a'
@sheet_panel.should_not be_valid
end
- it '存在する用紙でなければ失敗する' do
- @sheet_panel.sheet_id = 0
- @sheet_panel.should_not be_valid
- end
end
context 'panel_idを検証するとき' do
- it 'nullなら失敗する' do
- @sheet_panel.panel_id = nil
- @sheet_panel.should_not be_valid
- end
it '数値でなければ失敗する' do
@sheet_panel.panel_id = 'a'
@sheet_panel.should_not be_valid
end
- it '存在するコマでなければ失敗する' do
- @sheet_panel.panel_id = 0
- @sheet_panel.should_not be_valid
- end
end
context 'xを検証するとき' do