orange 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/lib/orange-core/carton.rb +5 -0
  2. data/lib/orange-core/core.rb +1 -0
  3. data/lib/orange-core/middleware/template.rb +2 -1
  4. data/lib/orange-core/resources/model_resource.rb +0 -77
  5. data/lib/orange-core/resources/scaffold.rb +106 -0
  6. data/lib/orange-core/views/default_resource/edit.haml +1 -1
  7. data/lib/orange-core/views/default_resource/show.haml +1 -1
  8. data/lib/orange-more/administration/middleware/access_control.rb +8 -0
  9. data/lib/orange-more/administration/resources/user_resource.rb +1 -1
  10. data/lib/orange-more/adverts/cartons/adverts_carton.rb +1 -1
  11. data/lib/orange-more/assets/cartons/asset_carton.rb +26 -22
  12. data/lib/orange-more/assets/resources/asset_resource.rb +56 -2
  13. data/lib/orange-more/assets/views/assets/change.haml +1 -0
  14. data/lib/orange-more/assets/views/assets/insert.haml +1 -0
  15. data/lib/orange-more/debugger/middleware/debugger.rb +8 -0
  16. data/lib/orange-more/debugger/views/debug_bar.haml +4 -0
  17. data/lib/orange-more/events/resources/event_resource.rb +4 -1
  18. data/lib/orange-more/members/resources/members_resource.rb +2 -1
  19. data/lib/orange-more/news/cartons/news.rb +1 -1
  20. data/lib/orange-more/pages/cartons/page_carton.rb +1 -1
  21. data/lib/orange-more/pages/cartons/page_version_carton.rb +1 -1
  22. data/lib/orange-more/pages/resources/page_resource.rb +34 -13
  23. data/lib/orange-more/sitemap/cartons/route.rb +2 -2
  24. data/lib/orange-more/sitemap/resources/sitemap_resource.rb +31 -0
  25. data/lib/orange-more/sitemap/views/sitemap/one_level.haml +1 -1
  26. data/lib/orange-more/sitemap/views/sitemap/table_row.haml +1 -1
  27. data/lib/orange-more/sitemap/views/sitemap/two_level.haml +3 -2
  28. data/lib/orange-more/subsites/resources/subsite_resource.rb +2 -2
  29. metadata +6 -3
@@ -169,5 +169,10 @@ module Orange
169
169
  add_scaffold(name, my_type, type, opts)
170
170
  end
171
171
 
172
+ def to_s
173
+ <<-DOC
174
+ {"class": "#{self.class.to_s}", "id": "#{self.id}"}
175
+ DOC
176
+ end
172
177
  end
173
178
  end
@@ -72,6 +72,7 @@ module Orange
72
72
  @file = __FILE__
73
73
  load(Orange::Parser.new, :parser)
74
74
  load(Orange::Mapper.new, :mapper)
75
+ load(Orange::Scaffold.new, :scaffold)
75
76
  load(Orange::PageParts.new, :page_parts)
76
77
  Orange.plugins.each{|p| p.resources.each{|args| load(*args)} if p.has_resources?}
77
78
  self.register(:stack_loaded) do |s|
@@ -23,7 +23,8 @@ module Orange::Middleware
23
23
  end
24
24
 
25
25
  def needs_wrapped?(packet)
26
- packet['template.file'] && !packet['template.disable']
26
+ return false if packet.request.xhr? && !packet['template.enable'] # don't wrap xhr unless specifically asked to
27
+ packet['template.file'] && !packet['template.disable']
27
28
  end
28
29
 
29
30
  def wrap(packet, content = false)
@@ -223,81 +223,4 @@ module Orange
223
223
 
224
224
  end
225
225
 
226
- class Packet
227
- # Adds view_[mode_name] magic methods to the packet
228
- meta_methods(/view_([a-zA-Z_]+)/) do |packet, match, args|
229
- model = args.shift
230
- args = args.extract_with_defaults(:mode => match[1].to_sym)
231
- packet.view(model, args)
232
- end
233
-
234
- # Creates a button that appears to be a link but
235
- # does form submission with custom method (_method param in POST)
236
- # This is to avoid issues of a destructive get.
237
- # @param [String] text link text to show
238
- # @param [String] link the actual href value of the link
239
- # @param [String, false] confirm text of the javascript confirm (false for none [default])
240
- # @param [optional, Array] args array of optional arguments, only opts[:method] defined
241
- # @option opts [String] method method name (Should be 'DELETE', 'PUT' or 'POST')
242
- def form_link(text, link, confirm = false, opts = {})
243
- text = "<img src='#{opts[:img]}' alt='#{text}' />" if opts[:img]
244
- css = opts[:class]? opts[:class] : 'form_button_link'
245
- meth = (opts[:method]? "<input type='hidden' name='_method' value='#{opts[:method]}' />" : '')
246
- if confirm
247
- "<form action='#{link}' method='post' class='mini' onsubmit='return confirm(\"#{confirm}\")'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
248
- else
249
- "<form action='#{link}' method='post' class='mini'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
250
- end
251
- end
252
-
253
- # Calls view for an orange resource.
254
- def view(model_name, *args)
255
- orange[model_name].view(self, *args)
256
- end
257
-
258
- # Returns a scaffolded attribute
259
- def view_attribute(prop, model_name, *args)
260
- args = args.extract_options!
261
- val = (args[:value] || '')
262
- label = args[:label] || false
263
- show = args[:show] || false
264
- name = prop[:name]
265
- human_readable_name = name.to_s.split('_').each{|w| w.capitalize!}.join(' ')
266
- unless show
267
- case prop[:type]
268
- when :title
269
- val.gsub!('"', '&quot;')
270
- ret = "<input class=\"title\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
271
- when :text
272
- val.gsub!('"', '&quot;')
273
- ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
274
- when :fulltext
275
- ret = "<textarea name='#{model_name}[#{name}]'>#{val}</textarea>"
276
- when :boolean
277
- human_readable_name = human_readable_name + '?'
278
- ret = "<input type='hidden' name='#{model_name}[#{name}]' value='0' /><input type='checkbox' name='#{model_name}[#{name}]' value='1' #{'checked="checked"' if (val && val != '')}/>"
279
- when :date
280
- val.gsub!('"', '&quot;')
281
- ret = "<input class=\"date\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
282
- else
283
- val.gsub!('"', '&quot;')
284
- ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
285
- end
286
- display_name = prop[:display_name] || human_readable_name
287
- ret = "<label for=''>#{display_name}</label><br />" + ret if label
288
- else
289
- case prop[:type]
290
- when :title
291
- ret = "<h3 class='#{model_name}-#{name}'>#{val}</h3>"
292
- when :text
293
- ret = "<p class='#{model_name}-#{name}'>#{val}</p>"
294
- when :fulltext
295
- ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
296
- else
297
- ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
298
- end
299
- end
300
- return ret
301
- end
302
- end
303
226
  end
@@ -0,0 +1,106 @@
1
+ require 'orange-core/core'
2
+
3
+ module Orange
4
+ class Scaffold < Resource
5
+ # Load the scaffold helpers
6
+ def afterLoad
7
+ orange.add_pulp Pulp::ScaffoldHelpers
8
+ Packet.meta_methods(/view_([a-zA-Z_]+)/) do |packet, match, args|
9
+ model = args.shift
10
+ args = args.extract_with_defaults(:mode => match[1].to_sym)
11
+ packet.view(model, args)
12
+ end
13
+ @scaffold_types = {}
14
+ add_scaffold_type(:boolean) do |name, val, opts|
15
+ if opts[:show]
16
+ val ? "true" : "false"
17
+ else
18
+ ret = "<input type='hidden' name='#{opts[:model_name]}[#{name}]' value='0' /><input type='checkbox' name='#{opts[:model_name]}[#{name}]' value='1' #{'checked="checked"' if (val && val != '')}/>"
19
+ ret = "<label for=''>#{opts[:display_name]}</label><br />" + ret if opts[:label]
20
+ end
21
+ end
22
+ end
23
+
24
+ def add_scaffold_type(type, &block)
25
+ @scaffold_types[type] = Proc.new
26
+ end
27
+
28
+ def scaffold_attribute(packet, prop, model_name, *args)
29
+ args = args.extract_options!
30
+ args.with_defaults!({:packet => packet, :value => '', :label => false, :show => false})
31
+ val = args[:value]
32
+ label = args[:label]
33
+ show = args[:show]
34
+ name = prop[:name]
35
+ human_readable_name = name.to_s.split('_').each{|w| w.capitalize!}.join(' ')
36
+ display_name = prop[:display_name] || human_readable_name
37
+ return @scaffold_types[prop[:type]].call(name, val, args.with_defaults!(:display_name => display_name, :model_name => model_name)) if @scaffold_types.has_key?(prop[:type])
38
+ unless show
39
+ case prop[:type]
40
+ when :title
41
+ val.gsub!('"', '&quot;')
42
+ ret = "<input class=\"title\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
43
+ when :text
44
+ val.gsub!('"', '&quot;')
45
+ ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
46
+ when :fulltext
47
+ ret = "<textarea name='#{model_name}[#{name}]'>#{val}</textarea>"
48
+ when :boolean
49
+ human_readable_name = human_readable_name + '?'
50
+ ret = "<input type='hidden' name='#{model_name}[#{name}]' value='0' /><input type='checkbox' name='#{model_name}[#{name}]' value='1' #{'checked="checked"' if (val && val != '')}/>"
51
+ when :date
52
+ val.gsub!('"', '&quot;')
53
+ ret = "<input class=\"date\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
54
+ else
55
+ val.gsub!('"', '&quot;')
56
+ ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
57
+ end
58
+ ret = "<label for=''>#{display_name}</label><br />" + ret if label
59
+ else
60
+ case prop[:type]
61
+ when :title
62
+ ret = "<h3 class='#{model_name}-#{name}'>#{val}</h3>"
63
+ when :text
64
+ ret = "<p class='#{model_name}-#{name}'>#{val}</p>"
65
+ when :fulltext
66
+ ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
67
+ else
68
+ ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
69
+ end
70
+ end
71
+ return ret
72
+ end
73
+ end
74
+
75
+ module Pulp::ScaffoldHelpers
76
+ # Creates a button that appears to be a link but
77
+ # does form submission with custom method (_method param in POST)
78
+ # This is to avoid issues of a destructive get.
79
+ # @param [String] text link text to show
80
+ # @param [String] link the actual href value of the link
81
+ # @param [String, false] confirm text of the javascript confirm (false for none [default])
82
+ # @param [optional, Array] args array of optional arguments, only opts[:method] defined
83
+ # @option opts [String] method method name (Should be 'DELETE', 'PUT' or 'POST')
84
+ def form_link(text, link, confirm = false, opts = {})
85
+ text = "<img src='#{opts[:img]}' alt='#{text}' />" if opts[:img]
86
+ css = opts[:class]? opts[:class] : 'form_button_link'
87
+ meth = (opts[:method]? "<input type='hidden' name='_method' value='#{opts[:method]}' />" : '')
88
+ if confirm
89
+ "<form action='#{link}' method='post' class='mini' onsubmit='return confirm(\"#{confirm}\")'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
90
+ else
91
+ "<form action='#{link}' method='post' class='mini'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
92
+ end
93
+ end
94
+
95
+ # Calls view for an orange resource.
96
+ def view(model_name, *args)
97
+ orange[model_name].view(self, *args)
98
+ end
99
+
100
+ # Returns a scaffolded attribute
101
+ def view_attribute(prop, model_name, *args)
102
+ orange[:scaffold].scaffold_attribute(self, prop, model_name, *args)
103
+ end
104
+ end
105
+
106
+ end
@@ -3,7 +3,7 @@
3
3
  = orange[:sitemap, true].sitemap_links(packet, {:slug_me => orange[:sitemap, true].slug_for(model, props)})
4
4
  %form{:action => packet.route_to(model_name, model[:id], 'save'), :method => 'post'}
5
5
  - for prop in props
6
- %p!= view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
6
+ %p!= view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]), :model => model)
7
7
  %input{:type => 'submit', :value => 'Save Changes'}
8
8
  - else
9
9
  %p Couldn't find the item you're looking for.
@@ -1,4 +1,4 @@
1
1
  - if model
2
2
  %div{ :class => model_name}
3
3
  - for prop in props
4
- = view_attribute(prop, model_name, :show => true, :value => model.attribute_get(prop[:name]))
4
+ = view_attribute(prop, model_name, :show => true, :value => model.attribute_get(prop[:name]), :model => model)
@@ -38,6 +38,14 @@ module Orange::Middleware
38
38
  return ret unless ret.blank? # unless handle_openid returns false, exit immediately
39
39
  end
40
40
  unless access_allowed?(packet)
41
+ if packet['user'] && packet['route.context'] == :admin
42
+ # User doesn't have permissions, try to get to a site that he does
43
+ site = packet['user'].orange_sites.first
44
+ if site.class.to_s == "OrangeSubsite"
45
+ subsite = orange[:sitemap].url_for(packet, {:resource => 'subsites', :resource_id => site.id})
46
+ packet.reroute("/admin#{subsite}sitemap")
47
+ end
48
+ end
41
49
  packet.flash['user.after_login'] = packet.request.path
42
50
  packet.reroute(@login)
43
51
  end
@@ -28,7 +28,7 @@ module Orange
28
28
  def onSave(packet, obj, params ={})
29
29
  sites = params.delete 'sites'
30
30
  obj.update(params)
31
- obj.orange_sites.delete_if{|i| true }
31
+ obj.orange_sites = []
32
32
  sites.each{|k,v| s = OrangeSite.first(:id => k); obj.orange_sites << s if s} if sites
33
33
  obj.save
34
34
  end
@@ -2,7 +2,7 @@ class OrangeAdvert < Orange::Carton
2
2
  id
3
3
  admin do
4
4
  title :title
5
- text :asset_id
5
+ asset :asset_id
6
6
  text :link
7
7
  text :alt_text
8
8
  end
@@ -1,23 +1,27 @@
1
- module Orange
2
- class Asset < Orange::Carton
3
- id
4
- admin do
5
- title :name
6
- text :caption
7
- end
8
- orange do
9
- string :path, :length => 255
10
- string :mime_type
11
- string :secondary_path, :length => 255, :required => false
12
- string :secondary_mime_type
13
- end
14
-
15
- def file_path
16
- File.join('', 'assets', 'uploaded', path)
17
- end
18
-
19
- def to_asset_tag(alt = "")
20
- "<img src=\"#{file_path}\" border=\"0\" alt=\"#{alt}\"/>"
21
- end
1
+ class OrangeAsset < Orange::Carton
2
+ id
3
+ admin do
4
+ title :name, :length => 255
5
+ text :caption, :length => 255
22
6
  end
23
- end
7
+ orange do
8
+ string :path, :length => 255
9
+ string :mime_type
10
+ string :secondary_path, :length => 255, :required => false
11
+ string :secondary_mime_type
12
+ end
13
+
14
+ def file_path
15
+ File.join('', 'assets', 'uploaded', path)
16
+ end
17
+
18
+ def to_s
19
+ <<-DOC
20
+ {"id": #{self.id}, "html": "#{self.to_asset_tag}"}
21
+ DOC
22
+ end
23
+
24
+ def to_asset_tag(alt = "")
25
+ "<img src='#{file_path}' border='0' alt='#{alt}' />"
26
+ end
27
+ end
@@ -1,7 +1,15 @@
1
1
  require 'fileutils'
2
2
  module Orange
3
+ class Orange::Carton
4
+ # Define a helper for input type="text" type database stuff
5
+ # Show in a context if wrapped in one of the helpers
6
+ def self.asset(name, opts = {})
7
+ add_scaffold(name, :asset, Integer, opts)
8
+ end
9
+ end
10
+
3
11
  class AssetResource < Orange::ModelResource
4
- use Orange::Asset
12
+ use OrangeAsset
5
13
  call_me :assets
6
14
 
7
15
  def stack_init
@@ -13,6 +21,22 @@ module Orange
13
21
  ''
14
22
  end
15
23
  end
24
+ orange[:scaffold].add_scaffold_type(:asset) do |name, val, opts|
25
+ if opts[:show]
26
+ opts[:model].to_asset_tag
27
+ else
28
+ packet = opts[:packet]
29
+
30
+ asset_html = val ? orange[:assets].asset_html(packet, val) : ""
31
+ ret = "<input type=\"hidden\" value=\"#{val}\" name=\"#{opts[:model_name]}[#{name}]\" />"
32
+ if val.blank?
33
+ ret += "<span class='asset_preview'></span><a class='insert_asset' rel=\"#{opts[:model_name]}[#{name}]\" href='/admin/assets/insert'>Insert Asset</a>"
34
+ else
35
+ ret += "<span class='asset_preview'>#{asset_html}</span><a class='insert_asset' rel=\"#{opts[:model_name]}[#{name}]\" href='/admin/assets/#{val}/change'>Change Asset</a>"
36
+ end
37
+ ret = "<label for=''>#{opts[:display_name]}</label><br />" + ret if opts[:label]
38
+ end
39
+ end
16
40
  end
17
41
 
18
42
  def onNew(packet, params = {})
@@ -41,6 +65,35 @@ module Orange
41
65
  m
42
66
  end
43
67
 
68
+ # Creates a new model object and saves it (if a post), then reroutes to the main page
69
+ # @param [Orange::Packet] packet the packet being routed
70
+ def new(packet, opts = {})
71
+ no_reroute = opts.delete(:no_reroute)
72
+ xhr = packet.request.xhr? || packet.request.params["fake_xhr"]
73
+ if packet.request.post? || !opts.blank?
74
+ params = opts.with_defaults(opts.delete(:params) || packet.request.params[@my_orange_name.to_s] || {})
75
+ before = beforeNew(packet, params)
76
+ obj = onNew(packet, params) if before
77
+ afterNew(packet, obj, params) if before
78
+ obj.save if obj && before
79
+ end
80
+ packet.reroute(@my_orange_name, :orange) unless (xhr || no_reroute)
81
+ packet['template.disable'] = true if xhr
82
+ (xhr ? obj.to_s : obj) || false
83
+ end
84
+
85
+ def insert(packet, opts = {})
86
+ do_view(packet, :insert, opts)
87
+ end
88
+
89
+ def change(packet, opts = {})
90
+ do_view(packet, :change, opts)
91
+ end
92
+
93
+ def find_extras(packet, mode, opts = {})
94
+ {:list => model_class.all}
95
+ end
96
+
44
97
  def onDelete(packet, m, opts = {})
45
98
  begin
46
99
  FileUtils.rm(orange.app_dir('assets','uploaded', m.path)) if m.path
@@ -51,7 +104,8 @@ module Orange
51
104
  m.destroy if m
52
105
  end
53
106
 
54
- def asset_html(packet, id)
107
+ def asset_html(packet, id = false)
108
+ id ||= packet['route.resource_id']
55
109
  m = model_class.get(id)
56
110
  m ? m.to_asset_tag : false
57
111
  end
@@ -0,0 +1 @@
1
+ %h2 Change an Asset
@@ -0,0 +1 @@
1
+ %h2 Insert an Asset
@@ -4,6 +4,7 @@ module Orange::Middleware
4
4
  class Debugger < Base
5
5
  def init(opts = {})
6
6
  orange.add_pulp Orange::Pulp::DebuggerHelpers if orange.options[:development_mode]
7
+ orange.mixin Orange::Mixins::DebuggerMixin if orange.options[:development_mode]
7
8
  end
8
9
 
9
10
  # Passes packet then parses the return
@@ -34,6 +35,13 @@ module Orange::Pulp::DebuggerHelpers
34
35
  end
35
36
  end
36
37
 
38
+
39
+ module Orange::Mixins::DebuggerMixin
40
+ def resources
41
+ @resources
42
+ end
43
+ end
44
+
37
45
  class Rack::Builder
38
46
  def inspect
39
47
  "#<Rack::Builder:#{self.object_id.to_s(16)} @ins=#{@ins.map{|x| x.instance_of?(Proc)? x.call(nil) : x }.inspect} >"
@@ -73,6 +73,10 @@
73
73
  %td Middleware
74
74
  %td.code
75
75
  %div #{h_debug packet.env['orange.core'].middleware}
76
+ %tr
77
+ %td Resources
78
+ %td.code
79
+ %div #{h_debug packet.env['orange.core'].resources}
76
80
  %tr
77
81
  %td Application
78
82
  %td.code
@@ -33,7 +33,7 @@ module Orange
33
33
  ev_json = {} if ev
34
34
  ev.each{|v| ev_json[v.id] = v.attributes.merge(:id => v.id)} if ev
35
35
  ee_json = {} if ee
36
- ee.each{|v| ee_json[v.id] = v.attributes.merge(:id => v.id)} if ee
36
+ ee.each{|v| ee_json[v.id] = v.attributes.merge(:id => v.id).reject{|k,v| [:venue, :organizer].include? k}} if ee
37
37
  extras.merge!(:eventbrite_venues => ev, :venues_json => ev_json.to_json,
38
38
  :eventbrite_events => ee, :events_json => ee_json.to_json
39
39
  ) if options[:eventbrite_key]
@@ -116,6 +116,9 @@ module Orange
116
116
  venue.save
117
117
  end
118
118
 
119
+ def find_list(packet, mode, opts = {})
120
+ model_class.all(:order => [:starts.desc]) || []
121
+ end
119
122
 
120
123
  def post_to_eventbrite
121
124
 
@@ -145,8 +145,8 @@ module Orange
145
145
  params = packet.request.params["members"]
146
146
  login = params["login_email"]
147
147
  password = params["login_password"]
148
- tester = model_class.new({:password => password})
149
148
  member = model_class.first({:email => login})
149
+ tester = model_class.new({:password => password, :salt => member.salt})
150
150
  if member && tester.hashed_password == member.hashed_password
151
151
  packet.session["member"] = member.id
152
152
  packet.reroute(@my_orange_name, :orange, :profile)
@@ -155,6 +155,7 @@ module Orange
155
155
  do_view(packet, :login, opts)
156
156
  end
157
157
  else
158
+ packet.reroute(@my_orange_name, :orange, :profile) if packet.session["member"]
158
159
  do_view(packet, :login, opts)
159
160
  end
160
161
  end
@@ -2,7 +2,7 @@ require 'dm-timestamps'
2
2
  class OrangeNews < Orange::Carton
3
3
  id
4
4
  front do
5
- title :title
5
+ title :title, :length => 255
6
6
  text :link, :length => 255
7
7
  fulltext :description
8
8
  end
@@ -4,7 +4,7 @@ require 'orange-more/administration/cartons/site_carton'
4
4
  class OrangePage < Orange::SiteCarton
5
5
  id
6
6
  front do
7
- title :title
7
+ title :title, :length => 255
8
8
  fulltext :body
9
9
  end
10
10
  boolean :published, :default => false
@@ -3,7 +3,7 @@ require 'orange-more/administration/cartons/site_carton'
3
3
 
4
4
  class OrangePageVersion < Orange::SiteCarton
5
5
  id
6
- title :title
6
+ title :title, :length => 255
7
7
  fulltext :body
8
8
  property :updated_at, DateTime
9
9
  boolean :published
@@ -37,7 +37,7 @@ module Orange
37
37
  no_reroute = opts[:no_reroute]
38
38
  if packet.request.post? || !opts.blank?
39
39
  my_id = opts[:resource_id] || packet['route.resource_id']
40
- m = model_class.get(my_id)
40
+ m = opts[:model] || model_class.get(my_id)
41
41
  if m
42
42
  params = {}
43
43
  params[:published] = true
@@ -49,15 +49,16 @@ module Orange
49
49
  m.versions.new(params.merge(:version => max + 1))
50
50
  m.save
51
51
 
52
- r = orange[:sitemap].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name)
53
- if r.blank?
52
+ r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name)
53
+ # Add route if none.
54
+ if (r.blank? && orange.loaded?(:sitemap))
54
55
  route_hash = {
55
56
  :orange_site_id => m.orange_site_id,
56
57
  :resource => @my_orange_name,
57
58
  :resource_id => m.id,
58
59
  :slug => orange[:sitemap].slug_for(m, params),
59
60
  :show_in_nav => false,
60
- :link_text => m.title
61
+ :link_text => "{title}"
61
62
  }
62
63
  parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages")
63
64
  route_hash[:parent] = parents.first unless parents.blank?
@@ -73,7 +74,7 @@ module Orange
73
74
  def onNew(packet, params = {})
74
75
  params[:published] = false
75
76
  m = model_class.new(params)
76
- m.orange_site = packet['site'] unless m.orange_site
77
+ m.orange_site = packet['subsite', false] ? packet['subsite'] : packet['site'] unless m.orange_site
77
78
  # m.versions.new(params.merge(:version => 1))
78
79
  m
79
80
  end
@@ -81,16 +82,31 @@ module Orange
81
82
  # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
82
83
  # @param [Orange::Packet] packet the packet being routed
83
84
  def onSave(packet, m, params = {})
85
+ r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name)
86
+ # Add route if none.
87
+ if (r.blank? && orange.loaded?(:sitemap))
88
+ route_hash = {
89
+ :orange_site_id => m.orange_site_id,
90
+ :resource => @my_orange_name,
91
+ :resource_id => m.id,
92
+ :slug => orange[:sitemap].slug_for(m, params),
93
+ :show_in_nav => false,
94
+ :link_text => "{title}"
95
+ }
96
+ parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages")
97
+ route_hash[:parent] = parents.first unless parents.blank?
98
+ orange[:sitemap].add_route_for(packet, route_hash)
99
+ end
84
100
  if (params["published"] == "1")
85
101
  params["published"] = true
102
+ m.orange_site = packet['subsite', false] ? packet['subsite'] : packet['site'] unless m.orange_site
103
+
86
104
  m.update(params)
87
- m.orange_site = packet['site'] unless m.orange_site
88
- orange[:pages].publish(packet, :no_reroute => true)
105
+ orange[:pages].publish(packet, :no_reroute => true, :model => m)
89
106
  else
90
107
  params["published"] = false
108
+ m.orange_site = packet['subsite', false] ? packet['subsite'] : packet['site'] unless m.orange_site
91
109
  m.update(params)
92
- m.orange_site = packet['site'] unless m.orange_site
93
- m.save
94
110
  end
95
111
  end
96
112
 
@@ -116,7 +132,7 @@ module Orange
116
132
  [:version, :orange_page_id, :page_id, :id].each { |i| attrs.delete(i) }
117
133
  m.attributes = attrs
118
134
  end
119
- end
135
+ end # end if version
120
136
  if mode == :show
121
137
  case packet['route.context']
122
138
  when :live
@@ -133,19 +149,24 @@ module Orange
133
149
  end
134
150
  m
135
151
  end
136
- else {}
137
- end
152
+ end # end if show
138
153
  m
139
154
  end
140
155
 
141
156
  def find_extras(packet, mode, opts = {})
142
157
  case mode
143
158
  when :edit
144
- return {:routes => orange[:sitemap].routes_for(packet)}
159
+ return {:routes => orange[:sitemap, true].routes_for(packet)}
145
160
  else {}
146
161
  end
147
162
  end
148
163
 
164
+ def routes(packet, opts = {})
165
+ model = opts if opts.is_a? model_class
166
+ model ||= opts[:model] || model_class.get(opts[:resource_id])
167
+ orange[:sitemap].routes_for(packet, {:resource => :pages, :resource_id => model.id})
168
+ end
169
+
149
170
  def sitemap_row(packet, opts = {})
150
171
  do_view(packet, :sitemap_row, opts)
151
172
  end
@@ -4,8 +4,8 @@ require 'dm-is-awesome_set'
4
4
  class OrangeRoute < Orange::SiteCarton
5
5
  id
6
6
  admin do
7
- text :slug, :display_name => "Search Engine Friendly Page URL"
8
- text :link_text
7
+ text :slug, :display_name => "Search Engine Friendly Page URL", :length => 255
8
+ text :link_text, :length => 255
9
9
  text :reroute_to, :length => 255
10
10
  boolean :show_in_nav, :default => false, :display_name => 'Show in Navigation?'
11
11
  end
@@ -90,6 +90,26 @@ module Orange
90
90
  packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
91
91
  end
92
92
 
93
+ def show_in_nav(packet, opts = {})
94
+ no_reroute = opts.delete(:no_reroute)
95
+ if packet.request.post? || !opts.blank?
96
+ obj = find_one(packet, :show_in_nav, (opts[:id] || opts[:resource_id] || packet['route.resource_id']))
97
+ obj.show_in_nav = true
98
+ obj.save
99
+ end
100
+ packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
101
+ end
102
+
103
+ def unshow_in_nav(packet, opts = {})
104
+ no_reroute = opts.delete(:no_reroute)
105
+ if packet.request.post? || !opts.blank?
106
+ obj = find_one(packet, :unshow_in_nav, (opts[:id] || opts[:resource_id] || packet['route.resource_id']))
107
+ obj.show_in_nav = false
108
+ obj.save
109
+ end
110
+ packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
111
+ end
112
+
93
113
  def higher(packet, opts = {})
94
114
  move(packet, false, :direction => :higher)
95
115
  end
@@ -208,6 +228,17 @@ module Orange
208
228
  return 'route-'+model.id
209
229
  end
210
230
 
231
+ def link_text_for(route)
232
+ return route.link_text unless route.resource && route.resource_id
233
+ if match = route.link_text.match(/^\{([-a-z0-9A-Z_]+)\}$/)
234
+ resource = route.resource.to_sym
235
+ return route.link_text unless orange.loaded?(resource)
236
+ orange[resource].model_class.get(route.resource_id).__send__(match[1])
237
+ else
238
+ route.link_text
239
+ end
240
+ end
241
+
211
242
  def slug(str)
212
243
  str.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "-")
213
244
  end
@@ -4,4 +4,4 @@
4
4
  - for item in model.children
5
5
  - next unless item.show_in_nav
6
6
  %li
7
- %a{:href => item.full_path}= item.link_text
7
+ %a{:href => item.full_path}= orange[:sitemap].link_text_for(item)
@@ -16,7 +16,7 @@
16
16
  .move_actions.dent_actions
17
17
  = form_link('Indent', route_to(model_name, model.id, 'indent'), false, {:method => 'post', :class => 'indent arrow'}) if model.previous_sibling && model.previous_sibling.level == model.level
18
18
  %p= '&nbsp;'
19
- %h4 #{model.link_text} <span>(#{model.full_path})</span>
19
+ %h4 #{orange[:sitemap].link_text_for(item)} <span>(#{model.full_path})</span>
20
20
  .linked_to
21
21
  %p
22
22
  Linked to:
@@ -4,9 +4,10 @@
4
4
  - for item in model.children
5
5
  - next unless item.show_in_nav
6
6
  %li
7
- %a{:href => item.full_path}= item.link_text
7
+ %a{:href => item.full_path}= orange[:sitemap].link_text_for(item)
8
8
  - unless item.descendants.empty?
9
9
  %ul.subnav
10
10
  - for x in item.children
11
+ - next unless x.show_in_nav
11
12
  %li
12
- %a{:href => x.full_path}= x.link_text
13
+ %a{:href => x.full_path}= orange[:sitemap].link_text_for(x)
@@ -23,8 +23,8 @@ module Orange
23
23
  packet.reroute(@my_orange_name, :orange)
24
24
  end
25
25
 
26
- def url_for(packet)
27
- orange[:sitemap].url_for(packet, {:resource => 'subsites', :resource_id => packet['subsite'].id})
26
+ def url_for(packet, opts = {})
27
+ orange[:sitemap].url_for(packet, {:resource => 'subsites', :resource_id => (opts.is_a?(model_class) ? opts.id : packet['subsite'].id)})
28
28
  end
29
29
 
30
30
  def subsite_nav(packet, opts = {})
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Haslem
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-24 00:00:00 -04:00
17
+ date: 2010-06-01 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -107,6 +107,7 @@ files:
107
107
  - lib/orange-core/resources/page_parts.rb
108
108
  - lib/orange-core/resources/parser.rb
109
109
  - lib/orange-core/resources/routable_resource.rb
110
+ - lib/orange-core/resources/scaffold.rb
110
111
  - lib/orange-core/stack.rb
111
112
  - lib/orange-core/templates/exceptions.haml
112
113
  - lib/orange-core/views/default_resource/create.haml
@@ -148,7 +149,9 @@ files:
148
149
  - lib/orange-more/assets/cartons/asset_carton.rb
149
150
  - lib/orange-more/assets/plugin.rb
150
151
  - lib/orange-more/assets/resources/asset_resource.rb
152
+ - lib/orange-more/assets/views/assets/change.haml
151
153
  - lib/orange-more/assets/views/assets/create.haml
154
+ - lib/orange-more/assets/views/assets/insert.haml
152
155
  - lib/orange-more/blog.rb
153
156
  - lib/orange-more/blog/cartons/blog.rb
154
157
  - lib/orange-more/blog/cartons/blog_post.rb