Chris@76
|
1 /*
|
Chris@76
|
2 smf_AdminIndex(oOptions)
|
Chris@76
|
3 {
|
Chris@76
|
4 public init()
|
Chris@76
|
5 public loadAdminIndex()
|
Chris@76
|
6 public setAnnouncements()
|
Chris@76
|
7 public showCurrentVersion()
|
Chris@76
|
8 public checkUpdateAvailable()
|
Chris@76
|
9 }
|
Chris@76
|
10
|
Chris@76
|
11 smf_ViewVersions(oOptions)
|
Chris@76
|
12 {
|
Chris@76
|
13 public init()
|
Chris@76
|
14 public loadViewVersions
|
Chris@76
|
15 public swapOption(oSendingElement, sName)
|
Chris@76
|
16 public compareVersions(sCurrent, sTarget)
|
Chris@76
|
17 public determineVersions()
|
Chris@76
|
18 }
|
Chris@76
|
19 */
|
Chris@76
|
20
|
Chris@76
|
21
|
Chris@76
|
22
|
Chris@76
|
23 // Handle the JavaScript surrounding the admin and moderation center.
|
Chris@76
|
24 function smf_AdminIndex(oOptions)
|
Chris@76
|
25 {
|
Chris@76
|
26 this.opt = oOptions;
|
Chris@76
|
27 this.init();
|
Chris@76
|
28 }
|
Chris@76
|
29
|
Chris@76
|
30 smf_AdminIndex.prototype.init = function ()
|
Chris@76
|
31 {
|
Chris@76
|
32 window.adminIndexInstanceRef = this;
|
Chris@76
|
33 var fHandlePageLoaded = function () {
|
Chris@76
|
34 window.adminIndexInstanceRef.loadAdminIndex();
|
Chris@76
|
35 }
|
Chris@76
|
36 addLoadEvent(fHandlePageLoaded);
|
Chris@76
|
37 }
|
Chris@76
|
38
|
Chris@76
|
39 smf_AdminIndex.prototype.loadAdminIndex = function ()
|
Chris@76
|
40 {
|
Chris@76
|
41 // Load the text box containing the latest news items.
|
Chris@76
|
42 if (this.opt.bLoadAnnouncements)
|
Chris@76
|
43 this.setAnnouncements();
|
Chris@76
|
44
|
Chris@76
|
45 // Load the current SMF and your SMF version numbers.
|
Chris@76
|
46 if (this.opt.bLoadVersions)
|
Chris@76
|
47 this.showCurrentVersion();
|
Chris@76
|
48
|
Chris@76
|
49 // Load the text box that sais there's a new version available.
|
Chris@76
|
50 if (this.opt.bLoadUpdateNotification)
|
Chris@76
|
51 this.checkUpdateAvailable();
|
Chris@76
|
52 }
|
Chris@76
|
53
|
Chris@76
|
54
|
Chris@76
|
55 smf_AdminIndex.prototype.setAnnouncements = function ()
|
Chris@76
|
56 {
|
Chris@76
|
57 if (!('smfAnnouncements' in window) || !('length' in window.smfAnnouncements))
|
Chris@76
|
58 return;
|
Chris@76
|
59
|
Chris@76
|
60 var sMessages = '';
|
Chris@76
|
61 for (var i = 0; i < window.smfAnnouncements.length; i++)
|
Chris@76
|
62 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
|
63
|
Chris@76
|
64 setInnerHTML(document.getElementById(this.opt.sAnnouncementContainerId), this.opt.sAnnouncementTemplate.replace('%content%', sMessages));
|
Chris@76
|
65 }
|
Chris@76
|
66
|
Chris@76
|
67 smf_AdminIndex.prototype.showCurrentVersion = function ()
|
Chris@76
|
68 {
|
Chris@76
|
69 if (!('smfVersion' in window))
|
Chris@76
|
70 return;
|
Chris@76
|
71
|
Chris@76
|
72 var oSmfVersionContainer = document.getElementById(this.opt.sSmfVersionContainerId);
|
Chris@76
|
73 var oYourVersionContainer = document.getElementById(this.opt.sYourVersionContainerId);
|
Chris@76
|
74
|
Chris@76
|
75 setInnerHTML(oSmfVersionContainer, window.smfVersion);
|
Chris@76
|
76
|
Chris@76
|
77 var sCurrentVersion = getInnerHTML(oYourVersionContainer);
|
Chris@76
|
78 if (sCurrentVersion != window.smfVersion)
|
Chris@76
|
79 setInnerHTML(oYourVersionContainer, this.opt.sVersionOutdatedTemplate.replace('%currentVersion%', sCurrentVersion));
|
Chris@76
|
80 }
|
Chris@76
|
81
|
Chris@76
|
82 smf_AdminIndex.prototype.checkUpdateAvailable = function ()
|
Chris@76
|
83 {
|
Chris@76
|
84 if (!('smfUpdatePackage' in window))
|
Chris@76
|
85 return;
|
Chris@76
|
86
|
Chris@76
|
87 var oContainer = document.getElementById(this.opt.sUpdateNotificationContainerId);
|
Chris@76
|
88
|
Chris@76
|
89 // Are we setting a custom title and message?
|
Chris@76
|
90 var sTitle = 'smfUpdateTitle' in window ? window.smfUpdateTitle : this.opt.sUpdateNotificationDefaultTitle;
|
Chris@76
|
91 var sMessage = 'smfUpdateNotice' in window ? window.smfUpdateNotice : this.opt.sUpdateNotificationDefaultMessage;
|
Chris@76
|
92
|
Chris@76
|
93 setInnerHTML(oContainer, this.opt.sUpdateNotificationTemplate.replace('%title%', sTitle).replace('%message%', sMessage));
|
Chris@76
|
94
|
Chris@76
|
95 // Parse in the package download URL if it exists in the string.
|
Chris@76
|
96 document.getElementById('update-link').href = this.opt.sUpdateNotificationLink.replace('%package%', window.smfUpdatePackage);
|
Chris@76
|
97
|
Chris@76
|
98 // If we decide to override life into "red" mode, do it.
|
Chris@76
|
99 if ('smfUpdateCritical' in window)
|
Chris@76
|
100 {
|
Chris@76
|
101 document.getElementById('update_table').style.backgroundColor = '#aa2222';
|
Chris@76
|
102 document.getElementById('update_title').style.backgroundColor = '#dd2222';
|
Chris@76
|
103 document.getElementById('update_title').style.color = 'white';
|
Chris@76
|
104 document.getElementById('update_message').style.backgroundColor = '#eebbbb';
|
Chris@76
|
105 document.getElementById('update_message').style.color = 'black';
|
Chris@76
|
106 }
|
Chris@76
|
107 }
|
Chris@76
|
108
|
Chris@76
|
109
|
Chris@76
|
110
|
Chris@76
|
111 function smf_ViewVersions (oOptions)
|
Chris@76
|
112 {
|
Chris@76
|
113 this.opt = oOptions;
|
Chris@76
|
114 this.oSwaps = {};
|
Chris@76
|
115 this.init();
|
Chris@76
|
116 }
|
Chris@76
|
117
|
Chris@76
|
118 smf_ViewVersions.prototype.init = function ()
|
Chris@76
|
119 {
|
Chris@76
|
120 // Load this on loading of the page.
|
Chris@76
|
121 window.viewVersionsInstanceRef = this;
|
Chris@76
|
122 var fHandlePageLoaded = function () {
|
Chris@76
|
123 window.viewVersionsInstanceRef.loadViewVersions();
|
Chris@76
|
124 }
|
Chris@76
|
125 addLoadEvent(fHandlePageLoaded);
|
Chris@76
|
126 }
|
Chris@76
|
127
|
Chris@76
|
128 smf_ViewVersions.prototype.loadViewVersions = function ()
|
Chris@76
|
129 {
|
Chris@76
|
130 this.determineVersions();
|
Chris@76
|
131 }
|
Chris@76
|
132
|
Chris@76
|
133 smf_ViewVersions.prototype.swapOption = function (oSendingElement, sName)
|
Chris@76
|
134 {
|
Chris@76
|
135 // If it is undefined, or currently off, turn it on - otherwise off.
|
Chris@76
|
136 this.oSwaps[sName] = !(sName in this.oSwaps) || !this.oSwaps[sName];
|
Chris@76
|
137 document.getElementById(sName).style.display = this.oSwaps[sName] ? '' : 'none';
|
Chris@76
|
138
|
Chris@76
|
139 // Unselect the link and return false.
|
Chris@76
|
140 oSendingElement.blur();
|
Chris@76
|
141 return false;
|
Chris@76
|
142 }
|
Chris@76
|
143
|
Chris@76
|
144 smf_ViewVersions.prototype.compareVersions = function (sCurrent, sTarget)
|
Chris@76
|
145 {
|
Chris@76
|
146 var aVersions = aParts = new Array();
|
Chris@76
|
147 var aCompare = new Array(sCurrent, sTarget);
|
Chris@76
|
148
|
Chris@76
|
149 for (var i = 0; i < 2; i++)
|
Chris@76
|
150 {
|
Chris@76
|
151 // Clean the version and extract the version parts.
|
Chris@76
|
152 var sClean = aCompare[i].toLowerCase().replace(/ /g, '').replace(/2.0rc1-1/, '2.0rc1.1');
|
Chris@76
|
153 aParts = sClean.match(/(\d+)(?:\.(\d+|))?(?:\.)?(\d+|)(?:(alpha|beta|rc)(\d+|)(?:\.)?(\d+|))?(?:(dev))?(\d+|)/);
|
Chris@76
|
154
|
Chris@76
|
155 // No matches?
|
Chris@76
|
156 if (aParts == null)
|
Chris@76
|
157 return false;
|
Chris@76
|
158
|
Chris@76
|
159 // Build an array of parts.
|
Chris@76
|
160 aVersions[i] = [
|
Chris@76
|
161 aParts[1] > 0 ? parseInt(aParts[1]) : 0,
|
Chris@76
|
162 aParts[2] > 0 ? parseInt(aParts[2]) : 0,
|
Chris@76
|
163 aParts[3] > 0 ? parseInt(aParts[3]) : 0,
|
Chris@76
|
164 typeof(aParts[4]) == 'undefined' ? 'stable' : aParts[4],
|
Chris@76
|
165 aParts[5] > 0 ? parseInt(aParts[5]) : 0,
|
Chris@76
|
166 aParts[6] > 0 ? parseInt(aParts[6]) : 0,
|
Chris@76
|
167 typeof(aParts[7]) != 'undefined',
|
Chris@76
|
168 ];
|
Chris@76
|
169 }
|
Chris@76
|
170
|
Chris@76
|
171 // Loop through each category.
|
Chris@76
|
172 for (i = 0; i < 7; i++)
|
Chris@76
|
173 {
|
Chris@76
|
174 // Is there something for us to calculate?
|
Chris@76
|
175 if (aVersions[0][i] != aVersions[1][i])
|
Chris@76
|
176 {
|
Chris@76
|
177 // Dev builds are a problematic exception.
|
Chris@76
|
178 // (stable) dev < (stable) but (unstable) dev = (unstable)
|
Chris@76
|
179 if (i == 3)
|
Chris@76
|
180 return aVersions[0][i] < aVersions[1][i] ? !aVersions[1][6] : aVersions[0][6];
|
Chris@76
|
181 else if (i == 6)
|
Chris@76
|
182 return aVersions[0][6] ? aVersions[1][3] == 'stable' : false;
|
Chris@76
|
183 // Otherwise a simple comparison.
|
Chris@76
|
184 else
|
Chris@76
|
185 return aVersions[0][i] < aVersions[1][i];
|
Chris@76
|
186 }
|
Chris@76
|
187 }
|
Chris@76
|
188
|
Chris@76
|
189 // They are the same!
|
Chris@76
|
190 return false;
|
Chris@76
|
191 }
|
Chris@76
|
192
|
Chris@76
|
193 smf_ViewVersions.prototype.determineVersions = function ()
|
Chris@76
|
194 {
|
Chris@76
|
195 var oHighYour = {
|
Chris@76
|
196 Sources: '??',
|
Chris@76
|
197 Default: '??',
|
Chris@76
|
198 Languages: '??',
|
Chris@76
|
199 Templates: '??'
|
Chris@76
|
200 };
|
Chris@76
|
201 var oHighCurrent = {
|
Chris@76
|
202 Sources: '??',
|
Chris@76
|
203 Default: '??',
|
Chris@76
|
204 Languages: '??',
|
Chris@76
|
205 Templates: '??'
|
Chris@76
|
206 };
|
Chris@76
|
207 var oLowVersion = {
|
Chris@76
|
208 Sources: false,
|
Chris@76
|
209 Default: false,
|
Chris@76
|
210 Languages: false,
|
Chris@76
|
211 Templates: false
|
Chris@76
|
212 };
|
Chris@76
|
213
|
Chris@76
|
214 var sSections = [
|
Chris@76
|
215 'Sources',
|
Chris@76
|
216 'Default',
|
Chris@76
|
217 'Languages',
|
Chris@76
|
218 'Templates'
|
Chris@76
|
219 ];
|
Chris@76
|
220
|
Chris@76
|
221 for (var i = 0, n = sSections.length; i < n; i++)
|
Chris@76
|
222 {
|
Chris@76
|
223 // Collapse all sections.
|
Chris@76
|
224 var oSection = document.getElementById(sSections[i]);
|
Chris@76
|
225 if (typeof(oSection) == 'object' && oSection != null)
|
Chris@76
|
226 oSection.style.display = 'none';
|
Chris@76
|
227
|
Chris@76
|
228 // Make all section links clickable.
|
Chris@76
|
229 var oSectionLink = document.getElementById(sSections[i] + '-link');
|
Chris@76
|
230 if (typeof(oSectionLink) == 'object' && oSectionLink != null)
|
Chris@76
|
231 {
|
Chris@76
|
232 oSectionLink.instanceRef = this;
|
Chris@76
|
233 oSectionLink.sSection = sSections[i];
|
Chris@76
|
234 oSectionLink.onclick = function () {
|
Chris@76
|
235 this.instanceRef.swapOption(this, this.sSection);
|
Chris@76
|
236 return false;
|
Chris@76
|
237 };
|
Chris@76
|
238 }
|
Chris@76
|
239 }
|
Chris@76
|
240
|
Chris@76
|
241 if (!('smfVersions' in window))
|
Chris@76
|
242 window.smfVersions = {};
|
Chris@76
|
243
|
Chris@76
|
244 for (var sFilename in window.smfVersions)
|
Chris@76
|
245 {
|
Chris@76
|
246 if (!document.getElementById('current' + sFilename))
|
Chris@76
|
247 continue;
|
Chris@76
|
248
|
Chris@76
|
249 var sYourVersion = getInnerHTML(document.getElementById('your' + sFilename));
|
Chris@76
|
250
|
Chris@76
|
251 var sCurVersionType;
|
Chris@76
|
252 for (var sVersionType in oLowVersion)
|
Chris@76
|
253 if (sFilename.substr(0, sVersionType.length) == sVersionType)
|
Chris@76
|
254 {
|
Chris@76
|
255 sCurVersionType = sVersionType;
|
Chris@76
|
256 break;
|
Chris@76
|
257 }
|
Chris@76
|
258
|
Chris@76
|
259 if (typeof(sCurVersionType) != 'undefined')
|
Chris@76
|
260 {
|
Chris@76
|
261 if ((this.compareVersions(oHighYour[sCurVersionType], sYourVersion) || oHighYour[sCurVersionType] == '??') && !oLowVersion[sCurVersionType])
|
Chris@76
|
262 oHighYour[sCurVersionType] = sYourVersion;
|
Chris@76
|
263 if (this.compareVersions(oHighCurrent[sCurVersionType], smfVersions[sFilename]) || oHighCurrent[sCurVersionType] == '??')
|
Chris@76
|
264 oHighCurrent[sCurVersionType] = smfVersions[sFilename];
|
Chris@76
|
265
|
Chris@76
|
266 if (this.compareVersions(sYourVersion, smfVersions[sFilename]))
|
Chris@76
|
267 {
|
Chris@76
|
268 oLowVersion[sCurVersionType] = sYourVersion;
|
Chris@76
|
269 document.getElementById('your' + sFilename).style.color = 'red';
|
Chris@76
|
270 }
|
Chris@76
|
271 }
|
Chris@76
|
272 else if (this.compareVersions(sYourVersion, smfVersions[sFilename]))
|
Chris@76
|
273 oLowVersion[sCurVersionType] = sYourVersion;
|
Chris@76
|
274
|
Chris@76
|
275 setInnerHTML(document.getElementById('current' + sFilename), smfVersions[sFilename]);
|
Chris@76
|
276 setInnerHTML(document.getElementById('your' + sFilename), sYourVersion);
|
Chris@76
|
277 }
|
Chris@76
|
278
|
Chris@76
|
279 if (!('smfLanguageVersions' in window))
|
Chris@76
|
280 window.smfLanguageVersions = {};
|
Chris@76
|
281
|
Chris@76
|
282 for (sFilename in window.smfLanguageVersions)
|
Chris@76
|
283 {
|
Chris@76
|
284 for (var i = 0; i < this.opt.aKnownLanguages.length; i++)
|
Chris@76
|
285 {
|
Chris@76
|
286 if (!document.getElementById('current' + sFilename + this.opt.aKnownLanguages[i]))
|
Chris@76
|
287 continue;
|
Chris@76
|
288
|
Chris@76
|
289 setInnerHTML(document.getElementById('current' + sFilename + this.opt.aKnownLanguages[i]), smfLanguageVersions[sFilename]);
|
Chris@76
|
290
|
Chris@76
|
291 sYourVersion = getInnerHTML(document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]));
|
Chris@76
|
292 setInnerHTML(document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]), sYourVersion);
|
Chris@76
|
293
|
Chris@76
|
294 if ((this.compareVersions(oHighYour.Languages, sYourVersion) || oHighYour.Languages == '??') && !oLowVersion.Languages)
|
Chris@76
|
295 oHighYour.Languages = sYourVersion;
|
Chris@76
|
296 if (this.compareVersions(oHighCurrent.Languages, smfLanguageVersions[sFilename]) || oHighCurrent.Languages == '??')
|
Chris@76
|
297 oHighCurrent.Languages = smfLanguageVersions[sFilename];
|
Chris@76
|
298
|
Chris@76
|
299 if (this.compareVersions(sYourVersion, smfLanguageVersions[sFilename]))
|
Chris@76
|
300 {
|
Chris@76
|
301 oLowVersion.Languages = sYourVersion;
|
Chris@76
|
302 document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]).style.color = 'red';
|
Chris@76
|
303 }
|
Chris@76
|
304 }
|
Chris@76
|
305 }
|
Chris@76
|
306
|
Chris@76
|
307 setInnerHTML(document.getElementById('yourSources'), oLowVersion.Sources ? oLowVersion.Sources : oHighYour.Sources);
|
Chris@76
|
308 setInnerHTML(document.getElementById('currentSources'), oHighCurrent.Sources);
|
Chris@76
|
309 if (oLowVersion.Sources)
|
Chris@76
|
310 document.getElementById('yourSources').style.color = 'red';
|
Chris@76
|
311
|
Chris@76
|
312 setInnerHTML(document.getElementById('yourDefault'), oLowVersion.Default ? oLowVersion.Default : oHighYour.Default);
|
Chris@76
|
313 setInnerHTML(document.getElementById('currentDefault'), oHighCurrent.Default);
|
Chris@76
|
314 if (oLowVersion.Default)
|
Chris@76
|
315 document.getElementById('yourDefault').style.color = 'red';
|
Chris@76
|
316
|
Chris@76
|
317 if (document.getElementById('Templates'))
|
Chris@76
|
318 {
|
Chris@76
|
319 setInnerHTML(document.getElementById('yourTemplates'), oLowVersion.Templates ? oLowVersion.Templates : oHighYour.Templates);
|
Chris@76
|
320 setInnerHTML(document.getElementById('currentTemplates'), oHighCurrent.Templates);
|
Chris@76
|
321
|
Chris@76
|
322 if (oLowVersion.Templates)
|
Chris@76
|
323 document.getElementById('yourTemplates').style.color = 'red';
|
Chris@76
|
324 }
|
Chris@76
|
325
|
Chris@76
|
326 setInnerHTML(document.getElementById('yourLanguages'), oLowVersion.Languages ? oLowVersion.Languages : oHighYour.Languages);
|
Chris@76
|
327 setInnerHTML(document.getElementById('currentLanguages'), oHighCurrent.Languages);
|
Chris@76
|
328 if (oLowVersion.Languages)
|
Chris@76
|
329 document.getElementById('yourLanguages').style.color = 'red';
|
Chris@76
|
330 } |