Removed categories.
Hesham E
committed Aug 20, 2010
commit d696cfa24acc8ed7b0461b5bf20c830a5e86d11f
Showing 40
changed files with
1 additions
and 991 deletions
app/controllers/cms_admin/categories_controller.rb
+0
-78
| @@ | @@ -1,78 +0,0 @@ |
| - | class CmsAdmin::CategoriesController < CmsAdmin::BaseController |
| - | before_filter :load_category, :except => [:create, :new, :index] |
| - | |
| - | def index |
| - | @cms_categories = CmsCategory.roots |
| - | end |
| - | |
| - | =begin |
| - | This was the old style of getting the children of the current note (old cms stuff) |
| - | def children |
| - | manage_session_array(:cms_category_tree, (params[:state] == 'open' ? :remove : :add), params[:id]) |
| - | end |
| - | =end |
| - | |
| - | def new |
| - | @cms_category = CmsCategory.new(params.slice(:parent_id)) |
| - | end |
| - | |
| - | def toggle |
| - | save_tree_state(@cms_category) |
| - | render :nothing => true |
| - | end |
| - | |
| - | def create |
| - | @cms_category = CmsCategory.new(params[:cms_category]) |
| - | @cms_category.save! |
| - | |
| - | flash[:notice] = 'Category created' |
| - | respond_to do |format| |
| - | format.html { redirect_to edit_cms_admin_category_path(@cms_category) } |
| - | format.js |
| - | end |
| - | |
| - | rescue ActiveRecord::RecordInvalid |
| - | respond_to do |format| |
| - | format.html { render :action => 'new' } |
| - | format.js |
| - | end |
| - | end |
| - | |
| - | def edit |
| - | # ... |
| - | end |
| - | |
| - | def update |
| - | @cms_category.update_attributes!(params[:cms_category]) |
| - | flash[:notice] = 'Category updated' |
| - | respond_to do |format| |
| - | format.html { redirect_to edit_cms_admin_category_path(@cms_category)} |
| - | format.js |
| - | end |
| - | |
| - | rescue ActiveRecord::RecordInvalid |
| - | respond_to do |format| |
| - | format.html { render :action => 'edit' } |
| - | format.js |
| - | end |
| - | end |
| - | |
| - | def show |
| - | |
| - | end |
| - | |
| - | def destroy |
| - | @cms_category.destroy |
| - | flash[:notice] = 'Category deleted' |
| - | redirect_to cms_admin_categories_path |
| - | end |
| - | |
| - | protected |
| - | |
| - | def load_category |
| - | @cms_category = CmsCategory.find(params[:id]) |
| - | rescue ActiveRecord::RecordNotFound |
| - | render :text => 'Item not found', :status => 404 |
| - | end |
| - | |
| - | end |
app/controllers/cms_admin/sites_controller.rb
+0
-63
| @@ | @@ -1,63 +0,0 @@ |
| - | class CmsAdmin::SitesController < CmsAdmin::BaseController |
| - | before_filter :load_site, :only => [ :edit, :update, :destroy ] |
| - | before_filter :build_site, :only => [ :new, :create ] |
| - | |
| - | def index |
| - | @sites = CmsSite.all |
| - | end |
| - | |
| - | def children |
| - | manage_session_array(:cms_site_tree, (params[:state] == 'open' ? :remove : :add), params[:id]) |
| - | end |
| - | |
| - | def new |
| - | if (CmsSite.count == 0) |
| - | @site.hostname = request.host |
| - | end |
| - | end |
| - | |
| - | def edit |
| - | # ... |
| - | end |
| - | |
| - | def create |
| - | @site.save! |
| - | |
| - | flash[:notice] = 'Site created' |
| - | |
| - | redirect_to edit_cms_admin_site_path(@site) |
| - | |
| - | rescue ActiveRecord::RecordInvalid |
| - | render(:action => :new) |
| - | end |
| - | |
| - | def update |
| - | @site.update_attributes!(params[:cms_site]) |
| - | |
| - | flash[:notice] = 'Site updated' |
| - | |
| - | redirect_to edit_cms_admin_site_path(@site) |
| - | |
| - | rescue ActiveRecord::RecordInvalid |
| - | render :action => :edit |
| - | end |
| - | |
| - | def destroy |
| - | @site.destroy |
| - | |
| - | flash[:notice] = 'Site removed' |
| - | redirect_to cms_admin_sites_path |
| - | end |
| - | |
| - | protected |
| - | def load_site |
| - | @site = CmsSite.find_by_id(params[:id]) |
| - | end |
| - | |
| - | def build_site |
| - | params[:cms_site] ||= { |
| - | } |
| - | |
| - | @site = CmsSite.new(params[:cms_site]) |
| - | end |
| - | end |
app/models/cms_category.rb
+0
-80
| @@ | @@ -1,80 +0,0 @@ |
| - | class CmsCategory < ActiveRecord::Base |
| - | |
| - | # -- AR Extensions -------------------------------------------------------- |
| - | |
| - | acts_as_tree :counter_cache => :children_count |
| - | |
| - | # -- Relationships -------------------------------------------------------- |
| - | |
| - | has_many :cms_page_categorizations, |
| - | :dependent => :destroy |
| - | |
| - | has_many :cms_pages, |
| - | :through => :cms_page_categorizations |
| - | |
| - | # -- Validations ---------------------------------------------------------- |
| - | |
| - | validates :slug, |
| - | :presence => true, |
| - | :uniqueness => { :scope => :parent_id } |
| - | validates :label, |
| - | :presence => true |
| - | |
| - | # -- Named Scopes --------------------------------------------------------- |
| - | |
| - | default_scope :order => 'label' |
| - | |
| - | # -- Callbacks ------------------------------------------------------------ |
| - | |
| - | before_validation :set_slug_if_blank |
| - | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | def set_slug_if_blank |
| - | self.slug = self.label.slugify if self.slug.blank? |
| - | end |
| - | |
| - | def self.categories_for_select(collection = CmsCategory.roots, level = 0) |
| - | out = [] |
| - | collection.each do |category| |
| - | out += [["#{". . " * level} #{category.label}", category.id]] |
| - | out += self.categories_for_select(category.children, level+1) if category.children.count > 0 |
| - | end |
| - | out |
| - | end |
| - | |
| - | def self.categorized_model_names |
| - | model_names = [] |
| - | CmsCategory.reflect_on_all_associations(:has_many).each do |model| |
| - | model_names << model.klass.to_s if model.through_reflection.present? |
| - | end |
| - | model_names |
| - | end |
| - | |
| - | def self.categorized_model_types |
| - | models_types = [] |
| - | CmsCategory.categorized_model_names.each do |model_name| |
| - | models_types << model_name.constantize |
| - | end |
| - | models_types |
| - | end |
| - | |
| - | # -- Instance Methods ----------------------------------------------------- |
| - | def number_of_records |
| - | # returns the number of records (of all types) under a certain category |
| - | count = 0 |
| - | CmsCategory.categorized_model_names.each do |model_name| |
| - | count += self.send(model_name.underscore.pluralize.to_sym).length |
| - | end |
| - | count |
| - | end |
| - | |
| - | def records |
| - | things = {} |
| - | CmsCategory.categorized_model_names.each do |model_name| |
| - | model_sym = model_name.underscore.pluralize.to_sym |
| - | things[model_sym] = self.send(model_sym) |
| - | end |
| - | things |
| - | end |
| - | end |
| - | |
app/models/cms_page.rb
+0
-1
| @@ | @@ -11,7 +11,6 @@ class CmsPage < ActiveRecord::Base |
| # -- AR Extensions -------------------------------------------------------- | |
| acts_as_tree :counter_cache => :children_count | |
| - | acts_as_categorized |
| # -- Properties ----------------------------------------------------------- | |
app/models/cms_page_categorization.rb
+0
-7
| @@ | @@ -1,7 +0,0 @@ |
| - | class CmsPageCategorization < ActiveRecord::Base |
| - | |
| - | acts_as_categorization |
| - | |
| - | end |
| - | |
| - | |
app/models/cms_site.rb
+0
-51
| @@ | @@ -1,51 +0,0 @@ |
| - | class CmsSite < ActiveRecord::Base |
| - | # -- Relationships -------------------------------------------------------- |
| - | |
| - | has_many :cms_pages, |
| - | :dependent => :destroy |
| - | |
| - | has_many :hostnames, |
| - | :class_name => 'CmsSiteHostname', |
| - | :dependent => :destroy |
| - | |
| - | accepts_nested_attributes_for :hostnames, |
| - | :allow_destroy => true, |
| - | :reject_if => proc { |attributes| attributes['hostname'].blank? } |
| - | |
| - | # -- Validations ---------------------------------------------------------- |
| - | |
| - | validates :label, |
| - | :presence => true, |
| - | :uniqueness => true |
| - | |
| - | validates :hostname, |
| - | :presence => true, |
| - | :uniqueness => true |
| - | |
| - | # -- Scopes --------------------------------------------------------------- |
| - | |
| - | default_scope :order => 'label ASC' |
| - | |
| - | # -- Callbacks ------------------------------------------------------------ |
| - | |
| - | after_create :create_page |
| - | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | |
| - | def self.options_for_select |
| - | [ [ '---', nil ] ] + CmsSite.all.collect { |l| [ l.label, l.id ] } |
| - | end |
| - | |
| - | # -- Instance Methods ----------------------------------------------------- |
| - | |
| - | protected |
| - | def create_page |
| - | self.cms_pages.create!( |
| - | :label => self.label, |
| - | :cms_layout => CmsLayout.first, |
| - | :site_root => true |
| - | ) |
| - | |
| - | self.save(false) if (self.changed?) |
| - | end |
| - | end |
app/views/cms_admin/categories/_category.html.haml
+0
-19
| @@ | @@ -1,19 +0,0 @@ |
| - | - item ||= nil |
| - | - if item.blank? |
| - | - is_checked = false |
| - | - else |
| - | - is_checked = item.cms_categories.collect(&:id).include?(category.id) |
| - | - item_type = item.class.to_s.underscore |
| - | |
| - | %li |
| - | - field_name = "#{item_type}[attr_category_ids][#{category.id}]" |
| - | = hidden_field_tag field_name, 0, :id => nil |
| - | .form_element.check_box_element |
| - | .value |
| - | = check_box_tag field_name, 1, is_checked, :onchange => "$.CMS.toggle_category_selections(this)", :id => "cms_category_id_#{category.id}" |
| - | = label_tag "cms_category_id_#{category.id}", category.label |
| - | |
| - | %ul{:id => dom_id(category)} |
| - | - unless category.children.empty? |
| - | - category.children.each do |sub_category| |
| - | = render :partial => 'cms_admin/categories/category', :locals => {:category => sub_category, :item => item } |
app/views/cms_admin/categories/_category_subform.html.haml
+0
-12
| @@ | @@ -1,12 +0,0 @@ |
| - | .form_element_group.categories |
| - | %h2 Categories |
| - | .form_element |
| - | .label Categories |
| - | .field |
| - | %ul#root_categories |
| - | = render :partial => 'cms_admin/categories/category', :locals => { :item => item }, :collection => CmsCategory.roots |
| - | |
| - | .form_element |
| - | .label Add Category |
| - | .field |
| - | = render :partial => 'cms_admin/categories/new', :locals => { :item_type => item.class.name.underscore } |
app/views/cms_admin/categories/_form.html.haml
+0
-14
| @@ | @@ -1,14 +0,0 @@ |
| - | %h2= @cms_category.new_record? ? "New Category" : "Editing \"#{@cms_category.label}\"" |
| - | = render :partial => 'cms_admin/flash_message' |
| - | = f.error_messages |
| - | |
| - | .form_element_group.horizontal |
| - | = f.text_field :label |
| - | = f.text_field :slug, :label => 'slug' |
| - | = f.select :parent_id, [['---', nil]] + CmsCategory.categories_for_select |
| - | = f.text_area :description |
| - | |
| - | .submit |
| - | = f.submit 'Save All Changes' |
| - | or |
| - | = link_to 'Return to List', cms_admin_categories_path |
app/views/cms_admin/categories/_new.html.haml
+0
-10
| @@ | @@ -1,10 +0,0 @@ |
| - | #new_category |
| - | - if defined? @cms_category and @cms_category.errors.present? |
| - | = "Label #{@cms_category.errors[:label]}" |
| - | = text_field :cms_category, :label |
| - | = select :cms_category, :parent_id, [['---', nil]] + CmsCategory.categories_for_select |
| - | = hidden_field_tag 'item_type', item_type |
| - | /= submit_tag "Add Category" |
| - | = tag "input", :type => "button", :value => "Add Category" |
| - | or |
| - | = link_to 'Manage Categories', cms_admin_categories_path |
app/views/cms_admin/categories/_toggle_link.html.haml
+0
-9
| @@ | @@ -1,9 +0,0 @@ |
| - | - category ||= toggle_link |
| - | |
| - | - if category.children.count > 0 |
| - | |
| - | - if session[:cms_category_tree] && session[:cms_category_tree].member?(category.id.to_s) |
| - | = link_to_remote category.children.count, :url => {:action => 'children', :id => category.id, :state => 'open'}, :loading => "$('category_#{category.id}_children').show()", :html => {:id => "category_#{category.id}_link", :class => 'tree_toggle open'} |
| - | |
| - | - else |
| - | = link_to_remote category.children.count, :url => {:action => 'children', :id => category.id, :state => 'closed'}, :loading => "$('category_#{category.id}_children').show()", :html => {:id => "category_#{category.id}_link", :class => 'tree_toggle closed'} |
| \ No newline at end of file | |
app/views/cms_admin/categories/_tree_branch.html.haml
+0
-30
| @@ | @@ -1,30 +0,0 @@ |
| - | - category = tree_branch |
| - | - children = category.children |
| - | |
| - | %li[category] |
| - | - if children.size > 0 |
| - | = link_to_toggle(category, children.size) |
| - | .item |
| - | .icon |
| - | - if category.siblings.size > 0 |
| - | .dragger |
| - | = link_to category.label, edit_cms_admin_category_path(category), :class => 'label' |
| - | |
| - | %span.action_links |
| - | [ |
| - | = link_to 'Add Child Category', new_cms_admin_category_path(:parent_id => category.id) |
| - | | |
| - | = link_to 'Edit', edit_cms_admin_category_path(category) |
| - | | |
| - | = link_to 'Remove', cms_admin_category_path(category), :method => 'delete', :confirm => 'Are you sure you want to remove this category?' |
| - | ] |
| - | |
| - | %br/ |
| - | - if category.number_of_records == 0 |
| - | Nothing in this category |
| - | - else |
| - | = link_to "#{pluralize(category.number_of_records,'thing')} in this category", cms_admin_category_path(category), :class => 'slug' |
| - | |
| - | - if children.size > 0 |
| - | %ul{:id => dom_id(category, :children), :class => "sortable #{tree_state(category)}"} |
| - | = render :partial => 'tree_branch', :collection => children |
app/views/cms_admin/categories/children.js.rjs
+0
-10
| @@ | @@ -1,10 +0,0 @@ |
| - | case params[:state] |
| - | when 'closed' |
| - | page.replace "category_#{@cms_category.id}_link", :partial => 'toggle_link', :object => @cms_category, :locals => { :state => 'open' } |
| - | page.replace_html "category_#{@cms_category.id}_children", :partial => 'tree_branch', :object => @cms_category.children |
| - | when 'open' |
| - | page.replace "category_#{@cms_category.id}_link", :partial => 'toggle_link', :object => @cms_category, :locals => { :state => 'closed' } |
| - | page.hide "category_#{@cms_category.id}_children" |
| - | page.replace_html "category_#{@cms_category.id}_children", '' |
| - | end |
| - | |
app/views/cms_admin/categories/create.js.haml
+0
-7
| @@ | @@ -1,7 +0,0 @@ |
| - | - if @cms_category.valid? |
| - | - if @cms_category.parent.blank? |
| - | =raw '$("#root_categories").append("' + (render :partial => 'category', :locals => { :category => @cms_category, :item_type => params[:item_type] }).gsub(/\n/,'').gsub(/"/,'\\"') + '");' |
| - | - else |
| - | =raw '$("#' + dom_id(@cms_category.parent) + '").append("' + (render :partial => 'category', :locals => { :category => @cms_category, :item_type => params[:item_type] }).gsub(/\n/,'').gsub(/"/,'\\"') + '");' |
| - | |
| - | =raw '$("#new_category").replaceWith("' + (render :partial => 'cms_admin/categories/new', :locals => {:item_type => params[:item_type]}).gsub(/\n/,'').gsub(/"/,'\\"') + '");' |
app/views/cms_admin/categories/edit.html.haml
+0
-3
| @@ | @@ -1,3 +0,0 @@ |
| - | = cms_form_for @cms_category, :url => {:action => :update}, :html => {:method => :put } do |form| |
| - | = render :partial => "form", :locals => {:f => form} |
| - | |
app/views/cms_admin/categories/index.html.haml
+0
-9
| @@ | @@ -1,9 +0,0 @@ |
| - | = link_to 'Add New Category', new_cms_admin_category_path, :class => 'top_button' |
| - | |
| - | %h2 Categories |
| - | = render :partial => 'cms_admin/flash_message' |
| - | - if @cms_categories.empty? |
| - | No Categories have been created yet |
| - | - else |
| - | %ul.tree_structure.sortable |
| - | = render :partial => 'tree_branch', :collection => @cms_categories |
app/views/cms_admin/categories/new.html.haml
+0
-2
| @@ | @@ -1,2 +0,0 @@ |
| - | = cms_form_for @cms_category, :url => {:action => :create } do |form| |
| - | = render :partial => 'form', :locals => {:f => form} |
app/views/cms_admin/categories/show.html.haml
+0
-14
| @@ | @@ -1,14 +0,0 @@ |
| - | %h2= "Category: #{@cms_category.label}" |
| - | - @cms_category.records.each_pair do |model_sym,records| |
| - | - model_type = model_sym.to_s |
| - | - content_for :head do |
| - | = stylesheet_link_tag model_type unless model_type == "cms_pages" |
| - | -# This requires that plugins have standardized names, like "cms_attachments.sass" |
| - | |
| - | %h3 |
| - | = "#{model_type[4..-1].humanize} (#{records.length})" |
| - | |
| - | - records.each do |record| |
| - | = link_to record.label, {:controller => model_type[4..-1], :action => :edit, :id => record.to_param}, :class => model_type[4..-1].singularize |
| - | - if records.empty? |
| - | %p No #{model_type[4..-1]} in this category |
app/views/cms_admin/pages/_form.html.haml
+0
-2
| @@ | @@ -7,8 +7,6 @@ |
| .form_element_group | |
| %h2 W3C Validation | |
| = link_to 'Check Validation', 'http://validator.w3.org/check?uri=http://'+request.host+@cms_page.full_path, :target => "_new" | |
| - | |
| - | = render :partial => 'cms_admin/categories/category_subform', :locals => { :item => @cms_page } |
| %h2= @cms_page.new_record? ? "New Page" : "Editing \"#{@cms_page.label}\"" | |
| = render :partial => 'cms_admin/flash_message' | |
app/views/cms_admin/sites/_form.html.haml
+0
-10
| @@ | @@ -1,10 +0,0 @@ |
| - | %h2= @site.new_record? ? "New Site" : "Editing \"#{@site.label}\"" |
| - | = render :partial => 'cms_admin/flash_message' |
| - | = f.error_messages |
| - | .form_element_group.horizontal |
| - | = f.text_field :label, :label => "Site Name" |
| - | = f.text_field :hostname, :label => "Hostname" |
| - | .submit |
| - | = f.submit 'Save All Changes', :onclick => 'this.f.target = ""' |
| - | or |
| - | = link_to 'Return to List', cms_admin_sites_path |
app/views/cms_admin/sites/_site.html.haml
+0
-14
| @@ | @@ -1,14 +0,0 @@ |
| - | %li[site] |
| - | .item |
| - | .icon |
| - | = link_to site.label, edit_cms_admin_site_path(site), :class => 'label' |
| - | |
| - | %span.action_links |
| - | [ |
| - | = link_to 'Edit', edit_cms_admin_site_path(site) |
| - | | |
| - | = link_to 'Remove', cms_admin_site_path(site), :method => 'delete', :confirm => 'Are you sure you want to remove this site?' |
| - | ] |
| - | .details |
| - | - url = "http://#{site.hostname}/" |
| - | = link_to(h(url), url) |
| \ No newline at end of file | |
app/views/cms_admin/sites/edit.html.haml
+0
-2
| @@ | @@ -1,2 +0,0 @@ |
| - | = cms_form_for(@site, :url => { :action => :update }) do |form| |
| - | = render :partial => 'form', :locals => {:f => form} |
app/views/cms_admin/sites/index.html.haml
+0
-10
| @@ | @@ -1,10 +0,0 @@ |
| - | = link_to('Add New Site', new_cms_admin_site_path, :class => 'top_button') |
| - | |
| - | %h2 Sites |
| - | = render :partial => 'cms_admin/flash_message' |
| - | %ul.tree_structure |
| - | - if @sites.blank? |
| - | %li No Sites Defined |
| - | - else |
| - | = render(:partial => 'site', :collection => @sites) |
| - | |
app/views/cms_admin/sites/new.html.haml
+0
-2
| @@ | @@ -1,2 +0,0 @@ |
| - | = cms_form_for(@site, :url => {:action => :create }) do |form| |
| - | = render :partial => 'form', :locals => {:f => form} |
app/views/layouts/cms_admin.html.haml
+0
-1
| @@ | @@ -27,7 +27,6 @@ |
| %li= active_link_to 'Layouts', cms_admin_layouts_path | |
| %li= active_link_to 'Pages', cms_admin_pages_path, :active => {:when => [['cms_admin/pages'], %w(index new edit create update)]} | |
| %li= active_link_to 'Snippets', cms_admin_snippets_path | |
| - | %li= active_link_to 'Categories', cms_admin_categories_path |
| - if (tabs = ComfortableMexicanSofa::Config.extension_tabs) | |
| %ul.secondary | |
config/routes.rb
+0
-7
| @@ | @@ -28,13 +28,6 @@ Rails.application.routes.draw do |
| put :reorder | |
| end | |
| end | |
| - | |
| - | resources :categories do |
| - | member do |
| - | match :toggle |
| - | match :children |
| - | end |
| - | end |
| end | |
| controller :cms_content do | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+0
-23
| @@ | @@ -54,27 +54,6 @@ class CreateCms < ActiveRecord::Migration |
| execute "INSERT INTO cms_blocks (id, cms_page_id, label, content_text) VALUES (1, 1, 'default', 'Default home page')" | |
| - | create_table :cms_categories do |t| |
| - | t.integer :parent_id |
| - | t.string :slug |
| - | t.string :label |
| - | t.text :description |
| - | t.integer :children_count, :null => false, :default => 0 |
| - | t.timestamps |
| - | end |
| - | add_index :cms_categories, :slug |
| - | add_index :cms_categories, [:parent_id, :slug] |
| - | |
| - | |
| - | create_table :cms_page_categorizations do |t| |
| - | t.integer :cms_category_id |
| - | t.integer :cms_page_id |
| - | t.timestamps |
| - | end |
| - | add_index :cms_page_categorizations, [:cms_category_id, :cms_page_id], :unique => true, |
| - | :name => 'index_page_categorizations_on_category_id_and_page_id' #auto-generated name was too long. |
| - | |
| - | |
| create_table :cms_snippets do |t| | |
| t.string :label | |
| t.text :content | |
| @@ | @@ -88,7 +67,5 @@ class CreateCms < ActiveRecord::Migration |
| drop_table :cms_pages | |
| drop_table :cms_snippets | |
| drop_table :cms_blocks | |
| - | drop_table :cms_categories |
| - | drop_table :cms_page_categorizations |
| end | |
| end | |
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb
+0
-1
| @@ | @@ -1,7 +1,6 @@ |
| %w( | |
| cms_rails_extensions | |
| cms_acts_as_tree | |
| - | acts_as_categorized |
| cms_tag | |
| cms_tags/block | |
| cms_tags/page_block | |
comfortable_mexican_sofa/acts_as_categorized.rb b/lib/comfortable_mexican_sofa/acts_as_categorized.rb
+0
-88
| @@ | @@ -1,88 +0,0 @@ |
| - | module ActsAsCategorized |
| - | module StubMethods |
| - | |
| - | def acts_as_categorized |
| - | |
| - | __categorized = self.to_s.underscore.to_sym |
| - | __categorizations = "#{__categorized}_categorizations".to_sym |
| - | |
| - | # -- Attributes ------------------------------------------------------- |
| - | attr_accessor :attr_category_ids # hash that comes from the form |
| - | |
| - | # -- Relationships ---------------------------------------------------- |
| - | has_many __categorizations, |
| - | :dependent => :destroy |
| - | has_many :cms_categories, |
| - | :through => __categorizations |
| - | |
| - | # -- Callbacks -------------------------------------------------------- |
| - | after_save :save_categorizations |
| - | |
| - | # -- Named Scopes ----------------------------------------------------- |
| - | |
| - | scope :in_category, lambda { |category| { |
| - | :joins => __categorizations, |
| - | :conditions => { __categorizations => {:cms_category_id => (category.is_a?(CmsCategory) ? category.id : category) } } |
| - | }} |
| - | |
| - | # -- Instance Methods ------------------------------------------------- |
| - | define_method :save_categorizations do |
| - | return if attr_category_ids.blank? |
| - | |
| - | category_ids_to_remove = attr_category_ids.select{ |k, v| v.to_i == 0}.collect{|k, v| k } |
| - | category_ids_to_create = attr_category_ids.select{ |k, v| v.to_i == 1}.collect{|k, v| k } |
| - | |
| - | # removing unchecked categories |
| - | send(__categorizations).all(:conditions => { :cms_category_id => category_ids_to_remove}).collect(&:destroy) |
| - | |
| - | # creating categorizations |
| - | category_ids_to_create.each do |category_id| |
| - | send(__categorizations).create(:cms_category_id => category_id) |
| - | end |
| - | end |
| - | end |
| - | |
| - | def acts_as_categorization |
| - | |
| - | __categorized = self.to_s.underscore.gsub('_categorization', '').to_sym |
| - | __categorized_id = "#{__categorized}_id".to_sym |
| - | __categorizations = "#{__categorized}_categorizations".to_sym |
| - | |
| - | # -- Relationships -------------------------------------------------------- |
| - | belongs_to __categorized.to_sym |
| - | belongs_to :cms_category |
| - | |
| - | # -- Validations ---------------------------------------------------------- |
| - | validates_presence_of __categorized_id, |
| - | :cms_category_id |
| - | |
| - | validates_uniqueness_of __categorized_id, :scope => :cms_category_id |
| - | |
| - | # -- AR Callbacks --------------------------------------------------------- |
| - | after_save :create_parent_categorization |
| - | after_destroy :destroy_children_categorizations |
| - | |
| - | # -- Instance Methods ----------------------------------------------------- |
| - | define_method :create_parent_categorization do |
| - | return unless cms_category.parent |
| - | |
| - | params = { |
| - | :cms_category_id => cms_category.parent_id, |
| - | __categorized_id => send(__categorized).id |
| - | } |
| - | self.class.create!(params) unless self.class.exists?(params) |
| - | end |
| - | |
| - | define_method :destroy_children_categorizations do |
| - | return if cms_category.children.blank? |
| - | |
| - | cms_category.children.each do |c| |
| - | send(__categorized).send(__categorizations).first(:conditions => {"cms_category_id" => c.id }).try(:destroy) |
| - | end |
| - | end |
| - | end |
| - | end |
| - | end |
| - | |
| - | ActiveRecord::Base.extend(ActsAsCategorized::StubMethods) |
| - | |
public/javascripts/cms/cms.js
+1
-41
| @@ | @@ -43,8 +43,7 @@ $.CMS = function(){ |
| // Datepicker | |
| $('input[data-datepicker]').datepicker({dateFormat : 'yy-mm-dd'}); | |
| - | // Add Category Subform |
| - | $.CMS.category_subform_submit(); |
| + | |
| }); // End $(document).ready() | |
| @@ | @@ -59,45 +58,6 @@ $.CMS = function(){ |
| } | |
| str = str.replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase(); | |
| return str; | |
| - | }, |
| - | toggle_category_selections: function(obj) { |
| - | if (obj.checked == true){ |
| - | $(obj).parents("ul#root_categories li") |
| - | .children("div.form_element") |
| - | .find("input[type=checkbox]") |
| - | .each(function() { |
| - | this.checked = true; |
| - | }); |
| - | } else { |
| - | // NOT WORKING |
| - | $(obj).parent().parent().parent().find("input[type=checkbox]").each(function() { |
| - | this.checked = false; |
| - | }); |
| - | } |
| - | }, |
| - | category_subform_submit: function(){ |
| - | $('#new_category input[type=button]').bind('click.cms', function() { |
| - | var currently_selected = []; |
| - | $.post( |
| - | '/cms-admin/categories.js', |
| - | $("#new_category [name^=cms_category]") |
| - | .add("input[name=item_type]") |
| - | .add("input[name='authenticity_token']") |
| - | .serialize(), |
| - | function(data) { |
| - | $("#cms_category_label").val("").focus(); |
| - | $.CMS.category_subform_submit(); |
| - | } |
| - | ); |
| - | return false; |
| - | }) |
| - | |
| - | $('#new_category input[name^=cms_category]').bind('keypress.cms', function(event) { |
| - | if (event.keyCode == '13') { |
| - | event.preventDefault(); |
| - | $('#new_category input[type=button]').trigger('click.cms'); |
| - | } |
| - | }) |
| } | |
| } | |
| }(); | |
public/stylesheets/cms_master.css
+0
-42
| @@ | @@ -384,21 +384,6 @@ table.formatted { |
| .form_element_group.publishing .form_element .field input { | |
| width: 200px; } | |
| - | .form_element_group.categories .label { |
| - | border-bottom: 2px solid white; |
| - | padding-bottom: 5px; |
| - | margin-bottom: 5px; } |
| - | .form_element_group.categories ul#root_categories { |
| - | margin-bottom: 10px; } |
| - | .form_element_group.categories ul#root_categories li li { |
| - | padding-left: 15px; } |
| - | .form_element_group.categories ul#root_categories input { |
| - | width: auto; } |
| - | .form_element_group.categories #new_category input, .form_element_group.categories #new_category select { |
| - | margin-bottom: 5px; } |
| - | .form_element_group.categories #new_category input.submit_button { |
| - | width: auto; } |
| - | |
| .submit { | |
| float: left; | |
| line-height: 30px; } | |
| @@ | @@ -448,30 +433,3 @@ form .errorExplanation { |
| width: 28px; | |
| height: 28px; | |
| background: url(/images/cms/icon_snippet.gif); } | |
| - | |
| - | #cms_admin_categories_index .icon { |
| - | background-image: url(/images/cms/icon_category.gif); } |
| - | #cms_admin_categories_index .categorizations { |
| - | font-size: 10px; } |
| - | |
| - | #cms_admin_categories_show h3 { |
| - | font-size: 12px; |
| - | text-transform: uppercase; |
| - | border-bottom: 1px solid #cccccc; |
| - | color: #cccccc; |
| - | margin-bottom: 15px; |
| - | clear: both; } |
| - | #cms_admin_categories_show .pages { |
| - | margin-bottom: 15px; |
| - | overflow: hidden; } |
| - | #cms_admin_categories_show a.page { |
| - | width: 150px; |
| - | float: left; |
| - | height: 30px; |
| - | padding-left: 35px; |
| - | font: 14px/30px Georgia, serif; |
| - | color: black; |
| - | margin: 0px 5px 5px 0px; |
| - | background: url(/images/cms/icon_regular.gif) left center no-repeat; } |
| - | #cms_admin_categories_show a:hover { |
| - | border-bottom: 0px; } |
public/stylesheets/sass/cms_master.sass
+0
-46
| @@ | @@ -410,24 +410,6 @@ table.formatted |
| input | |
| width: 200px | |
| - | .form_element_group.categories |
| - | .label |
| - | border-bottom: 2px solid #fff |
| - | padding-bottom: 5px |
| - | margin-bottom: 5px |
| - | ul#root_categories |
| - | margin-bottom: 10px |
| - | li li |
| - | padding-left: 15px |
| - | input |
| - | width: auto |
| - | #new_category |
| - | input, select |
| - | margin-bottom: 5px |
| - | input.submit_button |
| - | width: auto |
| - | |
| - | |
| .submit | |
| float: left | |
| line-height: 30px | |
| @@ | @@ -483,32 +465,4 @@ form |
| width: 28px | |
| height: 28px | |
| background: url(/images/cms/icon_snippet.gif) | |
| - | // --------------------------------------------------------------- Categories |
| - | #cms_admin_categories_index |
| - | .icon |
| - | background-image: url(/images/cms/icon_category.gif) |
| - | .categorizations |
| - | font-size: 10px |
| - | #cms_admin_categories_show |
| - | h3 |
| - | font-size: 12px |
| - | text-transform: uppercase |
| - | border-bottom: 1px solid #ccc |
| - | color: #ccc |
| - | margin-bottom: 15px |
| - | clear: both |
| - | .pages |
| - | margin-bottom: 15px |
| - | overflow: hidden |
| - | a.page |
| - | width: 150px |
| - | float: left |
| - | height: 30px |
| - | padding-left: 35px |
| - | font: 14px/30px Georgia, serif |
| - | color: #000 |
| - | margin: 0px 5px 5px 0px |
| - | background: url(/images/cms/icon_regular.gif) left center no-repeat |
| - | a:hover |
| - | border-bottom: 0px |
test/fixtures/cms_categories.yml
+0
-20
| @@ | @@ -1,20 +0,0 @@ |
| - | category_1: &category |
| - | label: Category 1 |
| - | slug: category_1 |
| - | parent_id: |
| - | description: Some Category Description |
| - | |
| - | category_2: |
| - | label: Category 2 |
| - | slug: category_2 |
| - | |
| - | category_2_1: |
| - | label: Category 2.1 |
| - | slug: category_2_1 |
| - | parent: category_2 |
| - | |
| - | category_2_2: |
| - | label: Category 2.2 |
| - | slug: category_2_2 |
| - | parent: category_2 |
| - | |
test/fixtures/cms_page_categorizations.yml
+0
-16
| @@ | @@ -1,16 +0,0 @@ |
| - | page_category_1: |
| - | cms_page: default |
| - | cms_category: category_2 |
| - | |
| - | page_category_2: |
| - | cms_page: default |
| - | cms_category: category_2_1 |
| - | |
| - | page_category_3: |
| - | cms_page: default |
| - | cms_category: category_2_2 |
| - | |
| - | page_category_4: |
| - | cms_page: complex |
| - | cms_category: category_2 |
| - | |
test/fixtures/cms_sites.yml
+0
-11
| @@ | @@ -1,11 +0,0 @@ |
| - | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
| - | |
| - | # This model initially had no columns defined. If you add columns to the |
| - | # model remove the '{}' from the fixture names and add the columns immediately |
| - | # below each fixture, per the syntax in the comments below |
| - | # |
| - | one: {} |
| - | # column: value |
| - | # |
| - | two: {} |
| - | # column: value |
test/functional/cms_admin/categories_controller_test.rb
+0
-87
| @@ | @@ -1,87 +0,0 @@ |
| - | require File.dirname(__FILE__) + '/../../test_helper' |
| - | |
| - | class CmsAdmin::CategoriesControllerTest < ActionController::TestCase |
| - | |
| - | def setup |
| - | http_auth |
| - | end |
| - | |
| - | def test_get_index |
| - | get :index |
| - | assert_response :success |
| - | assert assigns(:cms_categories) |
| - | end |
| - | |
| - | def test_get_new |
| - | get :new |
| - | assert_response :success |
| - | end |
| - | |
| - | def test_get_show |
| - | get :show, :id => cms_categories(:category_2) |
| - | assert_response :success |
| - | assert assigns(:cms_category) |
| - | end |
| - | |
| - | def test_get_edit |
| - | get :edit, :id => cms_categories(:category_1) |
| - | assert_response :success |
| - | assert assigns(:cms_category) |
| - | end |
| - | |
| - | def test_create |
| - | assert_difference 'CmsCategory.count', 1 do |
| - | post :create, :cms_category => { |
| - | :label => 'Category 1', |
| - | :description => 'This is a category', |
| - | } |
| - | end |
| - | assert_redirected_to edit_cms_admin_category_path(assigns(:cms_category)) |
| - | assert_equal 'Category created', flash[:notice] |
| - | end |
| - | |
| - | def test_create_fail |
| - | #assert_no_difference 'CmsCategory.count' do |
| - | post :create, :cms_category => { |
| - | :label => '', |
| - | :description => 'This is a category', |
| - | } |
| - | #end |
| - | #assert_response :success |
| - | #assert_template 'new' |
| - | #assert assigns(:cms_category).errors[:label] |
| - | end |
| - | |
| - | def test_update |
| - | category = cms_categories(:category_1) |
| - | put :update, :id => category, :cms_category => { |
| - | :label => 'Category 2', |
| - | :description => 'New Description' |
| - | } |
| - | assert_redirected_to edit_cms_admin_category_path(category) |
| - | category.reload |
| - | assert_equal 'Category 2', category.label |
| - | assert_equal 'New Description', category.description |
| - | assert_equal 'Category updated', flash[:notice] |
| - | end |
| - | |
| - | def test_update_fail |
| - | category = cms_categories(:category_1) |
| - | put :update, :id => category, :cms_category => { |
| - | :label => '', |
| - | :description => 'New Description' |
| - | } |
| - | assert_response :success |
| - | assert_template 'edit' |
| - | assert assigns(:cms_category).errors[:label] |
| - | end |
| - | |
| - | def test_destroy |
| - | assert_difference 'CmsCategory.count', -1 do |
| - | delete :destroy, :id => cms_categories(:category_1) |
| - | assert_redirected_to cms_admin_categories_path |
| - | assert_equal 'Category deleted', flash[:notice] |
| - | end |
| - | end |
| - | end |
| - | |
test/functional/cms_admin/sites_controller_test.rb
+0
-8
| @@ | @@ -1,8 +0,0 @@ |
| - | require 'test_helper' |
| - | |
| - | class CmsAdmin::SitesControllerTest < ActionController::TestCase |
| - | # Replace this with your real tests. |
| - | test "the truth" do |
| - | assert true |
| - | end |
| - | end |
test/unit/cms_category_test.rb
+0
-96
| @@ | @@ -1,96 +0,0 @@ |
| - | require File.dirname(__FILE__) + '/../test_helper' |
| - | |
| - | class CmsCategoryTest < ActiveSupport::TestCase |
| - | |
| - | def test_fixtures_validity |
| - | CmsCategory.all.each do |category| |
| - | assert category.valid?, category.errors.full_messages |
| - | end |
| - | end |
| - | |
| - | def test_should_create_category |
| - | assert_difference 'CmsCategory.count', 1 do |
| - | CmsCategory.create( |
| - | :label => 'Test Category', |
| - | :slug => 'test_category', |
| - | :description => 'Test Description' |
| - | ) |
| - | end |
| - | end |
| - | |
| - | def test_validation_on_blank |
| - | assert_no_difference 'CmsCategory.count' do |
| - | c = CmsCategory.create( |
| - | :label =>'', |
| - | :slug =>'' |
| - | ) |
| - | assert c.errors[:label] |
| - | assert c.errors[:slug] |
| - | end |
| - | end |
| - | |
| - | def test_validation_on_existing_slug |
| - | assert_no_difference 'CmsCategory.count' do |
| - | c = CmsCategory.create( |
| - | :label => 'Test Category', |
| - | :slug => cms_categories(:category_1).slug |
| - | ) |
| - | assert c.errors[:slug] |
| - | end |
| - | end |
| - | |
| - | def test_removing_category_blows_away_children_and_categorizations |
| - | category = cms_categories(:category_2) |
| - | |
| - | assert_equal 2, category.children.count |
| - | |
| - | assert_equal 2, category.cms_page_categorizations.count |
| - | assert_equal 2, category.cms_pages.count |
| - | |
| - | assert_no_difference ['CmsPage.count'] do |
| - | assert_difference ['CmsCategory.count'], -3 do |
| - | assert_difference ['CmsPageCategorization.count'], -4 do # -2 from child categories |
| - | category.destroy |
| - | end |
| - | end |
| - | end |
| - | end |
| - | |
| - | def test_categorized_model_names |
| - | model_names = CmsCategory.categorized_model_names |
| - | assert model_names.include?("CmsPage"), "CmsPage was not listed as categorized" |
| - | assert !model_names.include?("CmsPageCategorization"), "CmsPageCategorizations was listed as categorized" |
| - | assert !model_names.include?("CmsCategory"), "CmsCategory was listed as categorized" |
| - | end |
| - | |
| - | def test_categorized_model_types |
| - | model_types = CmsCategory.categorized_model_types |
| - | assert model_types.include?(CmsPage), "CmsPage was not listed as categorized" |
| - | assert !model_types.include?(CmsPageCategorization), "CmsPageCategorizations was listed as categorized" |
| - | assert !model_types.include?(CmsCategory), "CmsCategory was listed as categorized" |
| - | end |
| - | |
| - | def test_number_of_records |
| - | assert_equal 2, cms_categories(:category_2).number_of_records |
| - | assert_equal 1, cms_categories(:category_2_1).number_of_records |
| - | assert_equal 1, cms_categories(:category_2_2).number_of_records |
| - | assert_equal 0, cms_categories(:category_1).number_of_records |
| - | end |
| - | |
| - | def test_records |
| - | assert cms_categories(:category_2).records[:cms_pages].include?(cms_pages(:default)) |
| - | assert cms_categories(:category_2).records[:cms_pages].include?(cms_pages(:complex)) |
| - | assert cms_categories(:category_2_1).records[:cms_pages].include?(cms_pages(:default)) |
| - | assert cms_categories(:category_2_2).records[:cms_pages].include?(cms_pages(:default)) |
| - | assert cms_categories(:category_1).records[:cms_pages].empty? |
| - | end |
| - | |
| - | |
| - | def test_should_set_slug_if_blank |
| - | c = CmsCategory.new( |
| - | :label => 'Test Category' |
| - | ) |
| - | assert c.valid? |
| - | assert_equal 'test-category', c.slug |
| - | end |
| - | end |
test/unit/cms_page_categorization_test.rb
+0
-37
| @@ | @@ -1,37 +0,0 @@ |
| - | require 'test_helper' |
| - | |
| - | class CmsPageCategorizationTest < ActiveSupport::TestCase |
| - | |
| - | def test_fixtures_validity |
| - | CmsPageCategorization.all.each do |categorization| |
| - | assert categorization.valid?, categorization.errors.full_messages |
| - | end |
| - | end |
| - | |
| - | def test_creation |
| - | assert_difference 'CmsPageCategorization.count' do |
| - | CmsPageCategorization.create( |
| - | :cms_page => cms_pages(:complex), |
| - | :cms_category => cms_categories(:category_1) |
| - | ) |
| - | end |
| - | end |
| - | |
| - | def test_cascading_creation |
| - | assert_difference 'CmsPageCategorization.count', 2 do |
| - | CmsPageCategorization.create( |
| - | :cms_page => cms_pages(:unpublished), |
| - | :cms_category => cms_categories(:category_2_1) |
| - | ) |
| - | end |
| - | end |
| - | |
| - | def test_cascading_removal |
| - | categorization = cms_page_categorizations(:page_category_1) |
| - | assert_difference 'CmsPageCategorization.count', -3 do |
| - | categorization.destroy |
| - | end |
| - | end |
| - | |
| - | end |
| - | |
test/unit/cms_site_test.rb
+0
-8
| @@ | @@ -1,8 +0,0 @@ |
| - | require 'test_helper' |
| - | |
| - | class CmsSiteTest < ActiveSupport::TestCase |
| - | # Replace this with your real tests. |
| - | test "the truth" do |
| - | assert true |
| - | end |
| - | end |