diff --git a/resources/report/js/events.js b/resources/report/js/events.js index 38ff3836..6cae4031 100644 --- a/resources/report/js/events.js +++ b/resources/report/js/events.js @@ -301,6 +301,17 @@ function switchSidebarTab(evt) { function showAboutDialog(evt) { document.getElementById('about').showModal(); } +function areSettingsValid() { + /* Validate inputs individually. */ + var inputs = document.getElementById('settingsDialog').getElementsByTagName('input'); + for (var i = 0; i < inputs.length; ++i) { + if (!inputs[i].checkValidity()) { + return false; + console.log(inputs[i]); + } + } + return true; +} function closeSettingsDialog(evt) { if (evt.target.classList.contains('accept')) { if (!areSettingsValid()) { @@ -541,6 +552,73 @@ function jumpToGeneralInfo(evt) { window.location.hash = ''; document.getElementById('main').scrollTop = 0; } +function onContentRefresh(evt) { + /* Send a query for updated load order and plugin header info. */ + showProgress(l10n.jed.translate('Refreshing data...').fetch()); + loot.query('getGameData').then(function(result){ + /* Parse the data sent from C++. */ + try { + /* We don't want the plugin info creating cards, so don't convert + to plugin objects. */ + var gameInfo = JSON.parse(result); + } catch (e) { + console.log(e); + console.log('getGameData response: ' + result); + } + + /* Now overwrite plugin data with the newly sent data. Also update + card and li vars as they were unset when the game was switched + from before. */ + var pluginNames = []; + gameInfo.plugins.forEach(function(plugin){ + var foundPlugin = false; + for (var i = 0; i < loot.game.plugins.length; ++i) { + if (loot.game.plugins[i].name == plugin.name) { + + loot.game.plugins[i].isActive = plugin.isActive; + loot.game.plugins[i].isEmpty = plugin.isEmpty; + loot.game.plugins[i].loadsBSA = plugin.loadsBSA; + loot.game.plugins[i].crc = plugin.crc; + loot.game.plugins[i].version = plugin.version; + + loot.game.plugins[i].modPriority = plugin.modPriority; + loot.game.plugins[i].isGlobalPriority = plugin.isGlobalPriority; + loot.game.plugins[i].messages = plugin.messages; + loot.game.plugins[i].tags = plugin.tags; + loot.game.plugins[i].isDirty = plugin.isDirty; + + foundPlugin = true; + break; + } + } + if (!foundPlugin) { + /* A new plugin. */ + loot.game.plugins.push(new Plugin(plugin)); + } + pluginNames.push(plugin.name); + }); + for (var i = 0; i < loot.game.plugins.length;) { + var foundPlugin = false; + for (var j = 0; j < pluginNames.length; ++j) { + if (loot.game.plugins[i].name == pluginNames[j]) { + foundPlugin = true; + break; + } + } + if (!foundPlugin) { + /* Remove plugin. */ + loot.game.plugins.splice(i, 1); + } else { + ++i; + } + } + + /* Reapply filters. */ + setFilteredUIData(); + + closeProgressDialog(); + }).catch(processCefError); +} function setupEventHandlers() { /*Set up handlers for filters.*/ document.getElementById('hideVersionNumbers').addEventListener('change', toggleDisplayCSS, false); diff --git a/resources/report/js/helpers.js b/resources/report/js/helpers.js new file mode 100644 index 00000000..fd419402 --- /dev/null +++ b/resources/report/js/helpers.js @@ -0,0 +1,81 @@ +function processCefError(err) { + /* Error.stack seems to be Chromium-specific. It gives a lot more useful + info than just the error message. Also, this can be used to catch any + promise errors, not just CEF errors. */ + console.log(err.stack); + closeProgressDialog(); + showMessageBox(l10n.jed.translate('Error').fetch(), err.message); +} + +function showElement(element) { + if (element != null) { + element.classList.toggle('hidden', false); + } +} +function hideElement(element) { + if (element != null) { + element.classList.toggle('hidden', true); + } +} +function toggleDisplayCSS(evt) { + var attr = 'data-hide-' + evt.target.getAttribute('data-class'); + if (evt.target.checked) { + document.getElementById('main').setAttribute(attr, true); + } else { + document.getElementById('main').removeAttribute(attr); + } +} +function toast(text) { + var toast = document.getElementById('toast'); + toast.text = text; + toast.show(); +} +function showMessageDialog(title, text, positiveText, closeCallback) { + var dialog = document.createElement('loot-message-dialog'); + dialog.setButtonText(positiveText, l10n.jed.translate('Cancel').fetch()); + dialog.showModal(title, text, closeCallback); + document.body.appendChild(dialog); +} +function showMessageBox(title, text) { + var dialog = document.createElement('loot-message-dialog'); + dialog.setButtonText(l10n.jed.translate('OK').fetch()); + dialog.showModal(title, text); + document.body.appendChild(dialog); +} + +function showProgress(message) { + var progressDialog = document.getElementById('progressDialog'); + if (message) { + progressDialog.getElementsByTagName('p')[0].textContent = message; + } + if (!progressDialog.opened) { + progressDialog.showModal(); + } +} +function closeProgressDialog() { + var progressDialog = document.getElementById('progressDialog'); + if (progressDialog.opened) { + progressDialog.close(); + } +} +function handleUnappliedChangesClose(change) { + showMessageDialog('', l10n.jed.translate('You have not yet applied or cancelled your %s. Are you sure you want to quit?').fetch(change), l10n.jed.translate('Quit').fetch(), function(result){ + if (result) { + /* Cancel any sorting and close any editors. Cheat by sending a + cancelSort query for as many times as necessary. */ + var queries = []; + var numQueries = 0; + if (!document.getElementById('applySortButton').classList.contains('hidden')) { + numQueries += 1; + } + numQueries += document.body.getAttribute('data-editors'); + for (var i = 0; i < numQueries; ++i) { + queries.push(loot.query('cancelSort')); + } + Promise.all(queries).then(function(){ + window.close(); + }).catch(processCefError); + } + }); +} + diff --git a/resources/report/js/script.js b/resources/report/js/init.js similarity index 57% rename from resources/report/js/script.js rename to resources/report/js/init.js index c687991a..3047bb65 100644 --- a/resources/report/js/script.js +++ b/resources/report/js/init.js @@ -25,99 +25,6 @@ var marked; var l10n; -function processCefError(err) { - /* Error.stack seems to be Chromium-specific. It gives a lot more useful - info than just the error message. Also, this can be used to catch any - promise errors, not just CEF errors. */ - console.log(err.stack); - closeProgressDialog(); - showMessageBox(l10n.jed.translate('Error').fetch(), err.message); -} - -function showElement(element) { - if (element != null) { - element.classList.toggle('hidden', false); - } -} -function hideElement(element) { - if (element != null) { - element.classList.toggle('hidden', true); - } -} -function toggleDisplayCSS(evt) { - var attr = 'data-hide-' + evt.target.getAttribute('data-class'); - if (evt.target.checked) { - document.getElementById('main').setAttribute(attr, true); - } else { - document.getElementById('main').removeAttribute(attr); - } -} -function toast(text) { - var toast = document.getElementById('toast'); - toast.text = text; - toast.show(); -} -function showMessageDialog(title, text, positiveText, closeCallback) { - var dialog = document.createElement('loot-message-dialog'); - dialog.setButtonText(positiveText, l10n.jed.translate('Cancel').fetch()); - dialog.showModal(title, text, closeCallback); - document.body.appendChild(dialog); -} -function showMessageBox(title, text) { - var dialog = document.createElement('loot-message-dialog'); - dialog.setButtonText(l10n.jed.translate('OK').fetch()); - dialog.showModal(title, text); - document.body.appendChild(dialog); -} - -function showProgress(message) { - var progressDialog = document.getElementById('progressDialog'); - if (message) { - progressDialog.getElementsByTagName('p')[0].textContent = message; - } - if (!progressDialog.opened) { - progressDialog.showModal(); - } -} -function closeProgressDialog() { - var progressDialog = document.getElementById('progressDialog'); - if (progressDialog.opened) { - progressDialog.close(); - } -} -function areSettingsValid() { - /* Validate inputs individually. */ - var inputs = document.getElementById('settingsDialog').getElementsByTagName('input'); - for (var i = 0; i < inputs.length; ++i) { - if (!inputs[i].checkValidity()) { - return false; - console.log(inputs[i]); - } - } - return true; -} - -function handleUnappliedChangesClose(change) { - showMessageDialog('', l10n.jed.translate('You have not yet applied or cancelled your %s. Are you sure you want to quit?').fetch(change), l10n.jed.translate('Quit').fetch(), function(result){ - if (result) { - /* Cancel any sorting and close any editors. Cheat by sending a - cancelSort query for as many times as necessary. */ - var queries = []; - var numQueries = 0; - if (!document.getElementById('applySortButton').classList.contains('hidden')) { - numQueries += 1; - } - numQueries += document.body.getAttribute('data-editors'); - for (var i = 0; i < numQueries; ++i) { - queries.push(loot.query('cancelSort')); - } - Promise.all(queries).then(function(){ - window.close(); - }).catch(processCefError); - } - }); -} - function initVars() { loot.query('getVersion').then(function(result){ try { @@ -267,79 +174,12 @@ function initVars() { }).catch(processCefError); }).catch(processCefError); } -function onContentRefresh(evt) { - /* Send a query for updated load order and plugin header info. */ - showProgress(l10n.jed.translate('Refreshing data...').fetch()); - loot.query('getGameData').then(function(result){ - /* Parse the data sent from C++. */ - try { - /* We don't want the plugin info creating cards, so don't convert - to plugin objects. */ - var gameInfo = JSON.parse(result); - } catch (e) { - console.log(e); - console.log('getGameData response: ' + result); - } - - /* Now overwrite plugin data with the newly sent data. Also update - card and li vars as they were unset when the game was switched - from before. */ - var pluginNames = []; - gameInfo.plugins.forEach(function(plugin){ - var foundPlugin = false; - for (var i = 0; i < loot.game.plugins.length; ++i) { - if (loot.game.plugins[i].name == plugin.name) { - - loot.game.plugins[i].isActive = plugin.isActive; - loot.game.plugins[i].isEmpty = plugin.isEmpty; - loot.game.plugins[i].loadsBSA = plugin.loadsBSA; - loot.game.plugins[i].crc = plugin.crc; - loot.game.plugins[i].version = plugin.version; - - loot.game.plugins[i].modPriority = plugin.modPriority; - loot.game.plugins[i].isGlobalPriority = plugin.isGlobalPriority; - loot.game.plugins[i].messages = plugin.messages; - loot.game.plugins[i].tags = plugin.tags; - loot.game.plugins[i].isDirty = plugin.isDirty; - - foundPlugin = true; - break; - } - } - if (!foundPlugin) { - /* A new plugin. */ - loot.game.plugins.push(new Plugin(plugin)); - } - pluginNames.push(plugin.name); - }); - for (var i = 0; i < loot.game.plugins.length;) { - var foundPlugin = false; - for (var j = 0; j < pluginNames.length; ++j) { - if (loot.game.plugins[i].name == pluginNames[j]) { - foundPlugin = true; - break; - } - } - if (!foundPlugin) { - /* Remove plugin. */ - loot.game.plugins.splice(i, 1); - } else { - ++i; - } - } - - /* Reapply filters. */ - setFilteredUIData(); - - closeProgressDialog(); - }).catch(processCefError); -} window.addEventListener('polymer-ready', function(e) { /* Set the plugin list's scroll target to its parent. */ document.getElementById('main').lastElementChild.scrollTarget = document.getElementById('main'); - require(['bower_components/marked/lib/marked', 'js/l10n', 'js/plugin', 'js/loot', 'js/filters', 'js/events.js'], function(markedResponse, l10nResponse) { + require(['bower_components/marked/lib/marked', 'js/l10n', 'js/plugin', 'js/helpers', 'js/loot', 'js/filters', 'js/events'], function(markedResponse, l10nResponse) { /* Register object observers. */ Object.observe(loot, loot.observer); diff --git a/resources/report/report.html b/resources/report/report.html index 49b11d99..a05ff08e 100644 --- a/resources/report/report.html +++ b/resources/report/report.html @@ -298,5 +298,5 @@
LOOT is free, but if you want to show your appreciation with some money, donations may be made to WrinklyNinja (LOOT's creator and main developer) using PayPal, Bitcoin or Flattr.