Chris@76: /* Chris@76: smf_AdminIndex(oOptions) Chris@76: { Chris@76: public init() Chris@76: public loadAdminIndex() Chris@76: public setAnnouncements() Chris@76: public showCurrentVersion() Chris@76: public checkUpdateAvailable() Chris@76: } Chris@76: Chris@76: smf_ViewVersions(oOptions) Chris@76: { Chris@76: public init() Chris@76: public loadViewVersions Chris@76: public swapOption(oSendingElement, sName) Chris@76: public compareVersions(sCurrent, sTarget) Chris@76: public determineVersions() Chris@76: } Chris@76: */ Chris@76: Chris@76: Chris@76: Chris@76: // Handle the JavaScript surrounding the admin and moderation center. Chris@76: function smf_AdminIndex(oOptions) Chris@76: { Chris@76: this.opt = oOptions; Chris@76: this.init(); Chris@76: } Chris@76: Chris@76: smf_AdminIndex.prototype.init = function () Chris@76: { Chris@76: window.adminIndexInstanceRef = this; Chris@76: var fHandlePageLoaded = function () { Chris@76: window.adminIndexInstanceRef.loadAdminIndex(); Chris@76: } Chris@76: addLoadEvent(fHandlePageLoaded); Chris@76: } Chris@76: Chris@76: smf_AdminIndex.prototype.loadAdminIndex = function () Chris@76: { Chris@76: // Load the text box containing the latest news items. Chris@76: if (this.opt.bLoadAnnouncements) Chris@76: this.setAnnouncements(); Chris@76: Chris@76: // Load the current SMF and your SMF version numbers. Chris@76: if (this.opt.bLoadVersions) Chris@76: this.showCurrentVersion(); Chris@76: Chris@76: // Load the text box that sais there's a new version available. Chris@76: if (this.opt.bLoadUpdateNotification) Chris@76: this.checkUpdateAvailable(); Chris@76: } Chris@76: Chris@76: Chris@76: smf_AdminIndex.prototype.setAnnouncements = function () Chris@76: { Chris@76: if (!('smfAnnouncements' in window) || !('length' in window.smfAnnouncements)) Chris@76: return; Chris@76: Chris@76: var sMessages = ''; Chris@76: for (var i = 0; i < window.smfAnnouncements.length; i++) Chris@76: sMessages += this.opt.sAnnouncementMessageTemplate.replace('%href%', window.smfAnnouncements[i].href).replace('%subject%', window.smfAnnouncements[i].subject).replace('%time%', window.smfAnnouncements[i].time).replace('%message%', window.smfAnnouncements[i].message); Chris@76: Chris@76: setInnerHTML(document.getElementById(this.opt.sAnnouncementContainerId), this.opt.sAnnouncementTemplate.replace('%content%', sMessages)); Chris@76: } Chris@76: Chris@76: smf_AdminIndex.prototype.showCurrentVersion = function () Chris@76: { Chris@76: if (!('smfVersion' in window)) Chris@76: return; Chris@76: Chris@76: var oSmfVersionContainer = document.getElementById(this.opt.sSmfVersionContainerId); Chris@76: var oYourVersionContainer = document.getElementById(this.opt.sYourVersionContainerId); Chris@76: Chris@76: setInnerHTML(oSmfVersionContainer, window.smfVersion); Chris@76: Chris@76: var sCurrentVersion = getInnerHTML(oYourVersionContainer); Chris@76: if (sCurrentVersion != window.smfVersion) Chris@76: setInnerHTML(oYourVersionContainer, this.opt.sVersionOutdatedTemplate.replace('%currentVersion%', sCurrentVersion)); Chris@76: } Chris@76: Chris@76: smf_AdminIndex.prototype.checkUpdateAvailable = function () Chris@76: { Chris@76: if (!('smfUpdatePackage' in window)) Chris@76: return; Chris@76: Chris@76: var oContainer = document.getElementById(this.opt.sUpdateNotificationContainerId); Chris@76: Chris@76: // Are we setting a custom title and message? Chris@76: var sTitle = 'smfUpdateTitle' in window ? window.smfUpdateTitle : this.opt.sUpdateNotificationDefaultTitle; Chris@76: var sMessage = 'smfUpdateNotice' in window ? window.smfUpdateNotice : this.opt.sUpdateNotificationDefaultMessage; Chris@76: Chris@76: setInnerHTML(oContainer, this.opt.sUpdateNotificationTemplate.replace('%title%', sTitle).replace('%message%', sMessage)); Chris@76: Chris@76: // Parse in the package download URL if it exists in the string. Chris@76: document.getElementById('update-link').href = this.opt.sUpdateNotificationLink.replace('%package%', window.smfUpdatePackage); Chris@76: Chris@76: // If we decide to override life into "red" mode, do it. Chris@76: if ('smfUpdateCritical' in window) Chris@76: { Chris@76: document.getElementById('update_table').style.backgroundColor = '#aa2222'; Chris@76: document.getElementById('update_title').style.backgroundColor = '#dd2222'; Chris@76: document.getElementById('update_title').style.color = 'white'; Chris@76: document.getElementById('update_message').style.backgroundColor = '#eebbbb'; Chris@76: document.getElementById('update_message').style.color = 'black'; Chris@76: } Chris@76: } Chris@76: Chris@76: Chris@76: Chris@76: function smf_ViewVersions (oOptions) Chris@76: { Chris@76: this.opt = oOptions; Chris@76: this.oSwaps = {}; Chris@76: this.init(); Chris@76: } Chris@76: Chris@76: smf_ViewVersions.prototype.init = function () Chris@76: { Chris@76: // Load this on loading of the page. Chris@76: window.viewVersionsInstanceRef = this; Chris@76: var fHandlePageLoaded = function () { Chris@76: window.viewVersionsInstanceRef.loadViewVersions(); Chris@76: } Chris@76: addLoadEvent(fHandlePageLoaded); Chris@76: } Chris@76: Chris@76: smf_ViewVersions.prototype.loadViewVersions = function () Chris@76: { Chris@76: this.determineVersions(); Chris@76: } Chris@76: Chris@76: smf_ViewVersions.prototype.swapOption = function (oSendingElement, sName) Chris@76: { Chris@76: // If it is undefined, or currently off, turn it on - otherwise off. Chris@76: this.oSwaps[sName] = !(sName in this.oSwaps) || !this.oSwaps[sName]; Chris@76: document.getElementById(sName).style.display = this.oSwaps[sName] ? '' : 'none'; Chris@76: Chris@76: // Unselect the link and return false. Chris@76: oSendingElement.blur(); Chris@76: return false; Chris@76: } Chris@76: Chris@76: smf_ViewVersions.prototype.compareVersions = function (sCurrent, sTarget) Chris@76: { Chris@76: var aVersions = aParts = new Array(); Chris@76: var aCompare = new Array(sCurrent, sTarget); Chris@76: Chris@76: for (var i = 0; i < 2; i++) Chris@76: { Chris@76: // Clean the version and extract the version parts. Chris@76: var sClean = aCompare[i].toLowerCase().replace(/ /g, '').replace(/2.0rc1-1/, '2.0rc1.1'); Chris@76: aParts = sClean.match(/(\d+)(?:\.(\d+|))?(?:\.)?(\d+|)(?:(alpha|beta|rc)(\d+|)(?:\.)?(\d+|))?(?:(dev))?(\d+|)/); Chris@76: Chris@76: // No matches? Chris@76: if (aParts == null) Chris@76: return false; Chris@76: Chris@76: // Build an array of parts. Chris@76: aVersions[i] = [ Chris@76: aParts[1] > 0 ? parseInt(aParts[1]) : 0, Chris@76: aParts[2] > 0 ? parseInt(aParts[2]) : 0, Chris@76: aParts[3] > 0 ? parseInt(aParts[3]) : 0, Chris@76: typeof(aParts[4]) == 'undefined' ? 'stable' : aParts[4], Chris@76: aParts[5] > 0 ? parseInt(aParts[5]) : 0, Chris@76: aParts[6] > 0 ? parseInt(aParts[6]) : 0, Chris@76: typeof(aParts[7]) != 'undefined', Chris@76: ]; Chris@76: } Chris@76: Chris@76: // Loop through each category. Chris@76: for (i = 0; i < 7; i++) Chris@76: { Chris@76: // Is there something for us to calculate? Chris@76: if (aVersions[0][i] != aVersions[1][i]) Chris@76: { Chris@76: // Dev builds are a problematic exception. Chris@76: // (stable) dev < (stable) but (unstable) dev = (unstable) Chris@76: if (i == 3) Chris@76: return aVersions[0][i] < aVersions[1][i] ? !aVersions[1][6] : aVersions[0][6]; Chris@76: else if (i == 6) Chris@76: return aVersions[0][6] ? aVersions[1][3] == 'stable' : false; Chris@76: // Otherwise a simple comparison. Chris@76: else Chris@76: return aVersions[0][i] < aVersions[1][i]; Chris@76: } Chris@76: } Chris@76: Chris@76: // They are the same! Chris@76: return false; Chris@76: } Chris@76: Chris@76: smf_ViewVersions.prototype.determineVersions = function () Chris@76: { Chris@76: var oHighYour = { Chris@76: Sources: '??', Chris@76: Default: '??', Chris@76: Languages: '??', Chris@76: Templates: '??' Chris@76: }; Chris@76: var oHighCurrent = { Chris@76: Sources: '??', Chris@76: Default: '??', Chris@76: Languages: '??', Chris@76: Templates: '??' Chris@76: }; Chris@76: var oLowVersion = { Chris@76: Sources: false, Chris@76: Default: false, Chris@76: Languages: false, Chris@76: Templates: false Chris@76: }; Chris@76: Chris@76: var sSections = [ Chris@76: 'Sources', Chris@76: 'Default', Chris@76: 'Languages', Chris@76: 'Templates' Chris@76: ]; Chris@76: Chris@76: for (var i = 0, n = sSections.length; i < n; i++) Chris@76: { Chris@76: // Collapse all sections. Chris@76: var oSection = document.getElementById(sSections[i]); Chris@76: if (typeof(oSection) == 'object' && oSection != null) Chris@76: oSection.style.display = 'none'; Chris@76: Chris@76: // Make all section links clickable. Chris@76: var oSectionLink = document.getElementById(sSections[i] + '-link'); Chris@76: if (typeof(oSectionLink) == 'object' && oSectionLink != null) Chris@76: { Chris@76: oSectionLink.instanceRef = this; Chris@76: oSectionLink.sSection = sSections[i]; Chris@76: oSectionLink.onclick = function () { Chris@76: this.instanceRef.swapOption(this, this.sSection); Chris@76: return false; Chris@76: }; Chris@76: } Chris@76: } Chris@76: Chris@76: if (!('smfVersions' in window)) Chris@76: window.smfVersions = {}; Chris@76: Chris@76: for (var sFilename in window.smfVersions) Chris@76: { Chris@76: if (!document.getElementById('current' + sFilename)) Chris@76: continue; Chris@76: Chris@76: var sYourVersion = getInnerHTML(document.getElementById('your' + sFilename)); Chris@76: Chris@76: var sCurVersionType; Chris@76: for (var sVersionType in oLowVersion) Chris@76: if (sFilename.substr(0, sVersionType.length) == sVersionType) Chris@76: { Chris@76: sCurVersionType = sVersionType; Chris@76: break; Chris@76: } Chris@76: Chris@76: if (typeof(sCurVersionType) != 'undefined') Chris@76: { Chris@76: if ((this.compareVersions(oHighYour[sCurVersionType], sYourVersion) || oHighYour[sCurVersionType] == '??') && !oLowVersion[sCurVersionType]) Chris@76: oHighYour[sCurVersionType] = sYourVersion; Chris@76: if (this.compareVersions(oHighCurrent[sCurVersionType], smfVersions[sFilename]) || oHighCurrent[sCurVersionType] == '??') Chris@76: oHighCurrent[sCurVersionType] = smfVersions[sFilename]; Chris@76: Chris@76: if (this.compareVersions(sYourVersion, smfVersions[sFilename])) Chris@76: { Chris@76: oLowVersion[sCurVersionType] = sYourVersion; Chris@76: document.getElementById('your' + sFilename).style.color = 'red'; Chris@76: } Chris@76: } Chris@76: else if (this.compareVersions(sYourVersion, smfVersions[sFilename])) Chris@76: oLowVersion[sCurVersionType] = sYourVersion; Chris@76: Chris@76: setInnerHTML(document.getElementById('current' + sFilename), smfVersions[sFilename]); Chris@76: setInnerHTML(document.getElementById('your' + sFilename), sYourVersion); Chris@76: } Chris@76: Chris@76: if (!('smfLanguageVersions' in window)) Chris@76: window.smfLanguageVersions = {}; Chris@76: Chris@76: for (sFilename in window.smfLanguageVersions) Chris@76: { Chris@76: for (var i = 0; i < this.opt.aKnownLanguages.length; i++) Chris@76: { Chris@76: if (!document.getElementById('current' + sFilename + this.opt.aKnownLanguages[i])) Chris@76: continue; Chris@76: Chris@76: setInnerHTML(document.getElementById('current' + sFilename + this.opt.aKnownLanguages[i]), smfLanguageVersions[sFilename]); Chris@76: Chris@76: sYourVersion = getInnerHTML(document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i])); Chris@76: setInnerHTML(document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]), sYourVersion); Chris@76: Chris@76: if ((this.compareVersions(oHighYour.Languages, sYourVersion) || oHighYour.Languages == '??') && !oLowVersion.Languages) Chris@76: oHighYour.Languages = sYourVersion; Chris@76: if (this.compareVersions(oHighCurrent.Languages, smfLanguageVersions[sFilename]) || oHighCurrent.Languages == '??') Chris@76: oHighCurrent.Languages = smfLanguageVersions[sFilename]; Chris@76: Chris@76: if (this.compareVersions(sYourVersion, smfLanguageVersions[sFilename])) Chris@76: { Chris@76: oLowVersion.Languages = sYourVersion; Chris@76: document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]).style.color = 'red'; Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: setInnerHTML(document.getElementById('yourSources'), oLowVersion.Sources ? oLowVersion.Sources : oHighYour.Sources); Chris@76: setInnerHTML(document.getElementById('currentSources'), oHighCurrent.Sources); Chris@76: if (oLowVersion.Sources) Chris@76: document.getElementById('yourSources').style.color = 'red'; Chris@76: Chris@76: setInnerHTML(document.getElementById('yourDefault'), oLowVersion.Default ? oLowVersion.Default : oHighYour.Default); Chris@76: setInnerHTML(document.getElementById('currentDefault'), oHighCurrent.Default); Chris@76: if (oLowVersion.Default) Chris@76: document.getElementById('yourDefault').style.color = 'red'; Chris@76: Chris@76: if (document.getElementById('Templates')) Chris@76: { Chris@76: setInnerHTML(document.getElementById('yourTemplates'), oLowVersion.Templates ? oLowVersion.Templates : oHighYour.Templates); Chris@76: setInnerHTML(document.getElementById('currentTemplates'), oHighCurrent.Templates); Chris@76: Chris@76: if (oLowVersion.Templates) Chris@76: document.getElementById('yourTemplates').style.color = 'red'; Chris@76: } Chris@76: Chris@76: setInnerHTML(document.getElementById('yourLanguages'), oLowVersion.Languages ? oLowVersion.Languages : oHighYour.Languages); Chris@76: setInnerHTML(document.getElementById('currentLanguages'), oHighCurrent.Languages); Chris@76: if (oLowVersion.Languages) Chris@76: document.getElementById('yourLanguages').style.color = 'red'; Chris@76: }