active_scaffold 3.0.23 → 3.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/frontends/default/views/_action_group.html.erb +1 -1
 - data/frontends/default/views/_action_group.html.erb~ +24 -0
 - data/frontends/default/views/_form.html.erb~ +26 -0
 - data/frontends/default/views/_form_association.html.erb~ +19 -0
 - data/frontends/default/views/_form_association_footer.html.erb~ +16 -6
 - data/frontends/default/views/_horizontal_subform.html.erb~ +29 -0
 - data/frontends/default/views/_horizontal_subform_header.html.erb~ +3 -2
 - data/frontends/default/views/_list_actions.html.erb~ +15 -0
 - data/frontends/default/views/_list_inline_adapter.html.erb~ +10 -0
 - data/frontends/default/views/_list_messages.html.erb~ +30 -0
 - data/frontends/default/views/_list_pagination.html.erb~ +11 -0
 - data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
 - data/frontends/default/views/_render_field.js.erb~ +23 -0
 - data/frontends/default/views/_row.html.erb~ +6 -0
 - data/frontends/default/views/_vertical_subform.html.erb~ +12 -0
 - data/frontends/default/views/edit_associated.js.erb~ +13 -0
 - data/frontends/default/views/on_create.js.rjs +2 -2
 - data/frontends/default/views/render_field.js.erb~ +1 -0
 - data/lib/active_scaffold/actions/core.rb~ +13 -5
 - data/lib/active_scaffold/actions/create.rb~ +149 -0
 - data/lib/active_scaffold/actions/list.rb~ +196 -0
 - data/lib/active_scaffold/actions/nested.rb +6 -2
 - data/lib/active_scaffold/actions/nested.rb~ +252 -0
 - data/lib/active_scaffold/actions/search.rb~ +49 -0
 - data/lib/active_scaffold/actions/subform.rb~ +27 -0
 - data/lib/active_scaffold/actions/update.rb~ +149 -0
 - data/lib/active_scaffold/attribute_params.rb~ +202 -0
 - data/lib/active_scaffold/bridges/record_select/{lib/record_select_bridge.rb~ → helpers.rb~} +7 -16
 - data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +209 -0
 - data/lib/active_scaffold/config/create.rb +4 -4
 - data/lib/active_scaffold/config/nested.rb +1 -0
 - data/lib/active_scaffold/config/nested.rb~ +41 -0
 - data/lib/active_scaffold/config/search.rb~ +74 -0
 - data/lib/active_scaffold/constraints.rb~ +186 -0
 - data/lib/active_scaffold/data_structures/action_columns.rb~ +140 -0
 - data/lib/active_scaffold/data_structures/action_link.rb +4 -4
 - data/lib/active_scaffold/data_structures/action_link.rb~ +179 -0
 - data/lib/active_scaffold/data_structures/nested_info.rb~ +124 -0
 - data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +22 -0
 - data/lib/active_scaffold/extensions/action_view_rendering.rb~ +108 -0
 - data/lib/active_scaffold/extensions/cache_association.rb~ +12 -0
 - data/lib/active_scaffold/extensions/reverse_associations.rb~ +64 -0
 - data/lib/active_scaffold/extensions/routing_mapper.rb~ +34 -0
 - data/lib/active_scaffold/extensions/unsaved_associated.rb~ +62 -0
 - data/lib/active_scaffold/finder.rb~ +370 -0
 - data/lib/active_scaffold/helpers/controller_helpers.rb~ +101 -0
 - data/lib/active_scaffold/helpers/form_column_helpers.rb~ +321 -0
 - data/lib/active_scaffold/helpers/id_helpers.rb~ +123 -0
 - data/lib/active_scaffold/helpers/list_column_helpers.rb +9 -6
 - data/lib/active_scaffold/helpers/list_column_helpers.rb~ +368 -0
 - data/lib/active_scaffold/helpers/search_column_helpers.rb~ +94 -46
 - data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
 - data/lib/active_scaffold/helpers/view_helpers.rb~ +353 -0
 - data/lib/active_scaffold/version.rb +1 -1
 - data/lib/active_scaffold.rb +1 -1
 - data/lib/active_scaffold.rb~ +362 -0
 - metadata +110 -76
 - data/lib/active_scaffold/bridges/dragonfly/bridge.rb~ +0 -12
 - data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb~ +0 -36
 - data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb~ +0 -12
 - data/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb~ +0 -27
 - data/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb~ +0 -16
 
| 
         @@ -0,0 +1,362 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1
         
     | 
| 
      
 2 
     | 
    
         
            +
              raise "This version of ActiveScaffold requires Rails 3.1 or higher.  Please use an earlier version."
         
     | 
| 
      
 3 
     | 
    
         
            +
            end
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            begin
         
     | 
| 
      
 6 
     | 
    
         
            +
              require 'render_component'
         
     | 
| 
      
 7 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            require 'active_scaffold/active_record_permissions'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'active_scaffold/paginator'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'active_scaffold/responds_to_parent'
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            require 'active_scaffold/version'
         
     | 
| 
      
 15 
     | 
    
         
            +
            require 'active_scaffold/engine' unless defined? ACTIVE_SCAFFOLD_PLUGIN
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            module ActiveScaffold
         
     | 
| 
      
 18 
     | 
    
         
            +
              autoload :AttributeParams, 'active_scaffold/attribute_params'
         
     | 
| 
      
 19 
     | 
    
         
            +
              autoload :Configurable, 'active_scaffold/configurable'
         
     | 
| 
      
 20 
     | 
    
         
            +
              autoload :Constraints, 'active_scaffold/constraints'
         
     | 
| 
      
 21 
     | 
    
         
            +
              autoload :Finder, 'active_scaffold/finder'
         
     | 
| 
      
 22 
     | 
    
         
            +
              autoload :MarkedModel, 'active_scaffold/marked_model'
         
     | 
| 
      
 23 
     | 
    
         
            +
              autoload :Bridges, 'active_scaffold/bridges'
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              mattr_accessor :stylesheets
         
     | 
| 
      
 26 
     | 
    
         
            +
              self.stylesheets = []
         
     | 
| 
      
 27 
     | 
    
         
            +
              mattr_accessor :javascripts
         
     | 
| 
      
 28 
     | 
    
         
            +
              self.javascripts = []
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
         
     | 
| 
      
 31 
     | 
    
         
            +
                Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file|
         
     | 
| 
      
 32 
     | 
    
         
            +
                  basename = File.basename(file, ".rb")
         
     | 
| 
      
 33 
     | 
    
         
            +
                  mod.module_eval {
         
     | 
| 
      
 34 
     | 
    
         
            +
                    autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  }
         
     | 
| 
      
 36 
     | 
    
         
            +
                }
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              module Actions
         
     | 
| 
      
 40 
     | 
    
         
            +
                ActiveScaffold.autoload_subdir('actions', self)
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              module Config
         
     | 
| 
      
 44 
     | 
    
         
            +
                ActiveScaffold.autoload_subdir('config', self)
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              module DataStructures
         
     | 
| 
      
 48 
     | 
    
         
            +
                ActiveScaffold.autoload_subdir('data_structures', self)
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              module Helpers
         
     | 
| 
      
 52 
     | 
    
         
            +
                ActiveScaffold.autoload_subdir('helpers', self)
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              class ControllerNotFound < RuntimeError; end
         
     | 
| 
      
 56 
     | 
    
         
            +
              class DependencyFailure < RuntimeError; end
         
     | 
| 
      
 57 
     | 
    
         
            +
              class MalformedConstraint < RuntimeError; end
         
     | 
| 
      
 58 
     | 
    
         
            +
              class RecordNotAllowed < SecurityError; end
         
     | 
| 
      
 59 
     | 
    
         
            +
              class ActionNotAllowed < SecurityError; end
         
     | 
| 
      
 60 
     | 
    
         
            +
              class ReverseAssociationRequired < RuntimeError; end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              def self.included(base)
         
     | 
| 
      
 63 
     | 
    
         
            +
                base.extend(ClassMethods)
         
     | 
| 
      
 64 
     | 
    
         
            +
                base.module_eval do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  # TODO: these should be in actions/core
         
     | 
| 
      
 66 
     | 
    
         
            +
                  before_filter :handle_user_settings
         
     | 
| 
      
 67 
     | 
    
         
            +
                  before_filter :check_input_device
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                base.helper_method :touch_device?
         
     | 
| 
      
 71 
     | 
    
         
            +
                base.helper_method :hover_via_click?
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
              def self.set_defaults(&block)
         
     | 
| 
      
 75 
     | 
    
         
            +
                ActiveScaffold::Config::Core.configure &block
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
              
         
     | 
| 
      
 78 
     | 
    
         
            +
              def active_scaffold_config
         
     | 
| 
      
 79 
     | 
    
         
            +
                self.class.active_scaffold_config
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
              def active_scaffold_config_for(klass)
         
     | 
| 
      
 83 
     | 
    
         
            +
                self.class.active_scaffold_config_for(klass)
         
     | 
| 
      
 84 
     | 
    
         
            +
              end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
              def active_scaffold_session_storage(id = (params[:eid] || params[:controller]))
         
     | 
| 
      
 87 
     | 
    
         
            +
                session_index = "as:#{id}"
         
     | 
| 
      
 88 
     | 
    
         
            +
                session[session_index] ||= {}
         
     | 
| 
      
 89 
     | 
    
         
            +
                session[session_index]
         
     | 
| 
      
 90 
     | 
    
         
            +
              end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
              # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
         
     | 
| 
      
 93 
     | 
    
         
            +
              def handle_user_settings
         
     | 
| 
      
 94 
     | 
    
         
            +
                if self.class.uses_active_scaffold?
         
     | 
| 
      
 95 
     | 
    
         
            +
                  active_scaffold_config.actions.each do |action_name|
         
     | 
| 
      
 96 
     | 
    
         
            +
                    conf_instance = active_scaffold_config.send(action_name) rescue next
         
     | 
| 
      
 97 
     | 
    
         
            +
                    next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
         
     | 
| 
      
 98 
     | 
    
         
            +
                    active_scaffold_session_storage[action_name] ||= {}
         
     | 
| 
      
 99 
     | 
    
         
            +
                    conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  end
         
     | 
| 
      
 101 
     | 
    
         
            +
                end
         
     | 
| 
      
 102 
     | 
    
         
            +
              end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
              def check_input_device
         
     | 
| 
      
 105 
     | 
    
         
            +
                if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
         
     | 
| 
      
 106 
     | 
    
         
            +
                  session[:input_device_type] = 'TOUCH'
         
     | 
| 
      
 107 
     | 
    
         
            +
                  session[:hover_supported] = false
         
     | 
| 
      
 108 
     | 
    
         
            +
                else
         
     | 
| 
      
 109 
     | 
    
         
            +
                  session[:input_device_type] = 'MOUSE'
         
     | 
| 
      
 110 
     | 
    
         
            +
                  session[:hover_supported] = true
         
     | 
| 
      
 111 
     | 
    
         
            +
                end if session[:input_device_type].nil?
         
     | 
| 
      
 112 
     | 
    
         
            +
               end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
              def touch_device?
         
     | 
| 
      
 115 
     | 
    
         
            +
                session[:input_device_type] == 'TOUCH'
         
     | 
| 
      
 116 
     | 
    
         
            +
              end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
              def hover_via_click?
         
     | 
| 
      
 119 
     | 
    
         
            +
                session[:hover_supported] == false
         
     | 
| 
      
 120 
     | 
    
         
            +
              end
         
     | 
| 
      
 121 
     | 
    
         
            +
              
         
     | 
| 
      
 122 
     | 
    
         
            +
              def self.js_framework=(framework)
         
     | 
| 
      
 123 
     | 
    
         
            +
                @@js_framework = framework
         
     | 
| 
      
 124 
     | 
    
         
            +
              end
         
     | 
| 
      
 125 
     | 
    
         
            +
              
         
     | 
| 
      
 126 
     | 
    
         
            +
              def self.js_framework
         
     | 
| 
      
 127 
     | 
    
         
            +
                @@js_framework ||= if defined? Jquery
         
     | 
| 
      
 128 
     | 
    
         
            +
                  :jquery
         
     | 
| 
      
 129 
     | 
    
         
            +
                elsif defined? PrototypeRails
         
     | 
| 
      
 130 
     | 
    
         
            +
                  :prototype
         
     | 
| 
      
 131 
     | 
    
         
            +
                end
         
     | 
| 
      
 132 
     | 
    
         
            +
              end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
              # exclude bridges you do not need
         
     | 
| 
      
 135 
     | 
    
         
            +
              # name of bridge subdir should be used to exclude it
         
     | 
| 
      
 136 
     | 
    
         
            +
              # eg
         
     | 
| 
      
 137 
     | 
    
         
            +
              #   ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
         
     | 
| 
      
 138 
     | 
    
         
            +
              #   if you are using Activescaffold as a gem add to initializer
         
     | 
| 
      
 139 
     | 
    
         
            +
              #   if you are using Activescaffold as a plugin add to active_scaffold_env.rb
         
     | 
| 
      
 140 
     | 
    
         
            +
              def self.exclude_bridges=(bridges)
         
     | 
| 
      
 141 
     | 
    
         
            +
                @@exclude_bridges = bridges
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
              def self.exclude_bridges
         
     | 
| 
      
 145 
     | 
    
         
            +
                @@exclude_bridges ||= []
         
     | 
| 
      
 146 
     | 
    
         
            +
              end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
              def self.root
         
     | 
| 
      
 149 
     | 
    
         
            +
                File.dirname(__FILE__) + "/.."
         
     | 
| 
      
 150 
     | 
    
         
            +
              end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
              module ClassMethods
         
     | 
| 
      
 153 
     | 
    
         
            +
                def active_scaffold(model_id = nil, &block)
         
     | 
| 
      
 154 
     | 
    
         
            +
                  # initialize bridges here
         
     | 
| 
      
 155 
     | 
    
         
            +
                  ActiveScaffold::Bridges.run_all
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                  # converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'
         
     | 
| 
      
 158 
     | 
    
         
            +
                  model_id = self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                  # run the configuration
         
     | 
| 
      
 161 
     | 
    
         
            +
                  @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id)
         
     | 
| 
      
 162 
     | 
    
         
            +
                  @active_scaffold_config_block = block
         
     | 
| 
      
 163 
     | 
    
         
            +
                  self.links_for_associations
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                  @active_scaffold_frontends = []
         
     | 
| 
      
 166 
     | 
    
         
            +
                  if active_scaffold_config.frontend.to_sym != :default
         
     | 
| 
      
 167 
     | 
    
         
            +
                    active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views')
         
     | 
| 
      
 168 
     | 
    
         
            +
                    @active_scaffold_frontends << active_scaffold_custom_frontend_path
         
     | 
| 
      
 169 
     | 
    
         
            +
                  end
         
     | 
| 
      
 170 
     | 
    
         
            +
                  active_scaffold_default_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views')
         
     | 
| 
      
 171 
     | 
    
         
            +
                  @active_scaffold_frontends << active_scaffold_default_frontend_path
         
     | 
| 
      
 172 
     | 
    
         
            +
                  @active_scaffold_custom_paths = []
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                  self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock}
         
     | 
| 
      
 175 
     | 
    
         
            +
                  self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
         
     | 
| 
      
 176 
     | 
    
         
            +
                  self.active_scaffold_config.configure &block if block_given?
         
     | 
| 
      
 177 
     | 
    
         
            +
                  self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil?
         
     | 
| 
      
 178 
     | 
    
         
            +
                  self.active_scaffold_config._load_action_columns
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                  # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
         
     | 
| 
      
 181 
     | 
    
         
            +
                  klass = self.active_scaffold_config.model
         
     | 
| 
      
 182 
     | 
    
         
            +
                  klass.define_attribute_methods unless klass.attribute_methods_generated?
         
     | 
| 
      
 183 
     | 
    
         
            +
                  # include the rest of the code into the controller: the action core and the included actions
         
     | 
| 
      
 184 
     | 
    
         
            +
                  module_eval do
         
     | 
| 
      
 185 
     | 
    
         
            +
                    include ActiveScaffold::Finder
         
     | 
| 
      
 186 
     | 
    
         
            +
                    include ActiveScaffold::Constraints
         
     | 
| 
      
 187 
     | 
    
         
            +
                    include ActiveScaffold::AttributeParams
         
     | 
| 
      
 188 
     | 
    
         
            +
                    include ActiveScaffold::Actions::Core
         
     | 
| 
      
 189 
     | 
    
         
            +
                    active_scaffold_config.actions.each do |mod|
         
     | 
| 
      
 190 
     | 
    
         
            +
                      name = mod.to_s.camelize
         
     | 
| 
      
 191 
     | 
    
         
            +
                      include "ActiveScaffold::Actions::#{name}".constantize
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                      # sneak the action links from the actions into the main set
         
     | 
| 
      
 194 
     | 
    
         
            +
                      if link = active_scaffold_config.send(mod).link rescue nil
         
     | 
| 
      
 195 
     | 
    
         
            +
                        if link.is_a? Array
         
     | 
| 
      
 196 
     | 
    
         
            +
                          link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)}
         
     | 
| 
      
 197 
     | 
    
         
            +
                        elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
         
     | 
| 
      
 198 
     | 
    
         
            +
                          active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
         
     | 
| 
      
 199 
     | 
    
         
            +
                        end
         
     | 
| 
      
 200 
     | 
    
         
            +
                      end
         
     | 
| 
      
 201 
     | 
    
         
            +
                    end
         
     | 
| 
      
 202 
     | 
    
         
            +
                  end
         
     | 
| 
      
 203 
     | 
    
         
            +
                  self.append_view_path active_scaffold_paths
         
     | 
| 
      
 204 
     | 
    
         
            +
                  self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links?
         
     | 
| 
      
 205 
     | 
    
         
            +
                end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                def parent_prefixes
         
     | 
| 
      
 208 
     | 
    
         
            +
                  @parent_prefixes ||= super << 'active_scaffold_overrides' << ''
         
     | 
| 
      
 209 
     | 
    
         
            +
                end
         
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
                # To be called after include action modules
         
     | 
| 
      
 212 
     | 
    
         
            +
                def _add_sti_create_links
         
     | 
| 
      
 213 
     | 
    
         
            +
                  new_action_link = active_scaffold_config.action_links.collection['new']
         
     | 
| 
      
 214 
     | 
    
         
            +
                  unless new_action_link.nil? || active_scaffold_config.sti_children.empty?
         
     | 
| 
      
 215 
     | 
    
         
            +
                    active_scaffold_config.action_links.collection.delete('new')
         
     | 
| 
      
 216 
     | 
    
         
            +
                    active_scaffold_config.sti_children.each do |child|
         
     | 
| 
      
 217 
     | 
    
         
            +
                      new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
         
     | 
| 
      
 218 
     | 
    
         
            +
                      new_sti_link.label = child.to_s.camelize.constantize.model_name.human
         
     | 
| 
      
 219 
     | 
    
         
            +
                      new_sti_link.parameters = {:parent_sti => controller_path}
         
     | 
| 
      
 220 
     | 
    
         
            +
                      new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path }
         
     | 
| 
      
 221 
     | 
    
         
            +
                      active_scaffold_config.action_links.collection.create.add(new_sti_link)
         
     | 
| 
      
 222 
     | 
    
         
            +
                    end
         
     | 
| 
      
 223 
     | 
    
         
            +
                  end
         
     | 
| 
      
 224 
     | 
    
         
            +
                end
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
         
     | 
| 
      
 227 
     | 
    
         
            +
                def links_for_associations
         
     | 
| 
      
 228 
     | 
    
         
            +
                  return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested
         
     | 
| 
      
 229 
     | 
    
         
            +
                  active_scaffold_config.columns.each do |column|
         
     | 
| 
      
 230 
     | 
    
         
            +
                    next unless column.link.nil? and column.autolink?
         
     | 
| 
      
 231 
     | 
    
         
            +
                    #lazy load of action_link, cause it was really slowing down app in dev mode
         
     | 
| 
      
 232 
     | 
    
         
            +
                    #and might lead to trouble cause of cyclic constantization of controllers
         
     | 
| 
      
 233 
     | 
    
         
            +
                    #and might be unnecessary cause it is done before columns are configured
         
     | 
| 
      
 234 
     | 
    
         
            +
                    column.set_link(Proc.new {|col| link_for_association(col)})
         
     | 
| 
      
 235 
     | 
    
         
            +
                  end
         
     | 
| 
      
 236 
     | 
    
         
            +
                end
         
     | 
| 
      
 237 
     | 
    
         
            +
                
         
     | 
| 
      
 238 
     | 
    
         
            +
                def active_scaffold_controller_for_column(column, options = {})
         
     | 
| 
      
 239 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 240 
     | 
    
         
            +
                    if column.polymorphic_association?
         
     | 
| 
      
 241 
     | 
    
         
            +
                      :polymorph
         
     | 
| 
      
 242 
     | 
    
         
            +
                    elsif options.include?(:controller)
         
     | 
| 
      
 243 
     | 
    
         
            +
                      "#{options[:controller].to_s.camelize}Controller".constantize
         
     | 
| 
      
 244 
     | 
    
         
            +
                    else
         
     | 
| 
      
 245 
     | 
    
         
            +
                      active_scaffold_controller_for(column.association.klass)
         
     | 
| 
      
 246 
     | 
    
         
            +
                    end
         
     | 
| 
      
 247 
     | 
    
         
            +
                  rescue ActiveScaffold::ControllerNotFound
         
     | 
| 
      
 248 
     | 
    
         
            +
                    nil        
         
     | 
| 
      
 249 
     | 
    
         
            +
                  end
         
     | 
| 
      
 250 
     | 
    
         
            +
                end
         
     | 
| 
      
 251 
     | 
    
         
            +
                
         
     | 
| 
      
 252 
     | 
    
         
            +
                def link_for_association(column, options = {})
         
     | 
| 
      
 253 
     | 
    
         
            +
                  controller = active_scaffold_controller_for_column(column, options)
         
     | 
| 
      
 254 
     | 
    
         
            +
                  
         
     | 
| 
      
 255 
     | 
    
         
            +
                  unless controller.nil?
         
     | 
| 
      
 256 
     | 
    
         
            +
                    options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column
         
     | 
| 
      
 257 
     | 
    
         
            +
                    options[:parameters] ||= {}
         
     | 
| 
      
 258 
     | 
    
         
            +
                    options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name
         
     | 
| 
      
 259 
     | 
    
         
            +
                    if column.plural_association?
         
     | 
| 
      
 260 
     | 
    
         
            +
                      # note: we can't create nested scaffolds on :through associations because there's no reverse association.
         
     | 
| 
      
 261 
     | 
    
         
            +
                      
         
     | 
| 
      
 262 
     | 
    
         
            +
                      ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association?
         
     | 
| 
      
 263 
     | 
    
         
            +
                    else
         
     | 
| 
      
 264 
     | 
    
         
            +
                      actions = [:create, :update, :show] 
         
     | 
| 
      
 265 
     | 
    
         
            +
                      actions = controller.active_scaffold_config.actions unless controller == :polymorph
         
     | 
| 
      
 266 
     | 
    
         
            +
                      column.actions_for_association_links.delete :new unless actions.include? :create
         
     | 
| 
      
 267 
     | 
    
         
            +
                      column.actions_for_association_links.delete :edit unless actions.include? :update
         
     | 
| 
      
 268 
     | 
    
         
            +
                      column.actions_for_association_links.delete :show unless actions.include? :show
         
     | 
| 
      
 269 
     | 
    
         
            +
                      ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge({:crud_type => nil, :html_options => {:class => column.name}}))
         
     | 
| 
      
 270 
     | 
    
         
            +
                    end 
         
     | 
| 
      
 271 
     | 
    
         
            +
                  end
         
     | 
| 
      
 272 
     | 
    
         
            +
                end
         
     | 
| 
      
 273 
     | 
    
         
            +
                
         
     | 
| 
      
 274 
     | 
    
         
            +
                def link_for_association_as_scope(scope, options = {})
         
     | 
| 
      
 275 
     | 
    
         
            +
                  options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
         
     | 
| 
      
 276 
     | 
    
         
            +
                  options[:parameters] ||= {}
         
     | 
| 
      
 277 
     | 
    
         
            +
                  options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope
         
     | 
| 
      
 278 
     | 
    
         
            +
                  ActiveScaffold::DataStructures::ActionLink.new('index', options)
         
     | 
| 
      
 279 
     | 
    
         
            +
                end
         
     | 
| 
      
 280 
     | 
    
         
            +
             
     | 
| 
      
 281 
     | 
    
         
            +
                def add_active_scaffold_path(path)
         
     | 
| 
      
 282 
     | 
    
         
            +
                  @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild
         
     | 
| 
      
 283 
     | 
    
         
            +
                  @active_scaffold_custom_paths << path
         
     | 
| 
      
 284 
     | 
    
         
            +
                end
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
                def active_scaffold_paths
         
     | 
| 
      
 287 
     | 
    
         
            +
                  return @active_scaffold_paths unless @active_scaffold_paths.nil?
         
     | 
| 
      
 288 
     | 
    
         
            +
             
     | 
| 
      
 289 
     | 
    
         
            +
                  @active_scaffold_paths = []
         
     | 
| 
      
 290 
     | 
    
         
            +
                  @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil?
         
     | 
| 
      
 291 
     | 
    
         
            +
                  @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil?
         
     | 
| 
      
 292 
     | 
    
         
            +
                  @active_scaffold_paths
         
     | 
| 
      
 293 
     | 
    
         
            +
                end
         
     | 
| 
      
 294 
     | 
    
         
            +
             
     | 
| 
      
 295 
     | 
    
         
            +
                def active_scaffold_config
         
     | 
| 
      
 296 
     | 
    
         
            +
                  if @active_scaffold_config.nil?
         
     | 
| 
      
 297 
     | 
    
         
            +
                    self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config
         
     | 
| 
      
 298 
     | 
    
         
            +
                  else
         
     | 
| 
      
 299 
     | 
    
         
            +
                    @active_scaffold_config
         
     | 
| 
      
 300 
     | 
    
         
            +
                  end
         
     | 
| 
      
 301 
     | 
    
         
            +
                end
         
     | 
| 
      
 302 
     | 
    
         
            +
             
     | 
| 
      
 303 
     | 
    
         
            +
                def active_scaffold_config_block
         
     | 
| 
      
 304 
     | 
    
         
            +
                  @active_scaffold_config_block
         
     | 
| 
      
 305 
     | 
    
         
            +
                end
         
     | 
| 
      
 306 
     | 
    
         
            +
             
     | 
| 
      
 307 
     | 
    
         
            +
                def active_scaffold_superclasses_blocks
         
     | 
| 
      
 308 
     | 
    
         
            +
                  blocks = []
         
     | 
| 
      
 309 
     | 
    
         
            +
                  klass = self.superclass
         
     | 
| 
      
 310 
     | 
    
         
            +
                  while klass.respond_to? :active_scaffold_superclasses_blocks
         
     | 
| 
      
 311 
     | 
    
         
            +
                    blocks << klass.active_scaffold_config_block
         
     | 
| 
      
 312 
     | 
    
         
            +
                    klass = klass.superclass
         
     | 
| 
      
 313 
     | 
    
         
            +
                  end
         
     | 
| 
      
 314 
     | 
    
         
            +
                  blocks.compact.reverse
         
     | 
| 
      
 315 
     | 
    
         
            +
                end
         
     | 
| 
      
 316 
     | 
    
         
            +
             
     | 
| 
      
 317 
     | 
    
         
            +
                def active_scaffold_config_for(klass)
         
     | 
| 
      
 318 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 319 
     | 
    
         
            +
                    controller = active_scaffold_controller_for(klass)
         
     | 
| 
      
 320 
     | 
    
         
            +
                  rescue ActiveScaffold::ControllerNotFound
         
     | 
| 
      
 321 
     | 
    
         
            +
                    config = ActiveScaffold::Config::Core.new(klass)
         
     | 
| 
      
 322 
     | 
    
         
            +
                    config._load_action_columns
         
     | 
| 
      
 323 
     | 
    
         
            +
                    config
         
     | 
| 
      
 324 
     | 
    
         
            +
                  else
         
     | 
| 
      
 325 
     | 
    
         
            +
                    controller.active_scaffold_config
         
     | 
| 
      
 326 
     | 
    
         
            +
                  end
         
     | 
| 
      
 327 
     | 
    
         
            +
                end
         
     | 
| 
      
 328 
     | 
    
         
            +
             
     | 
| 
      
 329 
     | 
    
         
            +
                # Tries to find a controller for the given ActiveRecord model.
         
     | 
| 
      
 330 
     | 
    
         
            +
                # Searches in the namespace of the current controller for singular and plural versions of the conventional "#{model}Controller" syntax.
         
     | 
| 
      
 331 
     | 
    
         
            +
                # You may override this method to customize the search routine.
         
     | 
| 
      
 332 
     | 
    
         
            +
                def active_scaffold_controller_for(klass)
         
     | 
| 
      
 333 
     | 
    
         
            +
                  controller_namespace = self.to_s.split('::')[0...-1].join('::') + '::'
         
     | 
| 
      
 334 
     | 
    
         
            +
                  error_message = []
         
     | 
| 
      
 335 
     | 
    
         
            +
                  [controller_namespace, ''].each do |namespace|
         
     | 
| 
      
 336 
     | 
    
         
            +
                    ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name|
         
     | 
| 
      
 337 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 338 
     | 
    
         
            +
                        controller = "#{namespace}#{controller_name.camelize}Controller".constantize
         
     | 
| 
      
 339 
     | 
    
         
            +
                      rescue NameError => error
         
     | 
| 
      
 340 
     | 
    
         
            +
                        # Only rescue NameError associated with the controller constant not existing - not other compile errors
         
     | 
| 
      
 341 
     | 
    
         
            +
                        if error.message["uninitialized constant #{controller}"]
         
     | 
| 
      
 342 
     | 
    
         
            +
                          error_message << "#{namespace}#{controller_name.camelize}Controller"
         
     | 
| 
      
 343 
     | 
    
         
            +
                          next
         
     | 
| 
      
 344 
     | 
    
         
            +
                        else
         
     | 
| 
      
 345 
     | 
    
         
            +
                          raise
         
     | 
| 
      
 346 
     | 
    
         
            +
                        end
         
     | 
| 
      
 347 
     | 
    
         
            +
                      end
         
     | 
| 
      
 348 
     | 
    
         
            +
                      raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold?
         
     | 
| 
      
 349 
     | 
    
         
            +
                      raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model.to_s == klass.to_s
         
     | 
| 
      
 350 
     | 
    
         
            +
                      return controller
         
     | 
| 
      
 351 
     | 
    
         
            +
                    end
         
     | 
| 
      
 352 
     | 
    
         
            +
                  end
         
     | 
| 
      
 353 
     | 
    
         
            +
                  raise ActiveScaffold::ControllerNotFound, "Could not find " + error_message.join(" or "), caller
         
     | 
| 
      
 354 
     | 
    
         
            +
                end
         
     | 
| 
      
 355 
     | 
    
         
            +
             
     | 
| 
      
 356 
     | 
    
         
            +
                def uses_active_scaffold?
         
     | 
| 
      
 357 
     | 
    
         
            +
                  !active_scaffold_config.nil?
         
     | 
| 
      
 358 
     | 
    
         
            +
                end
         
     | 
| 
      
 359 
     | 
    
         
            +
              end
         
     | 
| 
      
 360 
     | 
    
         
            +
            end
         
     | 
| 
      
 361 
     | 
    
         
            +
             
     | 
| 
      
 362 
     | 
    
         
            +
            require 'active_scaffold_env'
         
     |