Permalink
Browse files

Add a select list to select the parent portfolio entry for a given po…

…rtfolio entry. Caveats being it can't be the entry itself and it can't be a descendant of the entry.
  • Loading branch information...
1 parent 8864f5f commit 3ae48d76fb1243a86ed68d0a58fed9394ab488d4 @parndt parndt committed Feb 27, 2010
@@ -1,6 +1,7 @@
class Admin::PortfolioEntriesController < Admin::BaseController
crudify :portfolio_entry, :order => 'position ASC', :conditions => "parent_id IS NULL"
+ before_filter :find_portfolio_entries_for_parents_list, :only => [:new, :create, :edit, :update]
def emancipate
if (entry = PortfolioEntry.find(params[:id])).present?
@@ -10,4 +11,18 @@ def emancipate
redirect_to :action => "index"
end
+protected
+
+ # This finds all of the entries that could possibly be assigned as the current entry's parent.
+ def find_portfolio_entries_for_parents_list
+ @portfolio_entries_for_parents_list = PortfolioEntry.find(:all, :order => "parent_id, position ASC")
+
+ # We need to remove all references to the current entry or any of its decendants or we get a nightmare.
+ unless @portfolio_entry.nil? or @portfolio_entry.new_record?
+ @portfolio_entries_for_parents_list.reject! do |entry|
+ entry.id == @portfolio_entry.id or @portfolio_entry.descendants.include?(entry)
+ end
+ end
+ end
+
end
@@ -1,28 +1,32 @@
class PortfolioEntry < ActiveRecord::Base
-
+
validates_presence_of :title
-
+
# call to gems included in refinery.
has_friendly_id :title, :use_slug => true, :strip_diacritics => true
acts_as_tree :order => "position"
-
+
has_and_belongs_to_many :images
def content
self.body
end
-
+
def content=(value)
self.body = value
end
-
+
def image_ids=(ids)
self.images.clear
-
+
ids.reject{|id| id.blank? }.each do |image_id|
image = Image.find(image_id.to_i) rescue nil
self.images << image unless image.nil?
end
end
-
+
+ def indented_title
+ "#{"--" * self.ancestors.size} #{self.title}".chomp
+ end
+
end
@@ -26,6 +26,12 @@
<%= f.label :body, 'Content' %>
<%= f.text_area :body, :class => "wymeditor", :rows => 7 %>
</div>
+ <% if @portfolio_entries_for_parents_list.any? %>
+ <div class='field'>
+ <%= f.label :parent_id %>
+ <%= f.collection_select :parent_id, @portfolio_entries_for_parents_list, :id, :indented_title, :include_blank => true %>
+ </div>
+ <% end %>
<div class='form-actions'>
<%= f.submit 'Save', :class => "wymupdate" %>
or
View
@@ -3,7 +3,7 @@
plugin.title = "Portfolio"
plugin.description = "Manage a portfolio"
plugin.url = "/admin/#{plugin.title.downcase}"
- plugin.version = '0.9.3.6'
+ plugin.version = '0.9.3.7'
plugin.menu_match = /admin\/portfolio(_entries)?/
plugin.activity = {
:class => PortfolioEntry,
View
@@ -23,13 +23,13 @@ Then run:
refinerycms-portfolio-install /path/to/your/refinery/application
Then place in your config/environment.rb (or config/application.rb for refinery 0.9.6.x) file before all other Refinery gem calls:
- config.gem "refinerycms-portfolio", :version => ">= 0.9.3.6", :lib => "portfolio", :source => "http://gemcutter.org"
+ config.gem "refinerycms-portfolio", :version => ">= 0.9.3.7", :lib => "portfolio", :source => "http://gemcutter.org"
..and follow the instructions!
### Method Two
Place in your config/environment.rb (or config/application.rb for refinery 0.9.6.x) file before all other Refinery gem calls:
- config.gem "refinerycms-portfolio", :version => ">= 0.9.3.6", :lib => "portfolio", :source => "http://gemcutter.org"
+ config.gem "refinerycms-portfolio", :version => ">= 0.9.3.7", :lib => "portfolio", :source => "http://gemcutter.org"
Then run in your application's directory:
rake gems:install
@@ -1,10 +1,10 @@
Gem::Specification.new do |s|
s.name = %q{refinerycms-portfolio}
- s.version = "0.9.3.6"
+ s.version = "0.9.3.7"
s.authors = ["Resolve Digital", "Philip Arndt"]
- s.date = %q{2010-02-18}
+ s.date = %q{2010-02-27}
s.description = %q{A really straightforward open source Ruby on Rails portfolio plugin designed for integration with RefineryCMS.}
s.summary = %q{Ruby on Rails portfolio plugin for RefineryCMS.}

0 comments on commit 3ae48d7

Please sign in to comment.