[icinga-checkins] icinga.org: icinga-web/master: LongPluginOutput: Fix missing support of multi line in html

git at icinga.org git at icinga.org
Tue Jun 24 09:55:02 CEST 2014


Module: icinga-web
Branch: master
Commit: 14fdf6323dde83ba51d61d29f7ff3ee4b23614f4
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=14fdf6323dde83ba51d61d29f7ff3ee4b23614f4

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Jun 20 13:41:10 2014 +0200

LongPluginOutput: Fix missing support of multi line in html

refs #2653

---

 app/modules/AppKit/config/javascript.xml           |    1 +
 app/modules/AppKit/lib/js/utils/String.js          |   30 ++++++++++++++++++++
 .../lib/js/Cronk/grid/renderer/ColumnRenderer.js   |   11 +++++++
 .../Cronks/Tackle/Information/LongPluginOutput.js  |    1 +
 .../Cronks/Tackle/Information/OutputPanel.js       |   12 ++++++++
 5 files changed, 55 insertions(+)

diff --git a/app/modules/AppKit/config/javascript.xml b/app/modules/AppKit/config/javascript.xml
index 81a48bc..81b87bc 100644
--- a/app/modules/AppKit/config/javascript.xml
+++ b/app/modules/AppKit/config/javascript.xml
@@ -59,6 +59,7 @@
             <ae:parameter>%core.root_dir%/lib/jsgettext/lib/Gettext.js</ae:parameter>
 
             <ae:parameter>%core.module_dir%/AppKit/lib/js/ext-overrides/TreeNodeDontLeak.js</ae:parameter>
+            <ae:parameter>%core.module_dir%/AppKit/lib/js/utils/String.js</ae:parameter>
         </javascript>
 
 <!--
diff --git a/app/modules/AppKit/lib/js/utils/String.js b/app/modules/AppKit/lib/js/utils/String.js
new file mode 100644
index 0000000..0ea3d3f
--- /dev/null
+++ b/app/modules/AppKit/lib/js/utils/String.js
@@ -0,0 +1,30 @@
+// {{{ICINGA_LICENSE_CODE}}}
+// -----------------------------------------------------------------------------
+// This file is part of icinga-web.
+//
+// Copyright (c) 2009-present Icinga Developer Team.
+// All rights reserved.
+//
+// icinga-web is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// icinga-web is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with icinga-web.  If not, see <http://www.gnu.org/licenses/>.
+// -----------------------------------------------------------------------------
+// {{{ICINGA_LICENSE_CODE}}}
+
+(function() {
+    "use static";
+
+    String.prototype.nl2br = function() {
+        return (this + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
+    };
+
+})();
\ No newline at end of file
diff --git a/app/modules/Cronks/lib/js/Cronk/grid/renderer/ColumnRenderer.js b/app/modules/Cronks/lib/js/Cronk/grid/renderer/ColumnRenderer.js
index 1635dc1..373b8c1 100644
--- a/app/modules/Cronks/lib/js/Cronk/grid/renderer/ColumnRenderer.js
+++ b/app/modules/Cronks/lib/js/Cronk/grid/renderer/ColumnRenderer.js
@@ -80,6 +80,13 @@ Ext.ns('Cronk.grid');
     Cronk.grid.ColumnRenderer = {
 
         customColumnPerfdataSanitized: function (cfg) {
+
+            var multiLine = false;
+
+            if (!Ext.isEmpty(cfg.multiLine) && cfg.multiLine) {
+                multiLine = true;
+            }
+
             return function (value, metaData, record, rowIndex, colIndex, store) {
                 if (!value) {
                     return _('no value');
@@ -99,6 +106,10 @@ Ext.ns('Cronk.grid');
 
                 metaData.attr = 'ext:qtip="' + Ext.util.Format.htmlEncode(value) + '"';
 
+                if (multiLine === true) {
+                    value = String(value).nl2br();
+                }
+
                 return value;
             };
         },
diff --git a/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/LongPluginOutput.js b/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/LongPluginOutput.js
index 8f93846..668efc0 100644
--- a/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/LongPluginOutput.js
+++ b/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/LongPluginOutput.js
@@ -29,6 +29,7 @@ Ext.ns('Icinga.Cronks.Tackle.Information');
     Icinga.Cronks.Tackle.Information.LongPluginOutput = Ext.extend(
         Icinga.Cronks.Tackle.Information.OutputPanel, {
         title: _("Long plugin output"),
+        keepLineBreaksInHTML: true,
         tplField: 'object_long_output'
     });
 
diff --git a/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/OutputPanel.js b/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/OutputPanel.js
index fbb8026..3049216 100644
--- a/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/OutputPanel.js
+++ b/app/modules/Cronks/lib/js/Icinga/Cronks/Tackle/Information/OutputPanel.js
@@ -28,6 +28,7 @@ Ext.ns('Icinga.Cronks.Tackle.Information');
 
     Icinga.Cronks.Tackle.Information.OutputPanel = Ext.extend(Ext.Panel, {
         autoScroll: true,
+        keepLineBreaksInHTML: false,
         
         constructor: function(c) {
             Icinga.Cronks.Tackle.Information
@@ -48,6 +49,17 @@ Ext.ns('Icinga.Cronks.Tackle.Information');
             
             Icinga.Cronks.Tackle.Information
                 .OutputPanel.superclass.initComponent.call(this);
+        },
+
+        update: function(htmlOrData, loadScripts, cb) {
+            if (!Ext.isEmpty(this.tplField) && this.keepLineBreaksInHTML === true) {
+                if (!Ext.isEmpty(htmlOrData[this.tplField])) {
+                    htmlOrData[this.tplField] = String(htmlOrData[this.tplField]).nl2br();
+                }
+            }
+
+            Icinga.Cronks.Tackle.Information
+                .OutputPanel.superclass.update.call(this, htmlOrData, loadScripts, cb);
         }
     });
 



More information about the icinga-checkins mailing list