Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Grid/columns: Replace new lines with the HTML break when `multiLine' …
Browse files Browse the repository at this point in the history
…is enabled

Example config:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<template match-pattern="icinga-(service-template|.+-service-problems)">
    <fields>
        <field name="plugin_long_output">
            <datasource>
                <parameter name="field">SERVICE_LONG_OUTPUT</parameter>
            </datasource>
            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Long output</parameter>
                <parameter name="jsFunc">
                    <parameter>
                        <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                        <parameter name="function">customColumnPerfdataSanitized</parameter>
                        <parameter name="arguments">
                            <parameter name="multiLine">1</parameter>
                        </parameter>
                    </parameter>
                </parameter>
            </display>
            <filter>
                <parameter name="enabled">false</parameter>
            </filter>
            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>
    </fields>
</template>

refs #2653
  • Loading branch information
lippserd committed Jun 26, 2014
1 parent 97bf45e commit 232b5c0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/modules/Cronks/lib/js/Cronk/grid/renderer/ColumnRenderer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// {{{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/>.
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -80,6 +80,8 @@ Ext.ns('Cronk.grid');
Cronk.grid.ColumnRenderer = {

customColumnPerfdataSanitized: function (cfg) {
var multiLine = cfg.multiLine ? true : false;

return function (value, metaData, record, rowIndex, colIndex, store) {
if (!value) {
return _('no value');
Expand All @@ -97,6 +99,15 @@ Ext.ns('Cronk.grid');
return output;
}

if (multiLine) {
/*
* According to http://www.ietf.org/rfc/rfc4627.txt the JSON representation of strings must escape
* control characters which includes the line feed `\n' and the carriage return `\r'. So '\n', '\r'
* and '\r\n' become '\\n', '\\r' and '\\r\\n' respectively.
*/
value = Ext.util.Format.nl2br(value.replace(/\\r/g, '\r').replace(/\\n/g, '\n'));
}

metaData.attr = 'ext:qtip="' + Ext.util.Format.htmlEncode(value) + '"';

return value;
Expand Down

0 comments on commit 232b5c0

Please sign in to comment.