<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <div class="moz-cite-prefix">On 06/17/2014 03:04 PM, Hongliang Wang
      wrote:<br>
    </div>
    <blockquote cite="mid:539FE86F.6040403@linux.vnet.ibm.com"
      type="cite">
      <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
      <br>
      <div class="moz-cite-prefix">On 06/17/2014 01:59 PM, Wen Wang
        wrote:<br>
      </div>
      <blockquote
        cite="mid:1402984765-25949-1-git-send-email-wenwang@linux.vnet.ibm.com"
        type="cite">
        <pre wrap="">From: Hongliang Wang <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:hlwang@linux.vnet.ibm.com">&lt;hlwang@linux.vnet.ibm.com&gt;</a>

V2 -&gt; V3
Eliminate menu drop down when click "Action" -&gt; "User"(Hongliang Wang)

V1 -&gt; V2
Accroding to Hongliang Wang, fix the bug that tabs keep shown when there
exists more than one network.

Bugfix that disabled the content display of the action button for an
exsiting
network when creating a new network.

Signed-off-by: Hongliang Wang <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:hlwang@linux.vnet.ibm.com">&lt;hlwang@linux.vnet.ibm.com&gt;</a>
Signed-off-by: Wen Wang <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:wenwang@linux.vnet.ibm.com">&lt;wenwang@linux.vnet.ibm.com&gt;</a>
---
 ui/css/theme-default/network.css |    4 +
 ui/css/theme-default/popover.css |    3 -
 ui/js/src/kimchi.network.js      |  118 +++++++++++++++++++-------------------
 ui/js/src/kimchi.popable.js      |   25 ++++-----
 ui/pages/tabs/network.html.tmpl  |   14 +++--
 5 files changed, 81 insertions(+), 83 deletions(-)

diff --git a/ui/css/theme-default/network.css b/ui/css/theme-default/network.css
index ec999e2..df66b75 100644
--- a/ui/css/theme-default/network.css
+++ b/ui/css/theme-default/network.css
@@ -303,3 +303,7 @@
     padding: 10px;
     width: 100%;
 }
+
+.ui-state-default a {
+    color: #212121;
+}
\ No newline at end of file
diff --git a/ui/css/theme-default/popover.css b/ui/css/theme-default/popover.css
index 945a5c2..a2ad39d 100644
--- a/ui/css/theme-default/popover.css
+++ b/ui/css/theme-default/popover.css
@@ -65,9 +65,6 @@
     left: auto;
     right: 22px;
 }
-.open&gt;.popover {
-    display: block;
-}

 /* Generated at <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://colorzilla.com/gradient-editor/">http://colorzilla.com/gradient-editor/</a> */
 .actionsheet {
diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index 54a6594..16b9ca6 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -100,78 +100,76 @@ kimchi.stopNetwork = function(network,menu) {
 }

 kimchi.addNetworkActions = function(network) {
-    $(".menu-container", "#" + network.name).menu({
-        position : {
-            my : "left top",
-            at : "left bottom",
-            of : "#" + network.name
-        },
-        select : function(evt, ui) {
-            $(".menu-container", "#" + network.name).toggle(false);
-            var menu = $(evt.currentTarget).parent();
-            if ($(evt.currentTarget).attr("nwAct") === "start") {
-                $(".network-state", $("#" + network.name)).switchClass("down", "nw-loading");
-                $("[nwAct='start']", menu).addClass("ui-state-disabled");
-                $("[nwAct='delete']", menu).addClass("ui-state-disabled");
-                $(":first-child", $("[nwAct='delete']", menu)).attr("disabled", true);
-                kimchi.toggleNetwork(network.name, true, function() {
-                    $("[nwAct='start']", menu).addClass("hide-action-item");
-                    $("[nwAct='start']", menu).removeClass("ui-state-disabled");
-                    $("[nwAct='stop']", menu).removeClass("hide-action-item");
-                    if (network.in_use) {
-                        $("[nwAct='stop']", menu).addClass("ui-state-disabled");
-                    }
-                    $(".network-state", $("#" + network.name)).switchClass("nw-loading", "up");
-                }, function(err) {
-                    $(".network-state", $("#" + network.name)).switchClass("nw-loading","down");
-                    $("[nwAct='start']", menu).removeClass("ui-state-disabled");
-                    if (!network.in_use) {
-                        $("[nwAct='delete']", menu).removeClass("ui-state-disabled");
-                    }
-                    $(":first-child", $("[nwAct='delete']", menu)).removeAttr("disabled");
-                    kimchi.message.error(err.responseJSON.reason);
-                });
-            } else if ($(evt.currentTarget).attr("nwAct") === "stop") {
-                if (!network.persistent) {
-                    var settings = {
-                        title : i18n['KCHAPI6001M'],
-                        content : i18n['KCHNET6004M'],
-                        confirm : i18n['KCHAPI6002M'],
-                        cancel : i18n['KCHAPI6003M']
-                    };
-                    kimchi.confirm(settings, function() {
-                        kimchi.stopNetwork(network, menu);
-                        $(evt.currentTarget).parents(".item").remove();
-                    }, null);
+    $(".menu-container", "#" + network.name).menu();
+
+    $('#' + network.name).on('click', '.menu-container li', function(evt) {
+        var menu = $(evt.currentTarget).parent();
+        if ($(evt.currentTarget).attr("nwAct") === "start") {
+            $(".network-state", $("#" + network.name)).switchClass("down", "nw-loading");
+            $("[nwAct='start']", menu).addClass("ui-state-disabled");
+            $("[nwAct='delete']", menu).addClass("ui-state-disabled");
+            $(":first-child", $("[nwAct='delete']", menu)).attr("disabled", true);
+            kimchi.toggleNetwork(network.name, true, function() {
+                $("[nwAct='start']", menu).addClass("hide-action-item");
+                $("[nwAct='start']", menu).removeClass("ui-state-disabled");
+                $("[nwAct='stop']", menu).removeClass("hide-action-item");
+                network.state = "up";
+                if (network.in_use) {
+                    $("[nwAct='stop']", menu).addClass("ui-state-disabled");
                 }
-                else {
-                    kimchi.stopNetwork(network, menu);
+                $(".network-state", $("#" + network.name)).switchClass("nw-loading", "up");
+            }, function(err) {
+                $(".network-state", $("#" + network.name)).switchClass("nw-loading","down");
+                $("[nwAct='start']", menu).removeClass("ui-state-disabled");
+                if (!network.in_use) {
+                    $("[nwAct='delete']", menu).removeClass("ui-state-disabled");
                 }
-            } else if ($(evt.currentTarget).attr("nwAct") === "delete") {
-                kimchi.confirm({
-                    title : i18n['KCHAPI6006M'],
-                    content : i18n['KCHNET6002M'],
+                $(":first-child", $("[nwAct='delete']", menu)).removeAttr("disabled");
+                kimchi.message.error(err.responseJSON.reason);
+            });
+        } else if ($(evt.currentTarget).attr("nwAct") === "stop") {
+            if (network.in_use) {
+                return false;
+            }
+            if (!network.persistent) {
+                var settings = {
+                    title : i18n['KCHAPI6001M'],
+                    content : i18n['KCHNET6004M'],
                     confirm : i18n['KCHAPI6002M'],
                     cancel : i18n['KCHAPI6003M']
-                }, function() {
-                    kimchi.deleteNetwork(network.name, function() {
-                        $(evt.currentTarget).parents(".item").remove();
-                    });
+                };
+                kimchi.confirm(settings, function() {
+                    kimchi.stopNetwork(network, menu);
+                    $(evt.currentTarget).parents(".item").remove();
                 }, null);
             }
+            else {
+                kimchi.stopNetwork(network, menu);
+                network.state = "down";
+            }
+        } else if ($(evt.currentTarget).attr("nwAct") === "delete") {
+            if (network.state === "up") {
+                return false;
+            }
+            kimchi.confirm({
+                title : i18n['KCHAPI6006M'],
+                content : i18n['KCHNET6002M'],
+                confirm : i18n['KCHAPI6002M'],
+                cancel : i18n['KCHAPI6003M']
+            }, function() {
+                kimchi.deleteNetwork(network.name, function() {
+                    $(evt.currentTarget).parents(".item").remove();
+                });
+            }, null);
         }
     });
-    $(".column-action", "#" + network.name).children(":first").button({
+
+    $("#networkBody .column-action .popable").button({
         icons : {
             secondary : "action-button-icon"
         }
-    }).click(function() {
-        $(".menu-container", "#" + network.name).toggle();
-        window.scrollBy(0, 150);
-    });
-    $(".menu-container", "#" + network.name).mouseleave(function() {
-        $(".menu-container", "#" + network.name).toggle(false);
     });
+
 };

 kimchi.initNetworkCreation = function() {
diff --git a/ui/js/src/kimchi.popable.js b/ui/js/src/kimchi.popable.js
index 295eaed..a171b9f 100644
--- a/ui/js/src/kimchi.popable.js
+++ b/ui/js/src/kimchi.popable.js
@@ -17,21 +17,18 @@
  */
 kimchi.popable = function() {
     $(document).click(function(e) {
-        $('.popable').removeClass('open');
-    });
-    $(document).on("click", ".popable", function(e) {
-        var isOpen = $(this).hasClass('open');
-        $(".popable").removeClass('open');
-        if (!isOpen &amp;&amp; $(this).find('ul').html() !== '') {
-            $(this).addClass('open');
-        }
+        $('.popable').each(function(i, n) {
+            n === e.target || $.contains(n, e.target) ||
+                $('.popover', n).toggle(false);
+        });
+     });
+     $(document).on('click', '.popable', function(e) {
+        var popup = $('.popover', this)[0];
+        $(popup).toggle();

         // Scroll the popup menu into viewport if invisible.
-        var popMenu = $('.popover', this).get(0);
-        false === kimchi.isElementInViewport(popMenu) &amp;&amp;
-            popMenu.scrollIntoView();
-
-        e.preventDefault();
-        e.stopPropagation();</pre>
      </blockquote>
      <br>
      <blockquote
        cite="mid:1402984765-25949-1-git-send-email-wenwang@linux.vnet.ibm.com"
        type="cite">
        <pre wrap="">+        $(popup).is(':visible') ||
+            kimchi.isElementInViewport(popup) ||
+            popup.scrollIntoView();</pre>
      </blockquote>
      The logic here is:<br>
      if popup is invisible, then return;<br>
      or else popup is visible,<br>
          if popup is totally in viewport, then return;<br>
          else, scroll popup into viewport totally.<br>
      <br>
      So we should change code to:<br>
      <br>
      <pre wrap="">+        <b>!</b>$(popup).is(':visible') ||
+            kimchi.isElementInViewport(popup) ||
+            popup.scrollIntoView();</pre>
    </blockquote>
    ACK<br>
    <blockquote cite="mid:539FE86F.6040403@linux.vnet.ibm.com"
      type="cite"> <br>
      <br>
      <blockquote
        cite="mid:1402984765-25949-1-git-send-email-wenwang@linux.vnet.ibm.com"
        type="cite">
        <pre wrap="">     });
 };
diff --git a/ui/pages/tabs/network.html.tmpl b/ui/pages/tabs/network.html.tmpl
index 35380f4..e477efb 100644
--- a/ui/pages/tabs/network.html.tmpl
+++ b/ui/pages/tabs/network.html.tmpl
@@ -105,12 +105,14 @@</pre>
      </blockquote>
      <br>
      <blockquote
        cite="mid:1402984765-25949-1-git-send-email-wenwang@linux.vnet.ibm.com"
        type="cite">
        <pre wrap="">  --&gt;&lt;span class='column column-interface cell'&gt;{interface}&lt;/span&gt;&lt;!--
  --&gt;&lt;span class='column column-space cell'&gt;{addrSpace}&lt;/span&gt;&lt;!--
  --&gt;&lt;span class='column-action'&gt;</pre>
      </blockquote>
      Seems commented elements can be removed (elements within &lt;!--
      --&gt;).<br>
    </blockquote>
    ACK<br>
    <blockquote cite="mid:539FE86F.6040403@linux.vnet.ibm.com"
      type="cite">
      <blockquote
        cite="mid:1402984765-25949-1-git-send-email-wenwang@linux.vnet.ibm.com"
        type="cite">
        <pre wrap="">-        &lt;span class="ui-button-secondary dropdown action-button"&gt;$_("Actions")&lt;/span&gt;
-        &lt;ul class='popover actionsheet right-side menu-container'&gt;
-            &lt;li nwAct="start" class='{startClass}'&gt;&lt;a&gt;$_("Start")&lt;/a&gt;&lt;/li&gt;
-            &lt;li nwAct="stop" class='{stopClass}'&gt;&lt;a {deleteDisabled}&gt;$_("Stop")&lt;/a&gt;&lt;/li&gt;
-            &lt;li nwAct="delete" class='{deleteClass}'&gt;&lt;a {deleteDisabled} class='red'&gt;$_("Delete")&lt;/a&gt;&lt;/li&gt;
-        &lt;/ul&gt;
+        &lt;span class="ui-button-secondary dropdown popable action-button"&gt;
+            $_("Actions")
+            &lt;ul class='popover actionsheet right-side menu-container'&gt;
+                &lt;li nwAct="start" class='{startClass}'&gt;&lt;a class='button-big'&gt;$_("Start")&lt;/a&gt;&lt;/li&gt;
+                &lt;li nwAct="stop" class='{stopClass}'&gt;&lt;a {stopDisabled} class='button-big'&gt;$_("Stop")&lt;/a&gt;&lt;/li&gt;
+                &lt;li nwAct="delete" class='{deleteClass}'&gt;&lt;a {deleteDisabled} class='red'&gt;$_("Delete")&lt;/a&gt;&lt;/li&gt;
+            &lt;/ul&gt;
+        &lt;/span&gt;
     &lt;/span&gt;
     &lt;/div&gt;
 &lt;/script&gt;
</pre>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>