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