Modulo:Mooc/Template/Overview
Aspetto
This is the Lua template class to expand the corresponding Wiki template.
local inheritance = require("Modulo:Inheritance");
local UnitTemplate = require("Modulo:Mooc/Template/Unit");
local Template = inheritance.extend(UnitTemplate);
Template.PATH = 'Mooc/Overview';
function Template:loadPageContent(mooc, index, templateParams)
local item = index["item"];
index["navigation"] = item;
local templateParams = item:getParams();
self:loadSectionNavigation(item, templateParams);
-- administration
templateParams['baseUrl'] = mooc:getBaseUrl();
templateParams['indexUrl'] = mooc:getIndexUrl();
-- content
templateParams['title'] = mooc:getBaseUrl();
-- children
self:loadChildren(item, templateParams);
-- navigation
self:loadNavigation(index, templateParams);
end
function Template:loadSectionNavigation(item, templateParams)
local url = item:getUrl();
local nNav = mw.html.create('div'):attr('id', 'item-navigation'):addClass('border-box');
nNav:node(self:renderSectionLink(url, 'lessons'));
nNav:node(self:renderSectionLink(url, 'discussion'));
templateParams['sectionNavigation'] = tostring(nNav);
end
function Template:loadChildren(item, templateParams)
local children = item:getChildren();
local container = mw.html.create('div');
container:addClass('children');
if children ~= nil then
local i = 0;
for _,v in ipairs(children) do
i = i + 1;
container:node(self:renderChildLesson(v, i));
end
end
-- button create child
container:node(self:renderCreateLessonLink());
container:node(self:renderCreateLessonBox());
templateParams['children'] = tostring(container);
end
function Template:renderChildLesson(lesson, numLesson)
local children = lesson:getChildren();
local container = mw.html.create('div'):addClass('lesson');
-- lesson title
container:tag('div'):addClass('title'):wikitext('[[' .. lesson:getUrl() .. '|' .. tostring(numLesson) .. '. ' .. lesson:getName() .. ']]');
-- associated units
local nChildren = container:tag('div'):addClass('children');
if children ~= nil then
for _,v in ipairs(children) do
nChildren:node(self:renderChildUnit(v));
end
end
return container;
end
function Template:renderCreateLessonLink()
local node = mw.html.create('div');
node:attr('id', 'addLesson'):addClass('child'):css('display', 'none');
local video = node:tag('div');
video:addClass('video');
local img = video:tag('div'):tag('span'):wikitext('[[File:AddMoocItem.png]]');
local title = node:tag('div');
title:addClass('title');
title:wikitext('new lesson');
return node;
end
function Template:renderCreateLessonBox()
local modal = mw.html.create('div');
modal:attr('id', 'modal-add-lesson-addLesson'):addClass('modal-box'):css('display', 'none');
return modal;
end
return Template;