From 53766116c95b2db8edf762b33ba659bb6792540a Mon Sep 17 00:00:00 2001 From: rlx Date: Wed, 13 Jan 2016 09:30:50 +0530 Subject: [PATCH] add update dialog --- static/js/updateDialog.js | 156 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 static/js/updateDialog.js diff --git a/static/js/updateDialog.js b/static/js/updateDialog.js new file mode 100644 index 0000000..c998b5e --- /dev/null +++ b/static/js/updateDialog.js @@ -0,0 +1,156 @@ +'use strict'; + +oml.ui.updateDialog = function() { + + var $content = Ox.Element(), + + $logo = $('') + .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}.

', + [oml.version] + ) + : Ox._( + '

You are running the development version of ' + + 'Open Media Library.

' + ) + ) + .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 ./ctl update.' + )); + $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; + +}; \ No newline at end of file