Browse Source

Add a link on the group to associate fixed ip for a member

Change-Id: If5e9c12890d79618050167966ddde57191b8e938
Closes-Bug: #1609363
ank 2 years ago
parent
commit
41664d882c
1 changed files with 29 additions and 14 deletions
  1. 29
    14
      gbpui/static/dashboard/js/member.js

+ 29
- 14
gbpui/static/dashboard/js/member.js View File

@@ -40,9 +40,13 @@ member = {
40 40
    * Generates the HTML structure for a group that will be displayed
41 41
    * as a list item in the group list.
42 42
    **/
43
-  generate_group_element: function(name, id, value) {
43
+  generate_group_element: function(name, id, value, selected) {
44 44
     var $li = $('<li>');
45
-    $li.attr('name', value).html(name + '<strong></strong><a href="#" class="btn btn-primary"></a>');
45
+    ip_lable = '<strong></strong>'
46
+    if (selected){
47
+      ip_lable = '<strong> <a>Set IP Address</a></strong>'
48
+    }
49
+    $li.attr('name', value).html(name + ip_lable + '<a href="#" class="btn btn-primary"></a>');
46 50
     return $li;
47 51
   },
48 52
 
@@ -69,6 +73,10 @@ member = {
69 73
       });
70 74
       groupListId.find("input:checkbox").removeAttr('checked');
71 75
       active_groups.each(function(index, value){
76
+        ip_ele = $("#selected_network li[name^='"+ value +"'] strong")
77
+        if(ip_ele.text() == "" && $("#id_count").val() == 1){
78
+          ip_ele.html(" <a>Set IP Address</a>")
79
+        }
72 80
         groupListId.find("input:checkbox[value^='" + value + "']")
73 81
           .prop('checked', true)
74 82
           .parents("li").attr('data-index',index);
@@ -89,12 +97,12 @@ member = {
89 97
     // Make sure we don't duplicate the groups in the list
90 98
     available_group.empty();
91 99
     $.each(self.groups_available, function(index, value){
92
-      available_group.append(self.generate_group_element(value.name, value.id, value.value));
100
+      available_group.append(self.generate_group_element(value.name, value.id, value.value, false));
93 101
     });
94 102
     // Make sure we don't duplicate the groups in the list
95 103
     selected_group.empty();
96 104
     $.each(self.groups_selected, function(index, value){
97
-      selected_group.append(self.generate_group_element(value.name, value.id, value.value));
105
+      selected_group.append(self.generate_group_element(value.name, value.id, value.value, true));
98 106
     });
99 107
 
100 108
     $(".networklist > li > a.btn").click(function(e){
@@ -105,6 +113,7 @@ member = {
105 113
         $this.parent().appendTo(selected_group);
106 114
       } else if ($this.parents("ul#selected_network").length > 0) {
107 115
         $this.parent().appendTo(available_group);
116
+        $this.parent().find("strong").html("");
108 117
       }
109 118
       updateForm();
110 119
     });
@@ -127,8 +136,8 @@ member = {
127 136
   },
128 137
   control_max_instances: function(){
129 138
       $("#id_count").attr('readonly', false)
130
-      $("#id_network").each(function() {
131
-         $input = $(this).find('li input');
139
+      $("#id_network li").each(function() {
140
+         $input = $(this).find('input');
132 141
          value = $input.val();
133 142
          fields = value.split(":")
134 143
          if ($input.is(":checked") && fields.length == 3){
@@ -151,9 +160,8 @@ member = {
151 160
       selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
152 161
       value = selected_element.val();
153 162
       values = value.split(':');
154
-      group = $(selected_group).text()
155
-      group = group.split("(")
156
-      $("#group").text(group[0])
163
+      group = $(selected_group).clone().find('strong').remove().end().text();
164
+      $("#group").text(group);
157 165
       subnets = values[1].split(";")
158 166
       $('#subnets_table tbody').empty();
159 167
       for (index=0; index < subnets.length; index++){
@@ -198,10 +206,7 @@ member = {
198 206
             selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
199 207
             selected_element.val(value)
200 208
             if(fixed_ip){
201
-              $("#selected_network li[name^='"+ ptg +"'] strong").text(" ( "+fixed_ip + " )")
202
-            }
203
-            else{
204
-              $("#selected_network li[name^='"+ ptg +"'] strong").text("")
209
+              $("#selected_network li[name^='"+ ptg +"'] strong").html(" ( "+fixed_ip +") <a>Edit IP</a>")
205 210
             }
206 211
             $("ul#selected_network li[name^='"+ ptg +"']").css("background-color", "");
207 212
             $("#fixed_ip_div").hide()
@@ -224,7 +229,7 @@ member = {
224 229
     value = ptg + ":" + subnet
225 230
     selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
226 231
     selected_element.val(value)
227
-    $("#selected_network li[name^='"+ ptg +"'] strong").text("")
232
+    $("#selected_network li[name^='"+ ptg +"'] strong").html(" <a>Set IP Address</a>")
228 233
     $("#fixed_ip_div").hide()
229 234
     $("ul#selected_network li").css("background-color", "");
230 235
     member.control_max_instances()
@@ -250,5 +255,15 @@ member = {
250 255
     title = help.attr("title")
251 256
     title = title + " Fixed IP can be assigned only when Instance Count is 1"
252 257
     help.attr("title", title)
258
+    $(document).on('input', '#id_count',function(){
259
+      if($("#id_count").val() > 1){
260
+        $("#selected_network li").find("strong").html("");
261
+      }
262
+      else{
263
+        $("#selected_network li").find("strong").html(" <a>Set IP Address</a>")
264
+        $("#errors").hide().text("")
265
+      }
266
+      $("#fixed_ip_div").hide()
267
+    })
253 268
   }
254 269
 };

Loading…
Cancel
Save