type: 'leaf',\r
args: {\r
parent_model_name: 'scroll',\r
+ destination_model_name: 'panel',\r
},\r
},\r
comic: {\r
type: 'leaf',\r
args: {\r
parent_model_name: 'comic',\r
+ destination_model_name: 'story',\r
},\r
},\r
story: {\r
type: 'leaf',\r
args: {\r
parent_model_name: 'story',\r
+ destination_model_name: 'sheet',\r
},\r
},\r
sheet: {\r
license_group: {\r
},\r
license: {\r
- type: 'leaf',\r
+ type: 'system_resource',\r
args: {\r
parent_model_name: 'license_group',\r
boost: {\r
end
end
+ def leaf_created_html_format format, redirect_url
+ format.html {
+ flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
+ redirect_to redirect_url
+ }
+ end
+
+ def leaf_not_created_html_format format, redirect_url
+ format.html {
+ flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
+ redirect_to redirect_url
+ }
+ end
+
+ def leaf_render_create redirect_url
+ if @item.store @operators
+ respond_to do |format|
+ leaf_created_html_format format, redirect_url
+ created_json_format format
+ end
+ else
+ respond_to do |format|
+ leaf_not_created_html_format format, redirect_url
+ not_created_json_format format
+ end
+ end
+ end
+
def updated_html_format format
format.html {
flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
end
end
+ def leaf_updated_html_format format, redirect_url
+ format.html {
+ flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
+ redirect_to redirect_url
+ }
+ end
+
+ def leaf_not_update_html_format format, redirect_url
+ format.html {
+ flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
+ redirect_to redirect_url
+ }
+ end
+
+ def leaf_render_update ot, redirect_url
+ if @item.store @operators, ot
+ respond_to do |format|
+ leaf_updated_html_format format, redirect_url
+ updated_json_format format
+ end
+ else
+ respond_to do |format|
+ leaf_not_updated_html_format format, redirect_url
+ not_updated_json_format format
+ end
+ end
+ end
+
def list_count
set_list
j = {:count => @list.count(@operators, {:id => params[:id]})}
end
def create
- @comic_story = ComicStory.new
- @comic_story.supply_default
- @comic_story.attributes = params[:comic_story]
- @comic_story.overwrite @operators
- @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
- @story = Story.show(@comic_story.story_id, @operators) if @comic_story.story_id
+ @my_model_class = self.class.model
+ @item = @my_model_class.new
+ @item.supply_default
+ @item.attributes = params[@item.item_name]
+ @item.overwrite @operators
+ @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+ @panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
- respond_to do |format|
- if @comic_story.store @operators
- flash[:notice] = I18n.t('flash.notice.created', :model => ComicStory.model_name.human)
- format.html { redirect_to play_comic_path(@comic) }
- format.json { render json: @comic_story.comic_story_as_json(@operators.author) }
- else
- flash[:notice] = I18n.t('flash.notice.not_created', :model => ComicStory.model_name.human)
- format.html { render action: "new" }
- format.json { render json: @comic_story.errors, status: :unprocessable_entity }
- end
- end
+ leaf_render_create play_scroll_path(@binder)
end
def update
- @comic_story = ComicStory.edit(params[:id], @operators)
- ot = @comic_story.t
- @comic_story.attributes = params[:comic_story]
- @comic_story.overwrite @operators
- @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
- respond_to do |format|
- if @comic_story.store @operators, ot
- flash[:notice] = I18n.t('flash.notice.updated', :model => ComicStory.model_name.human)
- format.html { redirect_to play_comic_path(@comic) }
- format.json { head :ok }
- else
- flash[:notice] = I18n.t('flash.notice.not_updated', :model => ComicStory.model_name.human)
- format.html { render action: "edit" }
- format.json { render json: @comic_story.errors, status: :unprocessable_entity }
- end
- end
+ @my_model_class = self.class.model
+ @item = @my_model_class.edit(params[:id], @operators)
+ ot = @item.t
+ @item.attributes = params[@item.item_name]
+ @item.overwrite @operators
+ @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+ # no check permission for destination
+ # swapable hidden panel
+ #@panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
+
+ leaf_render_update ot, play_scroll_path(@binder)
end
-
+
def destroy
@comic_story = ComicStory.edit(params[:id], @operators)
@comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
end
def create
- @scroll_panel = ScrollPanel.new
- @scroll_panel.supply_default
- @scroll_panel.attributes = params[:scroll_panel]
- @scroll_panel.overwrite @operators
- @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
- @panel = Panel.show(@scroll_panel.panel_id, @operators) if @scroll_panel.panel_id
+ @my_model_class = self.class.model
+ @item = @my_model_class.new
+ @item.supply_default
+ @item.attributes = params[@item.item_name]
+ @item.overwrite @operators
+ @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+ @panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
- respond_to do |format|
- if @scroll_panel.store @operators
- flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human)
- format.html { redirect_to play_scroll_path(@scroll) }
- format.json { render json: @scroll_panel.scroll_panel_as_json(@operators.author) }
- else
- flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human)
- format.html { render action: "new" }
- format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
- end
- end
+ leaf_render_create play_scroll_path(@binder)
end
def update
- @scroll_panel = ScrollPanel.edit(params[:id], @operators)
- ot = @scroll_panel.t
- @scroll_panel.attributes = params[:scroll_panel]
- @scroll_panel.overwrite @operators
- @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
- respond_to do |format|
- if @scroll_panel.store @operators, ot
- flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human)
- format.html { redirect_to play_scroll_path(@scroll) }
- format.json { head :ok }
- else
- flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human)
- format.html { render action: "edit" }
- format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
- end
- end
+ @my_model_class = self.class.model
+ @item = @my_model_class.edit(params[:id], @operators)
+ ot = @item.t
+ @item.attributes = params[@item.item_name]
+ @item.overwrite @operators
+ @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+ # no check permission for destination
+ # swapable hidden panel
+ #@panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
+
+ leaf_render_update ot, play_scroll_path(@binder)
end
-
+
def destroy
@scroll_panel = ScrollPanel.edit(params[:id], @operators)
@scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
def create
set_model
- @scroll = @item
@item = @my_model_class.new
@item.supply_default
@item.attributes = params[@my_model_class.item_name]
def update
set_edit
- @scroll = @item
@item.attributes = params[@my_model_class.item_name]
@item.overwrite @operators
render_update
end
def create
- @story_sheet = StorySheet.new
- @story_sheet.supply_default
- @story_sheet.attributes = params[:story_sheet]
- @story_sheet.overwrite @operators
- @story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id
- @sheet = Sheet.show(@story_sheet.sheet_id, @operators) if @story_sheet.sheet_id
+ @my_model_class = self.class.model
+ @item = @my_model_class.new
+ @item.supply_default
+ @item.attributes = params[@item.item_name]
+ @item.overwrite @operators
+ @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+ @panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
- respond_to do |format|
- if @story_sheet.store @operators
- flash[:notice] = I18n.t('flash.notice.created', :model => StorySheet.model_name.human)
- format.html { redirect_to play_story_path(@story) }
- format.json { render json: @story_sheet.to_json(StorySheet.show_json_opt) }
- else
- flash[:notice] = I18n.t('flash.notice.not_created', :model => StorySheet.model_name.human)
- format.html { render action: "new" }
- format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
- end
- end
+ leaf_render_create play_scroll_path(@binder)
end
def update
- @story_sheet = StorySheet.edit(params[:id], @operators)
- ot = @story_sheet.t
- @story_sheet.attributes = params[:story_sheet]
- @story_sheet.overwrite @operators
- @story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id
- respond_to do |format|
- if @story_sheet.store @operators, ot
- flash[:notice] = I18n.t('flash.notice.updated', :model => StorySheet.model_name.human)
- format.html { redirect_to play_story_path(@story) }
- format.json { head :ok }
- else
- flash[:notice] = I18n.t('flash.notice.not_updated', :model => StorySheet.model_name.human)
- format.html { render action: "edit" }
- format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
- end
- end
+ @my_model_class = self.class.model
+ @item = @my_model_class.edit(params[:id], @operators)
+ ot = @item.t
+ @item.attributes = params[@item.item_name]
+ @item.overwrite @operators
+ @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+ # no check permission for destination
+ # swapable hidden panel
+ #@panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
+
+ leaf_render_update ot, play_scroll_path(@binder)
end
-
+
def destroy
@story_sheet = StorySheet.edit(params[:id], @operators)
@story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id
'scrolls.visible > 0'
end
- def self.list_opt
- {
- :author => {},
- :scroll => {
- :author => {}
- },
- :panel => {
- :author => {},
- :panel_pictures => {:picture => {:artist => {}, :license => {}}},
- :speech_balloons =>{:balloon => {}, :speech => {}}
- }
- }
- end
-
- def self.list_json_opt
- {:include => {
- :author => {},
- :scroll => {
- :author => {}
- },
- :panel => {
- :author => {},
- :panel_pictures => {:picture => {:artist => {}, :license => {}}},
- :speech_balloons =>{:balloon => {}, :speech => {}}
- }
- }}
- end
-
def self.show_opt
{:include => {
:author => {},
self.scroll.own?(operators) and self.panel.usable?(operators)
end
- def store operators, old_t = nil
- res = false
- self.class.transaction do
- case self.allow? operators
- when true
- self.rotate old_t
- when false
- raise ActiveRecord::Forbidden
- else
- end
- res = self.save
- raise ActiveRecord::Rollback unless res
- res = self.class.validate_t(self.scroll_id)
- unless res
- self.errors.add :t, 'unserialized'
- raise ActiveRecord::Rollback
- end
- end
- res
- end
-
end
module Manifest
module ItemModule
class LeafPeta < BasePeta
- attr :parent_model_name
+ attr :parent_model_name, :destination_model_name
def set_default
super
def init
super
@parent_model_name = @args['parent_model_name']
+ @destination_model_name = @args['destination_model_name']
end
end
define_singleton_method("parent_model") do
pm
end
+ destm = Manifest.manifest.models[self.my_peta.destination_model_name].classify
+ define_singleton_method("destination_model") do
+ destm
+ end
pfk = self.my_peta.parent_model_name + '_id'
define_singleton_method("binder_key") do
pfk
end
+ dest_key = if self.my_peta.destination_model_name
+ self.my_peta.destination_model_name + '_id'
+ else
+ nil
+ end
+ define_singleton_method("destination_key") do
+ dest_key
+ end
# Instance Methods
end
self.parent_model
end
+ def self.binder_model
+ self.parent_model
+ end
+
+ def self.destination_model
+ self.parent_model
+ end
+
def root
self.__send__ self.class.root_model.item_name
end
self.root.visible? operators
end
- def self.play_list_where cid
- ['scroll_panels.scroll_id = ?', cid]
- end
-
def self.play_list_order
self.table_name + '.t'
end
- def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
- ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
- end
-
- def self.play_sheet_where sid
- ['story_sheets.story_id = ?', sid]
- end
-
- def self.play_sheet story, operators, page = 1
- ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
- if ss
- if ss.sheet
- Sheet.show(ss.sheet.id, operators)
- else
- nil
- end
- else
- nil
- end
- end
-
- def self.play_paginate story, page
- Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
- end
-
def self.new_t binder_id
r = self.max_t(binder_id)
r.blank? ? 0 : r.to_i + 1
r.map {|sp| sp.t}
end
- def self.top_sheet story, author
- StorySheet.play_list(story, author).first
- end
-
def self.serial? ary
i = 0
ary.compact.sort.each do |t|
self.class.binder_key
end
+ def destination_key
+ self.class.destination_key
+ end
+
def binder_id
self.attributes[self.binder_key]
end
+ def destination_id
+ if self.destination_key
+ self.attributes[self.destination_key]
+ else
+ nil
+ end
+ end
+
def insert_shift
self.class.update_all('t = t + 1',
[self.binder_key + ' = ? and t >= ?', self.binder_id, self.t]
end
end
+ def store operators, old_t = nil
+ res = false
+ self.class.transaction do
+ case self.allow? operators
+ when true
+ self.rotate old_t
+ when false
+ raise ActiveRecord::Forbidden
+ else
+ end
+ res = self.save
+ raise ActiveRecord::Rollback unless res
+ res = self.class.validate_t(self.binder_id)
+ unless res
+ self.errors.add :t, 'unserialized'
+ raise ActiveRecord::Rollback
+ end
+ end
+ res
+ end
+
def destroy_and_shorten
res = false
self.class.transaction do
"scroll_panel": {\r
"type": "leaf",\r
"args": {\r
- "parent_model_name": "scroll"\r
+ "parent_model_name": "scroll",\r
+ "destination_model_name": "panel"\r
}\r
},\r
"comic": {\r
"comic_story": {\r
"type": "leaf",\r
"args": {\r
- "parent_model_name": "comic"\r
+ "parent_model_name": "comic",\r
+ "destination_model_name": "story"\r
}\r
},\r
"story": {\r
"story_sheet": {\r
"type": "leaf",\r
"args": {\r
- "parent_model_name": "story"\r
+ "parent_model_name": "story",\r
+ "destination_model_name": "sheet"\r
}\r
},\r
"sheet": {\r