diff --git a/app/models/album.rb b/app/models/album.rb
index 7c97946..d411d94 100644
--- a/app/models/album.rb
+++ b/app/models/album.rb
@@ -13,7 +13,9 @@ class Album < ActiveRecord::Base
attr_accessor :tags
attr_protected :path
- named_scope :untouched, :conditions => "albums.Id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description IS NULL AND photos.id NOT IN ( SELECT photo_id FROM photo_tags) )", :order => 'title'
+ named_scope :untouched, :conditions => "albums.id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description IS NULL AND photos.id NOT IN ( SELECT photo_id FROM photo_tags) )", :order => 'title'
+ named_scope :unused, :conditions => "albums.id NOT IN (SELECT album_id FROM collection_albums)"
+ named_scope :used, :conditions => "albums.id IN (SELECT album_id FROM collection_albums)"
def to_param
"#{id}-#{title.parameterize}"
diff --git a/app/models/collection.rb b/app/models/collection.rb
index 97967ac..2e81eb7 100644
--- a/app/models/collection.rb
+++ b/app/models/collection.rb
@@ -1,18 +1,14 @@
class Collection < ActiveRecord::Base
has_many :collection_albums
has_many :albums, :through => :collection_albums
- #accepts_nested_attributes_for :albums, :allow_destroy => true
attr_accessor :album_list
def to_param
- #title.gsub(/[^a-z0-9]+/i, '-')
"#{id}-#{title.parameterize}"
end
-
+
def album_list=(albums)
- self.albums = Album.find(albums)
+ self.albums = Album.find(albums.map{|album|album[0]})
end
-
-
end
\ No newline at end of file
diff --git a/app/views/collections/_form.html.erb b/app/views/collections/_form.html.erb
index 15743bc..9efc9c2 100644
--- a/app/views/collections/_form.html.erb
+++ b/app/views/collections/_form.html.erb
@@ -4,5 +4,28 @@
<%= form.label :description %>
<%= form.text_area :description %>
-<%= form.label :album %>
-<%= collection_select :collection, :album_list, Album.find(:all, :order => :title), :id, :title, {:selected => @collection.albums.map{|album|album.id} }, {:multiple => true, :rows => 10} %>
\ No newline at end of file
+<%= form.label :albums %>
+
+
+<% +grouped_options = [ + ['Available albums',[['Choose album to add','']]], + ['Not used', Album.unused.map{|album|[album.title, album.id]} ], + ['In use', Album.used.map{|album|[album.title, album.id]} ] +] +grouped_options_for_select(grouped_options) +%> +<%= select_tag 'available_albums', grouped_options_for_select(grouped_options) %> +
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cd3f53c..68db9da 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -41,7 +41,7 @@ -<%= javascript_include_tag 'jquery-1.3.2.js', 'application' %> +<%= javascript_include_tag 'jquery-1.3.2.js', 'jquery.livequery.js', 'balder' %> <%= yield :javascript %>