Blob Blame History Raw
From 25413c28853e1d350982feba7e306e05b6e74f49 Mon Sep 17 00:00:00 2001
From: Ondrej Mular <omular@redhat.com>
Date: Sun, 14 Aug 2016 13:38:52 +0200
Subject: [PATCH] web UI: fix bad using of HTML ids

---
 pcsd/public/js/nodes-ember.js |  5 +++++
 pcsd/public/js/pcsd.js        | 11 ++++++++---
 pcsd/views/main.erb           |  4 ++--
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/pcsd/public/js/nodes-ember.js b/pcsd/public/js/nodes-ember.js
index c51a341..f176c39 100644
--- a/pcsd/public/js/nodes-ember.js
+++ b/pcsd/public/js/nodes-ember.js
@@ -823,6 +823,11 @@ Pcs.ResourceObj = Ember.Object.extend({
   id: null,
   _id: Ember.computed.alias('id'),
   name: Ember.computed.alias('id'),
+  treeview_element_id: function() {
+    if (this.get("id")) {
+      return this.get("id") + "-treeview-element";
+    }
+  }.property("id"),
   parent: null,
   meta_attr: [],
   meta_attributes: Ember.computed.alias('meta_attr'),
diff --git a/pcsd/public/js/pcsd.js b/pcsd/public/js/pcsd.js
index 56219d4..1060bd3 100644
--- a/pcsd/public/js/pcsd.js
+++ b/pcsd/public/js/pcsd.js
@@ -2077,8 +2077,13 @@ function fix_auth_of_cluster() {
   });
 }
 
-function get_tree_view_element_id(element) {
-  return $(element).parents('table.tree-element')[0].id;
+function get_tree_view_resource_id(element) {
+  var suffix = '-treeview-element';
+  var element_id = $(element).parents('table.tree-element')[0].id;
+  if (element_id && element_id.endsWith(suffix)) {
+    return element_id.substr(0, element_id.lastIndexOf(suffix));
+  }
+  return null;
 }
 
 function get_list_view_element_id(element) {
@@ -2166,7 +2171,7 @@ function tree_view_onclick(resource_id) {
 }
 
 function tree_view_select(element_id) {
-  var e = $('#' + element_id);
+  var e = $(`#${element_id}-treeview-element`);
   var view = e.parents('table.tree-view');
   view.find('div.arrow').hide();
   view.find('tr.children').hide();
diff --git a/pcsd/views/main.erb b/pcsd/views/main.erb
index 64fe560..8de1c60 100644
--- a/pcsd/views/main.erb
+++ b/pcsd/views/main.erb
@@ -99,8 +99,8 @@
   </script>
 
   <script type="text/x-handlebars" data-template-name="components/resource-tree-element">
-    <table class="tree-element"  cellpadding="0" cellspacing="0" style="width: 100%; border: none;" {{bind-attr id=node._id}}>
-    <tr class="tree-element-name" onclick="tree_view_onclick(get_tree_view_element_id(this));" onmouseover="$(this).addClass('mouse_on_row');" onmouseout="$(this).removeClass('mouse_on_row');" {{bind-attr nodeID=node.id}}>
+    <table class="tree-element"  cellpadding="0" cellspacing="0" style="width: 100%; border: none;" {{bind-attr id=node.treeview_element_id}}>
+    <tr class="tree-element-name" onclick="tree_view_onclick(get_tree_view_resource_id(this));" onmouseover="$(this).addClass('mouse_on_row');" onmouseout="$(this).removeClass('mouse_on_row');" {{bind-attr nodeID=node.id}}>
         <td style="width:20px;" class="node_list_check">
           <input type="checkbox" onchange="tree_view_checkbox_onchange(this)">
         </td>
-- 
1.8.3.1