openmedialibrary/static/js/updateDialog.js

166 lines
4.7 KiB
JavaScript
Raw Normal View History

2016-01-13 04:00:50 +00:00
'use strict';
oml.ui.updateDialog = function() {
2016-01-13 04:20:46 +00:00
var ui = oml.user.ui,
$content = Ox.Element(),
2016-01-13 04:00:50 +00:00
$logo = $('<img>')
.attr({
src: '/static/png/oml.png'
})
.css({
position: 'absolute',
left: '16px',
top: '16px',
width: '128px',
height: '128px'
})
.appendTo($content),
$text = Ox.Element()
.addClass('OxTextPage OxSelectable')
.css({
position: 'absolute',
right: '16px',
top: '16px',
width: '336px',
height: '128px',
})
.html(
oml.version != 'git'
? Ox._(
2016-01-13 05:31:15 +00:00
'You are running Open Media Library version {0}.<br><br>',
2016-01-13 04:00:50 +00:00
[oml.version]
)
: Ox._(
'You are running the development version of '
+ 'Open Media Library.<br><br>'
2016-01-13 04:00:50 +00:00
)
)
.appendTo($content),
$error = Ox.Element()
.addClass('OxTextPage OxSelectable')
.css({
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
width: '480px',
height: '16px',
margin: 'auto',
textAlign: 'center'
})
.html('Download failed.'),
$dontUpdateButton = Ox.Button({
style: 'squared',
title: Ox._('No, Don\'t Update')
})
.hide()
.bindEvent({
click: function() {
that.close();
}
}),
$updateButton = Ox.Button({
style: 'squared',
title: Ox._('Yes, Update')
})
.hide()
.bindEvent({
click: function() {
$dontUpdateButton.hide();
that.disableCloseButton();
that.disableButtons();
that.options({
content: Ox.LoadingScreen().start()
});
oml.isRelaunching = true;
oml.api.restart({update: true}, function(result) {
if (result.status.code == 200) {
setTimeout(reload, 500);
} else {
that.options({content: $error});
$updateButton.hide();
$closeButton.show();
that.enableCloseButton();
that.enableButtons();
}
});
}
}),
$closeButton = Ox.Button({
style: 'squared',
title: Ox._('Close')
})
.bindEvent({
click: function() {
that.close();
}
}),
that = Ox.Dialog({
buttons: [
$dontUpdateButton,
$updateButton,
$closeButton
],
closeButton: true,
content: $content,
height: 160,
removeOnClose: true,
title: 'Software Update',
width: 512
2016-01-13 06:45:39 +00:00
})
.bindEvent({
close: function() {
if (ui.page == 'update') {
oml.UI.set({page: ''});
}
}
2016-01-13 04:00:50 +00:00
});
if (oml.version != 'git') {
oml.api.getVersion(function(result) {
if (result.data.version == oml.version) {
$text.append(Ox._('You are up to date.'))
} else {
$text.append(Ox._(
'A newer version ({0}) is available.',
[result.data.version]
));
$closeButton.hide();
$dontUpdateButton.show();
$updateButton.show();
2016-01-13 04:00:50 +00:00
}
});
} else {
$text.append(Ox._(
'To update, run <span class="OxMonospace">./ctl update</span>.'
));
}
function reload() {
var ws = new WebSocket('ws:' + document.location.host + '/ws');
ws.onopen = function(event) {
document.location.href = document.location.protocol + '//'
+ document.location.host;
};
ws.onerror = function(event) {
ws.close();
};
ws.onclose = function(event) {
setTimeout(reload, 500);
};
}
return that;
2016-01-13 05:17:20 +00:00
};