[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: Register and implement announcement-banner behavavior

git at icinga.org git at icinga.org
Tue Nov 8 17:46:53 CET 2016


Module: icingaweb2
Branch: feature/announce-banner-11198
Commit: 1fa29a65c42463c3992df1e6f2af6e9429b477d7
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=1fa29a65c42463c3992df1e6f2af6e9429b477d7

Author: Florian Strohmaier <florian.strohmaier at netways.de>
Date:   Tue Nov  8 17:46:47 2016 +0100

Register and implement announcement-banner behavavior

---

 library/Icinga/Web/JavaScript.php                |    1 +
 public/js/icinga/behavior/announcement-banner.js |   65 ++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php
index e6278c7..75aba22 100644
--- a/library/Icinga/Web/JavaScript.php
+++ b/library/Icinga/Web/JavaScript.php
@@ -31,6 +31,7 @@ class JavaScript
         'js/icinga/behavior/navigation.js',
         'js/icinga/behavior/form.js',
         'js/icinga/behavior/actiontable.js',
+        'js/icinga/behavior/announcement-banner.js',
         'js/icinga/behavior/selectable.js'
     );
 
diff --git a/public/js/icinga/behavior/announcement-banner.js b/public/js/icinga/behavior/announcement-banner.js
new file mode 100644
index 0000000..393253c
--- /dev/null
+++ b/public/js/icinga/behavior/announcement-banner.js
@@ -0,0 +1,65 @@
+/*! Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
+
+;(function(Icinga, $) {
+
+    'use strict';
+
+    /**
+     * Add close button to each announcement element
+     *
+     * @param {jQuery} $container   The original event
+     */
+    function onRendered(e) {
+        console.log('layout rendered', e);
+        var _this = e.data.self;
+        var $announcements = $('#announcements > li');
+
+        var c = onCloseButtonClick;
+
+        $announcements.each(function() {
+            var $this = $(this);
+            if (!$this.children('button.button-close').length > 0) {
+                var $closeButton = $('<button class="button-close"><i class="icon-cancel"></i></button>');
+                $closeButton.on('click', onCloseButtonClick);
+                $this.append($closeButton)
+            }
+        });
+    }
+
+    /**
+     * Remove the announcement element
+     *
+     * @param {object} e   The original event
+     */
+
+    function onCloseButtonClick(e) {
+        var $t = $(e.target);
+        $t.parents('li').remove();
+        $('#header').css({
+          height: 'auto'
+        });
+        $('#main, #sidebar, .controls').css({
+            top: $('#header').outerHeight()
+        });
+    }
+
+    Icinga.Behaviors = Icinga.Behaviors || {};
+
+    /**
+     * Behavior for announcement banner to handle disposable announce elements
+     *
+     * The announcement behavior adds a close button to contained announcement elements, which disposes them on click
+     *
+     * @param {Icinga} icinga
+     *
+     * @constructor
+     */
+    var announcementBanner = function(icinga) {
+        Icinga.EventListener.call(this, icinga);
+        this.on('rendered', '#layout', onRendered, this);
+    };
+
+    announcementBanner.prototype = new Icinga.EventListener();
+
+    Icinga.Behaviors.announcementBanner = announcementBanner;
+})(Icinga, jQuery);



More information about the icinga-checkins mailing list