add update dialog

This commit is contained in:
rlx 2016-01-13 09:30:50 +05:30
parent 516397ae44
commit 53766116c9

156
static/js/updateDialog.js Normal file
View file

@ -0,0 +1,156 @@
'use strict';
oml.ui.updateDialog = function() {
var $content = Ox.Element(),
$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._(
'You are running Open Media Library version {0}.<br><br>',
[oml.version]
)
: Ox._(
'<p>You are running the development version of '
+ 'Open Media Library.</p>'
)
)
.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
});
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]
))
}
});
} else {
$text.append(Ox._(
'To update, run <span class="OxMonospace">./ctl update</span>.'
));
$closeButton.hide();
$dontUpdateButton.show();
$updateButton.show();
}
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;
};