From cb811687cd15adff98b30f841617e35b8e3ccb85 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Thu, 12 Jun 2014 11:34:31 +0900 Subject: [PATCH] fix editor --- app/controllers/ground_colors_controller.rb | 92 +---------------- app/controllers/ground_pictures_controller.rb | 103 +------------------ app/controllers/panel_pictures_controller.rb | 112 ++------------------- app/controllers/speech_balloons_controller.rb | 93 +---------------- app/models/panel.rb | 4 +- app/views/speech_balloons/_scenario.html.erb | 19 ++++ .../templates/r/panel_editor/panel_editor.html.erb | 2 +- lib/editor/panel_dock/bay/element.rb | 2 +- lib/editor/panel_dock/bay/priority.rb | 2 +- lib/editor/panel_dock/bay/scenario.rb | 2 +- lib/editor/panel_dock/board/element.rb | 2 +- lib/editor/pool.rb | 14 +-- lib/peta/root.rb | 15 --- 13 files changed, 53 insertions(+), 409 deletions(-) create mode 100644 app/views/speech_balloons/_scenario.html.erb diff --git a/app/controllers/ground_colors_controller.rb b/app/controllers/ground_colors_controller.rb index 32e3d644..168bda30 100644 --- a/app/controllers/ground_colors_controller.rb +++ b/app/controllers/ground_colors_controller.rb @@ -1,13 +1,13 @@ class GroundColorsController < ApplicationController if Manifest.manifest.magic_numbers['run_mode'] == 0 - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] else before_filter :authenticate_reader, :only => [ :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author ] - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] end def self.model @@ -53,88 +53,4 @@ class GroundColorsController < ApplicationController list_count end - def new - raise Pettanr::NotWork unless @operators.author.working_panel - @panel = Panel.edit(@operators.author.working_panel, @operators) - @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i - @ground_color.supply_default - - respond_to do |format| - format.html - format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) } - end - end - - def edit - @ground_color = GroundColor.show(params[:id], @operators) - @panel = Panel.edit(@ground_color.panel.id, @operators) - - respond_to do |format| - format.html - end - end - - def create - raise Pettanr::NotWork unless @operators.author.working_panel - @panel = Panel.edit(@operators.author.working_panel, @operators) - - @ground_color = GroundColor.new - @ground_color.attributes = params[:ground_color] - @ground_color.overwrite @panel.id - - respond_to do |format| - if @ground_color.valid? - if @ground_color.store @operators - flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human) - format.html { redirect_to @panel } - format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel } - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human) - format.html { render action: "new" } - format.json { render json: @ground_color.errors, status: :unprocessable_entity } - end - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human) - format.html { render action: "new" } - format.json { render json: @ground_color.errors, status: :unprocessable_entity } - end - end - end - - def update - @ground_color = GroundColor.show(params[:id], @operators) - @ground_color.attributes = params[:ground_color] - @panel = Panel.edit(@ground_color.panel.id, @operators) - @ground_color.overwrite @panel.id - - respond_to do |format| - if @ground_color.store @operators - flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human) - format.html { redirect_to @ground_color } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundColor.model_name.human) - format.html { render action: "edit" } - format.json { render json: @ground_color.errors, status: :unprocessable_entity } - end - end - end - - def destroy - @ground_color = GroundColor.show(params[:id], @operators) - @panel = Panel.edit(@ground_color.panel.id, @operators) - - respond_to do |format| - if @ground_color.remove @operators - flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human) - format.html { redirect_to @panel } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human) - format.html { redirect_to @ground_color } - format.json { render json: @ground_color.errors, status: :unprocessable_entity } - end - end - end - end diff --git a/app/controllers/ground_pictures_controller.rb b/app/controllers/ground_pictures_controller.rb index a4616e68..7d5fb1c9 100644 --- a/app/controllers/ground_pictures_controller.rb +++ b/app/controllers/ground_pictures_controller.rb @@ -1,15 +1,15 @@ class GroundPicturesController < ApplicationController if Manifest.manifest.magic_numbers['run_mode'] == 0 - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] else before_filter :authenticate_reader, :only => [ :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author ] - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] end - + def self.model GroundPicture end @@ -53,97 +53,4 @@ class GroundPicturesController < ApplicationController list_count end - def new - raise Pettanr::NotWork unless @operators.author.working_panel - @picture = Picture.show params[:picture_id], @operators - raise ActiveRecord::Forbidden unless @picture.enable? - @panel = Panel.edit(@operators.author.working_panel, @operators) - - @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id - @ground_picture.supply_default - - respond_to do |format| - format.html - format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) } - end - end - - def edit - @ground_picture = GroundPicture.show(params[:id], @operators) - @panel = Panel.edit(@ground_picture.panel.id, @operators) - - respond_to do |format| - format.html - end - end - - def create - raise Pettanr::NotWork unless @operators.author.working_panel - @panel = Panel.edit(@operators.author.working_panel, @operators) - - @ground_picture = GroundPicture.new - @ground_picture.attributes = params[:ground_picture] - @ground_picture.overwrite @panel.id - - @picture = Picture.show @ground_picture.picture_id, @operators - raise ActiveRecord::Forbidden unless @picture.enable? - - respond_to do |format| - if @ground_picture.valid? - if @ground_picture.store @operators - flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human) - format.html { redirect_to @panel } - format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel } - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human) - format.html { render action: "new" } - format.json { render json: @panel.errors, status: :unprocessable_entity } - end - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human) - format.html { render action: "new" } - format.json { render json: @ground_picture.errors, status: :unprocessable_entity } - end - end - end - - def update - @ground_picture = GroundPicture.show(params[:id], @operators) - @ground_picture.attributes = params[:ground_picture] - @panel = Panel.edit(@ground_picture.panel.id, @operators) - @ground_picture.overwrite @panel.id - - @picture = Picture.show @ground_picture.picture_id, @operators - raise ActiveRecord::Forbidden unless @picture.enable? - - respond_to do |format| - if @ground_picture.store @operators - flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human) - format.html { redirect_to @ground_picture } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human) - format.html { render action: "edit" } - format.json { render json: @ground_picture.errors, status: :unprocessable_entity } - end - end - end - - def destroy - @ground_picture = GroundPicture.show(params[:id], @operators) - @panel = Panel.edit(@ground_picture.panel.id, @operators) - - respond_to do |format| - if @ground_picture.remove @operators - flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human) - format.html { redirect_to @panel } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human) - format.html { redirect_to @ground_picture } - format.json { render json: @ground_picture.errors, status: :unprocessable_entity } - end - end - end - end diff --git a/app/controllers/panel_pictures_controller.rb b/app/controllers/panel_pictures_controller.rb index 728215c0..09d1f549 100644 --- a/app/controllers/panel_pictures_controller.rb +++ b/app/controllers/panel_pictures_controller.rb @@ -1,15 +1,15 @@ class PanelPicturesController < ApplicationController if Manifest.manifest.magic_numbers['run_mode'] == 0 - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] else before_filter :authenticate_reader, :only => [ :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author ] - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] end - + def self.model PanelPicture end @@ -40,7 +40,7 @@ class PanelPicturesController < ApplicationController show_json_format format end end - + def count list_count end @@ -53,104 +53,4 @@ class PanelPicturesController < ApplicationController list_count end - def new - raise Pettanr::NotWork unless @operators.author.working_panel - @picture = Picture.show params[:picture_id], @operators - raise ActiveRecord::Forbidden unless @picture.enable? - @panel = Panel.edit(@operators.author.working_panel, @operators) - - @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id - @item.supply_default - respond_to do |format| - format.html { - mounted = 1 - form_manager = Pettanr::Application::manifest.form_managers[@item.form_name] - @form = form_manager.open @item, @operators, mounted - } - format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) } - end - end - - def edit - @item = PanelPicture.show(params[:id], @operators) - @panel = Panel.edit(@item.panel.id, @operators) - - respond_to do |format| - format.html { - mounted = 1 - form_manager = Pettanr::Application::manifest.form_managers[@item.form_name] - @form = form_manager.open @item, @operators, mounted - } - end - end - - def create - raise Pettanr::NotWork unless @operators.author.working_panel - @panel = Panel.edit(@operators.author.working_panel, @operators) - - @panel_picture = PanelPicture.new - @panel_picture.attributes = params[:panel_picture] - @panel_picture.overwrite @panel.id - - @picture = Picture.show @panel_picture.picture_id, @operators - raise ActiveRecord::Forbidden unless @picture.enable? - - respond_to do |format| - if @panel_picture.valid? - if @panel_picture.store @operators - flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human) - format.html { redirect_to @panel } - format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel } - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human) - format.html { render action: "new" } - format.json { render json: @panel.errors, status: :unprocessable_entity } - end - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human) - format.html { render action: "new" } - format.json { render json: @panel_picture.errors, status: :unprocessable_entity } - end - end - end - - def update - @panel_picture = PanelPicture.show(params[:id], @operators) - @panel_picture.attributes = params[:panel_picture] - @panel = Panel.edit(@panel_picture.panel.id, @operators) - @panel_picture.overwrite @panel.id - - @picture = Picture.show @panel_picture.picture_id, @operators - raise ActiveRecord::Forbidden unless @picture.enable? - - respond_to do |format| - if @panel_picture.store @operators - flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human) - format.html { redirect_to @panel_picture } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human) - format.html { render action: "edit" } - format.json { render json: @panel_picture.errors, status: :unprocessable_entity } - end - end - end - - def destroy - @panel_picture = PanelPicture.show(params[:id], @operators) - @panel = Panel.edit(@panel_picture.panel.id, @operators) - - respond_to do |format| - if @panel_picture.remove @operators - flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human) - format.html { redirect_to @panel } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human) - format.html { redirect_to @panel_picture } - format.json { render json: @panel_picture.errors, status: :unprocessable_entity } - end - end - end - end diff --git a/app/controllers/speech_balloons_controller.rb b/app/controllers/speech_balloons_controller.rb index aeeb9ce0..688d8cd5 100644 --- a/app/controllers/speech_balloons_controller.rb +++ b/app/controllers/speech_balloons_controller.rb @@ -1,15 +1,15 @@ class SpeechBalloonsController < ApplicationController if Manifest.manifest.magic_numbers['run_mode'] == 0 - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] else before_filter :authenticate_reader, :only => [ :index, :show, :by_panel, :by_author, :by_speech_balloon_template, :count, :count_by_panel, :count_by_author, :count_by_speech_balloon_template ] - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] end - + def self.model SpeechBalloon end @@ -62,87 +62,4 @@ class SpeechBalloonsController < ApplicationController list_count end - def new - form_new - end - - def edit - form_edit - end - - def create - raise Pettanr::NotWork unless @operators.author.working_panel - SpeechBalloon.fold_extend_settings params - @panel = Panel.edit(@operators.author.working_panel, @operators) - @speech_balloon = SpeechBalloon.new - @speech_balloon.attributes = params[:speech_balloon] - - @speech_balloon_template = @speech_balloon.speech_balloon_template - @speech_balloon.boost - - params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture - - @speech_balloon.overwrite @panel.id - - respond_to do |format| - if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon]) - flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human) - format.html { redirect_to @panel } - format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel } - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human) - format.html { - render @speech_balloon_template.engine_name + '/speech_balloons/new' - } - format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } - end - end - end - - def update - @item = SpeechBalloon.show(params[:id], @operators) - @speech_balloon = @item - @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators - @form.fold_extend_settings params - @speech_balloon.attributes = params[:speech_balloon] - - @speech_balloon_template = @speech_balloon.speech_balloon_template - - params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.balloon.select_system_picture - - @panel = Panel.edit(@speech_balloon.panel.id, @operators) - @speech_balloon.overwrite @panel.id - - respond_to do |format| - if @speech_balloon.save - flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human) - format.html { redirect_to @speech_balloon } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human) - format.html { - render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit' - } - format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } - end - end - end - - def destroy - @speech_balloon = SpeechBalloon.show(params[:id], @operators) - @panel = Panel.edit(@speech_balloon.panel.id, @operators) - - respond_to do |format| - if @speech_balloon.remove @operators.author - flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human) - format.html { redirect_to @panel } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human) - format.html { redirect_to @speech_balloon } - format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } - end - end - end - end diff --git a/app/models/panel.rb b/app/models/panel.rb index e2a17b48..ad20b014 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -79,13 +79,13 @@ class Panel < Peta::Root end def scenario - panel_elements.map { |e| + scenario_elements.map { |e| e.scenario }.join end def plain_scenario - panel_elements.map { |e| + scenario_elements.map { |e| e.plain_scenario }.join end diff --git a/app/views/speech_balloons/_scenario.html.erb b/app/views/speech_balloons/_scenario.html.erb new file mode 100644 index 00000000..98333804 --- /dev/null +++ b/app/views/speech_balloons/_scenario.html.erb @@ -0,0 +1,19 @@ +<% if element.speech.quotes.blank? -%> +<% else -%> + +<% end -%> +<%= content_tag :div, '', element.balloon.tag_attributes('scenario', :class => "circle_speech_balloon-balloon-scenario") do %> + <%= h(element.caption) %> +<% end %> +<%= content_tag :div, '', element.speech.tag_attributes('scenario', :class => "circle_speech_balloon-speech-scenario") do %> + <%= h(element.speech.content) %> +<% end %> diff --git a/app/views/templates/r/panel_editor/panel_editor.html.erb b/app/views/templates/r/panel_editor/panel_editor.html.erb index a5070d22..e2bf1b45 100644 --- a/app/views/templates/r/panel_editor/panel_editor.html.erb +++ b/app/views/templates/r/panel_editor/panel_editor.html.erb @@ -4,7 +4,7 @@ <%= render editor.generator.template_name, :generator => editor.generator %>
<% WritingFormat.enable_list().each do |wf| %> -
+
<% end %>
diff --git a/lib/editor/panel_dock/bay/element.rb b/lib/editor/panel_dock/bay/element.rb index 2ae8eb49..f6937bda 100644 --- a/lib/editor/panel_dock/bay/element.rb +++ b/lib/editor/panel_dock/bay/element.rb @@ -13,7 +13,7 @@ module Editor end def elements - self.root_item.panel_elements + self.root_item.scenario_elements end end diff --git a/lib/editor/panel_dock/bay/priority.rb b/lib/editor/panel_dock/bay/priority.rb index 5218b7f3..95a997df 100644 --- a/lib/editor/panel_dock/bay/priority.rb +++ b/lib/editor/panel_dock/bay/priority.rb @@ -13,7 +13,7 @@ module Editor end def elements - self.root_item.panel_elements + self.root_item.scenario_elements end def class_name diff --git a/lib/editor/panel_dock/bay/scenario.rb b/lib/editor/panel_dock/bay/scenario.rb index 7ebb42d0..b3470772 100644 --- a/lib/editor/panel_dock/bay/scenario.rb +++ b/lib/editor/panel_dock/bay/scenario.rb @@ -13,7 +13,7 @@ module Editor end def elements - self.root_item.panel_elements + self.root_item.scenario_elements end def class_name diff --git a/lib/editor/panel_dock/board/element.rb b/lib/editor/panel_dock/board/element.rb index a525ad0b..36ae41a7 100644 --- a/lib/editor/panel_dock/board/element.rb +++ b/lib/editor/panel_dock/board/element.rb @@ -36,7 +36,7 @@ module Editor def initialize parent super - @form = Locmare::Form.new self.element.item_name, self.element, self.mounted, false, @operators + @form = Locmare::Bucket.new self.element.item_name, self.element, self.mounted, false, @operators @bucket = FormBucket.new self, @form end diff --git a/lib/editor/pool.rb b/lib/editor/pool.rb index f59608ca..8c60797f 100644 --- a/lib/editor/pool.rb +++ b/lib/editor/pool.rb @@ -14,17 +14,17 @@ module Editor def editize @root_item.boosts 'post' self.register nil, @root_item - # editize_element @root_item # test + editize_element @root_item end def editize_element parent - parent.class.child_element_names(@root_item.class.element_tree_name).each do |element_name| + parent.class.child_element_names.each do |element_name| e = parent.__send__ element_name - e = [e] unless e.respond_to? :each - e.each do |element| - element.boost - self.register parent, element - self.editize_element element + e = [e] unless e.respond_to?(:each) + e.each do |element_item| + element_item.boosts 'post' + self.register parent, element_item + self.editize_element element_item end end end diff --git a/lib/peta/root.rb b/lib/peta/root.rb index 9ff74f32..d2fd1009 100644 --- a/lib/peta/root.rb +++ b/lib/peta/root.rb @@ -64,21 +64,6 @@ module Peta res end - def elements - self.scenario_elements.map {|e| - #(-_-;)<... kore wa hidoi - JSON.parse e.to_json({:include => e.class.json_opt_for_panel}) - } - end - - def scenario_elements_as_json - self.to_json({:include => {:author => {}}, :methods => :elements}) - end - - def self.list_as_json_text ary - '[' + ary.map {|i| i.panel_elements_as_json }.join(',') + ']' - end - def new_t self.scenario_elements.size end -- 2.11.0