Class: Orange::PageResource
- Inherits:
-
ModelResource
- Object
- ModelResource
- Orange::PageResource
- Defined in:
- lib/orange-more/pages/resources/page_resource.rb
Instance Method Summary collapse
- #find_extras(packet, mode, opts = {}) ⇒ Object
- #find_list(packet, mode) ⇒ Object
-
#find_one(packet, mode, id = false) ⇒ Object
Returns a single object found by the model class, given an id.
- #init ⇒ Object
-
#onNew(packet, params = {}) ⇒ Object
Creates a new model object and saves it (if a post), then reroutes to the main page.
-
#onSave(packet, m, params = {}) ⇒ Object
Saves updates to an object specified by packet, then reroutes to main.
- #publish(packet, opts = {}) ⇒ Object
- #route_for(packet, id, opts = {}) ⇒ Object
- #routes(packet, opts = {}) ⇒ Object
- #sitemap_row(packet, opts = {}) ⇒ Object
- #stack_init ⇒ Object
Instance Method Details
#find_extras(packet, mode, opts = {}) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 164 def find_extras(packet, mode, opts = {}) case mode when :edit return {:routes => orange[:sitemap, true].routes_for(packet)} else {} end end |
#find_list(packet, mode) ⇒ Object
121 122 123 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 121 def find_list(packet, mode) model_class.all(:orange_site => packet['site']) || [] end |
#find_one(packet, mode, id = false) ⇒ Object
Returns a single object found by the model class, given an id. If id isn’t given, we return false.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 131 def find_one(packet, mode, id = false) return false unless id m = model_class.get(id) if packet['route.resource_path',''] =~ /version\// parts = packet['route.resource_path'].split('/') version = parts[2] v = m.versions.first(:version => version) if v attrs = v.attributes [:version, :orange_page_id, :page_id, :id].each { |i| attrs.delete(i) } m.attributes = attrs end end # end if version if mode == :show case packet['route.context'] when :live # Automatically set title, if possible unless orange[:page_parts].part(packet)[:title] != '' orange[:page_parts].part(packet)[:title] = m.title + " - " + packet['site'].name end m = m.versions.last(:published => '1') raise Orange::NotFoundException unless m when :preview # Automatically set title, if possible unless orange[:page_parts].part(packet)[:title] != '' orange[:page_parts].part(packet)[:title] = m.title + " - " + packet['site'].name end m end end # end if show m end |
#init ⇒ Object
27 28 29 30 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 27 def init [:sitemappable] = true orange.add_pulp(Orange::Pulp::PageHelpers) end |
#onNew(packet, params = {}) ⇒ Object
Creates a new model object and saves it (if a post), then reroutes to the main page
82 83 84 85 86 87 88 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 82 def onNew(packet, params = {}) params[:published] = false m = model_class.new(params) m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site # m.versions.new(params.merge(:version => 1)) m end |
#onSave(packet, m, params = {}) ⇒ Object
Saves updates to an object specified by packet, then reroutes to main
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 92 def onSave(packet, m, params = {}) r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name, :orange_site_id => m.orange_site.id) # Add route if none. if (r.blank? && orange.loaded?(:sitemap)) route_hash = { :orange_site_id => m.orange_site.id, :resource => @my_orange_name, :resource_id => m.id, :slug => orange[:sitemap].slug_for(m, params), :show_in_nav => false, :link_text => "{title}" } parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id) route_hash[:parent] = parents.first unless parents.blank? orange[:sitemap].add_route_for(packet, route_hash) end if (params["published"] == "1") params["published"] = true m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site m.update(params) orange[:pages].publish(packet, :no_reroute => true, :model => m) else params["published"] = false m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site m.update(params) end end |
#publish(packet, opts = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 36 def publish(packet, opts = {}) no_reroute = opts[:no_reroute] if packet.request.post? || !opts.blank? my_id = opts[:resource_id] || packet['route.resource_id'] m = opts[:model] || model_class.get(my_id) if m params = {} params[:published] = true m.update(params) params = m.attributes.merge(params) params.delete(:id) max = m.versions.max(:version) || 0 m.versions.new(params.merge(:version => max + 1)) m.save r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name, :orange_site_id => m.orange_site.id) # Add route if none. if (r.blank? && orange.loaded?(:sitemap)) route_hash = { :orange_site_id => m.orange_site.id, :resource => @my_orange_name, :resource_id => m.id, :slug => orange[:sitemap].slug_for(m, params), :show_in_nav => false, :link_text => "{title}" } parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id) route_hash[:parent] = parents.first unless parents.blank? orange[:sitemap].add_route_for(packet, route_hash) elsif orange.loaded?(:sitemap) r.each do |route| if route.default_slug? route.slug = orange[:sitemap].slug(m.title) route.save end end end end end packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute) end |
#route_for(packet, id, opts = {}) ⇒ Object
182 183 184 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 182 def route_for(packet, id, opts = {}) return orange[:sitemap].url_for(packet, {:resource => 'pages', :resource_id => id}) end |
#routes(packet, opts = {}) ⇒ Object
172 173 174 175 176 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 172 def routes(packet, opts = {}) model = opts if opts.is_a? model_class model ||= opts[:model] || model_class.get(opts[:resource_id]) orange[:sitemap].routes_for(packet, {:resource => :pages, :resource_id => model.id}) end |
#sitemap_row(packet, opts = {}) ⇒ Object
178 179 180 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 178 def sitemap_row(packet, opts = {}) do_view(packet, :sitemap_row, opts) end |
#stack_init ⇒ Object
32 33 34 |
# File 'lib/orange-more/pages/resources/page_resource.rb', line 32 def stack_init orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Pages') end |