OSDN Git Service

add editor
authoryasushiito <yas@pen-chan.jp>
Thu, 23 Jan 2014 09:46:11 +0000 (18:46 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 23 Jan 2014 09:46:11 +0000 (18:46 +0900)
37 files changed:
app/controllers/panels_controller.rb
app/models/panel.rb
app/views/panels/_form.html.erb
app/views/templates/r/editor/_board_bay.html.erb [deleted file]
app/views/templates/r/editor/_dock.html.erb
app/views/templates/r/editor/_dock_label.html.erb [deleted file]
app/views/templates/r/editor/_simple_bay.html.erb [deleted file]
app/views/templates/r/editor/dock/_bay_bodys.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/_bay_label.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/_bay_labels.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/_dock_bodys.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/_dock_label.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/_dock_labels.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/_element_form.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/bay/_board_bay.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/bay/_element_form.html.erb [new file with mode: 0644]
app/views/templates/r/editor/dock/bay/_simple_bay.html.erb [new file with mode: 0644]
config/environment.rb
lib/editor.rb
lib/editor/dock.rb [new file with mode: 0644]
lib/editor/dock/base.rb [new file with mode: 0644]
lib/editor/dock/bay.rb [new file with mode: 0644]
lib/editor/dock/bay/board/element.rb [new file with mode: 0644]
lib/editor/dock/bay/board/new.rb [new file with mode: 0644]
lib/editor/dock/bay/board/torder.rb [new file with mode: 0644]
lib/editor/dock/bay/board/zorder.rb [new file with mode: 0644]
lib/editor/dock/bay/element.rb [new file with mode: 0644]
lib/editor/dock/bay/new.rb [new file with mode: 0644]
lib/editor/dock/bay/root.rb [new file with mode: 0644]
lib/editor/dock/bay/torder.rb [new file with mode: 0644]
lib/editor/dock/bay/zorder.rb [new file with mode: 0644]
lib/editor/dock/board.rb [new file with mode: 0644]
lib/editor/dock/bucket.rb [new file with mode: 0644]
lib/editor/editor.rb
lib/editor/elements.rb [deleted file]
lib/editor/tsort.rb [deleted file]
lib/editor/zsort.rb [deleted file]

index c781dce..a632462 100644 (file)
@@ -111,6 +111,10 @@ class PanelsController < ApplicationController
     @panel = Panel.edit(params[:id], @operators)
     respond_to do |format|
       format.html {
+        @editor = Editor::Editor.new @panel, @operators
+        render :template => 'templates/r/editor/editor', :locals => {
+          :editor => @editor
+        }
       }
       format.js
     end
index 4d1b986..723bdb2 100644 (file)
@@ -92,7 +92,7 @@ class Panel < Pettanr::Content
     ]
   end
   
-  def field_tag_attributes column, opt = {}
+  def field_tag_attributes column, no_attr, opt = {}
     self.tag_attributes(column).merge(
       {:column => column}
     ).merge(opt)
index 38417cd..4276a97 100644 (file)
 
       <div class="field">
         <%= f.label :caption %>
-        <%= f.text_field :caption, @panel.field_tag_attributes(:caption, 'data-model' => 'panel') -%>
+        <%= f.text_field :caption, @panel.field_tag_attributes(:caption, 0, 'data-model' => 'panel') -%>
       </div>
       <div class="row_break">
       </div>
       <div class="field">
         <%= f.label :width %>
-        <%= f.number_field :width, @panel.field_tag_attributes(:width, :size => 5, 'data-model' => 'panel') %>
+        <%= f.number_field :width, @panel.field_tag_attributes(:width, 0, :size => 5, 'data-model' => 'panel') %>
       </div>
       <div class="field">
         <%= f.label :height %>
-        <%= f.number_field :height, @panel.field_tag_attributes(:height, :size => 5, 'data-model' => 'panel') %>
+        <%= f.number_field :height, @panel.field_tag_attributes(:height, 0, :size => 5, 'data-model' => 'panel') %>
       </div>
       <div class="row_break">
       </div>
       <div class="field">
         <%= f.label :border %>
-        <%= f.number_field :border, @panel.field_tag_attributes(:border, :size => 5, 'data-model' => 'panel') %>
+        <%= f.number_field :border, @panel.field_tag_attributes(:border, 0, :size => 5, 'data-model' => 'panel') %>
       </div>
       <div class="field">
         <%= f.label :publish %>
@@ -53,7 +53,7 @@
       <div class="row_break">
       </div>
       <% unless @panel.new_record?  %>
-        <%= f.hidden_field :id, @panel.field_tag_attributes(:id, 'data-model' => 'panel') %>
+        <%= f.hidden_field :id, @panel.field_tag_attributes(:id, 0, 'data-model' => 'panel') %>
       <% end %>
       <div class="actions">
         <%= f.submit 'panels.submit', :class => "submit" %>
diff --git a/app/views/templates/r/editor/_board_bay.html.erb b/app/views/templates/r/editor/_board_bay.html.erb
deleted file mode 100644 (file)
index 5d4a1dc..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<div id="tabs-3">
-  <div class="tsort-box">
-    <ul class="board-labels tsort tsort-tabs-nav" <%= raw @panel.tag_attr(:tsort) -%>>
-      <% bay.boards.each do |board| %>
-        <%= board.label render elm.path_name + '/element_face', :elm => elm %>
-        <li <%= raw elm.tag_attr(:tsort) -%>>
-          <div class="elements-tab">
-          </div>
-        </li>
-      <% end %>
-    </ul>
-  </div>
-  <div class="scenario" <%= raw @panel.tag_attr(:scenario) -%>>
-    <% @panel.panel_elements.each do |elm| %>
-      <div <%= raw elm.tag_attr() -%>>
-        <%= render elm.scenario_template, :elm => elm, :no_attr => 0 %>
-      </div>
-    <% end %>
-  </div>
-  <div class="tsort-row-break">
-  </div>
-</div>
index 6c1216d..aded099 100644 (file)
@@ -1,10 +1,6 @@
 
-<div id="tabs" class="panel-editor" panel_id="<%= @panel.tag_panel_id -%>" current="1">
+<div id="<%= dock.dom_id -%>" class="<%= dock.dom_class -%>" panel_id="<%= dock.root_item.tag_panel_id -%>" current="1">
 
-  <% dock.bodies.each do |body| %>
-    <%= render 'templates/r/editor/dock_label', :label => body.label %>
-  <% end %>
-  <% dock.bodies.each do |body| %>
-    <%= render body.bay.template_name, :bay => body.bay %>
-  <% end %>
+  <%= render dock.labels_template_name, :dock => dock %>
+  <%= render dock.bodys_template_name, :dock => dock %>
 </div>
diff --git a/app/views/templates/r/editor/_dock_label.html.erb b/app/views/templates/r/editor/_dock_label.html.erb
deleted file mode 100644 (file)
index 8e6bb2b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<li id="<%= label.label_id %>">
-  <a href="#<%= label.bay_id %>">
-    <%= label.caption %>
-  </a>
-</li>
diff --git a/app/views/templates/r/editor/_simple_bay.html.erb b/app/views/templates/r/editor/_simple_bay.html.erb
deleted file mode 100644 (file)
index 2766af8..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<div id="<%= bay.bay_id %>">
-  <%# render bucket_template_name, :bucket => bay.bucket %>
-</div>
diff --git a/app/views/templates/r/editor/dock/_bay_bodys.html.erb b/app/views/templates/r/editor/dock/_bay_bodys.html.erb
new file mode 100644 (file)
index 0000000..b4d9481
--- /dev/null
@@ -0,0 +1,5 @@
+  <div class="<%= bay.dom_bodys_class -%>" <%= raw @panel.tag_attr(:scenario) -%>>
+    <% bay.tabs.each do |board| %>
+      <%= render board.body.bucket.template_name, :form => board.body.bucket %>
+    <% end %>
+  </div>
diff --git a/app/views/templates/r/editor/dock/_bay_label.html.erb b/app/views/templates/r/editor/dock/_bay_label.html.erb
new file mode 100644 (file)
index 0000000..33d35fe
--- /dev/null
@@ -0,0 +1,5 @@
+<li <%= raw label.element.tag_attr(:tsort) -%>>
+  <div class="elements-tab">
+    <%= render label.face_template_name, :elm => label.element %>
+  </div>
+</li>
diff --git a/app/views/templates/r/editor/dock/_bay_labels.html.erb b/app/views/templates/r/editor/dock/_bay_labels.html.erb
new file mode 100644 (file)
index 0000000..e303ec9
--- /dev/null
@@ -0,0 +1,7 @@
+<div class="<%= bay.dom_labels_class %>">
+  <ul class="board-labels tsort tsort-tabs-nav" <%= raw @panel.tag_attr(:tsort) -%>>
+    <% bay.tabs.each do |board| %>
+      <%= render board.label.template_name, :label => board.label %>
+    <% end %>
+  </ul>
+</div>
diff --git a/app/views/templates/r/editor/dock/_dock_bodys.html.erb b/app/views/templates/r/editor/dock/_dock_bodys.html.erb
new file mode 100644 (file)
index 0000000..b2b9886
--- /dev/null
@@ -0,0 +1,3 @@
+<% dock.tabs.each do |tab| %>
+  <%= render tab.body.template_name, :bay => tab %>
+<% end %>
diff --git a/app/views/templates/r/editor/dock/_dock_label.html.erb b/app/views/templates/r/editor/dock/_dock_label.html.erb
new file mode 100644 (file)
index 0000000..b304c75
--- /dev/null
@@ -0,0 +1,5 @@
+<li id="<%= label.dom_id %>" class="<%= label.dom_class %>">
+  <a href="#<%= label.body.dom_id %>">
+    <%= label.caption %>
+  </a>
+</li>
diff --git a/app/views/templates/r/editor/dock/_dock_labels.html.erb b/app/views/templates/r/editor/dock/_dock_labels.html.erb
new file mode 100644 (file)
index 0000000..bf2b647
--- /dev/null
@@ -0,0 +1,5 @@
+<ul class="<%= dock.dom_labels_class -%>">
+  <% dock.tabs.each do |tab| %>
+    <%= render tab.label.template_name, :label => tab.label %>
+  <% end %>
+</ul>
diff --git a/app/views/templates/r/editor/dock/_element_form.html.erb b/app/views/templates/r/editor/dock/_element_form.html.erb
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/app/views/templates/r/editor/dock/bay/_board_bay.html.erb b/app/views/templates/r/editor/dock/bay/_board_bay.html.erb
new file mode 100644 (file)
index 0000000..3c80cb6
--- /dev/null
@@ -0,0 +1,6 @@
+<div id="<%= bay.body.dom_id -%>" class="<%= bay.body.dom_class -%>">
+  <%= render bay.labels_template_name, :bay => bay %>
+  <%= render bay.bodys_template_name, :bay => bay %>
+  <div class="tsort-row-break">
+  </div>
+</div>
diff --git a/app/views/templates/r/editor/dock/bay/_element_form.html.erb b/app/views/templates/r/editor/dock/bay/_element_form.html.erb
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/app/views/templates/r/editor/dock/bay/_simple_bay.html.erb b/app/views/templates/r/editor/dock/bay/_simple_bay.html.erb
new file mode 100644 (file)
index 0000000..d33c7f6
--- /dev/null
@@ -0,0 +1,3 @@
+<div id="<%= bay.body.dom_id -%>" class="<%= bay.body.dom_class -%>">
+  <%= render bay.body.bucket.template_name, :form => bay.body.bucket %>
+</div>
index 38a2094..7d9799f 100644 (file)
@@ -15,7 +15,7 @@ require 'owner'
 require 'content'
 require 'element'
 require 'element_part'
-require 'editor/editor'
+require_dependency 'editor/editor'
 # Initialize the rails application
 Pettanr::Application.initialize!
 Pettanr::Application.manifest.init
index a556fc2..264cc5a 100644 (file)
@@ -1,6 +1,3 @@
 module Editor
-  require "editor/editor"
-  require "editor/elements"
-  require "editor/tsort"
-  require "editor/zsort"
+  require_dependency "editor/editor"
 end
diff --git a/lib/editor/dock.rb b/lib/editor/dock.rb
new file mode 100644 (file)
index 0000000..487877d
--- /dev/null
@@ -0,0 +1,83 @@
+require_dependency "editor/dock/base"
+require_dependency "editor/dock/bay"
+require_dependency "editor/dock/board"
+require_dependency "editor/dock/bucket"
+require_dependency "editor/dock/bay/root"
+require_dependency "editor/dock/bay/element"
+require_dependency "editor/dock/bay/torder"
+require_dependency "editor/dock/bay/zorder"
+require_dependency "editor/dock/bay/new"
+module Editor
+
+  module DockModule
+    include TabModule
+    class Dock < Base
+      include BayModule
+      include BoardModule
+      include RootBayModule
+      include ElementBayModule
+      include TorderBayModule
+      include ZorderBayModule
+      include NewBayModule
+      attr_accessor :tabs
+      def initialize parent
+        super
+        tab = RootBay.new(self, 0, 'panel')
+        add_tab tab, RootBayLabel.new(tab, 'panel'), 
+          RootBayBody.new(tab)
+        
+        tab = ElementBay.new(self, 1, 'elements')
+        add_tab tab, ElementBayLabel.new(tab, 'elements'), 
+          ElementBayBody.new(tab)
+        
+        tab = TorderBay.new(self, 2, 'tsort')
+        add_tab tab, TorderBayLabel.new(tab, 'torder'), 
+          TorderBayBody.new(tab)
+        
+        tab = ZorderBay.new(self, 3, 'zsort')
+        add_tab tab, ZorderBayLabel.new(tab, 'zorder'), 
+          ZorderBayBody.new(tab)
+        
+        tab = NewBay.new(self, 4, 'new')
+        add_tab tab, NewBayLabel.new(tab, 'new'), 
+          NewBayBody.new(tab)
+        
+      end
+      
+      def editor
+        @parent
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def template_dir
+        @parent.template_dir + 'dock/'
+      end
+      
+      def labels_template_name
+        self.template_dir + 'dock_labels'
+      end
+      
+      def bodys_template_name
+        self.template_dir + 'dock_bodys'
+      end
+      
+      def dom_id
+        self.editor.dom_id + '-dock'
+      end
+      
+      def dom_class
+        self.editor.dom_class + '-dock'
+      end
+      
+      def dom_labels_class
+        self.dom_class + '-labels'
+      end
+      
+    end
+    
+    
+  end
+end
diff --git a/lib/editor/dock/base.rb b/lib/editor/dock/base.rb
new file mode 100644 (file)
index 0000000..2bc52f5
--- /dev/null
@@ -0,0 +1,140 @@
+module Editor
+
+  module TabModule
+    class Base
+      attr_accessor :parent, :tabs
+      def initialize parent
+        @parent = parent
+        @tabs = []
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def add_tab tab, label, body
+        @tabs << tab
+        tab.label = label
+        tab.body = body
+        tab
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def template_dir
+        @parent.template_dir
+      end
+      
+      def template_file_name
+        raise "no template_file_name"
+      end
+      
+      def template_name
+        self.template_dir + self.template_file_name
+      end
+      
+    end
+    
+    class Tab < Base
+      attr_accessor :index, :name, :label, :body
+      def initialize parent, index, name
+        super parent
+        @index = index
+        @name = name
+      end
+      
+      def dom_id
+        raise "no dom_id"
+      end
+      
+      def dom_class
+        raise "no dom_class"
+      end
+      
+    end
+    
+    class Label
+      attr_accessor :parent, :caption
+      def initialize parent, caption
+        @parent = parent
+        @caption = caption
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def template_dir
+        @parent.template_dir
+      end
+      
+      def template_name
+        self.template_dir + self.template_file_name
+      end
+      
+      def index
+        @parent.index
+      end
+      
+      def name
+        @parent.name
+      end
+      
+      def dom_id
+        raise "no dom_id"
+      end
+      
+      def dom_class
+        raise "no dom_class"
+      end
+      
+      def body
+        @parent.body
+      end
+      
+    end
+    
+    class Body
+      attr_accessor :parent
+      def initialize parent
+        @parent = parent
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def template_dir
+        @parent.template_dir
+      end
+      
+      def template_name
+        self.template_dir + self.template_file_name
+      end
+      
+      def index
+        @parent.index
+      end
+      
+      def name
+        @parent.name
+      end
+      
+      def label
+        @parent.label
+      end
+      
+      def dom_id
+        raise "no dom_id"
+      end
+      
+      def dom_class
+        raise "no dom_class"
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay.rb b/lib/editor/dock/bay.rb
new file mode 100644 (file)
index 0000000..8d82c0a
--- /dev/null
@@ -0,0 +1,119 @@
+module Editor
+
+  module BayModule
+    include Editor::TabModule
+    class Bay < Tab
+      attr_accessor :template_name
+      def initialize parent, index, name
+        super
+        @template_name = self.template_dir
+      end
+      
+      def dock
+        @parent
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def labels_template_name
+        self.template_dir + 'bay_labels'
+      end
+      
+      def bodys_template_name
+        self.template_dir + 'bay_bodys'
+      end
+      
+      def dom_id
+        @parent.dom_id + '-bay-' + self.name
+      end
+      
+      def dom_class
+        @parent.dom_class + '-bay'
+      end
+      
+      def dom_labels_class
+        self.dom_class + '-labels'
+      end
+      
+    end
+    
+    class SimpleBay < Bay
+      attr_accessor :bucket, :bucket_template_name
+      def initialize dock_body, index, name
+        super
+        @bucket = nil
+        @bucket_template_name = self.template_dir + ''
+      end
+      
+      def template_file_name
+        'bay/simple_bay'
+      end
+      
+    end
+    
+    class BoardBay < Bay
+      attr_accessor :boards
+      def initialize dock_body, index, name
+        super
+      end
+      
+      def template_file_name
+        'bay/board_bay'
+      end
+      
+      def dom_labels_class
+        self.dom_class + "-labels"
+      end
+      
+      def dom_bodys_class
+        self.dom_class + "-bodys"
+      end
+      
+    end
+    
+    class BayLabel < Label
+      def template_file_name
+        'dock_label'
+      end
+      
+      def bay
+        @parent
+      end
+      
+      def dock
+        self.bay.dock
+      end
+      
+      def dom_id
+        self.bay.dom_id + '-label'
+      end
+      
+      def dom_class
+        self.bay.dom_class + '-label'
+      end
+      
+    end
+    
+    class BayBody < Body
+      def bay
+        @parent
+      end
+      
+      def dock
+        self.bay.dock
+      end
+      
+      def dom_id
+        self.bay.dom_id + '-body'
+      end
+      
+      def dom_class
+        self.bay.dom_class + '-body'
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/board/element.rb b/lib/editor/dock/bay/board/element.rb
new file mode 100644 (file)
index 0000000..43315d0
--- /dev/null
@@ -0,0 +1,46 @@
+module Editor
+
+  module ElementBoardModule
+    include Editor::BoardModule
+    class ElementBoard < Board
+      attr_accessor :element
+      
+      def initialize parent, index, name, element
+        super parent, index, name
+        @element = element
+      end
+      
+    end
+    
+    class ElementBoardLabel < BoardLabel
+      def template_file_name
+        'bay_label'
+      end
+      
+      def face_template_name
+        self.element.path_name + '/element_face'
+      end
+      
+    end
+    
+    class ElementBoardBody < BoardBody
+      include Editor::BucketModule
+      attr_accessor :bucket
+      
+      def initialize parent
+        super
+        @bucket = FormBucket.new self, 'form'
+        
+    #    form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name]
+    #    form = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
+    #    bucket = Bucket.new self,form
+      end
+      
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/board/new.rb b/lib/editor/dock/bay/board/new.rb
new file mode 100644 (file)
index 0000000..23fc27e
--- /dev/null
@@ -0,0 +1,32 @@
+module Editor
+
+  module NewBoardModule
+    include Editor::BoardModule
+    class NewBoard < Board
+      def initialize parent, index, name
+        super
+      end
+      
+    end
+    
+    class NewBoardLabel < BoardLabel
+    end
+    
+    class NewBoardBody < BoardBody
+      include Editor::BucketModule
+      
+      def initialize parent
+        super
+    #    form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name]
+    #    form = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
+    #    bucket = Bucket.new self,form
+      end
+      
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/board/torder.rb b/lib/editor/dock/bay/board/torder.rb
new file mode 100644 (file)
index 0000000..6b49e60
--- /dev/null
@@ -0,0 +1,46 @@
+module Editor
+
+  module TorderBoardModule
+    include Editor::BoardModule
+    class TorderBoard < Board
+      attr_accessor :element
+      
+      def initialize parent, index, name, element
+        super parent, index, name
+        @element = element
+      end
+      
+    end
+    
+    class TorderBoardLabel < BoardLabel
+      def template_file_name
+        'bay_label'
+      end
+      
+      def face_template_name
+        self.element.path_name + '/element_face'
+      end
+      
+    end
+    
+    class TorderBoardBody < BoardBody
+      include Editor::BucketModule
+      attr_accessor :bucket
+      
+      def initialize parent
+        super
+        @bucket = FormBucket.new self, 'form'
+        
+    #    form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name]
+    #    form = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
+    #    bucket = Bucket.new self,form
+      end
+      
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/board/zorder.rb b/lib/editor/dock/bay/board/zorder.rb
new file mode 100644 (file)
index 0000000..e822825
--- /dev/null
@@ -0,0 +1,50 @@
+module Editor
+
+  module ZorderBoardModule
+    include Editor::BoardModule
+    class ZorderBoard < Board
+      attr_accessor :element
+      
+      def initialize parent, index, name, element
+        super parent, index, name
+        @element = element
+      end
+      
+      def mounted
+        false
+      end
+      
+    end
+    
+    class ZorderBoardLabel < BoardLabel
+      def template_file_name
+        'bay_label'
+      end
+      
+      def face_template_name
+        self.element.path_name + '/element_face'
+      end
+      
+    end
+    
+    class ZorderBoardBody < BoardBody
+      include Editor::BucketModule
+      attr_accessor :bucket
+      
+      def initialize parent
+        super
+        @bucket = FormBucket.new self, 'form'
+        
+    #    form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name]
+    #    form = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
+    #    bucket = Bucket.new self,form
+      end
+      
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/element.rb b/lib/editor/dock/bay/element.rb
new file mode 100644 (file)
index 0000000..9999add
--- /dev/null
@@ -0,0 +1,31 @@
+require_dependency "editor/dock/bay/board/element"
+module Editor
+
+  module ElementBayModule
+    include Editor::BayModule
+    class ElementBay < BoardBay
+      include Editor::ElementBoardModule
+      def initialize parent, index, name
+        super
+        
+        self.root_item.panel_elements.each_with_index do |element, i| 
+          tab = ElementBoard.new(self, i, element.item_name, element)
+          add_tab tab, ElementBoardLabel.new(tab, element.item_name), 
+            ElementBoardBody.new(tab)
+        end
+      end
+      
+    end
+    
+    class ElementBayLabel < BayLabel
+    end
+    
+    class ElementBayBody < BayBody
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/new.rb b/lib/editor/dock/bay/new.rb
new file mode 100644 (file)
index 0000000..5f757c0
--- /dev/null
@@ -0,0 +1,26 @@
+require_dependency "editor/dock/bay/board/new"
+module Editor
+
+  module NewBayModule
+    include Editor::BayModule
+    class NewBay < BoardBay
+      include Editor::NewBoardModule
+      def initialize parent, index, name
+        super
+        
+      end
+      
+    end
+    
+    class NewBayLabel < BayLabel
+    end
+    
+    class NewBayBody < BayBody
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/root.rb b/lib/editor/dock/bay/root.rb
new file mode 100644 (file)
index 0000000..bd8803b
--- /dev/null
@@ -0,0 +1,34 @@
+module Editor
+
+  module RootBayModule
+    include Editor::BayModule
+    class RootBay < SimpleBay
+    end
+    
+    class RootBayLabel < BayLabel
+    end
+    
+    class RootBayBody < BayBody
+      include Editor::BucketModule
+      attr_accessor :bucket
+      
+      def initialize parent
+        super
+        @bucket = FormBucket.new self, 'form'
+  #      form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name]
+   #     form = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
+   #     @bucket = Bucket.new self,form
+      end
+      
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+      def mounted
+        true
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/torder.rb b/lib/editor/dock/bay/torder.rb
new file mode 100644 (file)
index 0000000..e74b80d
--- /dev/null
@@ -0,0 +1,35 @@
+require_dependency "editor/dock/bay/board/torder"
+module Editor
+
+  module TorderBayModule
+    include Editor::BayModule
+    class TorderBay < BoardBay
+      include Editor::TorderBoardModule
+      def initialize parent, index, name
+        super
+        
+        self.root_item.panel_elements.each_with_index do |element, i| 
+          tab = TorderBoard.new(self, i, element.item_name, element)
+          add_tab tab, TorderBoardLabel.new(tab, element.item_name), 
+            TorderBoardBody.new(tab)
+        end
+      end
+      
+      def class_name
+        "tsort-box"
+      end
+      
+    end
+    
+    class TorderBayLabel < BayLabel
+    end
+    
+    class TorderBayBody < BayBody
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bay/zorder.rb b/lib/editor/dock/bay/zorder.rb
new file mode 100644 (file)
index 0000000..fe13a7f
--- /dev/null
@@ -0,0 +1,35 @@
+require_dependency "editor/dock/bay/board/zorder"
+module Editor
+
+  module ZorderBayModule
+    include Editor::BayModule
+    class ZorderBay < BoardBay
+      include Editor::ZorderBoardModule
+      def initialize parent, index, name
+        super
+        
+        self.root_item.panel_elements.each_with_index do |element, i| 
+          tab = ZorderBoard.new(self, i, element.item_name, element)
+          add_tab tab, ZorderBoardLabel.new(tab, element.item_name), 
+            ZorderBoardBody.new(tab)
+        end
+      end
+      
+      def class_name
+        "zsort-box"
+      end
+      
+    end
+    
+    class ZorderBayLabel < BayLabel
+    end
+    
+    class ZorderBayBody < BayBody
+      def template_file_name
+        @parent.template_file_name
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/board.rb b/lib/editor/dock/board.rb
new file mode 100644 (file)
index 0000000..96af170
--- /dev/null
@@ -0,0 +1,79 @@
+module Editor
+
+  module BoardModule
+    include Editor::TabModule
+    class Board < Tab
+      def initialize parent, index, name
+        super
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def bay
+        @parent
+      end
+      
+      def bay_index
+        self.bay.index
+      end
+      
+      def dom_id
+        self.bay.dom_id + '-board-' + self.name
+      end
+      
+      def dom_class
+        self.bay.dom_class + '-board'
+      end
+      
+      def header_class
+        ""
+      end
+      
+    end
+    
+    class BoardLabel < Label
+      def initialize parent, caption
+        super
+      end
+      
+      def board
+        @parent
+      end
+      
+      def bay
+        self.board.parent
+      end
+      
+      def element
+        @parent.element
+      end
+      
+      def bay_name
+        bay.name
+      end
+      
+      def dom_id
+        self.board.dom_id + '-label'
+      end
+      
+      def dom_class
+        self.board.dom_class + '-label'
+      end
+      
+    end
+    
+    class BoardBody < Body
+      def dom_id
+        self.board.dom_id + '-body'
+      end
+      
+      def dom_class
+        self.board.dom_class + '-body'
+      end
+      
+    end
+    
+  end
+end
diff --git a/lib/editor/dock/bucket.rb b/lib/editor/dock/bucket.rb
new file mode 100644 (file)
index 0000000..71d64a7
--- /dev/null
@@ -0,0 +1,48 @@
+module Editor
+
+  module BucketModule
+    class Bucket
+      attr_accessor :parent
+      def initialize parent
+        @parent = parent
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def template_dir
+        @parent.template_dir
+      end
+      
+      def template_name
+        self.template_dir + self.template_file_name
+      end
+      
+      def class_name
+        "elements-tabs"
+      end
+      
+    end
+    
+    class FormBucket < Bucket
+      def initialize parent, form
+        @parent = parent
+      end
+      
+      def root_item
+        @parent.root_item
+      end
+      
+      def template_file_name
+        'element_form'
+      end
+      
+      def class_name
+        "elements-tabs"
+      end
+      
+    end
+    
+  end
+end
index 878cc0d..07e4076 100644 (file)
@@ -1,270 +1,8 @@
+require_dependency "editor/dock"
 module Editor
 
   class Editor
-    class Dock
-      attr_accessor :editor, :bodies
-      def initialize editor
-        @editor = editor
-        @root_dock_body = DockBody.new(self, 0, )
-        @root_dock_body.label = DockLabel.new(@root_dock_body, 'panel')
-        @root_dock_body.bay = RootBay.new(@root_dock_body)
-        
-        @element_dock_body = DockBody.new(self, 0, )
-        @element_dock_body.label = DockLabel.new(@element_dock_body, 'elements')
-        @element_dock_body.bay = ElementBay.new(@element_dock_body)
-        
-        @torder_dock_body = DockBody.new(self, 0, )
-        @torder_dock_body.label = DockLabel.new(@torder_dock_body, 'torder')
-        @torder_dock_body.bay = TorderBay.new(@torder_dock_body)
-        
-        @zorder_dock_body = DockBody.new(self, 0, )
-        @zorder_dock_body.label = DockLabel.new(@zorder_dock_body, 'zorder')
-        @zorder_dock_body.bay = ZorderBay.new(@zorder_dock_body)
-        
-        @new_dock_body = DockBody.new(self, 0, )
-        @new_dock_body.label = DockLabel.new(@new_dock_body, 'new')
-        @new_dock_body.bay = NewBay.new(@new_dock_body)
-        
-        @bodies = [
-          @root_dock_body, @element_dock_body, @torder_dock_body, @zorder_dock_body, @new_dock_body
-        ]
-      end
-      
-      def root_item
-        @editor.root_item
-      end
-      
-    end
-    
-    class DockBody
-      attr_accessor :dock, :index, :label, :bay
-      def initialize dock, index
-        @dock = dock
-        @index = index
-        @label = label
-        @bay = bay
-      end
-      
-      def root_item
-        @dock.root_item
-      end
-      
-    end
-    
-    class DockLabel
-      attr_accessor :dock_body, :caption
-      def initialize dock_body, caption
-        @dock_body = dock_body
-        @caption = caption
-      end
-      
-      def root_item
-        @dock_body.root_item
-      end
-      
-      def index
-        @dock_body.index
-      end
-      
-      def label_id
-        "tabs-1-tab"
-      end
-      
-      def bay_id
-        @dock_body.bay.bay_id
-      end
-    end
-    
-    class Bay
-      attr_accessor :dock_body, :template_name
-      def initialize dock_body
-        @dock_body = dock_body
-        @template_dir = 'templates/r/editor/'
-        @template_name = @template_dir
-      end
-      
-      def root_item
-        @dock_body.root_item
-      end
-      
-      def index
-        @dock_body.index
-      end
-      
-      def label
-        @dock_body.label
-      end
-      
-      def label_id
-        self.label.label_id
-      end
-      
-      def bay_id
-        "tabs-2"
-      end
-      
-    end
-    
-    class Board
-      attr_accessor :bay, :board_index, :label, :bucket
-      def initialize bay, board_index, element
-        @bay = bay
-        @board_index = board_index
-        @element = element
-      end
-      
-      def root_item
-        @bay.root_item
-      end
-      
-      def bay_index
-        @bay.index
-      end
-      
-      def header_class
-        ""
-      end
-      
-    end
-    
-    class BoardLabel
-      def initialize board, caption
-      end
-      
-      def class_name
-        "elements-tabs"
-      end
-      
-    end
-    
-    class SimpleBay < Bay
-      attr_accessor :bucket, :bucket_template_name
-      def initialize dock_body
-        super
-        @template_name = @template_dir + 'simple_bay'
-        @bucket = nil
-        @bucket_template_name = @template_dir + ''
-      end
-      
-    end
-    
-    class BoardBay < Bay
-      attr_accessor :boards
-      def initialize dock_body
-        super
-        @template_name = @template_dir + 'board_bay'
-      end
-      
-    end
-    
-    class Bucket
-      def class_name
-        "elements-tabs"
-      end
-      
-    end
-    
-    class RootBay < SimpleBay
-      def initialize dock_body
-        super
-        form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name]
-        mounted = true
-        @bucket = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
-        @bucket_template_name = @template_dir + 'element_form'
-      end
-    end
-    
-    class ElementBay < BoardBay
-      def initialize dock_body
-        super
-        @boards = self.root_item.panel_elements.map {|element| 
-          board = ElementBoard.new self, index, element
-          board_label = BoardLabel.new board 
-          bucket = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
-          bucket_template_name = @template_dir + 'element_form'
-          board_bucket = bucket
-          board.label = board_label
-          board.bucket = board_bucket
-          board
-        }
-      end
-      
-    end
-    
-    class TorderBay < BoardBay
-      def initialize dock_body
-        super
-        @boards = self.root_item.panel_elements.map {|element| 
-          board = TorderBoard.new self, index, element
-          board_label = BoardLabel.new board 
-          bucket = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
-          bucket_template_name = @template_dir + 'element_form'
-          board_bucket = bucket
-          board.label = board_label
-          board.bucket = board_bucket
-          board
-        }
-      end
-      
-    end
-    
-    class ZorderBay < BoardBay
-      def initialize dock_body
-        super
-        @boards = self.root_item.panel_elements.map {|element| 
-          board = ZorderBoard.new self, index, element
-          board_label = BoardLabel.new board 
-          bucket = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
-          bucket_template_name = @template_dir + 'element_form'
-          board_bucket = bucket
-          board.label = board_label
-          board.bucket = board_bucket
-          board
-        }
-      end
-      
-    end
-    
-    class NewBay < BoardBay
-      def initialize dock_body
-        super
-        @boards = self.root_item.panel_elements.map {|element| 
-          board = NewBoard.new self, index, element
-          board_label = BoardLabel.new board 
-          bucket = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted
-          bucket_template_name = @template_dir + 'element_form'
-          board_bucket = bucket
-          board.label = board_label
-          board.bucket = board_bucket
-          board
-        }
-      end
-      
-    end
-    
-    class ElementBoard < Board
-      def class_name
-        "elements-tabs"
-      end
-      
-    end
-    
-    class TorderBoard < Board
-      def class_name
-        "tsort-box"
-      end
-      
-    end
-    
-    class ZorderBoard < Board
-      def class_name
-        "zsort-box"
-      end
-      
-    end
-    
-    class NewBoard < Board
-    end
+    include DockModule
     
     class Generator
       def initialize editor
@@ -277,16 +15,25 @@ module Editor
       
     end
     
-    attr_accessor :root_item, :dock, :generator, :operators
+    attr_accessor :root_item, :dock, :template_dir, :generator, :operators
     def initialize root_item, operators
       @root_item = root_item
       @operators = operators
+      @template_dir = 'templates/r/editor/'
       @dock = Dock.new self
       @generator = Generator.new self
     end
     
     #InstanceMethods
     
+    def dom_id
+      'editor-' + @root_item.id.to_s
+    end
+    
+    def dom_class
+      'editor'
+    end
+    
     def render view
       @docks.map {|element| 
         ElementTab.new self, element
diff --git a/lib/editor/elements.rb b/lib/editor/elements.rb
deleted file mode 100644 (file)
index 481a7ec..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-module Editor
-  class ElementTab
-    attr :element
-    # table_name
-    def initialize editor, element
-      @editor = editor
-      @element = element
-    end
-    
-    #InstanceMethods
-    def element_tab
-    end
-    
-    def form mounted
-      form_manager = Pettanr::Application::manifest.form_managers[@element.form_name]
-      form = form_manager.open element, @editor.operators, mounted
-    end
-    
-  end
-end
diff --git a/lib/editor/tsort.rb b/lib/editor/tsort.rb
deleted file mode 100644 (file)
index 5b63297..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-module Editor
-  class Tsort
-    # table_name
-    def initialize item, operators
-    end
-    
-    def self.singular
-      self.to_s
-    end
-    
-    #InstanceMethods
-    
-    def item_name
-      self.class.item_name
-    end
-    
-  end
-end
diff --git a/lib/editor/zsort.rb b/lib/editor/zsort.rb
deleted file mode 100644 (file)
index 8d2500b..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-module Editor
-  class Zsort
-    # table_name
-    def initialize item, operators
-    end
-    
-    def self.singular
-      self.to_s
-    end
-    
-    #InstanceMethods
-    
-    def item_name
-      self.class.item_name
-    end
-    
-  end
-end