Module:RosterTooltip

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_html = require('Module:HtmlUtil') local util_table = require('Module:TableUtil') local m_country = require('Module:Country') local m_role = require('Module:Role') local m_team = require('Module:Team')

local HEADINGS = { 'C', 'ID', 'Name', 'Role' } local FIELDS = { 'Country', 'ID', 'Name', 'Role' }

local h = {}

function h.doQuery(pagename) local query = h.makeQuery(pagename) local result = util_cargo.queryAndCast(query) return result end

function h.makeQuery(pagename) local query = { tables = 'ListplayerCurrent', fields = { 'ID', 'Name', 'Country', 'Role', 'IsSubstitute' },		where = ('Team="%s" AND ID IS NOT NULL'):format(pagename), orderBy = 'PlayerNo ASC' }	return query end

function h.processRow(row) row.Country = row.Country and m_country.onlyimage(row.Country) or '' row.Role = m_role.rolename(row.Role) return end

function h.printTable(data, team) local tbl = mw.html.create('table') :addClass('wikitable') :addClass('tooltip-table') tbl:tag('tr'):tag('th'):attr('colspan',#HEADINGS):wikitext(('%s Current Roster'):format(team)) util_html.printHeader(tbl, HEADINGS) util_html.printRowsByList(tbl, data, FIELDS) return tbl end local p = {} function p.main(frame) local args = util_args.merge(true) local pagename = args.page or mw.title.getCurrentTitle.text local team = m_team.teammediumname(pagename) local data = h.doQuery(pagename) if not next(data) then return '' end util_table.mapRowsInPlace(data, h.processRow) return h.printTable(data, team) end return p