From 5ed537dc0161c2a0fa8c1cb65bccddcbf781ffa5 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 28 Aug 2007 22:48:50 +0000 Subject: [PATCH] ActionItem18: moving comatose_admin funcionalities inside new cms controller --- app/controllers/cms_controller.rb | 2 ++ app/views/cms/_form.rhtml | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/views/cms/_page_list_item.rhtml | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/views/cms/delete.rhtml | 18 ++++++++++++++++++ app/views/cms/edit.rhtml | 5 +++++ app/views/cms/index.rhtml | 18 ++++++++++++++++++ app/views/cms/new.rhtml | 5 +++++ app/views/cms/reorder.rhtml | 30 ++++++++++++++++++++++++++++++ app/views/cms/versions.rhtml | 44 ++++++++++++++++++++++++++++++++++++++++++++ app/views/comatose_admin/_form.rhtml | 86 -------------------------------------------------------------------------------------- app/views/comatose_admin/_page_list_item.rhtml | 57 --------------------------------------------------------- app/views/comatose_admin/delete.rhtml | 18 ------------------ app/views/comatose_admin/edit.rhtml | 5 ----- app/views/comatose_admin/index.rhtml | 18 ------------------ app/views/comatose_admin/new.rhtml | 5 ----- app/views/comatose_admin/reorder.rhtml | 30 ------------------------------ app/views/comatose_admin/versions.rhtml | 44 -------------------------------------------- app/views/layouts/application.rhtml | 8 ++++---- config/routes.rb | 2 +- public/javascripts/cms.js | 401 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/javascripts/comatose_admin.js | 401 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public/stylesheets/comatose_admin.css | 4 ++++ test/functional/cms_controller_test.rb | 18 ++++++++++++++++++ 23 files changed, 693 insertions(+), 669 deletions(-) create mode 100644 app/controllers/cms_controller.rb create mode 100644 app/views/cms/_form.rhtml create mode 100644 app/views/cms/_page_list_item.rhtml create mode 100644 app/views/cms/delete.rhtml create mode 100644 app/views/cms/edit.rhtml create mode 100644 app/views/cms/index.rhtml create mode 100644 app/views/cms/new.rhtml create mode 100644 app/views/cms/reorder.rhtml create mode 100644 app/views/cms/versions.rhtml delete mode 100644 app/views/comatose_admin/_form.rhtml delete mode 100644 app/views/comatose_admin/_page_list_item.rhtml delete mode 100644 app/views/comatose_admin/delete.rhtml delete mode 100644 app/views/comatose_admin/edit.rhtml delete mode 100644 app/views/comatose_admin/index.rhtml delete mode 100644 app/views/comatose_admin/new.rhtml delete mode 100644 app/views/comatose_admin/reorder.rhtml delete mode 100644 app/views/comatose_admin/versions.rhtml create mode 100644 public/javascripts/cms.js delete mode 100644 public/javascripts/comatose_admin.js create mode 100644 test/functional/cms_controller_test.rb diff --git a/app/controllers/cms_controller.rb b/app/controllers/cms_controller.rb new file mode 100644 index 0000000..e545aed --- /dev/null +++ b/app/controllers/cms_controller.rb @@ -0,0 +1,2 @@ +class CmsController < ComatoseAdminController +end diff --git a/app/views/cms/_form.rhtml b/app/views/cms/_form.rhtml new file mode 100644 index 0000000..54fbe91 --- /dev/null +++ b/app/views/cms/_form.rhtml @@ -0,0 +1,86 @@ +<%= error_messages_for :page %> + +<% form_for :page, @page do |f| %> + +
+ + <%= f.text_field :title, :tabindex => 1, :maxlength => 255, :size => 30 %> <%= link_to_function "More...", "ComatoseEditForm.toggle_extra_fields(this, '%s', '%s')" % [_('More...'), _('Less...')], :id => 'more-options' %> +
+ +
+ + <%= f.text_field :slug, :tabindex=>6, :maxlength=>255, :size=>50, :disabled=>@root_pages.include?(@page) %> +
+ +
+ <% if show_field? 'keywords' %> + + <%= f.text_field :keywords, :tabindex=>7, :maxlength=>1000, :size=>50 %> + <% end %> +
+ +
+ <% if show_field? 'parent' %> + + <% if mode != :new and @root_pages.include? @page %> + + <% else %> + + <% end %> + <% end %> +
+ +
+ + <%= f.text_area :body, :rows => 14, :tabindex => 2 %> +
+ +
+ <% if show_field? 'filter' %> + + <%= select_tag 'page[filter_type]', options_for_select(TextFilters.all_titles.sort, @page.filter_type || Comatose.config.default_filter), :tabindex=>3, :id=>'page_filter_type' %> + <%= _('Converts plain text into HTML') %> + <% end %> +
+ +
+ <% if show_field? 'created_on' %> + + <%= f.datetime_select :created_on %> + <% end %> +
+ +
+<% unless @page.updated_on.nil? %> +
+ +
+<% end %> + +<%= image_tag 'comatose/spinner.gif', :id=>'spinner', :align=>'absmiddle', :style=>'display:none;' %> + <%= button_to_function('Preview', "ComatoseEditForm.preview_content('#{url_for :controller=>controller.controller_name, :action=>'preview', :id=>@page}', '%s')" % _('Loading preview ...'), :tabindex=>3, :id=>'preview-btn' ) if show_field? 'preview' %>   + <%= submit_tag ((mode == :edit) ? _('Save Changes') : _('Create Page')), :tabindex=>4 %> + <% if @page.versions.length > 0 %> +   <%= link_to _("Revert"), :action=>'versions', :id=>@page %> + <% end %> + or + <%= _("Cancel") %> +
+<% end %> + + + +<%= javascript_tag "ComatoseEditForm.init('#{mode.to_s}');" %> diff --git a/app/views/cms/_page_list_item.rhtml b/app/views/cms/_page_list_item.rhtml new file mode 100644 index 0000000..bbec58b --- /dev/null +++ b/app/views/cms/_page_list_item.rhtml @@ -0,0 +1,57 @@ +<%# Params: +# - page (Page Node) +# - level (integer indicating current tree depth) +# Called From: +# - index +# Description: +# This partial is used recursively. Render it with the root node, and it will recurse +# down all of the child nodes to build a list with proper indentation to indicate +# tree depth. +%> + +<% +# Create the page-level links... +links = [] +links << link_to(pluralize(page.versions.length, 'revision', 'revisions'), :action=>'versions', :id=>page) if page.versions.length > 0 +links << link_to('add child page', {:action=>'new', :parent=>page}, :title=> _("Add a child to '%s'") % page.title, :class=>'add-page') +links << link_to_function('reorder children', "ComatoseList.toggle_reorder('page_list_#{page.id}',this,#{page.id}, '%s', '%s')" % [_('reorder children'), _('finished reordering')], :title=> _("Reorder children of '%s'") % page.title, :class=>'reorder-children', :href=>url_for(:action=>'reorder', :id=>page)) if !page.children.empty? and page.children.length > 1 +links << link_to('delete', {:action=>'delete', :id=>page}, :confirm=> _('This will delete this page, and any children. Are you sure?'), :title=> _("Delete page '%s' and all it's children") % page.title, :class=>'delete-page', :method=>'post', :onmouseover=>"ComatoseList.item_hover('page_#{page.id}', 'over', true)", :onmouseout=>"ComatoseList.item_hover('page_#{page.id}', 'out', true)") unless @root_pages.include? page +# Level check, one, two, three... +collapse_children = (level >= Comatose.config.default_tree_level) +%> + +
  • + + + + + + + +
    + <% if !page.children.empty? %> + <%= image_tag( ((collapse_children) ? 'comatose/collapsed.gif' : 'comatose/expanded.gif'), :title=>'Expand/Collapse', :onclick=>"ComatoseList.toggle_tree_nodes(this,#{page.id});", :class=>'tree-controller', :size=>'12x12', :id=>"page_controller_#{page.id}" ) %> + <% else %> + <%= image_tag 'comatose/no-children.gif', :size=>'12x12', :class=>'tree-controller' %> + <% end %> + + <%= icon_for_document(page) %> + <%= _('DRAG') %> + + <%= link_to page.title, {:action=>'edit', :id=>page}, :title=>"Path:#{page.full_path}", :class=>'page' %> + + <%= links.join(', ') %>. +
    + + + + <%= sortable_element( "page_list_#{page.id}", + :complete => visual_effect(:highlight, "page_list_#{page.id}"), + :handle=>'handle', + :update=>'flash-content', + :url => { :action => "reorder", :id=>page } ) if !page.children.empty? and page.children.length > 1 %> +
  • diff --git a/app/views/cms/delete.rhtml b/app/views/cms/delete.rhtml new file mode 100644 index 0000000..fd3dd07 --- /dev/null +++ b/app/views/cms/delete.rhtml @@ -0,0 +1,18 @@ +

    + Page Delete Confirmation +

    + +
    +

    <%= _('Are you sure you want to delete the page titled "%s"?') % content_tag('strong', @page.title) %>

    + <% unless @page.children.empty? %> +

    <%= _("It has %s child pages that will also be deleted...") % content_tag('strong', @page.children.length) %>

    +<% end %> +
    + +<%= start_form_tag %> +
    + <%= submit_tag _("Yes, Delete The Page") %> + or + <%= link_to _("Cancel"), :action=>'index' %> +
    +<%= end_form_tag %> diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml new file mode 100644 index 0000000..6b2f158 --- /dev/null +++ b/app/views/cms/edit.rhtml @@ -0,0 +1,5 @@ +

    + <%= _("Edit Page") %> +

    + +<%= render :partial=>'form', :locals=>{:mode=>:edit} %> diff --git a/app/views/cms/index.rhtml b/app/views/cms/index.rhtml new file mode 100644 index 0000000..826c4e3 --- /dev/null +++ b/app/views/cms/index.rhtml @@ -0,0 +1,18 @@ +
    + <%= link_to 'Clear Page Cache', :controller=>controller.controller_name, :action=>'expire_page_cache' %> +
    + +

    + <%= _('Document List') %> + <%= image_tag 'comatose/spinner.gif', :id=>'spinner', :align=>'absmiddle', :style=>'display:none;' %> +

    + + + +
    + +<%= javascript_tag "ComatoseList.init()" %> diff --git a/app/views/cms/new.rhtml b/app/views/cms/new.rhtml new file mode 100644 index 0000000..26bf982 --- /dev/null +++ b/app/views/cms/new.rhtml @@ -0,0 +1,5 @@ +

    + <%= _('New Page') %> +

    + +<%= render :partial=>'form', :locals=>{:mode=>:new} %> diff --git a/app/views/cms/reorder.rhtml b/app/views/cms/reorder.rhtml new file mode 100644 index 0000000..d839538 --- /dev/null +++ b/app/views/cms/reorder.rhtml @@ -0,0 +1,30 @@ +

    <%= _('Reorder Pages') %>

    + +

    <%= _('"%s" child pages:') % @page.title %>

    + + + +
    + <%= link_to _("Finished"), :action=>'index' %> +
    diff --git a/app/views/cms/versions.rhtml b/app/views/cms/versions.rhtml new file mode 100644 index 0000000..c470c55 --- /dev/null +++ b/app/views/cms/versions.rhtml @@ -0,0 +1,44 @@ +

    <%= _('Page Revisions') %>

    +
    +
    +
    +
    + <% form_tag :action => 'versions', :id => @page, :html => { :method => :get } do %> + <%= _('View Version:') %><%= select_tag "version", options_from_collection_for_select(@page.versions, 'version', 'version', @version_num), {'onchange'=>'this.form.submit();'} %> + <%= submit_tag 'Go', {'id'=>'go-btn'} %> + <% end %> +
    + <%= _('Version %s') % @version_num %> +
    +
    + + + <% if show_field? 'keywords' %> + + <% end %> +
    + <%= @version.body.split("\n").join('
    ') unless @version.body.nil? %> + +
    + +
    +
    + <% _('Current Version') %> +
    +
    + + + <% if show_field? 'keywords' %> + + <% end %> +
    + <%= @page.body.split("\n").join('
    ') unless @page.body.nil? %> +
    + +
     
    diff --git a/app/views/comatose_admin/_form.rhtml b/app/views/comatose_admin/_form.rhtml deleted file mode 100644 index 54fbe91..0000000 --- a/app/views/comatose_admin/_form.rhtml +++ /dev/null @@ -1,86 +0,0 @@ -<%= error_messages_for :page %> - -<% form_for :page, @page do |f| %> - -
    - - <%= f.text_field :title, :tabindex => 1, :maxlength => 255, :size => 30 %> <%= link_to_function "More...", "ComatoseEditForm.toggle_extra_fields(this, '%s', '%s')" % [_('More...'), _('Less...')], :id => 'more-options' %> -
    - -
    - - <%= f.text_field :slug, :tabindex=>6, :maxlength=>255, :size=>50, :disabled=>@root_pages.include?(@page) %> -
    - -
    - <% if show_field? 'keywords' %> - - <%= f.text_field :keywords, :tabindex=>7, :maxlength=>1000, :size=>50 %> - <% end %> -
    - -
    - <% if show_field? 'parent' %> - - <% if mode != :new and @root_pages.include? @page %> - - <% else %> - - <% end %> - <% end %> -
    - -
    - - <%= f.text_area :body, :rows => 14, :tabindex => 2 %> -
    - -
    - <% if show_field? 'filter' %> - - <%= select_tag 'page[filter_type]', options_for_select(TextFilters.all_titles.sort, @page.filter_type || Comatose.config.default_filter), :tabindex=>3, :id=>'page_filter_type' %> - <%= _('Converts plain text into HTML') %> - <% end %> -
    - -
    - <% if show_field? 'created_on' %> - - <%= f.datetime_select :created_on %> - <% end %> -
    - -
    -<% unless @page.updated_on.nil? %> -
    - -
    -<% end %> - -<%= image_tag 'comatose/spinner.gif', :id=>'spinner', :align=>'absmiddle', :style=>'display:none;' %> - <%= button_to_function('Preview', "ComatoseEditForm.preview_content('#{url_for :controller=>controller.controller_name, :action=>'preview', :id=>@page}', '%s')" % _('Loading preview ...'), :tabindex=>3, :id=>'preview-btn' ) if show_field? 'preview' %>   - <%= submit_tag ((mode == :edit) ? _('Save Changes') : _('Create Page')), :tabindex=>4 %> - <% if @page.versions.length > 0 %> -   <%= link_to _("Revert"), :action=>'versions', :id=>@page %> - <% end %> - or - <%= _("Cancel") %> -
    -<% end %> - - - -<%= javascript_tag "ComatoseEditForm.init('#{mode.to_s}');" %> diff --git a/app/views/comatose_admin/_page_list_item.rhtml b/app/views/comatose_admin/_page_list_item.rhtml deleted file mode 100644 index bbec58b..0000000 --- a/app/views/comatose_admin/_page_list_item.rhtml +++ /dev/null @@ -1,57 +0,0 @@ -<%# Params: -# - page (Page Node) -# - level (integer indicating current tree depth) -# Called From: -# - index -# Description: -# This partial is used recursively. Render it with the root node, and it will recurse -# down all of the child nodes to build a list with proper indentation to indicate -# tree depth. -%> - -<% -# Create the page-level links... -links = [] -links << link_to(pluralize(page.versions.length, 'revision', 'revisions'), :action=>'versions', :id=>page) if page.versions.length > 0 -links << link_to('add child page', {:action=>'new', :parent=>page}, :title=> _("Add a child to '%s'") % page.title, :class=>'add-page') -links << link_to_function('reorder children', "ComatoseList.toggle_reorder('page_list_#{page.id}',this,#{page.id}, '%s', '%s')" % [_('reorder children'), _('finished reordering')], :title=> _("Reorder children of '%s'") % page.title, :class=>'reorder-children', :href=>url_for(:action=>'reorder', :id=>page)) if !page.children.empty? and page.children.length > 1 -links << link_to('delete', {:action=>'delete', :id=>page}, :confirm=> _('This will delete this page, and any children. Are you sure?'), :title=> _("Delete page '%s' and all it's children") % page.title, :class=>'delete-page', :method=>'post', :onmouseover=>"ComatoseList.item_hover('page_#{page.id}', 'over', true)", :onmouseout=>"ComatoseList.item_hover('page_#{page.id}', 'out', true)") unless @root_pages.include? page -# Level check, one, two, three... -collapse_children = (level >= Comatose.config.default_tree_level) -%> - -
  • - - - - - - - -
    - <% if !page.children.empty? %> - <%= image_tag( ((collapse_children) ? 'comatose/collapsed.gif' : 'comatose/expanded.gif'), :title=>'Expand/Collapse', :onclick=>"ComatoseList.toggle_tree_nodes(this,#{page.id});", :class=>'tree-controller', :size=>'12x12', :id=>"page_controller_#{page.id}" ) %> - <% else %> - <%= image_tag 'comatose/no-children.gif', :size=>'12x12', :class=>'tree-controller' %> - <% end %> - - <%= icon_for_document(page) %> - <%= _('DRAG') %> - - <%= link_to page.title, {:action=>'edit', :id=>page}, :title=>"Path:#{page.full_path}", :class=>'page' %> - - <%= links.join(', ') %>. -
    - -
      - <% for child in page.children %> - <%= render :partial=>'page_list_item', :locals=>{ :page=>child, :level=>level+1 } %> - <% end %> -
    - - <%= sortable_element( "page_list_#{page.id}", - :complete => visual_effect(:highlight, "page_list_#{page.id}"), - :handle=>'handle', - :update=>'flash-content', - :url => { :action => "reorder", :id=>page } ) if !page.children.empty? and page.children.length > 1 %> -
  • diff --git a/app/views/comatose_admin/delete.rhtml b/app/views/comatose_admin/delete.rhtml deleted file mode 100644 index fd3dd07..0000000 --- a/app/views/comatose_admin/delete.rhtml +++ /dev/null @@ -1,18 +0,0 @@ -

    - Page Delete Confirmation -

    - -
    -

    <%= _('Are you sure you want to delete the page titled "%s"?') % content_tag('strong', @page.title) %>

    - <% unless @page.children.empty? %> -

    <%= _("It has %s child pages that will also be deleted...") % content_tag('strong', @page.children.length) %>

    -<% end %> -
    - -<%= start_form_tag %> -
    - <%= submit_tag _("Yes, Delete The Page") %> - or - <%= link_to _("Cancel"), :action=>'index' %> -
    -<%= end_form_tag %> diff --git a/app/views/comatose_admin/edit.rhtml b/app/views/comatose_admin/edit.rhtml deleted file mode 100644 index 6b2f158..0000000 --- a/app/views/comatose_admin/edit.rhtml +++ /dev/null @@ -1,5 +0,0 @@ -

    - <%= _("Edit Page") %> -

    - -<%= render :partial=>'form', :locals=>{:mode=>:edit} %> diff --git a/app/views/comatose_admin/index.rhtml b/app/views/comatose_admin/index.rhtml deleted file mode 100644 index 826c4e3..0000000 --- a/app/views/comatose_admin/index.rhtml +++ /dev/null @@ -1,18 +0,0 @@ -
    - <%= link_to 'Clear Page Cache', :controller=>controller.controller_name, :action=>'expire_page_cache' %> -
    - -

    - <%= _('Document List') %> - <%= image_tag 'comatose/spinner.gif', :id=>'spinner', :align=>'absmiddle', :style=>'display:none;' %> -

    - - - -
    - -<%= javascript_tag "ComatoseList.init()" %> diff --git a/app/views/comatose_admin/new.rhtml b/app/views/comatose_admin/new.rhtml deleted file mode 100644 index 26bf982..0000000 --- a/app/views/comatose_admin/new.rhtml +++ /dev/null @@ -1,5 +0,0 @@ -

    - <%= _('New Page') %> -

    - -<%= render :partial=>'form', :locals=>{:mode=>:new} %> diff --git a/app/views/comatose_admin/reorder.rhtml b/app/views/comatose_admin/reorder.rhtml deleted file mode 100644 index d839538..0000000 --- a/app/views/comatose_admin/reorder.rhtml +++ /dev/null @@ -1,30 +0,0 @@ -

    <%= _('Reorder Pages') %>

    - -

    <%= _('"%s" child pages:') % @page.title %>

    - - - -
    - <%= link_to _("Finished"), :action=>'index' %> -
    diff --git a/app/views/comatose_admin/versions.rhtml b/app/views/comatose_admin/versions.rhtml deleted file mode 100644 index c470c55..0000000 --- a/app/views/comatose_admin/versions.rhtml +++ /dev/null @@ -1,44 +0,0 @@ -

    <%= _('Page Revisions') %>

    - -
    -
    -
    - <% form_tag :action => 'versions', :id => @page, :html => { :method => :get } do %> - <%= _('View Version:') %><%= select_tag "version", options_from_collection_for_select(@page.versions, 'version', 'version', @version_num), {'onchange'=>'this.form.submit();'} %> - <%= submit_tag 'Go', {'id'=>'go-btn'} %> - <% end %> -
    - <%= _('Version %s') % @version_num %> -
    -
    - - - <% if show_field? 'keywords' %> - - <% end %> -
    - <%= @version.body.split("\n").join('
    ') unless @version.body.nil? %> - -
    - -
    -
    - <% _('Current Version') %> -
    -
    - - - <% if show_field? 'keywords' %> - - <% end %> -
    - <%= @page.body.split("\n").join('
    ') unless @page.body.nil? %> -
    - -
     
    diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 98e158c..bc24ee1 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -2,9 +2,9 @@ <%= javascript_include_tag :defaults %> <%= design_all_header_tags %> - <%= javascript_include_tag 'comatose_admin' %> - <% if params[:controller] == 'comatose_admin' %> - <%= stylesheet_link_tag 'comatose_admin' %> + <%= javascript_include_tag 'cms' %> + <% if params[:controller] == 'cms' %> + <%= stylesheet_link_tag 'cms' %> <% end %> <%= stylesheet_link_tag 'common' %> @@ -37,7 +37,7 @@
    - <% if params[:controller] == 'comatose_admin' %> + <% if params[:controller] == 'cms' %>
    <%= yield %>
    diff --git a/config/routes.rb b/config/routes.rb index eb470fa..aa14a37 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,7 +23,7 @@ ActionController::Routing::Routes.draw do |map| map.connect 'customize/:profile/edit_template/:action/:id', :controller => 'edit_template' # content administration - map.comatose_admin 'cms/:profile' + map.connect 'cms/:profile/:action/:id', :controller => 'cms' # administrative tasks for a virtual community map.connect 'admin', :controller => 'admin_panel', :action => 'index' diff --git a/public/javascripts/cms.js b/public/javascripts/cms.js new file mode 100644 index 0000000..00dbec8 --- /dev/null +++ b/public/javascripts/cms.js @@ -0,0 +1,401 @@ +// CSS Browser Selector v0.2.3b (M@: added noscript support) +// Documentation: http://rafael.adm.br/css_browser_selector +// License: http://creativecommons.org/licenses/by/2.5/ +// Author: Rafael Lima (http://rafael.adm.br) +// Contributors: http://rafael.adm.br/css_browser_selector#contributors +var css_browser_selector = function() { + var + ua = navigator.userAgent.toLowerCase(), + is = function(t){ return ua.indexOf(t) != -1; }, + h = document.getElementsByTagName('html')[0], + b = (!(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua)) ? ((is('mac') ? 'ieMac ' : '') + 'ie ie' + RegExp.$1) + : is('gecko/') ? 'gecko' : is('opera') ? 'opera' : is('konqueror') ? 'konqueror' : is('applewebkit/') ? 'webkit safari' : is('mozilla/') ? 'gecko' : '', + os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : ''; + var c = b+os+' js'; + h.className = h.className.replace('noscript', '') + h.className?' '+c:c; +}(); + +// List View Functions +var ComatoseList = { + save_node_state: true, + state_store: 'cookie', // Only 'cookie' for now + state_key: 'ComatoseTreeState', + + init: function() { + var items = ComatoseList._read_state(); + items.each(function(node){ + ComatoseList.expand_node(node.replace('page_controller_', '')) + }); + }, + + toggle_tree_nodes : function(img, id) { + if(/expanded/.test(img.src)) { + $('page_list_'+ id).addClassName('collapsed'); + img.src = img.src.replace(/expanded/, 'collapsed') + if(ComatoseList.save_node_state) { + var items = ComatoseList._read_state(); + items = items.select(function(id){ return id != img.id; }) + ComatoseList._write_state(items); + } + } else { + $('page_list_'+ id).removeClassName('collapsed'); + img.src = img.src.replace(/collapsed/, 'expanded') + if(ComatoseList.save_node_state) { + var items = ComatoseList._read_state(); + items.push(img.id); + ComatoseList._write_state(items); + } + } + }, + + expand_node: function(id) { + $('page_list_'+ id).removeClassName('collapsed'); + $('page_controller_'+ id).src = $('page_controller_'+ id).src.replace(/collapsed/, 'expanded') + }, + + collapse_node: function(id) { + $('page_list_'+ id).addClassName('collapsed'); + $('page_controller_'+ id).src = $('page_controller_'+ id).src.replace(/expanded/, 'collapsed') + }, + + item_hover : function(node, state, is_delete) { + if( state == 'over') { + $(node).addClassName( (is_delete) ? 'hover-delete' : 'hover' ); + } else { + $(node).removeClassName( (is_delete) ? 'hover-delete' : 'hover' ); + } + }, + + toggle_reorder: function(node, anc, id, reorder_text, finished_text) { + if( $(node).hasClassName('do-reorder') ) { + $(node).removeClassName( 'do-reorder' ); + $(anc).removeClassName('reordering'); + $(anc).innerHTML = reorder_text; + } else { + $(node).addClassName( 'do-reorder' ); + $(anc).addClassName('reordering'); + $(anc).innerHTML = finished_text; + // Make sure the children are visible... + ComatoseList.expand_node(id); + } + }, + + _write_state: function(items) { + var cookie = {}; var options = {}; var expiration = new Date(); + cookie[ ComatoseList.state_key ] = items.join(','); + expiration.setDate(expiration.getDate()+30) + options['expires'] = expiration; + Cookie.write( cookie, options ); + }, + + _read_state: function() { + var state = Cookie.read( ComatoseList.state_key ); + return (state != "" && state != null) ? state.split(',') : []; + } +} + +// Edit Form Functions +var ComatoseEditForm = { + + default_data: {}, + last_preview: {}, + last_title_slug: '', + mode : null, + liquid_horiz: false, // changed from true to false by terceiro + width_offset: 325, + + // Initialize the page... + init : function(mode) { + this.mode = mode; + this.default_data = Form.serialize(document.forms[0]); + if(mode == 'new') { + this.last_title_slug = $('page_title').value.toSlug(); + Event.observe('page_title', 'blur', ComatoseEditForm.title_updated_aggressive); + } else { + Event.observe('page_title', 'blur', ComatoseEditForm.title_updated); + } + $('page_title').focus(); + Hide.these( + 'preview-area', + 'slug_row', + 'parent_row', + 'keywords_row', + 'filter_row', + 'created_row' + ); + $('page_title').select(); + // Create the horizontal liquidity of the fields + if(this.liquid_horiz) { + xOffset = this.width_offset; + new Layout.LiquidHoriz((xOffset + 50), 'page_title'); + new Layout.LiquidHoriz(xOffset, 'page_slug','page_keywords','page_parent','page_body'); + } + }, + // For use when updating an existing page... + title_updated : function() { + slug = $('page_slug'); + if(slug.value == "") { + title = $('page_title'); + slug.value = title.value.toSlug(); + } + }, + // For use when creating a new page... + title_updated_aggressive : function() { + slug = $('page_slug'); + title = $('page_title'); + if(slug.value == "" || slug.value == this.last_title ) { + slug.value = title.value.toSlug(); + } + this.last_title = slug.value; + }, + // Todo: Make the meta fields remember their visibility? + toggle_extra_fields : function(anchor, more_label, less_label) { + if(anchor.innerHTML == more_label) { + Show.these( + 'slug_row', + 'keywords_row', + 'parent_row', + 'filter_row', + 'created_row' + ); + anchor.innerHTML = less_label; + } else { + Hide.these( + 'slug_row', + 'keywords_row', + 'parent_row', + 'filter_row', + 'created_row' + ); + anchor.innerHTML = more_label; + } + }, + // Uses server to create preview of content... + preview_content : function(preview_url, preview_label) { + $('preview-area').show(); + var params = Form.serialize(document.forms[0]); + if( params != this.last_preview ) { + $('preview-panel').innerHTML = "" + preview_label + ""; + new Ajax.Updater( + 'preview-panel', + preview_url, + { parameters: params } + ); + } + this.last_preview = params; + }, + cancel : function(url, cancel_warning) { + var current_data = Form.serialize(document.forms[0]); + var data_changed = (this.default_data != current_data) + if(data_changed) { + if( confirm(cancel_warning) ) { + location.href = url; + } + } else { + location.href = url; + } + + } +} + +var Hide = { + these : function() { + for (var i = 0; i < arguments.length; i++) { + try { + $(arguments[i]).hide(); + } catch (e) {} + } + } +} + +var Show = { + these : function() { + for (var i = 0; i < arguments.length; i++) { + try { + $(arguments[i]).show(); + } catch (e) {} + } + } +} + +// Layout namespace +var Layout = {}; + +// This class allows dom objects to stretch with the browser +// (for when a good, cross-browser, CSS approach can't be found) +Layout.LiquidBase = Class.create(); +// Base class for all Liquid* layouts... +Object.extend(Layout.LiquidBase.prototype, { + enabled: true, + elems: [], + offset: null, + // Constructor is (offset, **array_of_elements) + initialize: function() { + args = $A(arguments) + this.offset = args.shift(); + this.elems = args.select( function(elem){ return ($(elem) != null) } ); + if( this.elems.length > 0 ) { + this.on_resize(); // Initial size + Event.observe(window, 'resize', this.on_resize.bind(this) ); + Event.observe(window, 'load', this.on_resize.bind(this) ); + } + }, + resize_in: function(timeout) { + setTimeout( this.on_resize.bind(this), timeout ); + }, + on_resize: function() { + // Need to override! + alert('Override on_resize, please!'); + } +}); + + +// Liquid vertical layout +Layout.LiquidVert = Class.create(); +Object.extend(Layout.LiquidVert.prototype, Object.extend(Layout.LiquidBase.prototype, { + on_resize: function() { + if( this.offset != null && this.enabled ) { + var new_height = ((window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - this.offset) +"px"; + this.elems.each(function(e){ $(e).style.height = new_height; }) + } + } +}) ); + + +// Liquid horizontal layout +Layout.LiquidHoriz = Class.create(); +Object.extend(Layout.LiquidHoriz.prototype, Object.extend(Layout.LiquidBase.prototype, { + on_resize: function() { + if( this.offset != null && this.enabled ) { + var new_width = ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) - this.offset) +"px"; + this.elems.each( function(e){ $(e).style.width = new_width; }) + } + } +}) ); + +// String Extensions... Yes, these are from Radiant! ;-) +Object.extend(String.prototype, { + upcase: function() { + return this.toUpperCase(); + }, + downcase: function() { + return this.toLowerCase(); + }, + strip: function() { + return this.replace(/^\s+/, '').replace(/\s+$/, ''); + }, + toInteger: function() { + return parseInt(this); + }, + toSlug: function() { + // M@: Modified from Radiant's version, removes multple --'s next to each other + // This is the same RegExp as the one on the page model... + return this.strip().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=_+]+/g, '-').replace(/[\-]{2,}/g, '-'); + } +}); + +// Run a spinner when an AJAX request in running... +var ComatoseAJAXSpinner = { + busy : function () { + if($('spinner') && Ajax.activeRequestCount > 0) { + Effect.Appear('spinner',{duration:0.5,queue:'end'}); + } + }, + + notBusy: function() { + if($('spinner') && Ajax.activeRequestCount == 0) { + Effect.Fade('spinner',{duration:0.5,queue:'end'}); + } + } +} +// Register it with Prototype... +Ajax.Responders.register({ + onCreate: ComatoseAJAXSpinner.busy, + onComplete: ComatoseAJAXSpinner.notBusy +}); + + +if(!window.Cookie) + (function (){ + // From Mephisto! + window.Cookie = { + version: '0.7', + cookies: {}, + _each: function(iterator) { + $H(this.cookies).each(iterator); + }, + + getAll: function() { + this.cookies = {}; + $A(document.cookie.split('; ')).each(function(cookie) { + var seperator = cookie.indexOf('='); + this.cookies[cookie.substring(0, seperator)] = + unescape(cookie.substring(seperator + 1, cookie.length)); + }.bind(this)); + return this.cookies; + }, + + read: function() { + var cookies = $A(arguments), results = []; + this.getAll(); + cookies.each(function(name) { + if (this.cookies[name]) results.push(this.cookies[name]); + else results.push(null); + }.bind(this)); + return results.length > 1 ? results : results[0]; + }, + + write: function(cookies, options) { + if (cookies.constructor == Object && cookies.name) cookies = [cookies]; + if (cookies.constructor == Array) { + $A(cookies).each(function(cookie) { + this._write(cookie.name, cookie.value, cookie.expires, + cookie.path, cookie.domain); + }.bind(this)); + } else { + options = options || {expires: false, path: '', domain: ''}; + for (name in cookies){ + this._write(name, cookies[name], + options.expires, options.path, options.domain); + } + } + }, + + _write: function(name, value, expires, path, domain) { + if (name.indexOf('=') != -1) return; + var cookieString = name + '=' + escape(value); + if (expires) cookieString += '; expires=' + expires.toGMTString(); + if (path) cookieString += '; path=' + path; + if (domain) cookieString += '; domain=' + domain; + document.cookie = cookieString; + }, + + erase: function(cookies) { + var cookiesToErase = {}; + $A(arguments).each(function(cookie) { + cookiesToErase[cookie] = ''; + }); + + this.write(cookiesToErase, {expires: (new Date((new Date()).getTime() - 1e11))}); + this.getAll(); + }, + + eraseAll: function() { + this.erase.apply(this, $H(this.getAll()).keys()); + } + }; + + Object.extend(Cookie, { + get: Cookie.read, + set: Cookie.write, + + add: Cookie.read, + remove: Cookie.erase, + removeAll: Cookie.eraseAll, + + wipe: Cookie.erase, + wipeAll: Cookie.eraseAll, + destroy: Cookie.erase, + destroyAll: Cookie.eraseAll + }); + })(); diff --git a/public/javascripts/comatose_admin.js b/public/javascripts/comatose_admin.js deleted file mode 100644 index 00dbec8..0000000 --- a/public/javascripts/comatose_admin.js +++ /dev/null @@ -1,401 +0,0 @@ -// CSS Browser Selector v0.2.3b (M@: added noscript support) -// Documentation: http://rafael.adm.br/css_browser_selector -// License: http://creativecommons.org/licenses/by/2.5/ -// Author: Rafael Lima (http://rafael.adm.br) -// Contributors: http://rafael.adm.br/css_browser_selector#contributors -var css_browser_selector = function() { - var - ua = navigator.userAgent.toLowerCase(), - is = function(t){ return ua.indexOf(t) != -1; }, - h = document.getElementsByTagName('html')[0], - b = (!(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua)) ? ((is('mac') ? 'ieMac ' : '') + 'ie ie' + RegExp.$1) - : is('gecko/') ? 'gecko' : is('opera') ? 'opera' : is('konqueror') ? 'konqueror' : is('applewebkit/') ? 'webkit safari' : is('mozilla/') ? 'gecko' : '', - os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : ''; - var c = b+os+' js'; - h.className = h.className.replace('noscript', '') + h.className?' '+c:c; -}(); - -// List View Functions -var ComatoseList = { - save_node_state: true, - state_store: 'cookie', // Only 'cookie' for now - state_key: 'ComatoseTreeState', - - init: function() { - var items = ComatoseList._read_state(); - items.each(function(node){ - ComatoseList.expand_node(node.replace('page_controller_', '')) - }); - }, - - toggle_tree_nodes : function(img, id) { - if(/expanded/.test(img.src)) { - $('page_list_'+ id).addClassName('collapsed'); - img.src = img.src.replace(/expanded/, 'collapsed') - if(ComatoseList.save_node_state) { - var items = ComatoseList._read_state(); - items = items.select(function(id){ return id != img.id; }) - ComatoseList._write_state(items); - } - } else { - $('page_list_'+ id).removeClassName('collapsed'); - img.src = img.src.replace(/collapsed/, 'expanded') - if(ComatoseList.save_node_state) { - var items = ComatoseList._read_state(); - items.push(img.id); - ComatoseList._write_state(items); - } - } - }, - - expand_node: function(id) { - $('page_list_'+ id).removeClassName('collapsed'); - $('page_controller_'+ id).src = $('page_controller_'+ id).src.replace(/collapsed/, 'expanded') - }, - - collapse_node: function(id) { - $('page_list_'+ id).addClassName('collapsed'); - $('page_controller_'+ id).src = $('page_controller_'+ id).src.replace(/expanded/, 'collapsed') - }, - - item_hover : function(node, state, is_delete) { - if( state == 'over') { - $(node).addClassName( (is_delete) ? 'hover-delete' : 'hover' ); - } else { - $(node).removeClassName( (is_delete) ? 'hover-delete' : 'hover' ); - } - }, - - toggle_reorder: function(node, anc, id, reorder_text, finished_text) { - if( $(node).hasClassName('do-reorder') ) { - $(node).removeClassName( 'do-reorder' ); - $(anc).removeClassName('reordering'); - $(anc).innerHTML = reorder_text; - } else { - $(node).addClassName( 'do-reorder' ); - $(anc).addClassName('reordering'); - $(anc).innerHTML = finished_text; - // Make sure the children are visible... - ComatoseList.expand_node(id); - } - }, - - _write_state: function(items) { - var cookie = {}; var options = {}; var expiration = new Date(); - cookie[ ComatoseList.state_key ] = items.join(','); - expiration.setDate(expiration.getDate()+30) - options['expires'] = expiration; - Cookie.write( cookie, options ); - }, - - _read_state: function() { - var state = Cookie.read( ComatoseList.state_key ); - return (state != "" && state != null) ? state.split(',') : []; - } -} - -// Edit Form Functions -var ComatoseEditForm = { - - default_data: {}, - last_preview: {}, - last_title_slug: '', - mode : null, - liquid_horiz: false, // changed from true to false by terceiro - width_offset: 325, - - // Initialize the page... - init : function(mode) { - this.mode = mode; - this.default_data = Form.serialize(document.forms[0]); - if(mode == 'new') { - this.last_title_slug = $('page_title').value.toSlug(); - Event.observe('page_title', 'blur', ComatoseEditForm.title_updated_aggressive); - } else { - Event.observe('page_title', 'blur', ComatoseEditForm.title_updated); - } - $('page_title').focus(); - Hide.these( - 'preview-area', - 'slug_row', - 'parent_row', - 'keywords_row', - 'filter_row', - 'created_row' - ); - $('page_title').select(); - // Create the horizontal liquidity of the fields - if(this.liquid_horiz) { - xOffset = this.width_offset; - new Layout.LiquidHoriz((xOffset + 50), 'page_title'); - new Layout.LiquidHoriz(xOffset, 'page_slug','page_keywords','page_parent','page_body'); - } - }, - // For use when updating an existing page... - title_updated : function() { - slug = $('page_slug'); - if(slug.value == "") { - title = $('page_title'); - slug.value = title.value.toSlug(); - } - }, - // For use when creating a new page... - title_updated_aggressive : function() { - slug = $('page_slug'); - title = $('page_title'); - if(slug.value == "" || slug.value == this.last_title ) { - slug.value = title.value.toSlug(); - } - this.last_title = slug.value; - }, - // Todo: Make the meta fields remember their visibility? - toggle_extra_fields : function(anchor, more_label, less_label) { - if(anchor.innerHTML == more_label) { - Show.these( - 'slug_row', - 'keywords_row', - 'parent_row', - 'filter_row', - 'created_row' - ); - anchor.innerHTML = less_label; - } else { - Hide.these( - 'slug_row', - 'keywords_row', - 'parent_row', - 'filter_row', - 'created_row' - ); - anchor.innerHTML = more_label; - } - }, - // Uses server to create preview of content... - preview_content : function(preview_url, preview_label) { - $('preview-area').show(); - var params = Form.serialize(document.forms[0]); - if( params != this.last_preview ) { - $('preview-panel').innerHTML = "" + preview_label + ""; - new Ajax.Updater( - 'preview-panel', - preview_url, - { parameters: params } - ); - } - this.last_preview = params; - }, - cancel : function(url, cancel_warning) { - var current_data = Form.serialize(document.forms[0]); - var data_changed = (this.default_data != current_data) - if(data_changed) { - if( confirm(cancel_warning) ) { - location.href = url; - } - } else { - location.href = url; - } - - } -} - -var Hide = { - these : function() { - for (var i = 0; i < arguments.length; i++) { - try { - $(arguments[i]).hide(); - } catch (e) {} - } - } -} - -var Show = { - these : function() { - for (var i = 0; i < arguments.length; i++) { - try { - $(arguments[i]).show(); - } catch (e) {} - } - } -} - -// Layout namespace -var Layout = {}; - -// This class allows dom objects to stretch with the browser -// (for when a good, cross-browser, CSS approach can't be found) -Layout.LiquidBase = Class.create(); -// Base class for all Liquid* layouts... -Object.extend(Layout.LiquidBase.prototype, { - enabled: true, - elems: [], - offset: null, - // Constructor is (offset, **array_of_elements) - initialize: function() { - args = $A(arguments) - this.offset = args.shift(); - this.elems = args.select( function(elem){ return ($(elem) != null) } ); - if( this.elems.length > 0 ) { - this.on_resize(); // Initial size - Event.observe(window, 'resize', this.on_resize.bind(this) ); - Event.observe(window, 'load', this.on_resize.bind(this) ); - } - }, - resize_in: function(timeout) { - setTimeout( this.on_resize.bind(this), timeout ); - }, - on_resize: function() { - // Need to override! - alert('Override on_resize, please!'); - } -}); - - -// Liquid vertical layout -Layout.LiquidVert = Class.create(); -Object.extend(Layout.LiquidVert.prototype, Object.extend(Layout.LiquidBase.prototype, { - on_resize: function() { - if( this.offset != null && this.enabled ) { - var new_height = ((window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - this.offset) +"px"; - this.elems.each(function(e){ $(e).style.height = new_height; }) - } - } -}) ); - - -// Liquid horizontal layout -Layout.LiquidHoriz = Class.create(); -Object.extend(Layout.LiquidHoriz.prototype, Object.extend(Layout.LiquidBase.prototype, { - on_resize: function() { - if( this.offset != null && this.enabled ) { - var new_width = ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) - this.offset) +"px"; - this.elems.each( function(e){ $(e).style.width = new_width; }) - } - } -}) ); - -// String Extensions... Yes, these are from Radiant! ;-) -Object.extend(String.prototype, { - upcase: function() { - return this.toUpperCase(); - }, - downcase: function() { - return this.toLowerCase(); - }, - strip: function() { - return this.replace(/^\s+/, '').replace(/\s+$/, ''); - }, - toInteger: function() { - return parseInt(this); - }, - toSlug: function() { - // M@: Modified from Radiant's version, removes multple --'s next to each other - // This is the same RegExp as the one on the page model... - return this.strip().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=_+]+/g, '-').replace(/[\-]{2,}/g, '-'); - } -}); - -// Run a spinner when an AJAX request in running... -var ComatoseAJAXSpinner = { - busy : function () { - if($('spinner') && Ajax.activeRequestCount > 0) { - Effect.Appear('spinner',{duration:0.5,queue:'end'}); - } - }, - - notBusy: function() { - if($('spinner') && Ajax.activeRequestCount == 0) { - Effect.Fade('spinner',{duration:0.5,queue:'end'}); - } - } -} -// Register it with Prototype... -Ajax.Responders.register({ - onCreate: ComatoseAJAXSpinner.busy, - onComplete: ComatoseAJAXSpinner.notBusy -}); - - -if(!window.Cookie) - (function (){ - // From Mephisto! - window.Cookie = { - version: '0.7', - cookies: {}, - _each: function(iterator) { - $H(this.cookies).each(iterator); - }, - - getAll: function() { - this.cookies = {}; - $A(document.cookie.split('; ')).each(function(cookie) { - var seperator = cookie.indexOf('='); - this.cookies[cookie.substring(0, seperator)] = - unescape(cookie.substring(seperator + 1, cookie.length)); - }.bind(this)); - return this.cookies; - }, - - read: function() { - var cookies = $A(arguments), results = []; - this.getAll(); - cookies.each(function(name) { - if (this.cookies[name]) results.push(this.cookies[name]); - else results.push(null); - }.bind(this)); - return results.length > 1 ? results : results[0]; - }, - - write: function(cookies, options) { - if (cookies.constructor == Object && cookies.name) cookies = [cookies]; - if (cookies.constructor == Array) { - $A(cookies).each(function(cookie) { - this._write(cookie.name, cookie.value, cookie.expires, - cookie.path, cookie.domain); - }.bind(this)); - } else { - options = options || {expires: false, path: '', domain: ''}; - for (name in cookies){ - this._write(name, cookies[name], - options.expires, options.path, options.domain); - } - } - }, - - _write: function(name, value, expires, path, domain) { - if (name.indexOf('=') != -1) return; - var cookieString = name + '=' + escape(value); - if (expires) cookieString += '; expires=' + expires.toGMTString(); - if (path) cookieString += '; path=' + path; - if (domain) cookieString += '; domain=' + domain; - document.cookie = cookieString; - }, - - erase: function(cookies) { - var cookiesToErase = {}; - $A(arguments).each(function(cookie) { - cookiesToErase[cookie] = ''; - }); - - this.write(cookiesToErase, {expires: (new Date((new Date()).getTime() - 1e11))}); - this.getAll(); - }, - - eraseAll: function() { - this.erase.apply(this, $H(this.getAll()).keys()); - } - }; - - Object.extend(Cookie, { - get: Cookie.read, - set: Cookie.write, - - add: Cookie.read, - remove: Cookie.erase, - removeAll: Cookie.eraseAll, - - wipe: Cookie.erase, - wipeAll: Cookie.eraseAll, - destroy: Cookie.erase, - destroyAll: Cookie.eraseAll - }); - })(); diff --git a/public/stylesheets/comatose_admin.css b/public/stylesheets/comatose_admin.css index ed238c2..abb8b70 100644 --- a/public/stylesheets/comatose_admin.css +++ b/public/stylesheets/comatose_admin.css @@ -122,3 +122,7 @@ div.comatose_field select { font-weight: normal; display: block; } + +.collapsed { + display: none; +} diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb new file mode 100644 index 0000000..cd739aa --- /dev/null +++ b/test/functional/cms_controller_test.rb @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'cms_controller' + +# Re-raise errors caught by the controller. +class CmsController; def rescue_action(e) raise e end; end + +class CmsControllerTest < Test::Unit::TestCase + def setup + @controller = CmsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end -- libgit2 0.21.2