App-MFILE-WWW
view release on metacpan or search on metacpan
share/js/core/html.js view on Meta::CPAN
// *************************************************************************
// Copyright (c) 2014-2017, SUSE LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of SUSE LLC nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// *************************************************************************
//
// html.js - functions that generate HTML source code
//
"use strict";
define ([
'cf',
'lib',
'app/lib',
'target'
], function (
cf,
coreLib,
appLib,
target
) {
var browserNavMenu = function (len, pos) {
var r = '',
context = {
forward: 0,
back: 0,
jumpToEnd: 0,
jumpToBegin: 0
};
// context-sensitive navigation menu: selections are based on
// set length and cursor position:
// if set.length <= 1: no navigation menu at all
// if 1 < set.length <= 5: forward, back
// if set.length > 5: forward, back, jump to end/beginning
// if pos == 1 then back and jump to beginning are deactivated
// if pos == set.length then forward and jump to end are deactivated
// here in html.js, we add <span> elements for each context-sensitive
// selection. Each such element has a unique identifier, so that in
// start.js we can check for the presence of each and handle accordingly
if (len > 1) {
// (a) determine context
if (len > 1) {
context.forward = 1;
context.back = 1;
}
if (len > 5) {
context.jumpToEnd = 1;
context.jumpToBegin = 1;
}
if (pos === 0) {
context.back = 0;
context.jumpToBegin = 0;
}
if (pos === len - 1) {
context.forward = 0;
context.jumpToEnd = 0;
}
// (b) construct navigation menu
r += 'Navigation: ';
if (context.back) {
r += '<span id="navBack">[\u2190] Previous </span>';
}
if (context.forward) {
r += '<span id="navForward">[\u2192] Next </span>';
}
if (context.jumpToBegin) {
r += '<span id="navJumpToBegin">[\u2303\u2190] Jump to first </span>';
}
if (context.jumpToEnd) {
r += '<span id="navJumpToEnd">[\u2303\u2192] Jump to last </span>';
}
r += '<br>';
} else {
r = '';
}
return r;
}, // browserNavMenu
genericTable = function (tname, tobj, targetType) {
return function (set) {
// console.log("Generating source code of " + tname);
// console.log("tobj", tobj);
// console.log("set", set);
var r = '<form id="' + tobj.name + '">',
allEntries,
entry,
column,
share/js/core/html.js view on Meta::CPAN
r += '</div>';
if (cf('displaySessionData') === true) {
r += 'Plack session ID: ' + cf('sessionID');
r += ' (last_seen ' + cf('sessionLastSeen') + ')</br>';
}
return r;
}, // body
dbrowser: function (dbn) {
// dfn is dbrowser name
// dfo is dbrowser object
var dbo = target.pull(dbn);
return function (set, pos) {
// console.log("Generating source code of dbrowser " + dbn);
var r = '<form id="' + dbo.name + '">',
len,
i,
obj,
entry,
allEntries,
needed;
r += '<br><b>' + dbo.title + '</b><br><br>';
if (dbo.preamble) {
r += dbo.preamble + '<br><br>';
}
// determine characters needed for padding (based on longest
// entry)
allEntries = dbo.getEntries();
if (! vetEntries(dbn, allEntries)) {
// no point in going any further
return null;
}
needed = maxLength(allEntries) + 2;
// display entries
len = allEntries.length;
obj = set[pos];
console.log('Browsing object', obj);
if (len > 0) {
for (i = 0; i < len; i += 1) {
entry = allEntries[i];
if (entry.name === 'divider') {
r += Array(entry.maxlen).join(entry.text) + '<br>';
} else if (entry.name === 'emptyLine') {
r += '<br>';
} else if (coreLib.privCheck(entry.aclProfileRead)) {
r += coreLib.rightPadSpaces(entry.text.concat(':'), needed);
r += '<span id="' + entry.name + '">';
r += valueToDisplay(obj, entry.prop);
r += '</span><br>';
}
}
r += '<br>';
}
// context-sensitive navigation menu: selections are based on
// set length and cursor position
r += browserNavMenu(set.length, pos);
// miniMenu at the bottom: selections are target names defined
// in the 'miniMenu' property of the dbrowser object
r += miniMenu(dbo);
// your choice section
r += yourChoice();
r += '</form>';
// console.log("Assembled source code for " + dbn + " - it has " + r.length + " characters");
return r;
};
}, // dbrowser
dcallback: function (dcn) {
// console.log("Entering html.dcallback with argument " + dcn);
// dcn is dcallback name
// dco is dcallback object
var dco = target.pull(dcn),
r = '';
r += '<br><div id="dcallback"></div><br>';
r += '<form id="' + dcn + '">';
// miniMenu at the bottom
r += miniMenu(dco);
// your choice section
r += yourChoice();
r += '</form>';
return r;
}, // dcallback
dform: function (dfn) {
// dfn is dform name
// dfo is dform object
var dfo = target.pull(dfn);
return function (obj) {
// console.log("Generating source code of dform " + dfn + " with object", obj);
var r = '<form id="' + dfo.name + '">',
len,
i,
allEntries,
needed,
entry;
r += '<br><b>' + dfo.title + '</b><br><br>';
if (dfo.preamble) {
r += dfo.preamble + '<br><br>';
}
// determine characters needed for padding (based on longest
// entry)
if (dfo.entriesRead === undefined || dfo.entriesRead === null) {
// console.log("No entriesRead, initializing allEntries to empty array");
allEntries = coreLib.forceArray([]);
} else {
( run in 1.418 second using v1.01-cache-2.11-cpan-39bf76dae61 )