6 $(document).
ready(
function() {
8 var updateBtn = $(
"#checkForUpdatesBtn");
9 var readFilebaseNode = $(
"#readFilebaseNode");
10 let installedVersion = $(
'#installedVersion').text();
11 var currentVersion =
'';
12 var updateVersion =
'';
13 var statusBarNode = $(
"#statusBarNode");
14 var extendedInfoNode = $(
"#extendedInfoNode");
15 var statusBarMessage =
'';
18 let lang = $(
'#checkForUpdatesBtn');
19 let updateCheck = lang.attr(
'data-UPDATE_CHECK');
21 function fastForwardVersionNumber(fastForwardBtn) {
24 $(fastForwardBtn).click(
function ()
26 var updateVersion = $(
"#updateVersion").text();
27 console.log(
'Fast forward button clicked');
30 url:
'js/update-fastForward.php',
32 data: {fastForward:
true, updateVersion: updateVersion },
33 success:
function (data) {
34 console.log(
'Fast forward to latest version successful');
36 $(fastForwardBtn).removeClass().addClass(
'btn btn-success disabled animated fadeIn slow').html(
"<i class=\"fa fa-refresh fa-spin\"></i> fast-forwarding...");
39 setTimeout(
function () {
43 error:
function (data) {
44 console.log(
'Fast forward to latest version failed');
53 $(updateBtn).click(
function() {
55 $(updateBtn).html(
"<i class=\"fa fa-refresh fa-spin\"></i> " + updateCheck);
58 checkVersion(
function(
error, updateVersion) {
60 let lang = $(
'#checkForUpdatesBtn');
61 let updateAvailable = lang.attr(
'data-UPDATE_AVAILABLE');
62 let updateAvailableSubtext = lang.attr(
'data-UPDATE_AVAILABLE_SUBTEXT');
63 let updateNotAvailable = lang.attr(
'data-UPDATE_NOT_AVAILABLE');
64 let updateNotAvailableSubtext = lang.attr(
'data-UPDATE_NOT_AVAILABLE_SUBTEXT');
65 let updateInstall = lang.attr(
'data-UPDATE_INSTALL');
66 let updateUpToDate = lang.attr(
'data-UPDATE_UP_TO_DATE');
67 let updateCurrentInstalledVersion = lang.attr(
'data-UPDATE_CURRENT_INSTALLED_VERSION');
68 let updateNoUpdate = lang.attr(
'data-UPDATE_NO_UPDATE');
69 let verifyFiles = lang.attr(
'data-UPDATE_VERIFY_FILES');
70 let verifyingFiles = lang.attr(
'data-UPDATE_VERIFYING_FILES');
71 let latestAvailableVersion = lang.attr(
'data-UPDATE_LATEST_AVAILABLE_VERSION');
72 let updateChanges = lang.attr(
'data-UPDATE_CHANGES');
73 let released = lang.attr(
'data-RELEASED');
74 let githubReference = lang.attr(
'data-GITHUB_REFERENCE');
75 let githubMilestoneText = lang.attr(
'data-GITHUB_MILESTONE');
82 if (compareVersions(installedVersion, updateVersion) < 0)
85 getUpdateConfig(
function(
error, data) {
90 { console.log(
'Update config:', data);
93 if (data.updateConfig && data.updateConfig.UPDATE
94 && data.updateConfig.UPDATE.buildMessage
95 && data.updateConfig.UPDATE.buildTime
96 && data.updateConfig.UPDATE.updateVersion
97 && data.updateConfig.UPDATE.updateFilebase)
100 let buildMessage = data.updateConfig.UPDATE.buildMessage;
101 let buildTime = data.updateConfig.UPDATE.buildTime;
102 let updateVersion = data.updateConfig.UPDATE.updateVersion;
105 if (data.updateConfig.UPDATE.githubIssues){
106 var githubIssues = data.updateConfig.UPDATE.githubIssues;
108 else { githubIssues = false; }
110 if (data.updateConfig.UPDATE.githubMilestone){
111 var githubMilestone = data.updateConfig.UPDATE.githubMilestone;
113 else { githubMilestone = false; }
123 const regex = /#(
\d+)/
g;
125 const issueNumbers = [];
128 while ((match = regex.exec(githubIssues)) !==
null) {
129 issueNumbers.push(match[1]);
132 const repoUrl =
'https://github.com/YaWK/yawk.io/issues/';
133 var issuesWithLinks = githubIssues.replace(regex, (match, issueNumber) => {
134 return `<
a href=
"${repoUrl}${issueNumber}" target=
"_blank">${match}</
a>`;
140 var githubRelatedIssues =
'<li>'+githubReference+
': <b>'+issuesWithLinks+
'</b></li>';
144 githubRelatedIssues =
'';
148 if (githubMilestone){
150 const regex = /#(
\d+)/
g;
152 const milestoneNumbers = [];
155 while ((match = regex.exec(githubMilestone)) !==
null) {
156 milestoneNumbers.push(match[1]);
160 const repoUrl =
'https://github.com/YaWK/yawk.io/milestone/';
161 var milestoneWithLinks = githubMilestone.replace(regex, (match, milestoneNumber) => {
162 return `<
a href=
"${repoUrl}${milestoneNumber}" target=
"_blank">${match}</
a>`;
166 var githubRelatedMilestone =
'<li>'+githubMilestoneText+
': <b>'+milestoneWithLinks+
'</b></li>';
170 githubRelatedMilestone =
'';
174 statusBarMessage = updateAvailable;
175 successMsg =
'<h3 class="text-primary animated fadeIn"><b><i class="fa fa-globe animated bounce slow"></i></b> ' + updateAvailable +
'<br><small>'+updateAvailableSubtext+
'</small></h3>';
176 statusBarNode.html(successMsg).fadeIn(1000);
178 let extendedInfo =
'<ul class="animated fadeIn slow delay-1s"><li><span class="text-primary"><b>' + latestAvailableVersion +
'</b> build <b>' +
'<span id="updateVersion">'+updateVersion+
'</span></b></span></li><li>' + updateCurrentInstalledVersion +
' build <b class="text-muted">' +
'<span id="currentVersion">'+installedVersion +
'</span></b></li>' +
'<li>'+updateChanges+
': <b>'+ buildMessage +
'</b></li>'+githubRelatedIssues+githubRelatedMilestone+
'<li>'+released+
': ' + buildTime +
'</li></ul>';
179 extendedInfoNode.html(extendedInfo).fadeIn(1000);
180 console.log(statusBarMessage);
185 $(
"#checkForUpdatesBtn").
remove();
188 var newBtn = $(
'<a>', {
189 'href':
'#startUpdateBtn',
190 'id':
'getFilebaseBtn',
191 'class':
'btn btn-primary pull-right animated fadeIn slow',
192 'html':
'<i class="fa fa-search"></i> ' + verifyFiles
195 $(
'#updateBtnNode').append(newBtn);
199 var getFilebaseBtn = $(
"#getFilebaseBtn");
200 $(getFilebaseBtn).click(
function() {
201 console.log(
'install update button clicked, read local filebase and store to ini file');
202 getFilebaseBtn.removeClass().addClass(
'btn btn-primary pull-right disabled').html(
"<i class=\"fa fa-refresh fa-spin\"></i> " + verifyingFiles);
205 Promise.all([generateLocalFileBase(updateInstall)])
206 .then(([localFilebase]) => {
208 readUpdateFileBase();
217 console.error(
'updateConfig, UPDATE, or properties not found in xhr data');
224 statusBarMessage = updateNotAvailable +
' (' + installedVersion +
') ' + updateNotAvailableSubtext;
225 errorMsg =
'<h3 class="text-success animated fadeIn slow"><i class="fa fa-check-circle-o"></i> ' + statusBarMessage +
'</h3>';
226 statusBarNode.html(
errorMsg).fadeIn(1000);
227 $(updateBtn).removeClass().addClass(
'btn btn-default pull-right disabled animated fadeIn slow').html(
"<i class=\"fa fa-check-circle-o\"></i> " + updateNoUpdate);
228 console.log(statusBarMessage);
240 function generateLocalFileBase(updateInstall) {
241 var updateBtnText = updateInstall;
242 return new Promise((resolve, reject) => {
245 url:
'js/update-generateLocalFilebase.php',
246 success:
function (response) {
248 $(readFilebaseNode).html(response).fadeIn(1000);
252 var newBtn = $(
'<a>', {
253 'href':
'#startUpdateBtn',
254 'id':
'startUpdateBtn',
255 'class':
'btn btn-success pull-right animated flipInX',
256 'html':
'<i class="fa fa-download"></i> ' + updateBtnText
260 $(
"#getFilebaseBtn").
remove();
261 $(
'#updateBtnNode').append(newBtn);
264 var startUpdateBtn = $(
"#startUpdateBtn");
265 $(startUpdateBtn).click(
function() {
266 console.log(
'start update button clicked, start update process');
273 error:
function (response) {
274 reject(
'generateLocalFileBase() ERROR: ' + response);
279 var delay = (
function() {
281 return function(callback, ms) {
282 clearTimeout (timer);
283 timer = setTimeout(callback, ms);
291 function runMigrations(){
292 console.log(
'called runMigrations()');
293 var runMigrationsNode = $(
"#runMigrationsNode");
294 var currentVersion = $(
"#currentVersion").text();
295 var updateVersion = $(
"#updateVersion").text();
299 url:
'js/update-runMigrations.php',
301 updateVersion: updateVersion,
302 currentVersion: currentVersion
304 success:
function (response)
306 $(runMigrationsNode).html(response).fadeIn(1000);
307 console.log(
"runMigrations() response: ", response);
310 error:
function (response)
312 $(runMigrationsNode).html(response).fadeIn(1000);
313 console.error(
'runMigrations() ERROR: ', response);
326 function fetchFiles()
327 { var fetchUpdateNode = $(
"#fetchUpdateNode");
328 var currentVersion = $(
"#currentVersion").text();
329 var updateVersion = $(
"#updateVersion").text();
333 url:
'js/update-fetchFiles.php',
335 updateVersion: updateVersion,
336 currentVersion: currentVersion
338 success:
function (response) {
340 console.log(
"fetchUpdate() response: " + response);
341 $(fetchUpdateNode).append(response).fadeIn(1000);
343 var fastForwardBtn = $(
"#fastForwardUpdateBtn");
345 fastForwardVersionNumber(fastForwardBtn);
348 error:
function (response) {
349 console.log(
'fetchUpdate() ERROR: ' +response);
358 function readUpdateFileBase(){
359 console.log(
'readUpdateFileBase() called');
363 url:
'js/update-readUpdateFilebase.php',
364 success:
function (response) {
367 $(readUpdateFilebaseNode).html(response).fadeIn(1000);
369 error:
function (response) {
370 console.log(
'readUpdateFileBase() ERROR: ' +response);
380 function checkVersion(callback) {
381 fetch(
'https://update.yawk.io/?action=version')
384 return response.json();
386 throw new Error(
'API error: ' + response.status);
390 if (data && data.yawkversion) {
391 callback(null, data.yawkversion);
393 callback(
'Error fetching version: ' + JSON.stringify(data));
397 callback(
'Error: ' +
error);
406 function getUpdateConfig(callback)
408 fetch(
'https://update.yawk.io/?action=getUpdateConfig')
411 return response.json();
413 throw new Error(
'API error: ' + response.status);
418 callback(
null, data);
420 callback(
'Error fetching data: ' + JSON.stringify(data));
424 callback(
'Error: ' +
error);
439 function compareVersions(v1, v2) {
440 const v1Parts = v1.split(
'.').map(Number);
441 const v2Parts = v2.split(
'.').map(Number);
442 const maxLength = Math.max(v1Parts.length, v2Parts.length);
444 for (let
i = 0;
i < maxLength;
i++) {
445 const v1Part = v1Parts[
i] || 0;
446 const v2Part = v2Parts[
i] || 0;
448 if (v1Part > v2Part) {
451 if (v1Part < v2Part) {
document ready(function() { $('a[data-confirm]').click(function(ev) { modal='#dataConfirmModal';var href=$(this).attr('href');var title=$(this).attr('title');var icon=$(this).attr('data-icon');if(!icon) { icon='fa fa-trash-o';} if(!$(modal).length) { $('body').append('< div id="dataConfirmModal" class="modal fade" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true">< div class="modal-dialog">< div class="modal-content">< div class="modal-header">< button type="button" class="close" data-dismiss="modal" aria-hidden="true">< i class="fa fa-times"></i ></button >< br >< div class="col-md-1">< h3 class="modal-title">< i class="'+icon+'"></i ></h3 ></div >< div class="col-md-11">< h3 class="modal-title" id="dataConfirmLabel">'+title+'</h3 ></div ></h3 ></div >< div class="modal-body"></div >< div class="modal-footer">< button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Abbrechen</button >< a type="button" class="btn btn-danger" id="dataConfirmOK">< i class="'+icon+'"></i > L öschen</a ></div ></div ></div ></div >');} $(modal).find('.modal-body').text($(this).attr('data-confirm'));$('#dataConfirmOK').attr('href', href);$(modal).modal({show:true});return false;});$('#terminateUser').click(function() { var terminate=window.confirm("ACHTUNG!\nDas wird Deinen Account permanent deaktivieren.\n"+"Bist Du Dir sicher, dass Du das tun willst?");if(terminate===true) { var terminateUser=window.confirm("Bist Du Dir wirklich ganz sicher?\n"+"Diese Aktion kann nicht rueckgaengig gemacht werden.");if(terminateUser===true) { $.get('system/templates/YaWK-bootstrap3/js/terminate-user.php', function(data) { if(data==="true") { setTimeout("window.location='logout.html'", 0);} else { alert("Fehler: "+data);} });} } });function dismissNotifications() { $.ajax({ url:'js/dismiss-notifications.php', type:'POST', success:function(data) { if(!data) { alert('Something went wrong!');return false;} } });$("#bell-label").fadeOut();$('#notification-header').html('You have 0 notifications');$('#notification-menu').fadeOut();} $("#dismiss").click(function() { dismissNotifications();});function disableButtons(delay) { $('#loginButton').removeClass().addClass('btn btn-success disabled').attr('id', 'LOGIN_FORBIDDEN');$('#resetPasswordButton').removeClass().addClass('btn btn-danger disabled');setTimeout(function() { $('#LOGIN_FORBIDDEN').attr('id', 'loginButton').removeClass().addClass('btn btn-success');$('#resetPasswordButton').removeClass().addClass('btn btn-danger');}, delay);} $("#loginButton").click(function(){ if($('#loginButton').length > 0) { if($('#loginButton').hasClass('btn') &&$('#loginButton').hasClass('btn-success') &&$('#loginButton').hasClass('disabled')) { } else { $("#loginForm").submit();disableButtons(10000);} } else if($('#LOGIN_FORBIDDEN').length > 0) { if($('#LOGIN_FORBIDDEN').hasClass('btn') &&$('#LOGIN_FORBIDDEN').hasClass('btn-success') &&$('#LOGIN_FORBIDDEN').hasClass('disabled')) { } else { } } });$("#blockedBtn").hover(function() { $("#blockedBtn").hide();$("#askBtn").fadeIn(820);});})