Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 195: | Line 195: | ||
end | end | ||
-- Documents section | |||
addSectionRow(tbl, 'Documents') | addSectionRow(tbl, 'Documents') | ||
| Line 209: | Line 209: | ||
) | ) | ||
-- Query for | -- Query for document count | ||
local | local documentsCountWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[Category:Documents]]\n' .. | ' [[Category:Documents]]\n' .. | ||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ||
' |format=count\n' .. | |||
' |format= | |||
'}}' | '}}' | ||
local | local documentCount = frame:preprocess(documentsCountWikitext) | ||
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0 | |||
-- | -- Create the content row | ||
local | local tr = tbl:tag('tr') | ||
local td = tr:tag('td'):attr('colspan', '2') | |||
css(td, 'padding:0.2em 0.4em;') | |||
if hasDocuments then | if hasDocuments then | ||
-- | -- Create UL element | ||
local ul = mw.html.create('ul') | |||
local | ul:css('margin', '0'):css('padding-left', '1.5em') | ||
-- Get list of document pages | -- Get list of document pages | ||
| Line 241: | Line 241: | ||
-- Process each document page | -- Process each document page | ||
if docPages and trim(docPages) then | if docPages and trim(docPages) then | ||
for docPage in docPages:gmatch('[^,\n]+') do | for docPage in docPages:gmatch('[^,\n]+') do | ||
docPage = trim(docPage) | docPage = trim(docPage) | ||
if docPage and docPage ~= '' then | if docPage and docPage ~= '' then | ||
-- Get type and URL | -- Get type and URL | ||
local typeQuery = '{{#show:' .. docPage .. '|?Has document type}}' | local typeQuery = '{{#show:' .. docPage .. '|?Has document type}}' | ||
local urlQuery = '{{#show:' .. docPage .. '|?Has document URL}}' | local urlQuery = '{{#show:' .. docPage .. '|?Has document URL}}' | ||
local docType = frame:preprocess(typeQuery) | local docType = trim(frame:preprocess(typeQuery)) | ||
local docUrl = frame:preprocess(urlQuery) | local docUrl = trim(frame:preprocess(urlQuery)) | ||
if docUrl and docUrl ~= '' then | if docUrl and docUrl ~= '' then | ||
local displayText = (docType and docType ~= '') and docType or 'Document' | local displayText = (docType and docType ~= '') and docType or 'Document' | ||
-- Create list item with link | |||
local li = ul:tag('li') | |||
local a = li:tag('a') | |||
a:attr('href', docUrl) | |||
a:attr('class', 'external') | |||
a:wikitext(displayText) | |||
end | end | ||
end | end | ||
| Line 263: | Line 265: | ||
end | end | ||
-- Add the UL to the td | |||
td:node(ul) | |||
-- | -- Add upload link | ||
local | local uploadDiv = mw.html.create('div') | ||
uploadDiv:css('margin-top', '0.5em'):css('font-style', 'italic') | |||
local uploadLink = uploadDiv:tag('a') | |||
uploadLink:attr('href', tostring(uploadUrl)) | |||
uploadLink:attr('class', 'external') | |||
uploadLink:wikitext('Upload a document') | |||
td:node(uploadDiv) | |||
else | else | ||
-- Just show the upload link | -- Just show the upload link | ||
local | local uploadDiv = mw.html.create('div') | ||
uploadDiv:css('font-style', 'italic') | |||
local uploadLink = uploadDiv:tag('a') | |||
uploadLink:attr('href', tostring(uploadUrl)) | |||
uploadLink:attr('class', 'external') | |||
uploadLink:wikitext('Upload a document') | |||
td:node(uploadDiv) | |||
end | end | ||