refinerycms 0.9.5.31 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/.gitignore +1 -0
  2. data/VERSION +1 -1
  3. data/bin/refinery +2 -1
  4. data/config/environment.rb +1 -1
  5. data/config/environments/development.rb +3 -0
  6. data/contributors.md +2 -0
  7. data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +13 -0
  8. data/db/migrate/20100204011654_change_part_titles_to_titleized_version_for_new_format.rb +13 -0
  9. data/db/schema.rb +6 -10
  10. data/public/javascripts/admin.js +1 -1
  11. data/public/javascripts/jquery-ui-1.8rc1.min.js +375 -0
  12. data/public/javascripts/jquery.js +4231 -2529
  13. data/public/javascripts/refinery/admin.js +609 -38
  14. data/public/javascripts/refinery/boot_wym.js +3 -3
  15. data/public/javascripts/thickbox.js +116 -129
  16. data/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +3674 -3732
  17. data/public/javascripts/wymeditor/skins/refinery/skin.js +8 -8
  18. data/public/stylesheets/refinery/refinery.css +142 -32
  19. data/public/stylesheets/wymeditor/skins/refinery/skin.css +8 -1
  20. data/readme.md +35 -21
  21. data/test/fixtures/page_parts.yml +9 -0
  22. data/test/fixtures/pages.yml +88 -0
  23. data/test/performance/browsing_test.rb +9 -0
  24. data/test/test_helper.rb +38 -0
  25. data/test/unit/image_test.rb +14 -0
  26. data/test/unit/page_part_test.rb +19 -0
  27. data/test/unit/page_test.rb +130 -0
  28. data/vendor/plugins/authentication/app/controllers/sessions_controller.rb +1 -1
  29. data/vendor/plugins/authentication/app/views/admin/users/index.html.erb +1 -2
  30. data/vendor/plugins/authentication/authentication.md +9 -1
  31. data/vendor/plugins/dashboard/dashboard.md +3 -3
  32. data/vendor/plugins/images/app/controllers/admin/images_controller.rb +17 -13
  33. data/vendor/plugins/images/app/helpers/admin/images_helper.rb +6 -0
  34. data/vendor/plugins/images/app/models/image.rb +24 -39
  35. data/vendor/plugins/images/app/views/admin/images/_form.html.erb +11 -4
  36. data/vendor/plugins/images/app/views/admin/images/_grid_view.html.erb +1 -2
  37. data/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb +1 -2
  38. data/vendor/plugins/images/app/views/admin/images/index.html.erb +1 -1
  39. data/vendor/plugins/images/app/views/admin/images/insert.html.erb +8 -71
  40. data/vendor/plugins/images/images.md +12 -7
  41. data/vendor/plugins/inquiries/app/views/admin/inquiries/_inquiry.html.erb +6 -13
  42. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/index.html.erb +1 -2
  43. data/vendor/plugins/inquiries/inquiries.md +8 -8
  44. data/vendor/plugins/news/app/views/admin/news_items/_news_item.html.erb +1 -2
  45. data/vendor/plugins/news/news.md +4 -4
  46. data/vendor/plugins/pages/app/controllers/admin/page_dialogs_controller.rb +11 -10
  47. data/vendor/plugins/pages/app/controllers/admin/page_parts_controller.rb +5 -1
  48. data/vendor/plugins/pages/app/controllers/admin/pages_controller.rb +2 -2
  49. data/vendor/plugins/pages/app/models/page.rb +75 -29
  50. data/vendor/plugins/pages/app/models/page_part.rb +1 -1
  51. data/vendor/plugins/pages/app/views/admin/page_dialogs/_page_link.html.erb +2 -2
  52. data/vendor/plugins/pages/app/views/admin/page_dialogs/link_to.html.erb +8 -112
  53. data/vendor/plugins/pages/app/views/admin/pages/_form.html.erb +50 -154
  54. data/vendor/plugins/pages/app/views/admin/pages/_list.html.erb +10 -10
  55. data/vendor/plugins/pages/app/views/admin/pages/_page_part_field.html.erb +4 -4
  56. data/vendor/plugins/pages/app/views/admin/pages/_sortable_list.html.erb +1 -1
  57. data/vendor/plugins/pages/pages.md +30 -25
  58. data/vendor/plugins/refinery/app/views/admin/_head.html.erb +5 -14
  59. data/vendor/plugins/refinery/app/views/admin/_menu.html.erb +2 -64
  60. data/vendor/plugins/refinery/app/views/shared/_message.html.erb +0 -6
  61. data/vendor/plugins/refinery/app/views/shared/admin/_error_messages_for.html.erb +1 -6
  62. data/vendor/plugins/refinery/app/views/shared/admin/_form_actions.html.erb +8 -10
  63. data/vendor/plugins/refinery/app/views/shared/admin/_image_picker.html.erb +22 -38
  64. data/vendor/plugins/refinery/app/views/shared/admin/_make_sortable.html.erb +6 -65
  65. data/vendor/plugins/refinery/app/views/shared/admin/_resource_picker.html.erb +16 -16
  66. data/vendor/plugins/refinery/app/views/shared/admin/_sortable_list.html.erb +3 -4
  67. data/vendor/plugins/refinery/lib/crud.rb +1 -1
  68. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_singular_name.html.erb +1 -1
  69. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_sortable_list.html.erb +1 -1
  70. data/vendor/plugins/refinery/plugins.md +19 -12
  71. data/vendor/plugins/refinery_dialogs/app/controllers/admin/dialogs_controller.rb +6 -4
  72. data/vendor/plugins/refinery_dialogs/app/views/admin/dialogs/show.html.erb +3 -3
  73. data/vendor/plugins/refinery_dialogs/app/views/layouts/admin_dialog.html.erb +7 -14
  74. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_refinery_setting.html.erb +1 -1
  75. data/vendor/plugins/refinery_settings/settings.md +51 -1
  76. data/vendor/plugins/resources/app/controllers/admin/resources_controller.rb +16 -11
  77. data/vendor/plugins/resources/app/views/admin/resources/_form.html.erb +9 -2
  78. data/vendor/plugins/resources/app/views/admin/resources/_resource.html.erb +1 -3
  79. data/vendor/plugins/resources/app/views/admin/resources/index.html.erb +2 -2
  80. data/vendor/plugins/resources/app/views/admin/resources/insert.html.erb +14 -60
  81. data/vendor/plugins/resources/resources.md +1 -1
  82. data/vendor/plugins/themes/app/controllers/admin/themes_controller.rb +6 -6
  83. data/vendor/plugins/themes/app/models/theme.rb +3 -3
  84. data/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb +14 -20
  85. data/vendor/plugins/themes/themes.md +21 -19
  86. metadata +18 -19
  87. data/public/javascripts/builder.js +0 -136
  88. data/public/javascripts/controls.js +0 -963
  89. data/public/javascripts/dragdrop.js +0 -973
  90. data/public/javascripts/effects.js +0 -1128
  91. data/public/javascripts/fastinit.js +0 -84
  92. data/public/javascripts/livepipe.js +0 -180
  93. data/public/javascripts/prototype.js +0 -4874
  94. data/public/javascripts/refinery/dialog.js +0 -52
  95. data/public/javascripts/refinery/parse_url.js +0 -38
  96. data/public/javascripts/refinery/prototype.enhancements.js +0 -24
  97. data/public/javascripts/refinery/tooltips.js +0 -173
  98. data/public/javascripts/scriptaculous.js +0 -47
  99. data/public/javascripts/slider.js +0 -275
  100. data/public/javascripts/tabs.js +0 -149
  101. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_make_sortable.html.erb +0 -7
@@ -1,7 +1,11 @@
1
1
  class Admin::PagePartsController < Admin::BaseController
2
2
 
3
3
  def new
4
- render :partial => "/admin/pages/page_part_field", :locals => {:title => params[:title], :body => params[:body], :new_part => true, :part_index => params[:part_index]}
4
+ render :partial => "/admin/pages/page_part_field", :locals => {
5
+ :part => PagePart.new(:title => params[:title], :body => params[:body]),
6
+ :new_part => true,
7
+ :part_index => params[:part_index]
8
+ }
5
9
  end
6
10
 
7
11
  def destroy
@@ -5,7 +5,7 @@ class Admin::PagesController < Admin::BaseController
5
5
 
6
6
  def new
7
7
  @page = Page.new
8
- RefinerySetting.find_or_set(:default_page_parts, ["body", "side_body"]).each do |page_part|
8
+ RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |page_part|
9
9
  @page.parts << PagePart.new(:title => page_part)
10
10
  end
11
11
  end
@@ -15,4 +15,4 @@ protected
15
15
  expire_fragment(%r{site_menu})
16
16
  end
17
17
 
18
- end
18
+ end
@@ -3,39 +3,54 @@ class Page < ActiveRecord::Base
3
3
  validates_presence_of :title
4
4
 
5
5
  acts_as_tree :order => "position ASC", :include => [:children, :slugs]
6
-
6
+
7
+ # Docs for friendly_id http://github.com/norman/friendly_id
7
8
  has_friendly_id :title, :use_slug => true, :strip_diacritics => true
8
9
 
9
- belongs_to :image
10
- belongs_to :custom_title_image, :class_name => "Image"
11
-
12
10
  has_many :parts, :class_name => "PagePart", :order => "position ASC"
13
11
  accepts_nested_attributes_for :parts, :allow_destroy => true
14
-
12
+
13
+ # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
15
14
  acts_as_indexed :fields => [:title, :meta_keywords, :meta_description, :custom_title, :browser_title, :all_page_part_content],
16
- :index_file => %W(#{RAILS_ROOT} tmp index)
15
+ :index_file => %W(#{RAILS_ROOT} tmp index)
17
16
 
18
17
  before_destroy :deletable?
19
18
 
20
- # deletable needs to check a couple other fields too
19
+ # when a dialog pops up to link to a page, how many pages per page should there be
20
+ PAGES_PER_DIALOG = 14
21
+
22
+ # when listing pages out in the admin area, how many pages should show per page
23
+ PAGES_PER_ADMIN_INDEX = 20
24
+
25
+ # when collecting the pages path how is each of the pages seperated?
26
+ PATH_SEPERATOR = " - "
27
+
28
+ # Am I allowed to delete this page?
29
+ # If a link_url is set we don't want to break the link so we don't allow them to delete
30
+ # If deletable is set to false then we don't allow this page to be deleted. These are often Refinery system pages
21
31
  def deletable?
22
32
  self.deletable && self.link_url.blank? and self.menu_match.blank?
23
33
  end
24
34
 
25
- # provide helpful feedback
35
+ # Before destroying a page we check to see if it's a deletable page or not
36
+ # Refinery system pages are not deletable.
26
37
  def destroy
27
38
  if self.deletable?
28
39
  super
29
40
  else
30
- puts "This page is not deletable. Please use .destroy! if you really want it gone or first:"
31
- puts "unset .link_url" if self.link_url.present?
32
- puts "unset .menu_match" if self.menu_match.present?
33
- puts "set .deletable to true" unless self.deletable
41
+ unless RAILS_ENV == "test"
42
+ # give useful feedback when trying to delete from console
43
+ puts "This page is not deletable. Please use .destroy! if you really want it deleted "
44
+ puts "unset .link_url," if self.link_url.present?
45
+ puts "unset .menu_match," if self.menu_match.present?
46
+ puts "set .deletable to true" unless self.deletable
47
+ end
48
+
34
49
  return false
35
50
  end
36
51
  end
37
52
 
38
- # provide a method to definitely get rid of the page.
53
+ # If you want to destroy a page that is set to be not deletable this is the way to do it.
39
54
  def destroy!
40
55
  self.update_attributes({
41
56
  :menu_match => nil,
@@ -45,17 +60,29 @@ class Page < ActiveRecord::Base
45
60
  self.destroy
46
61
  end
47
62
 
48
- # used for the browser title to get the full path to this page
63
+ def indented_title
64
+ "#{"--" * self.ancestors.size} #{self.title}".chomp
65
+ end
66
+
67
+ # Used for the browser title to get the full path to this page
68
+ # It automatically prints out this page title and all of it's parent page titles joined by a PATH_SEPERATOR
49
69
  def path(reverse = true)
50
70
  unless self.parent.nil?
51
71
  parts = [self.title, self.parent.path(reverse)]
52
72
  parts.reverse! if reverse
53
- parts.join(" - ")
73
+ parts.join(PATH_SEPERATOR)
54
74
  else
55
75
  self.title
56
76
  end
57
77
  end
58
-
78
+
79
+ # When this page is rendered in the navigation, where should it link?
80
+ # If a custom "link_url" is set, it uses that otherwise it defaults to a normal page URL.
81
+ # The "link_url" is often used to link to a plugin rather than a page.
82
+ #
83
+ # For example if I had a "Contact Us" page I don't want it to just render a contact us page
84
+ # I want it to show the Inquiries form so I can collect inquiries. So I would set the "link_url"
85
+ # to "/inquiries/new"
59
86
  def url
60
87
  if self.link_url.present?
61
88
  self.link_url
@@ -63,54 +90,73 @@ class Page < ActiveRecord::Base
63
90
  "/pages/#{self.to_param}"
64
91
  end
65
92
  end
66
-
93
+
94
+ # Returns true if this page is "published"
67
95
  def live?
68
96
  not self.draft?
69
97
  end
70
-
98
+
99
+ # Return true if this page can be shown in the navigation. If it's a draft or is set to not show in the menu it will return false.
71
100
  def in_menu?
72
- self.live? and self.show_in_menu?
101
+ is_in_menu = self.live? && self.show_in_menu?
102
+ self.ancestors.each {|a| is_in_menu = false unless a.in_menu? }
103
+ is_in_menu
73
104
  end
74
-
105
+
106
+ # Returns true if this page is the home page or links to it.
75
107
  def home?
76
108
  self.link_url == "/"
77
109
  end
78
-
110
+
111
+ # Returns all visible sibling pages that can be rendered for the menu
79
112
  def shown_siblings
80
113
  self.siblings.reject { |sibling| not sibling.in_menu? }
81
114
  end
82
-
115
+
116
+ # Returns all the top level pages, usually to render the top level navigation.
83
117
  def self.top_level(include_children = false)
84
118
  include_associations = [:parts]
85
119
  include_associations.push(:slugs) if self.class.methods.include? "find_one_with_friendly"
86
120
  include_associations.push(:children) if include_children
87
121
  find_all_by_parent_id(nil,:conditions => {:show_in_menu => true, :draft => false}, :order => "position ASC", :include => include_associations)
88
122
  end
89
-
123
+
124
+ # Accessor method to get a page part from a page.
125
+ # Example:
126
+ #
127
+ # Page.first[:body]
128
+ #
129
+ # Will return the body page part of the first page.
90
130
  def [](part_title)
91
131
  # don't want to override a super method when trying to call a page part.
92
132
  # the way that we call page parts seems flawed, will probably revert to page.parts[:title] in a future release.
93
133
  if (super_value = super).blank?
94
134
  # self.parts is already eager loaded so we can now just grab the first element matching the title we specified.
95
- part = self.parts.reject {|part| part.title != part_title.to_s}.first
135
+ part = self.parts.detect {|part| (part.title == part_title.to_s) || (part.title.downcase.gsub(" ", "_") == part_title.to_s.downcase.gsub(" ", "_")) }
96
136
 
97
137
  return part.body unless part.nil?
98
138
  end
99
139
 
100
140
  super_value
101
141
  end
102
-
142
+
143
+ # In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
103
144
  def title_with_meta
104
- "#{self.title} #{"<em>(hidden)</em>" unless self.show_in_menu?} #{"<em>(draft)</em>" if self.draft?}"
145
+ title = self.title
146
+ title << " <em>(hidden)</em>" unless self.show_in_menu?
147
+ title << " <em>(draft)</em>" if self.draft?
148
+
149
+ title.strip
105
150
  end
106
151
 
107
- # used for search only
152
+ # Used to index all the content on this page so it can be easily searched.
108
153
  def all_page_part_content
109
154
  self.parts.collect {|p| p.body}.join(" ")
110
155
  end
111
-
156
+
157
+ # Returns how many pages per page should there be when paginating pages
112
158
  def self.per_page(dialog = false)
113
- size = (dialog ? 14 : 20)
159
+ dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
114
160
  end
115
161
 
116
162
  end
@@ -7,4 +7,4 @@ class PagePart < ActiveRecord::Base
7
7
 
8
8
  has_friendly_id :title, :use_slug => true, :strip_diacritics => true
9
9
 
10
- end
10
+ end
@@ -1,5 +1,5 @@
1
- <% linked = (page_link.url == params[:current_link]) unless params[:current_link].blank? %>
1
+ <% linked = (page_link.url == params[:current_link]) if params[:current_link].present? %>
2
2
  <li class='clearfix<%= " child#{child}" if child %><%= " linked" if linked%>' id="<%= dom_id(page_link) -%>">
3
3
  <%= link_to page_link.title_with_meta, page_link.url, :title => 'Link to this Page', :rel => page_link.title, :class => 'page_link' %>
4
4
  </li>
5
- <%= render :partial => 'page_link', :collection => page_link.children, :locals => {:child => child ? (child+1) : 1} unless page_link.children.empty? %>
5
+ <%= render :partial => 'page_link', :collection => page_link.children, :locals => {:child => child ? (child+1) : 1} unless page_link.children.empty? %>
@@ -68,7 +68,7 @@
68
68
  <div id='web_address_content'>
69
69
  <label for='web_address_text'>Location</label>
70
70
  <%= text_field :web_address, :text, :value => web_address_text, :style => "width: 70%" %>
71
- <img id='web_address_test_loader' src='/images/refinery/ajax-loader.gif' alt='Testing...' style='display: none;'>
71
+ <img id='web_address_test_loader' src='/images/refinery/ajax-loader.gif' alt='Testing...' style='display: none;'/>
72
72
  <span id='web_address_test_result'></span>
73
73
 
74
74
  <label>New Window</label>
@@ -88,7 +88,7 @@
88
88
  <div class='field'>
89
89
  <label for='email_address_text'>Email Address</label>
90
90
  <%= text_field :email_address, :text, :value => email_address_text, :style => "width: 70%"%>
91
- <img id='web_address_test_loader' src='/images/refinery/ajax-loader.gif' alt='Testing...' style='display: none;'>
91
+ <img id='email_address_test_loader' src='/images/refinery/ajax-loader.gif' alt='Testing...' style='display: none;'/>
92
92
  <span id='email_address_test_result'></span>
93
93
  </div>
94
94
 
@@ -140,114 +140,10 @@
140
140
  </div>
141
141
 
142
142
  <% content_for :head do %>
143
- <script type='text/javascript'>
144
-
145
- FastInit.addOnLoad(function()
146
- {
147
- $$('.link_list li').each(function(li)
148
- {
149
- li.observe('click', function(ev)
150
- {
151
- ev.preventDefault();
152
-
153
- $$('.link_list li.linked').each(function(linked)
154
- {
155
- linked.removeClassName('linked');
156
- });
157
-
158
- this.addClassName('linked');
159
- var link = this.down('a.page_link');
160
- var port = (window.location.port.length > 0 ? (":" + window.location.port) : "")
161
- var url = link.href.gsub(window.location.protocol + "//" + window.location.hostname + port, "");
162
-
163
- parent.document.getElementById('wym_href').value = url;
164
- parent.document.getElementById('wym_title').value = link.rel;
165
- parent.document.getElementById('wym_target').value = '';
166
- });
167
- });
168
-
169
- $('web_address_text').observe('change', function(e)
170
- {
171
- var prefix = 'web_address_';
172
- $(prefix + 'test_loader').show();
173
-
174
- $(prefix + 'test_result').hide();
175
-
176
- var req = new Ajax.Request("<%= test_url_admin_pages_dialogs_url %>",
177
- {
178
- asynchronous: true
179
- , method: 'get'
180
- , parameters: {url: this.value}
181
- , onComplete: function(e)
182
- {
183
- $(prefix + 'test_result').update(e.transport.responseText).show();
184
- $(prefix + 'test_loader').hide();
185
- }
186
- });
187
-
188
- parent.document.getElementById('wym_href').value = $(prefix + 'text').value;
189
- parent.document.getElementById('wym_title').value = $(prefix + 'text').value;
190
- parent.document.getElementById('wym_target').value = ($(prefix + 'target_blank').checked ? "_blank" : "");
191
- });
192
-
193
- $('web_address_target_blank').observe('click', function(e)
194
- {
195
- parent.document.getElementById('wym_target').value = this.checked ? "_blank" : "";
196
- })
197
-
198
- $$('#email_address_text', '#email_default_subject_text', '#email_default_body_text').each(function(input)
199
- {
200
- input.observe('change', function(e)
201
- {
202
- var default_subject = $('email_default_subject_text').value;
203
- var default_body = $('email_default_body_text').value;
204
- var mailto = "mailto:" + $('email_address_text').value.replace('mailto:', '');
205
- $('email_address_test_result').hide();
206
-
207
- var req = new Ajax.Request("<%= test_email_admin_pages_dialogs_url %>",
208
- {
209
- asynchronous: true
210
- , method: 'get'
211
- , parameters: {email: mailto}
212
- , onComplete: function(e)
213
- {
214
- $('email_address_test_result').update(e.transport.responseText).show();
215
- $('email_address_test_loader').hide();
216
- }
217
- });
218
-
219
- var modifier = "?";
220
- if (default_subject.length > 0)
221
- {
222
- mailto += modifier + "subject=" + default_subject;
223
- modifier = "&";
224
- }
225
- if (default_body.length > 0)
226
- {
227
- mailto += modifier + "body=" + default_body;
228
- modifier = "&";
229
- }
230
-
231
- parent.document.getElementById('wym_href').value = mailto;
232
- parent.document.getElementById('wym_title').value = $('email_address_text').value.replace('mailto:', '');
233
- parent.document.getElementById('wym_target').value = '';
234
- });
235
- });
236
-
237
- $('link_to_your_page').observe('click', function(e)
238
- {
239
- $$('li.linked').each(function(li)
240
- {
241
- parent.document.getElementById('wym_href').value = li.down('a.page_link').href;
242
- parent.document.getElementById('wym_title').value = li.down('span').innerHTML.gsub(/<em>\((\w)*\)<\/em>/, "").trim();
243
- });
244
- });
245
- $('link_to_web_address').observe('click', function(e)
246
- {
247
- parent.document.getElementById('wym_href').value = $('web_address_text').value;
248
- parent.document.getElementById('wym_title').value = $('web_address_text').value;
249
- parent.document.getElementById('wym_target').value = ($('web_address_target_blank').checked ? "_blank" : "");
250
- });
251
- });
252
- </script>
143
+ <script type='text/javascript'>
144
+ $(document).ready(function(){
145
+ link_dialog.init('<%= test_url_admin_pages_dialogs_url %>',
146
+ '<%= test_email_admin_pages_dialogs_url %>');
147
+ });
148
+ </script>
253
149
  <% end %>
@@ -1,47 +1,52 @@
1
1
  <%= error_messages_for :page %>
2
2
 
3
3
  <% form_for [:admin, @page] do |f| %>
4
- <div class='field'>
4
+ <div class="field">
5
5
  <%= f.label :title %>
6
6
  <%= f.text_field :title, :class => "larger", :style => 'width: 954px' %>
7
7
  </div>
8
- <div class='clearfix'>
9
- <div class='clearfix'>
10
- <ul id='page_parts'>
11
- <% @page.parts.each do |p| %>
12
- <li class='tab<%= " active" if @page.parts.index(p) == 0 %>'>
13
- <%= link_to p.title.titleize, "#part_#{p.title}" %>
8
+ <div id="page-tabs" class="clearfix">
9
+ <ul id="page_parts">
10
+ <% @page.parts.each_with_index do |part, part_index| %>
11
+ <li>
12
+ <%= link_to part.title, "##{@page.new_record? ? "page_part_new_#{part_index}" : dom_id(part)}" %>
13
+ </li>
14
+ <% end %>
15
+ </ul>
16
+ <% if RefinerySetting.find_or_set(:new_page_parts, false) %>
17
+ <ul id="page_parts_controls">
18
+ <li>
19
+ <%= link_to refinery_icon_tag("add.png"), "#", :id => "add_page_part", :title => "Create Content Section" %>
20
+ </li>
21
+ <li>
22
+ <%= link_to(refinery_icon_tag("delete.png"), "#", :title => 'Delete content section', :class => 'delete_page_part', :name => "Delete Content Section", :id => "delete_page_part") %>
14
23
  </li>
15
- <% end %>
16
24
  </ul>
17
- <% if RefinerySetting.find_or_set(:new_page_parts, false) %>
18
- <ul id='page_parts_controls'>
19
- <li>
20
- <%= link_to refinery_icon_tag("add.png"), "#", :id => "add_page_part", :title => "Create Content Section" %>
21
- </li>
22
- <li>
23
- <%= link_to(refinery_icon_tag("delete.png"), "#", :title => 'Delete content section', :class => 'delete_page_part', :name => "Delete Content Section", :id => "delete_page_part") %>
24
- </li>
25
- </ul>
26
- <% end %>
27
- </div>
25
+ <% end %>
28
26
 
29
- <div id='page_part_editors'>
27
+ <div id='page_part_editors' style="clear:left">
30
28
  <% part_index = -1 %>
31
29
  <% f.fields_for :parts do |p| %>
32
- <%= render :partial => "page_part_field", :locals => {:title => p.object.title, :body => p.object.body, :part_index => (part_index += 1), :new_part => @page.new_record?} %>
30
+ <%= render :partial => "page_part_field", :locals => {
31
+ :part => p.object,
32
+ :part_index => (part_index += 1),
33
+ :new_part => @page.new_record?
34
+ } %>
33
35
  <% end %>
34
36
  </div>
35
37
  </div>
36
38
  <p>
37
- <%= link_to "&raquo; Hide/Show Advanced Options", "", :id => "toggle_advanced_options",
38
- :rel => "Click to access meta tag settings and menu options" %>
39
+ <a href="#" id="toggle_advanced_options" rel="Click to access meta tag settings and menu options">&raquo; Hide/Show Advanced Options</a>
39
40
  </p>
40
41
  <div id='more_options' style="display:none;">
42
+ <div class='field'>
43
+ <%= f.label :parent_id %>
44
+ <%= f.collection_select :parent_id, Page.find(:all, :order => "parent_id, position ASC"), :id, :indented_title, :include_blank => true %>
45
+ </div>
41
46
  <div class='field'>
42
47
  <%= label_tag :custom_title %>
43
48
  <%= label_tag "", 'Type:', :class => "stripped" %>
44
- <% ["none", "text", "image"].each do |type| %>
49
+ <% ["none", "text"].each do |type| %>
45
50
  <%= f.radio_button :custom_title_type, "#{type}" %>
46
51
  <%= label_tag "page_custom_title_type_#{type}", "#{type.titleize}", :class => "stripped" %>
47
52
  <% end %>
@@ -55,16 +60,6 @@
55
60
  </small>
56
61
  </p>
57
62
  </div>
58
- <div id='custom_title_image' style='display: <%= @page.custom_title_type == 'image' ? 'block' : 'none' %>' class='clearfix'>
59
- <%= render :partial => "/shared/admin/image_picker", :locals =>
60
- {
61
- :f => f,
62
- :field => :custom_title_image_id,
63
- :image => @page.custom_title_image,
64
- :toggle_image_display => false
65
- }
66
- %>
67
- </div>
68
63
  </div>
69
64
  <div class='field'>
70
65
  <%= label_tag :skip_to_first_child? %>
@@ -116,129 +111,30 @@
116
111
  <%= f.label :draft, "Save as Draft", :class => "stripped" %>
117
112
  </div>
118
113
  <%= render :partial => "/shared/admin/form_actions", :locals => {:f => f, :continue_editing => true} %>
119
- <div id='new_page_part_dialog' style='display: none'>
120
- <div class='field'>
121
- <label for='new_page_part_title'>Title</label>
122
- <input id='new_page_part_title' value='' class='larger' size='40' />
123
- <input id='new_page_part_index' type='hidden' value='<%= @page.parts.size %>' />
124
- </div>
125
- <div id='dialog-form-actions' class='form-actions'>
126
- <%= f.submit 'Save', :id => "new_page_part_save" %>
127
- or
128
- <%= link_to "Cancel", "", :id => "new_page_part_cancel", :class => "close_dialog" %>
114
+ <% if RefinerySetting.find_or_set(:new_page_parts, false) %>
115
+ <div id='new_page_part_dialog' style='display: none'>
116
+ <div class='field'>
117
+ <label for='new_page_part_title'>Title</label>
118
+ <input id='new_page_part_title' value='' class='larger' size='40' />
119
+ <input id='new_page_part_index' type='hidden' value='<%= @page.parts.size %>' />
120
+ </div>
121
+ <%= render :partial => "/shared/admin/form_actions", :locals => {
122
+ :f => f,
123
+ :continue_editing => false,
124
+ :submit_button_id => "new_page_part_save",
125
+ :cancel_button_id => "new_page_part_cancel"
126
+ } %>
129
127
  </div>
130
- </div>
128
+ <% end %>
131
129
  <% end %>
130
+
132
131
  <% content_for :head do %>
133
132
  <script type='text/javascript'>
134
- switch_custom_title_type = function(type)
135
- {
136
- $('custom_title_text').hide();
137
- $('custom_title_image').hide();
138
-
139
- $('custom_title_' + type).show();
140
- }
141
-
142
- FastInit.addOnLoad(function(){
143
- $('toggle_advanced_options').observe('click', function(e)
144
- {
145
- $('more_options').toggle();
146
- e.preventDefault();
147
- });
148
-
149
- $$('input[type=radio]').each(function(radio)
150
- {
151
- if (radio.name == 'page[custom_title_type]')
152
- {
153
- radio.observe('change', function(e)
154
- {
155
- switch_custom_title_type(this.value);
156
- });
157
- }
158
- });
159
-
160
- <% if RefinerySetting.find_or_set(:new_page_parts, false) %>
161
- $('add_page_part').observe('click', function(e) {
162
- tb_show('Create Content Section', '#?auto_size_content=true&draggable=true&titlebar=true&inlineId=new_page_part_dialog&TB_inline=true&modal=true');
163
-
164
- e.preventDefault();
165
- });
166
-
167
- $('new_page_part_save').observe('click', function(e) {
168
- if ((part_title = $('new_page_part_title').value).length > 0) {
169
- tab_title = part_title.toLowerCase().gsub(" ", "_");
170
- if ($$('#part_' + tab_title).size() == 0) {
171
- // first get the response from the server
172
- new Ajax.Request("<%= new_admin_page_part_url %>", {
173
- asynchronous: true
174
- , method: 'get'
175
- , parameters: {
176
- title: tab_title
177
- , part_index: $('new_page_part_index').value
178
- , body: ''
179
- }
180
- , onComplete: function(e){
181
- $('page_part_editors').insert(e.transport.responseText , {position: 'bottom'});
182
- // Add a new tab for the new content section.
183
- $$('#page_parts').first().insert((new Element("li").addClassName("tab").insert(new Element("a", {href: "#part_" + tab_title}).update(part_title))));
184
-
185
- // turn the new textarea into a wymeditor.
186
- jQuery('#page_parts_attributes_' + $('new_page_part_index').value + "_body").wymeditor(wymeditor_boot_options);
187
-
188
- // Wipe the title and increment the index counter by one.
189
- $('new_page_part_index').value = (parseInt($('new_page_part_index').value) + 1);
190
- $('new_page_part_title').value = "";
191
- }
192
- });
193
-
194
- tb_remove();
195
- } else {
196
- alert("A content section with that title already exists, please choose another.");
197
- }
198
- } else {
199
- alert("You have not entered a title for the content section, please enter one.");
200
- }
201
- });
202
-
203
- $('new_page_part_cancel').observe('click', function(e) {
204
- $('new_page_part_title').value = "";
205
- tb_remove();
206
- e.preventDefault();
207
- });
208
-
209
- $('delete_page_part').observe('click', function(e) {
210
- selected_part_link = $$('#page_parts li.active a').first();
211
- part_container = $(selected_part_link.getAttribute('href').gsub("#", ""));
212
- result = confirm("This will remove the content section '" + selected_part_link.innerHTML + "' when the page is saved and erase all content that has been entered into it, Are you sure?");
213
- if (result) {
214
- if ((part_id = $(part_container.down('textarea').id.gsub('_body', '_id'))) != null) {
215
- new Ajax.Request("<%= admin_page_parts_url %>/" + part_id.value, {
216
- asynchronous: true
217
- , method: "DELETE"
218
- , parameters:
219
- {
220
- authenticity_token: $$('input[name=authenticity_token]').first().value
221
- }
222
- });
223
- }
224
-
225
- // remove actual elements from DOM.
226
- part_container.remove();
227
- selected_part_link.up('li').remove();
228
-
229
- WYMeditor.loaded();
230
- }
231
-
232
- e.preventDefault();
233
- });
234
- <% end %>
133
+ $(document).ready(function(){
134
+ var page_parts = <%= RefinerySetting.find_or_set(:new_page_parts, false) == true ? 'true' : 'false' %>;
135
+ var new_part_url = "<%= new_admin_page_part_url %>";
136
+ var del_part_url = "<%= admin_page_parts_url %>";
137
+ page_options.init(page_parts, new_part_url, del_part_url);
235
138
  });
236
-
237
- // Hook into the loaded function. This will be called when WYMeditor has done its thing.
238
- WYMeditor.loaded = function()
239
- {
240
- new Control.Tabs('page_parts', {setClassOnContainer: true}).first();
241
- }
242
-
243
139
  </script>
244
- <% end %>
140
+ <% end %>