Module:Rb row/common: Difference between revisions
Appearance
m Removes variable definition in favor of argument |
m Adds background color option to condition row rendering |
||
| Line 3: | Line 3: | ||
-- @param conditionType string the type of condition. Should match one either eventCancelledValue or eventNotHeldValue. | -- @param conditionType string the type of condition. Should match one either eventCancelledValue or eventNotHeldValue. | ||
-- @param columnCount number The number of columns that the row will span | -- @param columnCount number The number of columns that the row will span | ||
-- @param enableColumnColor boolean Whether the background color of the cell should be shown. Varies based on the type of condition (conditionType). | |||
-- @param eventCancelledValue string The string literal that represents that the event was cancelled | -- @param eventCancelledValue string The string literal that represents that the event was cancelled | ||
-- @param eventNotHeldValue string The string literal that represents that the event was not held | -- @param eventNotHeldValue string The string literal that represents that the event was not held | ||
-- @param conditionReason string? Specifies the reason as to why the condition happened | -- @param conditionReason string? Specifies the reason as to why the condition happened | ||
-- @param conditionMessageOverride string? Overrides the default condition template with a custom reasonmessage | -- @param conditionMessageOverride string? Overrides the default condition template with a custom reasonmessage | ||
function p.generateConditionRow(conditionType, columnCount, eventCancelledValue, eventNotHeldValue, conditionReason, conditionMessageOverride) | function p.generateConditionRow(conditionType, columnCount, enableColumnColor, eventCancelledValue, eventNotHeldValue, conditionReason, conditionMessageOverride) | ||
local conditionCell = mw.html.create("td") | local conditionCell = mw.html.create("td") | ||
conditionCell:attr("colspan", tostring(columnCount)) | conditionCell:attr("colspan", tostring(columnCount)) | ||
| Line 15: | Line 16: | ||
if conditionType == eventCancelledValue then | if conditionType == eventCancelledValue then | ||
isValidCondition = true | isValidCondition = true | ||
if enableColumnColor then | |||
conditionCell:css({["background"] = "#ffdddd"}) | |||
end | |||
text = "Cancelled" | text = "Cancelled" | ||
elseif conditionType == eventNotHeldValue then | elseif conditionType == eventNotHeldValue then | ||
isValidCondition = true | isValidCondition = true | ||
if enableColumnColor then | |||
conditionCell:css({["background"] = "#ffdead"}) | |||
end | |||
text = "Not held" | text = "Not held" | ||
end | end | ||
Revision as of 23:17, 18 December 2024
Documentation for this module may be created at Module:Rb row/common/doc
local p = {}
-- @param conditionType string the type of condition. Should match one either eventCancelledValue or eventNotHeldValue.
-- @param columnCount number The number of columns that the row will span
-- @param enableColumnColor boolean Whether the background color of the cell should be shown. Varies based on the type of condition (conditionType).
-- @param eventCancelledValue string The string literal that represents that the event was cancelled
-- @param eventNotHeldValue string The string literal that represents that the event was not held
-- @param conditionReason string? Specifies the reason as to why the condition happened
-- @param conditionMessageOverride string? Overrides the default condition template with a custom reasonmessage
function p.generateConditionRow(conditionType, columnCount, enableColumnColor, eventCancelledValue, eventNotHeldValue, conditionReason, conditionMessageOverride)
local conditionCell = mw.html.create("td")
conditionCell:attr("colspan", tostring(columnCount))
local isValidCondition = false
local text = ""
if conditionType == eventCancelledValue then
isValidCondition = true
if enableColumnColor then
conditionCell:css({["background"] = "#ffdddd"})
end
text = "Cancelled"
elseif conditionType == eventNotHeldValue then
isValidCondition = true
if enableColumnColor then
conditionCell:css({["background"] = "#ffdead"})
end
text = "Not held"
end
if isValidCondition then
if conditionMessageOverride ~= nil then
text = string.format("''%s %s''", text, conditionMessageOverride)
elseif conditionReason ~= nil then
text = string.format("''%s due to %s''", text, conditionReason)
else
text = string.format("''%s''", text)
end
else
mw.addWarning(string.format("Condition can only be %s or %s", eventCancelledValue, eventNotHeldValue))
end
conditionCell:wikitext(text)
return conditionCell
end
return p