var WarningsRenderer = {}; // renders a Wikibase entity into a link WarningsRenderer._renderEntity = function (entity) { if (!entity.id && entity.value) { entity.id = entity.value.id; } var id = entity.id; var is_new = entity.siteIri === "http://localhost/entity/"; if (is_new) { id = $.i18n('wikibase-preview/new-id'); } var fullLabel = id; if (entity.label) { fullLabel = entity.label + ' (' + id + ')'; } var url = entity.iri; if (!url && entity.value) { url = WikibaseManager.getSelectedWikibaseSiteIri() + entity.value.id; } if (is_new) { return '' + fullLabel + ''; } else { return '' + fullLabel + ''; } }; // replaces the issue properties in localization template WarningsRenderer._replaceIssueProperties = function (template, properties) { template = template.replace(new RegExp('{wikibase_name}', 'g'), WikibaseManager.getSelectedWikibaseName); if (!properties) { return template; } var expanded = template; for (var key in properties) { if (properties.hasOwnProperty(key)) { var rendered = properties[key]; if (key.endsWith('_entity')) { rendered = WarningsRenderer._renderEntity(properties[key]); } expanded = expanded.replace(new RegExp('{' + key + '}', 'g'), rendered); } } return expanded; }; WarningsRenderer._renderWarning = function (warning) { var title = WarningsRenderer._replaceIssueProperties($.i18n('warnings-messages/' + warning.type + '/title'), warning.properties); var body = WarningsRenderer._replaceIssueProperties($.i18n('warnings-messages/' + warning.type + '/body'), warning.properties); var tr = $('').addClass('wb-warning'); var severityTd = $('') .addClass('wb-warning-severity') .addClass('wb-warning-severity-' + warning.severity) .appendTo(tr); var bodyTd = $('') .addClass('wb-warning-body') .appendTo(tr); var h1 = $('

') .html(title) .appendTo(bodyTd); var p = $('

') .html(body) .appendTo(bodyTd); var countTd = $('') .addClass('wb-warning-count') .appendTo(tr); var countSpan = $('') .text(warning.count) .appendTo(countTd); return tr; };