Table of contents
No headers
/***
USAGE:
KB(description)
Show a knowledge base that organizes subpages into featured pages and pages by tags.
PARAMETERS:
description : str
Description of what this knowledge base covers.
***/
// redirect to custom page, if any
var template_custom = __page.path .. 'Custom';
if (wiki.pageexists(template_custom)) {
return template(template_custom, $);
}
// read parameters
var description = $0 ?? $description;
if(description is xml) {
let description = xml.html(description["//*[@id='kb-description']"]) !! '(bad description format)';
}
// read request parameters
var view = __request.args.v;
switch(view) {
case 'all':
case 'tags':
break;
case 'featured':
default:
let view = 'featured';
}
// read sub-pages
var pages = map.values(page.subpages);
// text definitions
var featured_title = wiki.localize('MindTouch.IDF.kb.view.featured');
var tags_title = wiki.localize('MindTouch.IDF.kb.view.tagged');
var all_title = wiki.localize('MindTouch.IDF.kb.view.all');
var create_label = wiki.localize('MindTouch.IDF.kb.action');
var notags_label = xml.text(wiki.localize('MindTouch.IDF.kb.tagged.notags'));
// ui layouts
var user_can_create = wiki.pagepermissions().create;
var create_button = user_can_create ? <div class="new-kb">
wiki.create{
label: create_label,
template: 'MindTouch/IDF/Pages/Knowledge_Base_Page',
title: create_label
};
</div> : nil;
var missing_text = <div class="mt-control-nocontent">
<p class="nocontent-title">
wiki.localize("MindTouch.IDF.kb.empty");
</p>
<p>
if(user_can_create) {
wiki.localize("MindTouch.IDF.kb.text.author");
} else {
wiki.localize("MindTouch.IDF.kb.text.visitor");
}
</p>
create_button
</div>;
// the output is part of a table
<td>
// show tabs with button
<div class="mt-control-nav">
create_button;
<ul>
<li class=(view === 'featured' ? 'active' : nil)>
<a href=(page.uri & { v: 'featured' }) rel="custom">
featured_title
</a>
</li>
<li class=(view === 'tags' ? 'active' : nil)>
<a href=(page.uri & { v: 'tags' }) rel="custom">
tags_title
</a>
</li>
<li class=(view === 'all' ? 'active' : nil)>
<a href=(page.uri & { v: 'all' }) rel="custom">
all_title
</a>
</li>
</ul>
</div>
// show tab contents
switch(view) {
case 'featured':
template('MindTouch/IDF/Controls/TopPages', {
id: 'mindtouch-kb',
pages: pages,
limit: 15,
description: description,
missing: missing_text
});
case 'tags':
template('MindTouch/IDF/Controls/PageDirectory', {
id: 'mindtouch-kb',
pages: pages,
mapping: '',
description: description,
missing: missing_text,
unclassified: notags_label
});
case 'all':
template('MindTouch/IDF/Controls/PageDirectory', {
id: 'mindtouch-kb',
pages: pages,
description: description,
missing: missing_text,
unclassified: notags_label,
columns: 1
});
}
</td>
.mt-control-nav ul li {
list-style-type: none;
}
#mindtouch-kb,
#mindtouch-kb td {
border:none;
color:#333335;
}
#mindtouch-kb h3 {
border-top: 2px solid #000000;
font-size: 16px;
font-weight: bold;
margin: 15px 0 0 0;
color:#4F6B72;
padding: 6px 0 0 0;
}
#mindtouch-kb p {
color:#4F6B72;
}
#mindtouch-kb .left {
margin-right:15px;
}
#mindtouch-kb .right {
margin-left:25px;
}
#mindtouch-kb ul,
#mindtouch-kb ol {
padding-left:17px;
}
#mindtouch-kb ul li,
#mindtouch-kb ol li {
margin-bottom:5px;
}
#mindtouch-kb a {
text-decoration:none;
}
#mindtouch-kb a:hover {
text-decoration:underline;
}
#mindtouch-kb .count {
color:#737373;
font-weight:normal;
font-size:10px;
letter-spacing:.5px;
}
.new-kb {
float:right;
}

Comments