Blame SOURCES/bz1158571-01-web-UI-mark-unsaved-permissions-forms.patch

71541a
From 5c62afc314bfbff55e36c0f7f8e9aec0cc9246c4 Mon Sep 17 00:00:00 2001
71541a
From: Tomas Jelinek <tojeline@redhat.com>
71541a
Date: Wed, 2 Sep 2015 14:04:55 +0200
71541a
Subject: [PATCH] web UI: mark unsaved permissions forms
71541a
71541a
---
71541a
 pcsd/public/js/pcsd.js              | 36 ++++++++++++++++++++++++++++++++++++
71541a
 pcsd/views/_permissions_cluster.erb |  5 ++++-
71541a
 pcsd/views/permissions.erb          |  8 +++++++-
71541a
 3 files changed, 47 insertions(+), 2 deletions(-)
71541a
71541a
diff --git a/pcsd/public/js/pcsd.js b/pcsd/public/js/pcsd.js
71541a
index 2c71e6b..879b533 100644
71541a
--- a/pcsd/public/js/pcsd.js
71541a
+++ b/pcsd/public/js/pcsd.js
71541a
@@ -2205,6 +2205,7 @@ function permissions_load_cluster(cluster_name, callback) {
71541a
       $("#" + element_id + " :checkbox").each(function(key, checkbox) {
71541a
         permissions_fix_dependent_checkboxes(checkbox);
71541a
       });
71541a
+      permissions_cluster_dirty_flag(cluster_name, false);
71541a
       if (callback) {
71541a
         callback();
71541a
       }
71541a
@@ -2259,8 +2260,27 @@ function permissions_save_cluster(form) {
71541a
   });
71541a
 }
71541a
 
71541a
+function permissions_cluster_dirty_flag(cluster_name, flag) {
71541a
+  var cluster_row = permissions_get_cluster_row(cluster_name);
71541a
+  if (cluster_row) {
71541a
+    var dirty_elem = cluster_row.find("span[class=unsaved_changes]");
71541a
+    if (dirty_elem) {
71541a
+      if (flag) {
71541a
+        dirty_elem.show();
71541a
+      }
71541a
+      else {
71541a
+        dirty_elem.hide();
71541a
+      }
71541a
+    }
71541a
+  }
71541a
+}
71541a
+
71541a
 function permission_remove_row(button) {
71541a
+  var cluster_name = permissions_get_clustername(
71541a
+    $(button).parents("form").first()
71541a
+  );
71541a
   $(button).parent().parent().remove();
71541a
+  permissions_cluster_dirty_flag(cluster_name, true);
71541a
 }
71541a
 
71541a
 function permissions_add_row(template_row) {
71541a
@@ -2268,6 +2288,9 @@ function permissions_add_row(template_row) {
71541a
   var user_type = permissions_get_row_type(template_row);
71541a
   var max_key = -1;
71541a
   var exists = false;
71541a
+  var cluster_name = permissions_get_clustername(
71541a
+    $(template_row).parents("form").first()
71541a
+  );
71541a
 
71541a
   if("" == user_name) {
71541a
     alert("Please enter the name");
71541a
@@ -2326,6 +2349,8 @@ function permissions_add_row(template_row) {
71541a
   template_inputs.removeAttr("checked").removeAttr("selected");
71541a
   template_inputs.removeAttr("disabled").removeAttr("readonly");
71541a
   $(template_row).find(":input[type=text]").val("");
71541a
+
71541a
+  permissions_cluster_dirty_flag(cluster_name, true);
71541a
 }
71541a
 
71541a
 function permissions_get_dependent_checkboxes(checkbox) {
71541a
@@ -2400,3 +2425,14 @@ function permissions_get_checkbox_permission(checkbox) {
71541a
   return "";
71541a
 }
71541a
 
71541a
+function permissions_get_cluster_row(cluster_name) {
71541a
+  var cluster_row = null;
71541a
+  $('#cluster_list td[class=node_name]').each(function(index, elem) {
71541a
+    var jq_elem = $(elem);
71541a
+    if (jq_elem.text().trim() == cluster_name.trim()) {
71541a
+      cluster_row = jq_elem.parents("tr").first();
71541a
+    }
71541a
+  });
71541a
+  return cluster_row;
71541a
+}
71541a
+
71541a
diff --git a/pcsd/views/_permissions_cluster.erb b/pcsd/views/_permissions_cluster.erb
71541a
index 232a5de..4048366 100644
71541a
--- a/pcsd/views/_permissions_cluster.erb
71541a
+++ b/pcsd/views/_permissions_cluster.erb
71541a
@@ -58,7 +58,10 @@
71541a
                   <% if user['allow'].include?(perm['code']) %>
71541a
                     checked="checked"
71541a
                   <% end %>
71541a
-                  onchange="permissions_fix_dependent_checkboxes(this);"
71541a
+                  onchange="
71541a
+                    permissions_fix_dependent_checkboxes(this);
71541a
+                    permissions_cluster_dirty_flag('<%= h(@cluster_name) %>', true);
71541a
+                  "
71541a
                 >
71541a
               
71541a
             <% } %>
71541a
diff --git a/pcsd/views/permissions.erb b/pcsd/views/permissions.erb
71541a
index b02d9d3..1e38d7e 100644
71541a
--- a/pcsd/views/permissions.erb
71541a
+++ b/pcsd/views/permissions.erb
71541a
@@ -16,7 +16,8 @@
71541a
       
71541a
         
71541a
            
71541a
-          CLUSTER NAME
71541a
+           
71541a
+          CLUSTER NAME
71541a
            
71541a
         
71541a
         <% @clusters.each do |c| %>
71541a
@@ -28,6 +29,11 @@
71541a
             
71541a
               
71541a
             
71541a
+            
71541a
+              
71541a
+                title="There are unsaved changes in the form"
71541a
+              >(*)
71541a
+            
71541a
             
71541a
               <%= h(c.name) %>
71541a
             
71541a
-- 
71541a
1.9.1
71541a