orange-more 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/README.markdown +17 -0
  2. data/lib/orange-more.rb +23 -0
  3. data/lib/orange-more/administration.rb +1 -0
  4. data/lib/orange-more/administration/assets/css/admin.css +286 -0
  5. data/lib/orange-more/administration/assets/css/blueprint-ie.css +35 -0
  6. data/lib/orange-more/administration/assets/css/blueprint-print.css +29 -0
  7. data/lib/orange-more/administration/assets/css/blueprint.css +257 -0
  8. data/lib/orange-more/administration/assets/js/jquery.js +152 -0
  9. data/lib/orange-more/administration/cartons/site.rb +7 -0
  10. data/lib/orange-more/administration/cartons/site_carton.rb +12 -0
  11. data/lib/orange-more/administration/cartons/user.rb +27 -0
  12. data/lib/orange-more/administration/middleware/access_control.rb +156 -0
  13. data/lib/orange-more/administration/middleware/site_load.rb +25 -0
  14. data/lib/orange-more/administration/plugin.rb +23 -0
  15. data/lib/orange-more/administration/resources/admin_resource.rb +27 -0
  16. data/lib/orange-more/administration/resources/site_resource.rb +10 -0
  17. data/lib/orange-more/administration/resources/user_resource.rb +40 -0
  18. data/lib/orange-more/administration/templates/admin.haml +25 -0
  19. data/lib/orange-more/administration/views/openid_login.haml +14 -0
  20. data/lib/orange-more/administration/views/users/create.haml +10 -0
  21. data/lib/orange-more/administration/views/users/edit.haml +15 -0
  22. data/lib/orange-more/adverts.rb +1 -0
  23. data/lib/orange-more/adverts/cartons/adverts_carton.rb +14 -0
  24. data/lib/orange-more/adverts/plugin.rb +13 -0
  25. data/lib/orange-more/adverts/resources/adverts_resource.rb +27 -0
  26. data/lib/orange-more/adverts/views/adverts/adverts.haml +2 -0
  27. data/lib/orange-more/analytics.rb +1 -0
  28. data/lib/orange-more/analytics/middleware/analytics.rb +30 -0
  29. data/lib/orange-more/analytics/plugin.rb +11 -0
  30. data/lib/orange-more/analytics/resources/analytics_resource.rb +42 -0
  31. data/lib/orange-more/assets.rb +1 -0
  32. data/lib/orange-more/assets/cartons/asset_carton.rb +27 -0
  33. data/lib/orange-more/assets/plugin.rb +13 -0
  34. data/lib/orange-more/assets/resources/asset_resource.rb +115 -0
  35. data/lib/orange-more/assets/views/assets/change.haml +1 -0
  36. data/lib/orange-more/assets/views/assets/create.haml +13 -0
  37. data/lib/orange-more/assets/views/assets/insert.haml +1 -0
  38. data/lib/orange-more/blog.rb +1 -0
  39. data/lib/orange-more/blog/cartons/blog.rb +8 -0
  40. data/lib/orange-more/blog/cartons/blog_post.rb +60 -0
  41. data/lib/orange-more/blog/plugin.rb +14 -0
  42. data/lib/orange-more/blog/resources/blog_post_resource.rb +54 -0
  43. data/lib/orange-more/blog/resources/blog_resource.rb +104 -0
  44. data/lib/orange-more/blog/views/blog/blog_archive_view.haml +6 -0
  45. data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +12 -0
  46. data/lib/orange-more/blog/views/blog/blog_post_view.haml +4 -0
  47. data/lib/orange-more/blog/views/blog/sitemap_row.haml +14 -0
  48. data/lib/orange-more/blog/views/blog_posts/edit.haml +8 -0
  49. data/lib/orange-more/blog/views/blog_posts/show.haml +4 -0
  50. data/lib/orange-more/cloud.rb +1 -0
  51. data/lib/orange-more/cloud/plugin.rb +10 -0
  52. data/lib/orange-more/cloud/resources/cloud_resource.rb +21 -0
  53. data/lib/orange-more/contactforms.rb +1 -0
  54. data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +15 -0
  55. data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +6240 -0
  56. data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +660 -0
  57. data/lib/orange-more/contactforms/assets/js/lib/jquery.js +4376 -0
  58. data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +122 -0
  59. data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +12 -0
  60. data/lib/orange-more/contactforms/plugin.rb +13 -0
  61. data/lib/orange-more/contactforms/resources/contactforms_resource.rb +56 -0
  62. data/lib/orange-more/contactforms/views/contactforms/contactform.haml +20 -0
  63. data/lib/orange-more/debugger.rb +1 -0
  64. data/lib/orange-more/debugger/assets/css/debug_bar.css +46 -0
  65. data/lib/orange-more/debugger/middleware/debugger.rb +50 -0
  66. data/lib/orange-more/debugger/plugin.rb +12 -0
  67. data/lib/orange-more/debugger/views/debug_bar.haml +87 -0
  68. data/lib/orange-more/disqus.rb +1 -0
  69. data/lib/orange-more/disqus/plugin.rb +11 -0
  70. data/lib/orange-more/disqus/resources/disqus_resource.rb +9 -0
  71. data/lib/orange-more/disqus/views/disqus/comment_thread.haml +7 -0
  72. data/lib/orange-more/donations.rb +1 -0
  73. data/lib/orange-more/donations/cartons/donation_carton.rb +9 -0
  74. data/lib/orange-more/donations/plugin.rb +12 -0
  75. data/lib/orange-more/donations/resources/donations_resource.rb +51 -0
  76. data/lib/orange-more/donations/views/donations/donate_form.haml +21 -0
  77. data/lib/orange-more/donations/views/donations/donate_thanks.haml +2 -0
  78. data/lib/orange-more/donations/views/donations/paypal_form.haml +13 -0
  79. data/lib/orange-more/events.rb +1 -0
  80. data/lib/orange-more/events/assets/js/events.js +55 -0
  81. data/lib/orange-more/events/cartons/orange_calendar.rb +8 -0
  82. data/lib/orange-more/events/cartons/orange_event.rb +60 -0
  83. data/lib/orange-more/events/plugin.rb +14 -0
  84. data/lib/orange-more/events/resources/calendar_resource.rb +33 -0
  85. data/lib/orange-more/events/resources/event_resource.rb +147 -0
  86. data/lib/orange-more/events/views/calendar/calendar.haml +8 -0
  87. data/lib/orange-more/events/views/events/create.haml +55 -0
  88. data/lib/orange-more/events/views/events/edit.haml +59 -0
  89. data/lib/orange-more/events/views/events/list.haml +13 -0
  90. data/lib/orange-more/events/views/events/show.haml +4 -0
  91. data/lib/orange-more/events/views/events/table_row.haml +17 -0
  92. data/lib/orange-more/members.rb +1 -0
  93. data/lib/orange-more/members/cartons/member_carton.rb +38 -0
  94. data/lib/orange-more/members/plugin.rb +13 -0
  95. data/lib/orange-more/members/resources/members_resource.rb +327 -0
  96. data/lib/orange-more/members/views/members/create.haml +12 -0
  97. data/lib/orange-more/members/views/members/edit.haml +15 -0
  98. data/lib/orange-more/members/views/members/live.show.haml +1 -0
  99. data/lib/orange-more/members/views/members/login.haml +17 -0
  100. data/lib/orange-more/members/views/members/logout.haml +1 -0
  101. data/lib/orange-more/members/views/members/profile.haml +50 -0
  102. data/lib/orange-more/members/views/members/register.haml +37 -0
  103. data/lib/orange-more/news.rb +1 -0
  104. data/lib/orange-more/news/cartons/news.rb +12 -0
  105. data/lib/orange-more/news/plugin.rb +13 -0
  106. data/lib/orange-more/news/resources/news_resource.rb +83 -0
  107. data/lib/orange-more/news/views/news/archive.haml +14 -0
  108. data/lib/orange-more/news/views/news/edit.haml +7 -0
  109. data/lib/orange-more/news/views/news/latest.haml +8 -0
  110. data/lib/orange-more/news/views/news/sitemap_row.haml +14 -0
  111. data/lib/orange-more/pages.rb +1 -0
  112. data/lib/orange-more/pages/cartons/page_carton.rb +14 -0
  113. data/lib/orange-more/pages/cartons/page_version_carton.rb +12 -0
  114. data/lib/orange-more/pages/plugin.rb +13 -0
  115. data/lib/orange-more/pages/resources/page_resource.rb +179 -0
  116. data/lib/orange-more/pages/views/pages/edit.haml +34 -0
  117. data/lib/orange-more/pages/views/pages/show.haml +6 -0
  118. data/lib/orange-more/sitemap.rb +1 -0
  119. data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
  120. data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
  121. data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
  122. data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
  123. data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
  124. data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
  125. data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
  126. data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
  127. data/lib/orange-more/sitemap/assets/js/sitemap.js +11 -0
  128. data/lib/orange-more/sitemap/cartons/route.rb +44 -0
  129. data/lib/orange-more/sitemap/middleware/flex_router.rb +25 -0
  130. data/lib/orange-more/sitemap/plugin.rb +17 -0
  131. data/lib/orange-more/sitemap/resources/sitemap_resource.rb +295 -0
  132. data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +30 -0
  133. data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +12 -0
  134. data/lib/orange-more/sitemap/views/sitemap/list.haml +4 -0
  135. data/lib/orange-more/sitemap/views/sitemap/one_level.haml +7 -0
  136. data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +15 -0
  137. data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +14 -0
  138. data/lib/orange-more/sitemap/views/sitemap/table_row.haml +30 -0
  139. data/lib/orange-more/sitemap/views/sitemap/two_level.haml +13 -0
  140. data/lib/orange-more/slices.rb +1 -0
  141. data/lib/orange-more/slices/middleware/radius_parser.rb +24 -0
  142. data/lib/orange-more/slices/plugin.rb +15 -0
  143. data/lib/orange-more/slices/resources/radius.rb +117 -0
  144. data/lib/orange-more/slices/resources/slices.rb +35 -0
  145. data/lib/orange-more/subsites.rb +1 -0
  146. data/lib/orange-more/subsites/cartons/subsite.rb +8 -0
  147. data/lib/orange-more/subsites/middleware/subsite_load.rb +29 -0
  148. data/lib/orange-more/subsites/plugin.rb +17 -0
  149. data/lib/orange-more/subsites/resources/subsite_resource.rb +54 -0
  150. data/lib/orange-more/subsites/views/subsites/index.haml +2 -0
  151. data/lib/orange-more/testimonials.rb +1 -0
  152. data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +15 -0
  153. data/lib/orange-more/testimonials/plugin.rb +13 -0
  154. data/lib/orange-more/testimonials/resources/testimonials_resource.rb +42 -0
  155. data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +4 -0
  156. data/spec/orange-core/application_spec.rb +183 -0
  157. data/spec/orange-core/carton_spec.rb +136 -0
  158. data/spec/orange-core/core_spec.rb +248 -0
  159. data/spec/orange-core/magick_spec.rb +96 -0
  160. data/spec/orange-core/middleware/base_spec.rb +38 -0
  161. data/spec/orange-core/middleware/globals_spec.rb +3 -0
  162. data/spec/orange-core/middleware/rerouter_spec.rb +3 -0
  163. data/spec/orange-core/middleware/restful_router_spec.rb +3 -0
  164. data/spec/orange-core/middleware/route_context_spec.rb +3 -0
  165. data/spec/orange-core/middleware/route_site_spec.rb +3 -0
  166. data/spec/orange-core/middleware/show_exceptions_spec.rb +3 -0
  167. data/spec/orange-core/middleware/static_file_spec.rb +3 -0
  168. data/spec/orange-core/middleware/static_spec.rb +3 -0
  169. data/spec/orange-core/mock/mock_app.rb +16 -0
  170. data/spec/orange-core/mock/mock_carton.rb +43 -0
  171. data/spec/orange-core/mock/mock_core.rb +2 -0
  172. data/spec/orange-core/mock/mock_middleware.rb +25 -0
  173. data/spec/orange-core/mock/mock_mixins.rb +19 -0
  174. data/spec/orange-core/mock/mock_model_resource.rb +47 -0
  175. data/spec/orange-core/mock/mock_pulp.rb +24 -0
  176. data/spec/orange-core/mock/mock_resource.rb +26 -0
  177. data/spec/orange-core/mock/mock_router.rb +10 -0
  178. data/spec/orange-core/orange_spec.rb +19 -0
  179. data/spec/orange-core/packet_spec.rb +203 -0
  180. data/spec/orange-core/resource_spec.rb +96 -0
  181. data/spec/orange-core/resources/mapper_spec.rb +5 -0
  182. data/spec/orange-core/resources/model_resource_spec.rb +246 -0
  183. data/spec/orange-core/resources/parser_spec.rb +5 -0
  184. data/spec/orange-core/resources/routable_resource_spec.rb +5 -0
  185. data/spec/orange-core/spec_helper.rb +53 -0
  186. data/spec/orange-core/stack_spec.rb +232 -0
  187. data/spec/stats.rb +182 -0
  188. metadata +312 -0
@@ -0,0 +1,34 @@
1
+ - if model
2
+ - if resource.options[:sitemappable, false]
3
+ = orange[:sitemap, true].sitemap_links(packet, {:slug_me => orange[:sitemap, true].slug_for(model, props)})
4
+ %form{:action => route_to(model_name, model[:id], 'save'), :method => 'post'}
5
+ - for prop in props
6
+ %p~ view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
7
+ %a{:href => route_to(model_name, model['id'], {:context => 'preview', :mode => 'show'}), :rel => 'external', :target => "_blank"}Preview
8
+ :javascript
9
+ $(function(){
10
+ $('button.link_button').click(
11
+ function(){
12
+ $('input[name="pages[published]"]').val('1');
13
+ }
14
+ );
15
+ });
16
+ %input{:type => 'hidden', :id => 'pages[published]', :name => 'pages[published]', :value => '0'}
17
+ %input{:type => 'submit', :value => 'Save Changes'}
18
+ / = route_to(model_name, model[:id], 'publish')
19
+ = form_link('Publish', packet.route_to(model_name, model[:id], 'save'))
20
+ %h3 Published Versions
21
+ %ul.version_list
22
+ / %li (Current Draft)
23
+ - for version in model.versions.all(:order => :version.desc, :limit=> 3)
24
+ %li
25
+ .version_container
26
+ %span.version_info
27
+ %strong Version #{version.version}
28
+ %span.version_info
29
+ Last Updated:
30
+ %strong #{fuzzy_time(version.updated_at)}
31
+ %span.version_info
32
+ %a{:href => route_to(model_name, model[:id], 'edit', "version", version.version)}Edit
33
+ - else
34
+ %p Couldn't find the item you're looking for.
@@ -0,0 +1,6 @@
1
+ - if model
2
+ %div{ :class => model_name}
3
+ - for prop in props
4
+ = view_attribute(prop, model_name, :show => true, :value => model.attribute_get(prop[:name]))
5
+ - if props.empty?
6
+ %p= model.body
@@ -0,0 +1 @@
1
+ require File.join('orange-more', 'sitemap', 'plugin')
@@ -0,0 +1,11 @@
1
+ jQuery(function($){
2
+ $('.sitemap_links_info a.more_info').toggle(
3
+ function(){
4
+ jQuery('.sitemap_links').show();
5
+ jQuery('.sitemap_links_info a.more_info').text('Less Info');
6
+ },
7
+ function(){
8
+ jQuery('.sitemap_links').hide();
9
+ jQuery('.sitemap_links_info a.more_info').text('More Info');
10
+ });
11
+ });
@@ -0,0 +1,44 @@
1
+ require 'orange-more/administration/cartons/site_carton'
2
+ require 'dm-is-awesome_set'
3
+
4
+ class OrangeRoute < Orange::SiteCarton
5
+ id
6
+ admin do
7
+ text :slug, :display_name => "Search Engine Friendly Page URL", :length => 255
8
+ text :link_text, :length => 255
9
+ text :reroute_to, :length => 255
10
+ boolean :show_in_nav, :default => false, :display_name => 'Show in Navigation?'
11
+ end
12
+ orange do
13
+ string :resource
14
+ string :resource_id
15
+ string :resource_action
16
+ boolean :accept_args, :default => true
17
+ end
18
+ include DataMapper::Transaction::Resource # Make sure Transactions are included (for awesome_set)
19
+ is :awesome_set, :scope => [:orange_site]
20
+
21
+ def full_path
22
+ self_and_ancestors.inject('') do |path, part|
23
+ if part.parent # Check if this is a child
24
+ path = path + part.slug + '/'
25
+ else # The root slug is just the initial '/'
26
+ path = path + '/'
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.home_for_site(site_id)
32
+ site_id = OrangeSite.get(site_id) unless site_id.is_a? OrangeSite
33
+ root(:orange_site => site_id)
34
+ end
35
+
36
+
37
+ def self.create_home_for_site(site_id, opts = {})
38
+ opts = opts.with_defaults({:orange_site_id => site_id, :slug => '_index_', :accept_args => false, :link_text => 'Home'})
39
+ home = self.new(opts)
40
+ home.move(:root)
41
+ home.save
42
+ home
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ require 'orange-core/middleware/base'
2
+
3
+ module Orange::Middleware
4
+ # The FlexRouter middleware takes a resource that can route paths and
5
+ # then intercepts routes for that resource. By default,
6
+ # it uses the Orange::SitemapResource.
7
+ #
8
+ # The resource is automatically loaded into the core as
9
+ # :sitemap. The resource must respond to "route?(path)"
10
+ # and "route(packet)".
11
+ #
12
+ # Pass a different routing resource using the :resource arg
13
+ class FlexRouter < Base
14
+ # Sets the sitemap resource as the router if the resource can accept
15
+ # the path.
16
+ def packet_call(packet)
17
+ return (pass packet) if packet['route.router'] # Don't route if other middleware
18
+ # already has
19
+ path = packet['route.path'] || packet.request.path_info
20
+ packet['route.router'] = orange[:sitemap] if orange[:sitemap].route?(packet, path)
21
+ pass packet
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
2
+ Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
3
+ Dir.glob(File.join(File.dirname(__FILE__), 'middleware', '*.rb')).each {|f| require f }
4
+
5
+ module Orange::Plugins
6
+ class Sitemap < Base
7
+ assets_dir File.join(File.dirname(__FILE__), 'assets')
8
+ views_dir File.join(File.dirname(__FILE__), 'views')
9
+
10
+ resource Orange::SitemapResource.new
11
+ router Orange::Middleware::FlexRouter
12
+
13
+ end
14
+ end
15
+
16
+ Orange.plugin(Orange::Plugins::Sitemap.new)
17
+
@@ -0,0 +1,295 @@
1
+ require 'orange-core/core'
2
+ require 'orange-core/resources/model_resource'
3
+ module Orange
4
+
5
+ class SitemapResource < ModelResource
6
+ use OrangeRoute
7
+ call_me :sitemap
8
+ def stack_init
9
+ orange[:admin, true].add_link('Content', :resource => @my_orange_name, :text => 'Sitemap')
10
+ orange[:radius, true].define_tag "link" do |tag|
11
+ packet = tag.locals.packet
12
+ slug = tag.expand
13
+ id = tag.attr['id'] if tag.attr['id']
14
+ route = orange[:sitemap].find_route(packet, {:id => id}) if id
15
+ route = orange[:sitemap].find_route(packet, {:slug => slug}) unless route
16
+ route = orange[:sitemap].find_route(packet, {:link_text => slug}) unless route
17
+
18
+ orange[:sitemap].to_html(packet, route, tag.attr["text"])
19
+ end
20
+ orange.register(:model_resource_deleted) do |packet, opts|
21
+ model_class.all(opts).destroy!
22
+ end
23
+ end
24
+
25
+ def to_href(packet, route)
26
+ unless route.is_a? model_class
27
+ route = model_class.get(route)
28
+ end
29
+ full_path = route ? route.full_path : "#not-found"
30
+ end
31
+
32
+ def to_html(packet, route, text = false)
33
+ unless route.is_a? model_class
34
+ route = model_class.get(route)
35
+ end
36
+ full_path = route ? route.full_path : "#not-found"
37
+ link_text = route ? link_text_for(route) : "(Broken link tag)"
38
+ link_text = text if text
39
+ "<a href='#{full_path}'>#{link_text}</a>"
40
+ end
41
+
42
+ def route_actions(packet, opts = {})
43
+ do_view(packet, :route_actions, opts)
44
+ end
45
+
46
+ def route(packet)
47
+ return packet.reroute(packet['route.reroute']) if packet['route.reroute']
48
+ resource = packet['route.resource']
49
+ raise 'resource not found' unless orange.loaded? resource
50
+ unless (packet['route.resource_action'])
51
+ packet['route.resource_action'] = (packet['route.resource_id'] ? :show : :index)
52
+ end
53
+
54
+ packet[:content] = (orange[resource].view packet)
55
+ end
56
+
57
+ # Path should be an array of path parts
58
+ def find_route_info(packet, path)
59
+ parts = path.split('/')
60
+ pad = parts.shift
61
+ matched = home(packet, :subsite => true)
62
+ extras = ''
63
+ while (!parts.empty?)
64
+ next_part = parts.shift
65
+ matches = matched.children.first(:slug => next_part)
66
+ if(matches)
67
+ matched = matches
68
+ else
69
+ extras = parts.unshift(next_part).unshift(pad).join('/')
70
+ parts = []
71
+ end
72
+ end
73
+ [extras, matched]
74
+ end
75
+
76
+ def route?(packet, path)
77
+ extras, matched = find_route_info(packet, path)
78
+ return false if(extras.length > 0 && !matched.accept_args)
79
+ return false if matched.resource.blank? && matched.reroute_to.blank?
80
+ packet['route.reroute'] = matched.reroute_to unless matched.reroute_to.blank?
81
+ packet['route.path'] = path
82
+ packet['route.route'] = matched
83
+ packet['route.resource'] = matched.resource.to_sym unless matched.resource.blank?
84
+ packet['route.resource_id'] = matched.resource_id.to_i unless matched.resource_id.blank?
85
+ packet['route.resource_action'] = matched.resource_action.to_sym unless matched.resource_action.blank?
86
+ # allow "resource_paths" - extra arguments added as path parts
87
+ packet['route.resource_path'] = extras
88
+ return true
89
+ end
90
+
91
+ # Creates a new model object and saves it (if a post), then reroutes to the main page
92
+ # @param [Orange::Packet] packet the packet being routed
93
+ def onNew(packet, params = {})
94
+ params.with_defaults!(:orange_site_id => (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id))
95
+ model_class.new(params)
96
+ end
97
+
98
+ def afterNew(packet, obj, params = {})
99
+ obj.move(:into => home(packet))
100
+ end
101
+
102
+ def move(packet, obj, opts = {})
103
+ no_reroute = opts.delete(:no_reroute)
104
+ if packet.request.post? || !opts.blank?
105
+ dir = opts[:direction]
106
+ dir = {:into => opts[:parent]} if (dir == :into)
107
+ obj ||= find_one(packet, :move, (opts[:id] || packet['route.resource_id']))
108
+ obj.move(dir) if obj
109
+ end
110
+ packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
111
+ end
112
+
113
+ def show_in_nav(packet, opts = {})
114
+ no_reroute = opts.delete(:no_reroute)
115
+ if packet.request.post? || !opts.blank?
116
+ obj = find_one(packet, :show_in_nav, (opts[:id] || opts[:resource_id] || packet['route.resource_id']))
117
+ obj.show_in_nav = true
118
+ obj.save
119
+ end
120
+ packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
121
+ end
122
+
123
+ def unshow_in_nav(packet, opts = {})
124
+ no_reroute = opts.delete(:no_reroute)
125
+ if packet.request.post? || !opts.blank?
126
+ obj = find_one(packet, :unshow_in_nav, (opts[:id] || opts[:resource_id] || packet['route.resource_id']))
127
+ obj.show_in_nav = false
128
+ obj.save
129
+ end
130
+ packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
131
+ end
132
+
133
+ def higher(packet, opts = {})
134
+ move(packet, false, :direction => :higher)
135
+ end
136
+
137
+ def into(packet, opts = {})
138
+ opts[:parent_id] ||= packet['route.resource_path'].split('/').last
139
+ opts[:parent] = find_one(packet, :move, (opts[:parent_id])) unless opts[:parent]
140
+ move(packet, false, :direction => :into, :parent => opts[:parent])
141
+ end
142
+
143
+ def lower(packet, opts = {})
144
+ move(packet, false, :direction => :lower)
145
+ end
146
+
147
+ def outdent(packet, opts = {})
148
+ move(packet, false, :direction => :outdent)
149
+ end
150
+
151
+ def indent(packet, opts = {})
152
+ move(packet, false, :direction => :indent)
153
+ end
154
+
155
+ def home(packet, opts = {})
156
+ if(opts[:subsite])
157
+ site_id = opts[:orange_site_id] || packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id
158
+ else
159
+ site_id = opts[:orange_site_id] || packet['site'].id
160
+ end
161
+ model_class.home_for_site(site_id) || create_home_for_site(packet, site_id)
162
+ end
163
+
164
+ def create_home_for_site(packet, site_id)
165
+ page = orange[:pages, true].new(packet, :title => 'Homepage', :body => 'this is an orange webpage', :no_reroute => true)
166
+ if page
167
+ model_class.create_home_for_site(site_id, :resource => 'pages', :resource_id => page.id)
168
+ else
169
+ model_class.create_home_for_site(site_id)
170
+ end
171
+ end
172
+
173
+ def one_level(packet, opts = {})
174
+ opts.with_defaults!(:model => home(packet))
175
+ do_view(packet, :one_level, opts)
176
+ end
177
+
178
+ def two_level(packet, opts = {})
179
+ opts.with_defaults!(:model => home(packet))
180
+ do_view(packet, :two_level, opts)
181
+ end
182
+
183
+ def breadcrumb(packet, opts = {})
184
+ opts.with_defaults!(:model => packet['route.route'])
185
+ do_view(packet, :breadcrumb, opts)
186
+ end
187
+
188
+ def routes_for(packet, opts = {})
189
+ keys = {}
190
+ keys[:resource] = opts[:resource] || packet['route.resource']
191
+ keys[:resource_id] = opts[:resource_id] || packet['route.resource_id']
192
+ keys[:orange_site_id] = opts[:orange_site_id] || (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id)
193
+ keys[:slug] = opts[:slug]
194
+ keys.delete_if{|k,v| v.blank? }
195
+ model_class.all(keys)
196
+ end
197
+
198
+ def find_route(packet, opts = {})
199
+ site_id = packet['site'].id
200
+ subsite_id = packet['subsite'].blank? ? nil : packet['subsite'].id
201
+ # First try subsite, if necessary
202
+ m = model_class.first(opts.merge(:orange_site_id => subsite_id)) if subsite_id
203
+ m = model_class.first(opts.merge(:orange_site_id => site_id)) unless m
204
+ m
205
+ end
206
+
207
+ def add_link_for(packet)
208
+ linky = ['add_route']
209
+ linky << (packet['subsite'].blank? ? (packet['site'].blank? ? '0' : packet['site'].id) : packet['subsite'].id)
210
+ linky << (packet['route.resource'].blank? ? '0' : packet['route.resource'])
211
+ linky << (packet['route.resource_id'].blank? ? '0' : packet['route.resource_id'])
212
+ packet.route_to(:sitemap, linky.join('/') )
213
+ end
214
+
215
+ def add_route_for(packet, opts = {})
216
+ unless opts.blank?
217
+ parent = opts.delete(:parent) || home(packet, opts)
218
+ unless parent.is_a? model_class
219
+ parent = model_class.get(parent) # Get parent object if parent was an id number
220
+ end
221
+ me = model_class.new(opts)
222
+ me.save
223
+ me.move(:into => parent)
224
+ end
225
+ end
226
+
227
+ def url_for(packet, opts = {})
228
+ include_subsite = opts.delete(:include_subsite) || false
229
+ m = model_class.first(opts)
230
+ if !packet['subsite'].blank? && include_subsite
231
+ return orange[:subsites].url_for(packet).gsub(/\/$/, '') + (m ? m.full_path : '#not_found')
232
+ else
233
+ return (m ? m.full_path : '#not_found')
234
+ end
235
+ end
236
+
237
+ def add_route(packet, opts = {})
238
+ args = packet['route.resource_path'].split('/')
239
+ args.shift
240
+ args = [:orange_site_id, :resource, :resource_id, :slug].inject_hash{|results, key|
241
+ results[key] = args.shift
242
+ }
243
+ me = model_class.new(args)
244
+ me.save
245
+ me.move(:into => home(packet))
246
+ packet.reroute(@my_orange_name, :orange, me.id, 'edit')
247
+ do_view(packet, :add_route, {})
248
+ end
249
+
250
+ def slug_for(model, props)
251
+ hash = model.attributes
252
+ # return slug(model.title) if hash.has_key?(:title)
253
+ # return slug(model.name) if hash.has_key?(:name)
254
+ return 'page-'+model.id.to_s
255
+ end
256
+
257
+ def link_text_for(route)
258
+ return route.link_text unless route.resource && route.resource_id
259
+ if match = route.link_text.match(/^\{([-a-z0-9A-Z_]+)\}$/)
260
+ resource = route.resource.to_sym
261
+ return route.link_text unless orange.loaded?(resource)
262
+ orange[resource].model_class.get(route.resource_id).__send__(match[1])
263
+ else
264
+ route.link_text
265
+ end
266
+ end
267
+
268
+ def slug(str)
269
+ str.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "-")
270
+ end
271
+
272
+ def find_list(packet, mode, *args)
273
+ home(packet, :subsite => true).self_and_descendants
274
+ end
275
+
276
+ def table_row(packet, opts ={})
277
+ opts[:route] = opts[:model] || find_one(packet, :table_row, opts[:id])
278
+ resource = opts[:route].resource
279
+ resource = resource.to_sym unless resource.blank?
280
+ if resource && orange[resource].respond_to?(:sitemap_row)
281
+ opts.delete(:model)
282
+ orange[resource].sitemap_row(packet, opts.merge(:resource_name => resource, :id => opts[:route].resource_id))
283
+ else
284
+ do_view(packet, :table_row, opts)
285
+ end
286
+ end
287
+
288
+ def sitemap_links(packet, opts = {})
289
+ packet.add_js('sitemap.js', :module => '_sitemap_')
290
+ opts.with_defaults!({:list => routes_for(packet) })
291
+ opts.merge!({:add_route_link => add_link_for(packet)})
292
+ do_list_view(packet, :sitemap_links, opts)
293
+ end
294
+ end
295
+ end