[ARVADOS] created: bed3cfb9cce29a86e66201807c2289b79c34efcd

git at public.curoverse.com git at public.curoverse.com
Fri Feb 21 17:04:16 EST 2014


        at  bed3cfb9cce29a86e66201807c2289b79c34efcd (commit)


commit bed3cfb9cce29a86e66201807c2289b79c34efcd
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Feb 21 17:05:21 2014 -0500

    Added localStorage selection to generic index pages.

diff --git a/apps/workbench/app/assets/javascripts/application.js b/apps/workbench/app/assets/javascripts/application.js
index 9284282..1108aba 100644
--- a/apps/workbench/app/assets/javascripts/application.js
+++ b/apps/workbench/app/assets/javascripts/application.js
@@ -41,14 +41,83 @@ jQuery(function($){
         }
         targets.fadeToggle(200);
     });
+
+    var add_selection = function(v) {
+        var lst = JSON.parse(localStorage.persistentSelection);
+        lst.push(v);
+        localStorage.persistentSelection = JSON.stringify(lst);
+        update_count();
+    };
+
+    var remove_selection = function(v) {
+        var lst = JSON.parse(localStorage.persistentSelection);
+        var i = jQuery.inArray(v, lst);
+        if (i > -1) {
+            lst.splice(i, 1);
+        }
+        localStorage.persistentSelection = JSON.stringify(lst);
+        update_count();
+    };
+
+    var remove_selection_click = function(e) {
+        remove_selection($(this).attr('name'));
+    };
+
+    var update_count = function(e) {
+        var lst = JSON.parse(localStorage.persistentSelection);
+        $("#persistent-selection-count").text(lst.length);
+
+        if (lst.length > 0) {
+            $('#persistent-selection-list').empty();
+            for (var i = 0; i < lst.length; i++) {
+                $('#persistent-selection-list').append("<li role=\"presentation\"><span><a href=\"#\">" + lst[i] + "</a>"
+                                                       + "<a href=\"#\" class=\"remove-selection\" name=\"" + lst[i] + "\">" 
+                                                       + "<span class=\"glyphicon glyphicon-trash pull-right\"></span>"
+                                                       + "</a></span></li>");
+            }
+        } else {
+            $('#persistent-selection-list').html("<li role=\"presentation\">No selections.</li>");
+        }
+
+        var checkboxes = $('.persistent-selection:checkbox');
+        for (i = 0; i < checkboxes.length; i++) {
+            if (jQuery.inArray($(checkboxes[i]).val(), lst) > -1) {
+                checkboxes[i].checked = true;
+            }
+            else {
+                checkboxes[i].checked = false;
+            }
+        }
+        
+        $('.remove-selection').on('click', remove_selection_click);
+    };
+
     $(document).
         on('ajax:send', function(e, xhr) {
             $('.loading').fadeTo('fast', 1);
         }).
         on('ajax:complete', function(e, status) {
             $('.loading').fadeOut('fast', 0);
+        }).
+        on('change', '.persistent-selection:checkbox', function(e) {
+            console.log($(this));
+            console.log($(this).val());
+
+            if (!localStorage.persistentSelection) {
+                localStorage.persistentSelection = JSON.stringify([]);
+            }
+            
+            var inc = 0;
+            if ($(this).is(":checked")) {
+                add_selection($(this).val());
+            }
+            else {
+                remove_selection($(this).val());
+            }
         });
 
+    $(window).on('load storage', update_count);
+
     HeaderRowFixer = function(selector) {
         this.duplicateTheadTr = function() {
             $(selector).each(function() {
diff --git a/apps/workbench/app/assets/javascripts/sizing.js b/apps/workbench/app/assets/javascripts/sizing.js
index 388f727..55d2301 100644
--- a/apps/workbench/app/assets/javascripts/sizing.js
+++ b/apps/workbench/app/assets/javascripts/sizing.js
@@ -11,14 +11,14 @@ function graph_zoom(divId, svgId, scale) {
 }
 
 function smart_scroll_fixup(s) {
-    console.log(s);
+    //console.log(s);
     if (s != null && s.type == 'shown.bs.tab') {
         s = [s.target];
     }
     else {
         s = $(".smart-scroll");
     }
-    console.log(s);
+    //console.log(s);
     for (var i = 0; i < s.length; i++) {
         a = s[i];
         var h = window.innerHeight - a.getBoundingClientRect().top - 20;
diff --git a/apps/workbench/app/assets/stylesheets/application.css.scss b/apps/workbench/app/assets/stylesheets/application.css.scss
index 5ada51a..dbaa063 100644
--- a/apps/workbench/app/assets/stylesheets/application.css.scss
+++ b/apps/workbench/app/assets/stylesheets/application.css.scss
@@ -158,3 +158,12 @@ table.table-fixed-header-row tbody {
     position:relative;
     top:1.5em;
 }
+
+#persistent-selection-list li {
+    margin-left: 1em;
+    padding: 3px 20px;
+    font-weight: normal;
+    line-height: 1.42857;
+    color: rgb(51, 51, 51);
+    border-bottom: 1px solid rgb(221, 221, 221)
+}
diff --git a/apps/workbench/app/views/application/_show_recent.html.erb b/apps/workbench/app/views/application/_show_recent.html.erb
index c58c628..0008d09 100644
--- a/apps/workbench/app/views/application/_show_recent.html.erb
+++ b/apps/workbench/app/views/application/_show_recent.html.erb
@@ -8,9 +8,12 @@
 
 <% attr_blacklist = ' created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at' %>
 
+<%= form_tag do |f| %>
+
 <table class="table table-condensed arv-index">
   <thead>
     <tr>
+      <th></th>
       <% @objects.first.attributes_for_display.each do |attr, attrvalue| %>
       <% next if attr_blacklist.index(" "+attr) %>
       <th class="arv-attr-<%= attr %>">
@@ -26,6 +29,10 @@
   <tbody>
     <% @objects.each do |object| %>
     <tr data-object-uuid="<%= object.uuid %>">
+      <td>
+        <%= check_box_tag 'uuids[]', object.uuid, false, :class => 'persistent-selection' %>
+      </td>
+
       <% object.attributes_for_display.each do |attr, attrvalue| %>
       <% next if attr_blacklist.index(" "+attr) %>
       <td class="arv-object-<%= object.class.to_s %> arv-attr-<%= attr %>">
@@ -55,3 +62,5 @@
 </table>
 
 <% end %>
+
+<% end %>
diff --git a/apps/workbench/app/views/layouts/application.html.erb b/apps/workbench/app/views/layouts/application.html.erb
index 0716bcc..ecbe3db 100644
--- a/apps/workbench/app/views/layouts/application.html.erb
+++ b/apps/workbench/app/views/layouts/application.html.erb
@@ -118,18 +118,15 @@
         </li>
         -->
 
-        <!-- XXX placeholder for this when persistent selection is implemented
         <li class="dropdown">
           <a href="#" class="dropdown-toggle" data-toggle="dropdown">
             <span class="glyphicon glyphicon-paperclip"></span>
-            <span class="badge badge-alert"><%= @selection_count %></span>
+            <span class="badge" id="persistent-selection-count"></span>
             <span class="caret"></span>
           </a>
-          <ul class="dropdown-menu" role="menu">
-              <li style="padding: 10px">No selections.</li>
+          <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
           </ul>
         </li>
-        -->
 
         <% if current_user.is_active %>
         <li class="dropdown notification-menu">

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list