commit bf16d41408b3309a93dcd0dd0723a4d478023818
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Tue Jun 8 02:20:40 2010 +0200

    [evol] artworks context menu: finished mechanism + checked for empty selection + implemented associate_with_tag action

diff --git a/app/controllers/admin/artworks_controller.rb b/app/controllers/admin/artworks_controller.rb
index a104388..4a219fa 100644
--- a/app/controllers/admin/artworks_controller.rb
+++ b/app/controllers/admin/artworks_controller.rb
@@ -3,19 +3,38 @@ class Admin::ArtworksController < Admin::AdminController
 
   before_filter :load_form_data, :only => [:new, :create, :edit, :update]
 
+  SELECTION_ACTION_LIST = [[_('Associate with Tag'), 'associate_with_tag'], [_('Delete'), 'delete']]
+
+  def index
+    @selection_action_list = SELECTION_ACTION_LIST
+  end
+
   def artworks_selection
-    item_list = params['artworks_selection_items'].collect {|x| x.to_i }
+    if Hash[SELECTION_ACTION_LIST].values.include? params['artworks_selection_action']
+      @action = "selection_" + params['artworks_selection_action']
 
-    case params['artworks_selection_action']
-    when 'to_tag'
-      render :text => "Action: assign Artworks to a tag<br/>List: " + item_list.join(", ")
-    when 'delete'
-      render :text => "Action: delete Artworks<br/>List: " + item_list.join(", ")
+      artworks_ids = params['artworks_selection_ids'].collect {|x| x.to_i }
+      @selection = Artwork.find(artworks_ids)
+
+      render :action => @action
     else
       render_404
     end
   end
 
+  def selection_associate_with_tag
+    artwork_list = params['artworks_selection_ids'].collect {|x| Artwork.find(x.to_i) }
+    tag_list = params['tags_selection_ids'].collect {|x| Tag.find(x.to_i) }
+
+    artwork_list.each do |artwork|
+      artwork.tags += tag_list
+    end
+
+    redirect_to :action => "index"
+  end
+
+  protected
+
   private
 
   def load_form_data
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3b3a872..f45a8ee 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -299,16 +299,34 @@ module ApplicationHelper
     zone_id = prefix_id + "_zone"
     form_id = prefix_id + "_form"
     action_id = prefix_id + "_action"
-    items_id = prefix_id + "_items"
+    items_id = prefix_id + "_ids[]"
+
+    empty_selection_msg = _("Empty selection")
 
     menu_items = []
     item_list.each do |item_data|
       menu_items << {
         :name => "'#{item_data[0]}'",
         :callback => "function() { 
-          document.getElementById('#{action_id}').value = '#{item_data[1]}';
-          document.getElementById('#{form_id}').submit();
-          /*alert('#{item_data[1]}');*/
+            items = $A(document.getElementsByName('#{items_id}'));
+
+            one_checkbox_set = false;
+            for (var i = 0; i < items.length; ++i)
+            {
+              if (items[i].checked)
+              {
+                one_checkbox_set = true;
+                break;
+              }
+            }
+
+            if (one_checkbox_set)
+            {
+              $('#{action_id}').value = '#{item_data[1]}';
+              $('#{form_id}').submit();
+            }
+            else
+              alert('#{empty_selection_msg}');
           }
         "
       }
diff --git a/app/models/artwork.rb b/app/models/artwork.rb
index 4e88591..8ceb5a9 100644
--- a/app/models/artwork.rb
+++ b/app/models/artwork.rb
@@ -21,4 +21,12 @@ class Artwork < ActiveRecord::Base
     return nil if self.artwork_step_images.empty?
     self.artwork_step_images.last
   end
+
+  def full_title
+    str = ""
+    str += self.artwork_set.name unless artwork_set.nil?
+    str += " :: " + self.artwork_group.name unless artwork_group.nil?
+    str += " :: " unless str == ""
+    str += self.title
+  end
 end
diff --git a/app/views/admin/artworks/index.rhtml b/app/views/admin/artworks/index.rhtml
index ecdaed2..3b7966d 100644
--- a/app/views/admin/artworks/index.rhtml
+++ b/app/views/admin/artworks/index.rhtml
@@ -20,7 +20,7 @@
     <% @artworks = resource_model.paginate(:all, :include => [:artwork_set, :artwork_group], :order => params[:sort], :page => params[:page]) %>
     <% @artworks.each do |artwork| %>
     <tr>
-      <td><%= check_box_tag 'artworks_selection_items[]', artwork.id %></td>
+      <td><%= check_box_tag 'artworks_selection_ids[]', artwork.id, false, :id => "artworks_selection_id_#{artwork.id}" %></td>
       <td><%= link_to_resource artwork, artwork.title %></td>
       <td><%= artwork.artwork_set.name if artwork.artwork_set %></td>
       <td><%= artwork.artwork_group.name if artwork.artwork_group %></td>
@@ -32,8 +32,7 @@
   </table>
   <%= hidden_field_tag 'artworks_selection_action' %>
   <% 
-    action_list = [[_('Affect to Tag'), 'to_tag'], [_('Delete'), 'delete']]
-    gen_action_proto_menu('artworks_selection', action_list)
+    gen_action_proto_menu('artworks_selection', @selection_action_list)
   %>
   <% end %>
   <%= will_paginate @artworks %>
diff --git a/app/views/admin/artworks/selection_associate_with_tag.rhtml b/app/views/admin/artworks/selection_associate_with_tag.rhtml
new file mode 100644
index 0000000..872e58b
--- /dev/null
+++ b/app/views/admin/artworks/selection_associate_with_tag.rhtml
@@ -0,0 +1,15 @@
+<blockquote>
+	<%= _("You asked to associate this selection of Artworks:") %> <%= display_list(@selection.collect{|t| t.full_title}, true) %>
+	<%= _("with tags; pick your selection in the list of existing tags:") %>
+	<% form_tag( :action => @action ) do %>
+		<% @selection.each do |artwork| %>
+		<%= hidden_field_tag 'artworks_selection_ids[]', artwork.id %>
+		<% end %>
+	<blockquote>
+		<% Tag.find(:all, :order => "name ASC").each do |tag| %>
+		<%= check_box_tag 'tags_selection_ids[]', tag.id %><%= label_tag "tags_selection_ids_#{tag.id}", tag.name %><br />
+		<% end %>
+	</blockquote>
+	<%= submit_tag _("Associate") %>
+	<% end %>
+</blockquote>
diff --git a/app/views/admin/artworks/selection_delete.rhtml b/app/views/admin/artworks/selection_delete.rhtml
new file mode 100644
index 0000000..86a2c9d
--- /dev/null
+++ b/app/views/admin/artworks/selection_delete.rhtml
@@ -0,0 +1,4 @@
+<blockquote>
+	<%= _("You asked to delete this selection of Artworks:") %> <%= display_list(@selection.collect{|t| t.full_title}, true) %>
+	<%= _("but this dangerous action is not implemented yet, sorry.") %>
+</blockquote>
diff --git a/po/MyCyma.pot b/po/MyCyma.pot
index a9f59e7..cc9650e 100644
--- a/po/MyCyma.pot
+++ b/po/MyCyma.pot
@@ -7,7 +7,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: MyCyma 0.2.0\n"
-"POT-Creation-Date: 2010-06-06 17:09+0200\n"
+"POT-Creation-Date: 2010-06-08 01:47+0200\n"
 "PO-Revision-Date: 2008-07-28 02:17+0200\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -308,6 +308,7 @@ msgid "Modify"
 msgstr ""
 
 #: app/helpers/application_helper.rb:92
+#: app/controllers/admin/artworks_controller.rb:6
 msgid "Delete"
 msgstr ""
 
@@ -377,10 +378,18 @@ msgstr ""
 msgid "Missing Thumbnail!"
 msgstr ""
 
+#: app/helpers/application_helper.rb:304
+msgid "Empty selection"
+msgstr ""
+
 #: app/controllers/application.rb:42
 msgid "Please login to continue"
 msgstr ""
 
+#: app/controllers/admin/artworks_controller.rb:6
+msgid "Associate with Tag"
+msgstr ""
+
 #: app/controllers/logon_controller.rb:9
 msgid "Login successful"
 msgstr ""
@@ -404,71 +413,71 @@ msgstr ""
 msgid "Latest 10 Productions"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:20
+#: app/views/layouts/application.rhtml:32
 msgid "View"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:22
+#: app/views/layouts/application.rhtml:34
 msgid "Cyma Tree"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:29
+#: app/views/layouts/application.rhtml:41
 msgid "Setup the Cyma"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:31
+#: app/views/layouts/application.rhtml:43
 msgid "Manage Artworks"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:32
+#: app/views/layouts/application.rhtml:44
 msgid "Manage Artwork Conditions"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:33
+#: app/views/layouts/application.rhtml:45
 msgid "Manage Artwork Materials"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:34
+#: app/views/layouts/application.rhtml:46
 msgid "Manage Artwork Placement Reasons"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:35
+#: app/views/layouts/application.rhtml:47
 msgid "Manage Artwork Sets & Groups"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:36
+#: app/views/layouts/application.rhtml:48
 msgid "Manage Artwork Sizes"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:37
+#: app/views/layouts/application.rhtml:49
 msgid "Manage Artwork Supports"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:39
+#: app/views/layouts/application.rhtml:51
 msgid "Manage Tags"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:42
+#: app/views/layouts/application.rhtml:54
 msgid "Manage Users"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:47
+#: app/views/layouts/application.rhtml:59
 msgid "About"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:49
+#: app/views/layouts/application.rhtml:61
 msgid "Project page"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:50
+#: app/views/layouts/application.rhtml:62
 msgid "Author site"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:55
+#: app/views/layouts/application.rhtml:67
 msgid "Loggued in as '%s'"
 msgstr ""
 
-#: app/views/layouts/application.rhtml:56
+#: app/views/layouts/application.rhtml:68
 msgid "Not loggued in"
 msgstr ""
 
@@ -512,7 +521,7 @@ msgid "Position"
 msgstr ""
 
 #: app/views/admin/artwork_step_images/index.rhtml:17
-#: app/views/admin/artworks/index.rhtml:9
+#: app/views/admin/artworks/index.rhtml:12
 msgid "Preview"
 msgstr ""
 
@@ -524,7 +533,7 @@ msgstr ""
 #: app/views/admin/artwork_conditions/index.rhtml:5
 #: app/views/admin/artwork_sets/index.rhtml:5
 #: app/views/admin/artwork_sizes/index.rhtml:5
-#: app/views/admin/artworks/index.rhtml:11
+#: app/views/admin/artworks/index.rhtml:14
 #: app/views/admin/artwork_groups/index.rhtml:5
 #: app/views/admin/tags/index.rhtml:5
 msgid "Actions"
@@ -868,27 +877,47 @@ msgstr ""
 msgid "New Artwork"
 msgstr ""
 
-#: app/views/admin/artworks/index.rhtml:1
+#: app/views/admin/artworks/selection_delete.rhtml:2
+msgid "You asked to delete this selection of Artworks:"
+msgstr ""
+
+#: app/views/admin/artworks/selection_delete.rhtml:3
+msgid "but this dangerous action is not implemented yet, sorry."
+msgstr ""
+
+#: app/views/admin/artworks/selection_associate_with_tag.rhtml:2
+msgid "You asked to associate this selection of Artworks:"
+msgstr ""
+
+#: app/views/admin/artworks/selection_associate_with_tag.rhtml:3
+msgid "with tags; pick your selection in the list of existing tags:"
+msgstr ""
+
+#: app/views/admin/artworks/selection_associate_with_tag.rhtml:13
+msgid "Associate"
+msgstr ""
+
+#: app/views/admin/artworks/index.rhtml:2
 msgid "List of Artworks"
 msgstr ""
 
-#: app/views/admin/artworks/index.rhtml:6
+#: app/views/admin/artworks/index.rhtml:9
 msgid "Title"
 msgstr ""
 
-#: app/views/admin/artworks/index.rhtml:7
+#: app/views/admin/artworks/index.rhtml:10
 msgid "Set"
 msgstr ""
 
-#: app/views/admin/artworks/index.rhtml:8
+#: app/views/admin/artworks/index.rhtml:11
 msgid "Group"
 msgstr ""
 
-#: app/views/admin/artworks/index.rhtml:10 app/views/view/artwork.rhtml:4
+#: app/views/admin/artworks/index.rhtml:13 app/views/view/artwork.rhtml:4
 msgid "Steps"
 msgstr ""
 
-#: app/views/admin/artworks/index.rhtml:24
+#: app/views/admin/artworks/index.rhtml:28
 #: app/views/admin/artworks/show.rhtml:52
 msgid "View Steps"
 msgstr ""
diff --git a/po/fr/MyCyma.po b/po/fr/MyCyma.po
index 1f7e35d..3ab4307 100644
--- a/po/fr/MyCyma.po
+++ b/po/fr/MyCyma.po
@@ -7,7 +7,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: MyCyma 0.2.0\n"
-"POT-Creation-Date: 2010-06-06 17:09+0200\n"
+"POT-Creation-Date: 2010-06-08 01:47+0200\n"
 "PO-Revision-Date: 2008-07-28 02:17+0200\n"
 "Last-Translator: Marc Dequènes (Duck) <Duck@DuckCorp.org>\n"
 "MIME-Version: 1.0\n"
@@ -307,6 +307,7 @@ msgid "Modify"
 msgstr "Modifier"
 
 #: app/helpers/application_helper.rb:92
+#: app/controllers/admin/artworks_controller.rb:6
 msgid "Delete"
 msgstr "Supprimer"
 
@@ -376,10 +377,18 @@ msgstr "Image Manquante!"
 msgid "Missing Thumbnail!"
 msgstr "Vignette manquante !"
 
+#: app/helpers/application_helper.rb:304
+msgid "Empty selection"
+msgstr "Selection vide"
+
 #: app/controllers/application.rb:42
 msgid "Please login to continue"
 msgstr "Veuillez vous identifier pour continuer"
 
+#: app/controllers/admin/artworks_controller.rb:6
+msgid "Associate with Tag"
+msgstr "Associer à un Tag"
+
 #: app/controllers/logon_controller.rb:9
 msgid "Login successful"
 msgstr "Identification réussie"
@@ -406,71 +415,71 @@ msgstr ""
 msgid "Latest 10 Productions"
 msgstr "10 Dernières Réalisations"
 
-#: app/views/layouts/application.rhtml:20
+#: app/views/layouts/application.rhtml:32
 msgid "View"
 msgstr "Vue"
 
-#: app/views/layouts/application.rhtml:22
+#: app/views/layouts/application.rhtml:34
 msgid "Cyma Tree"
 msgstr "Arbre de la Cimaise"
 
-#: app/views/layouts/application.rhtml:29
+#: app/views/layouts/application.rhtml:41
 msgid "Setup the Cyma"
 msgstr "Gérer la Cimaise"
 
-#: app/views/layouts/application.rhtml:31
+#: app/views/layouts/application.rhtml:43
 msgid "Manage Artworks"
 msgstr "Gérer les Œuvres"
 
-#: app/views/layouts/application.rhtml:32
+#: app/views/layouts/application.rhtml:44
 msgid "Manage Artwork Conditions"
 msgstr "Gérer les États des Œuvres"
 
-#: app/views/layouts/application.rhtml:33
+#: app/views/layouts/application.rhtml:45
 msgid "Manage Artwork Materials"
 msgstr "Gérer les Matériaux des Œuvres"
 
-#: app/views/layouts/application.rhtml:34
+#: app/views/layouts/application.rhtml:46
 msgid "Manage Artwork Placement Reasons"
 msgstr "Gérer les Raisons de Placement des Œuvres"
 
-#: app/views/layouts/application.rhtml:35
+#: app/views/layouts/application.rhtml:47
 msgid "Manage Artwork Sets & Groups"
 msgstr "Gérer les Séries et les Ensembles d'Œuvres"
 
-#: app/views/layouts/application.rhtml:36
+#: app/views/layouts/application.rhtml:48
 msgid "Manage Artwork Sizes"
 msgstr "Gérer les Dimensions des Œuvres"
 
-#: app/views/layouts/application.rhtml:37
+#: app/views/layouts/application.rhtml:49
 msgid "Manage Artwork Supports"
 msgstr "Gérer les Supports"
 
-#: app/views/layouts/application.rhtml:39
+#: app/views/layouts/application.rhtml:51
 msgid "Manage Tags"
 msgstr "Gérer les Tags"
 
-#: app/views/layouts/application.rhtml:42
+#: app/views/layouts/application.rhtml:54
 msgid "Manage Users"
 msgstr "Gérer les Utilisateurs"
 
-#: app/views/layouts/application.rhtml:47
+#: app/views/layouts/application.rhtml:59
 msgid "About"
 msgstr "À Propos"
 
-#: app/views/layouts/application.rhtml:49
+#: app/views/layouts/application.rhtml:61
 msgid "Project page"
 msgstr "Page du Projet"
 
-#: app/views/layouts/application.rhtml:50
+#: app/views/layouts/application.rhtml:62
 msgid "Author site"
 msgstr "Site de l'auteur"
 
-#: app/views/layouts/application.rhtml:55
+#: app/views/layouts/application.rhtml:67
 msgid "Loggued in as '%s'"
 msgstr "Identifié en '%s'"
 
-#: app/views/layouts/application.rhtml:56
+#: app/views/layouts/application.rhtml:68
 msgid "Not loggued in"
 msgstr "Non identifié"
 
@@ -514,7 +523,7 @@ msgid "Position"
 msgstr "Position"
 
 #: app/views/admin/artwork_step_images/index.rhtml:17
-#: app/views/admin/artworks/index.rhtml:9
+#: app/views/admin/artworks/index.rhtml:12
 msgid "Preview"
 msgstr "Prévisualisation"
 
@@ -526,7 +535,7 @@ msgstr "Prévisualisation"
 #: app/views/admin/artwork_conditions/index.rhtml:5
 #: app/views/admin/artwork_sets/index.rhtml:5
 #: app/views/admin/artwork_sizes/index.rhtml:5
-#: app/views/admin/artworks/index.rhtml:11
+#: app/views/admin/artworks/index.rhtml:14
 #: app/views/admin/artwork_groups/index.rhtml:5
 #: app/views/admin/tags/index.rhtml:5
 msgid "Actions"
@@ -870,27 +879,47 @@ msgstr "Modifier les Dimensions"
 msgid "New Artwork"
 msgstr "Nouvelle Œuvre"
 
-#: app/views/admin/artworks/index.rhtml:1
+#: app/views/admin/artworks/selection_delete.rhtml:2
+msgid "You asked to delete this selection of Artworks:"
+msgstr "Vous avez demandé à effacer cette selection d'Œuvres"
+
+#: app/views/admin/artworks/selection_delete.rhtml:3
+msgid "but this dangerous action is not implemented yet, sorry."
+msgstr "mais cette opération dangereuse n'est pas encore possible."
+
+#: app/views/admin/artworks/selection_associate_with_tag.rhtml:2
+msgid "You asked to associate this selection of Artworks:"
+msgstr "Vous avez demandé à associer cette selection d'Œuvres:"
+
+#: app/views/admin/artworks/selection_associate_with_tag.rhtml:3
+msgid "with tags; pick your selection in the list of existing tags:"
+msgstr "à des tags ; faite votre selection dans la liste des tags existants :"
+
+#: app/views/admin/artworks/selection_associate_with_tag.rhtml:13
+msgid "Associate"
+msgstr "Associer"
+
+#: app/views/admin/artworks/index.rhtml:2
 msgid "List of Artworks"
 msgstr "Liste des Œuvres"
 
-#: app/views/admin/artworks/index.rhtml:6
+#: app/views/admin/artworks/index.rhtml:9
 msgid "Title"
 msgstr "Titre"
 
-#: app/views/admin/artworks/index.rhtml:7
+#: app/views/admin/artworks/index.rhtml:10
 msgid "Set"
 msgstr "Série"
 
-#: app/views/admin/artworks/index.rhtml:8
+#: app/views/admin/artworks/index.rhtml:11
 msgid "Group"
 msgstr "Ensemble"
 
-#: app/views/admin/artworks/index.rhtml:10 app/views/view/artwork.rhtml:4
+#: app/views/admin/artworks/index.rhtml:13 app/views/view/artwork.rhtml:4
 msgid "Steps"
 msgstr "Étapes"
 
-#: app/views/admin/artworks/index.rhtml:24
+#: app/views/admin/artworks/index.rhtml:28
 #: app/views/admin/artworks/show.rhtml:52
 msgid "View Steps"
 msgstr "Voir les Étapes"
