[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: public/js: keep chosen detail tab when...

git at icinga.org git at icinga.org
Wed May 25 11:25:27 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: 81dcfb4f7e638e11914a3429e5d1f2a0a17e5b90
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=81dcfb4f7e638e11914a3429e5d1f2a0a17e5b90

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue May 24 20:20:42 2016 +0200

public/js: keep chosen detail tab when...

...switching between objects

---

 public/js/module.js |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/public/js/module.js b/public/js/module.js
index d0fada7..a7644f5 100644
--- a/public/js/module.js
+++ b/public/js/module.js
@@ -20,6 +20,7 @@
              */
             this.module.on('rendered', this.rendered);
             this.module.on('click', 'fieldset > legend', this.toggleFieldset);
+            this.module.on('click', 'div.controls ul.tabs a', this.detailTabClick);
             this.module.on('click', 'input.related-action', this.extensibleSetAction);
             this.module.on('focus', 'form input', this.formElementFocus);
             this.module.on('focus', 'form textarea', this.formElementFocus);
@@ -27,6 +28,68 @@
             this.module.icinga.logger.debug('Director module initialized');
         },
 
+        detailTabClick: function(ev)
+        {
+            var $a = $(ev.currentTarget);
+            if ($a.closest('#col2').length === 0) {
+                return;
+            }
+
+            this.alignDetailLinks();
+        },
+
+        alignDetailLinks: function()
+        {
+            var self = this;
+            var $a = $('#col2 div.controls ul.tabs li.active a');
+            if ($a.length !== 1) {
+                return;
+            }
+
+            var $leftTable = $('#col1 div.content').find('table.icinga-objects');
+            if ($leftTable.length !== 1) {
+                return;
+            }
+
+            var tabPath = self.pathFromHref($a);
+
+            $leftTable.find('tr').each(function(idx, tr) {
+                var $tr = $(tr);
+                if ($tr.is('[href]')) {
+                    self.setHrefPath($tr, tabPath);
+                } else {
+                    // Unfortunately we currently run BEFORE the  action table
+                    // handler
+                    var $a = $tr.find('a[href].rowaction');
+                    if ($a.length === 0) {
+                        $a = $tr.find('a[href]').first();
+                    }
+
+                    if ($a.length) {
+                        self.setHrefPath($a, tabPath);
+                    }
+                }
+            });
+
+            $leftTable.find('tr[href]').each(function(idx, tr) {
+                var $tr = $(tr);
+                self.setHrefPath($tr, tabPath);
+            });
+        },
+
+        pathFromHref: function($el)
+        {
+            return this.module.icinga.utils.parseUrl($el.attr('href')).path
+        },
+
+        setHrefPath: function($el, path)
+        {
+            var a = this.module.icinga.utils.getUrlHelper();
+            a.href = $el.attr('href');
+            a.pathname = path;
+            $el.attr('href', a.href);
+        },
+
         extensibleSetAction: function(ev)
         {
             var el = ev.currentTarget;
@@ -172,6 +235,7 @@
                 $('#' + iid).focus();
                 $container.removeData('activeExtensibleEntry');
             }
+            this.alignDetailLinks();
         },
 
         restoreContainerFieldsets: function($container)



More information about the icinga-checkins mailing list