eventually this should be expanded to select / disable select links
  depending on which instance actions are appropriate for the current
  instance state.
---
 src/app/views/instance/index.haml     |    4 ++
 src/app/views/templates/index.haml    |    4 ++-
 src/public/javascripts/application.js |   50 ++++++++++++---------------------
 3 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/src/app/views/instance/index.haml 
b/src/app/views/instance/index.haml
index 83690b7..ad7aa71 100644
--- a/src/app/views/instance/index.haml
+++ b/src/app/views/instance/index.haml
@@ -1,3 +1,7 @@
+:javascript
+  $(document).ready(function() {
+    $("input[name='id[]']").buttonSensitivity(['li.shutdown', 
'li.delete']).change();
+  });
 - columns = [                                                     |
   {:name => '', :sortable => false},                              |
   {:name => 'STATUS', :sortable => false},                        |
diff --git a/src/app/views/templates/index.haml 
b/src/app/views/templates/index.haml
index 0d4c515..4696fcf 100644
--- a/src/app/views/templates/index.haml
+++ b/src/app/views/templates/index.haml
@@ -65,7 +65,9 @@
 :javascript
   $(document).ready(function () {
     var $filters = $('.filters input');
-    $("#tables input[type='checkbox']").buttonSensitivity().change();
+    $("#tables input[type='radio']").buttonSensitivity(['li.edit',
+                                                        'li.delete',
+                                                        'li.build']).change();
     $filters.removeAttr("disabled").change(function () {
       $filters.each(function () {
         if ($(this).filter(':checked').length) {
diff --git a/src/public/javascripts/application.js 
b/src/public/javascripts/application.js
index 50edbe4..c185c57 100644
--- a/src/public/javascripts/application.js
+++ b/src/public/javascripts/application.js
@@ -77,40 +77,26 @@ var Aggregator = {
         }
     });
   };
-  $.fn.buttonSensitivity = function () {
-    var $checkboxes = $(this),
-      $edit = $('.actionsidebar .edit'),
-      $delete = $('.actionsidebar .delete'),
-      $rename = $('.actionsidebar .rename'),
-      $copy = $('.actionsidebar .copy'),
-      $build = $('.actionsidebar .build');
-    return $checkboxes.change(function () {
-      var $checked = $checkboxes.filter(':checked');
+  $.fn.buttonSensitivity = function (selectors_to_toggle) {
+    var $inputs = $(this);
+    function toggle_selectors(){
+      var $checked = $inputs.filter(':checked');
       if ($checked.length === 0) {
-        //disable the build, edit and delete action if there is none selected
-        $build.addClass("disabled");
-        $edit.addClass("disabled");
-        $delete.addClass("disabled");
-        $("input", $build).attr("disabled","disabled");
-        $("input", $edit).attr("disabled","disabled");
-        $("input", $delete).attr("disabled","disabled");
-      } else if ($checked.length > 1) {
-        //disable the build and edit if there is more than one
-        $edit.addClass("disabled");
-        $build.addClass("disabled");
-        $delete.removeClass("disabled");
-        $("input", $build).attr("disabled","disabled");
-        $("input", $edit).attr("disabled","disabled");
-        $("input", $delete).removeAttr("disabled");
-      } else {
-        $("input", $build).removeAttr("disabled");
-        $("input", $edit).removeAttr("disabled");
-        $("input", $delete).removeAttr("disabled");
-        $build.removeClass("disabled");
-        $edit.removeClass("disabled");
-        $delete.removeClass("disabled");
+        for(i in selectors_to_toggle){
+          selector_to_toggle = selectors_to_toggle[i];
+          $(selector_to_toggle).addClass('disabled');
+          $('input', selector_to_toggle).attr('disabled', 'disabled');
+        }
+      }else{
+        for(i in selectors_to_toggle){
+          selector_to_toggle = selectors_to_toggle[i];
+          $(selector_to_toggle).removeClass('disabled');
+          $('input', selector_to_toggle).removeAttr('disabled');
+        }
       }
-    });
+    }
+    toggle_selectors();
+    return $inputs.change(toggle_selectors);
   };
   $.fn.positionAncestor = function(selector) {
     var left = 0;
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to