From 8d640950783a674f653b85c09cea349d234ba0b1 Mon Sep 17 00:00:00 2001 From: "Mark Aherne (Faerdan)" Date: Wed, 8 Jan 2014 02:30:33 +0000 Subject: [PATCH] NanoUI Updates. * Restructured HTML in an attempt to fix the "blank UI" issue. * Added a crap ton of debugging messages. * Added a loading message to the UI. Conflicts: code/modules/nano/nanoui.dm nano/js/nano_update.js --- code/modules/nano/nanoui.dm | 24 ++++++++++------------ nano/js/nano_config.js | 13 ++++++++---- nano/js/nano_update.js | 40 ++++++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index 018e27d8272..e7cf5d3b201 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -93,12 +93,9 @@ nanoui is used to open and update nano browser uis * @return nothing */ /datum/nanoui/proc/add_common_assets() - //add_script("libraries.min.js") // The jQuery library - add_script("1-jquery.js") - add_script("2-jsviews.js") - add_script("3-jquery.timers.js") + add_script("libraries.min.js") // The jQuery library + add_script("nano_config.js") // The NanoConfig JS, this is used to store configuration values. add_script("nano_update.js") // The NanoUpdate JS, this is used to receive updates and apply them. - add_script("nano_config.js") // The NanoUpdate JS, this is used to receive updates and apply them. add_script("nano_base_helpers.js") // The NanoBaseHelpers JS, this is used to set up template helpers which are common to all templates add_stylesheet("shared.css") // this CSS sheet is common to all UIs add_stylesheet("icons.css") // this CSS sheet is common to all UIs @@ -263,8 +260,12 @@ nanoui is used to open and update nano browser uis */ /datum/nanoui/proc/get_header() var/head_content = "" + + for (var/filename in scripts) + head_content += " " + for (var/filename in stylesheets) - head_content += "" + head_content += " " var/templatel_data[0] for (var/key in templates) @@ -297,7 +298,7 @@ nanoui is used to open and update nano browser uis } else { - alert('receiveUpdateData error: something is not defined!'); + alert('receiveUpdateData ERROR: something is not defined!'); if (typeof NanoUpdate == 'undefined') { alert('NanoUpdate not defined!'); @@ -313,7 +314,7 @@ nanoui is used to open and update nano browser uis
[title ? "
[title]
" : ""]
- +
Initiating...
"} /** @@ -322,13 +323,8 @@ nanoui is used to open and update nano browser uis * @return string HTML footer content */ /datum/nanoui/proc/get_footer() - var/scriptsContent = "" - - for (var/filename in scripts) - scriptsContent += "" return {" - [scriptsContent]
@@ -431,7 +427,7 @@ nanoui is used to open and update nano browser uis if (!src_object || !user) close() return - + if (status && (update || is_auto_updating)) src_object.ui_interact(user, ui_key, src) // Update the UI (update_status() is called whenever a UI is updated) else diff --git a/nano/js/nano_config.js b/nano/js/nano_config.js index 7766b64a4b5..8352b197ccf 100644 --- a/nano/js/nano_config.js +++ b/nano/js/nano_config.js @@ -4,7 +4,12 @@ var NanoConfig = function () return { init: function () { - + if (typeof jQuery == 'undefined') { + alert('ERROR: jQuery failed to load!'); + } + if (typeof $.views == 'undefined') { + alert('ERROR: JSRender failed to load!'); + } } } } (); @@ -32,7 +37,7 @@ if (!Array.prototype.indexOf) } return -1; }; -} +}; if (!String.prototype.format) { @@ -54,7 +59,7 @@ if (!String.prototype.format) }); }; String.prototype.format.regex = new RegExp("{-?[0-9]+}", "g"); -} +}; Object.size = function(obj) { var size = 0, key; @@ -70,7 +75,7 @@ if(!window.console) { return false; } }; -} +}; String.prototype.toTitleCase = function () { var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|vs?\.?|via)$/i; diff --git a/nano/js/nano_update.js b/nano/js/nano_update.js index 7bfd196bcaa..e25626162ff 100644 --- a/nano/js/nano_update.js +++ b/nano/js/nano_update.js @@ -23,6 +23,8 @@ NanoUpdate = function () // this function sets up the templates and base functionality var init = function () { + $('#uiNoJavaScript').html('Loading...'); + // this callback is triggered after new data is processed // it updates the status/visibility icon and adds click event handling to buttons/links NanoUpdate.addAfterUpdateCallback(function (updateData) { @@ -73,7 +75,7 @@ NanoUpdate = function () var templateData = body.data('templateData'); var initialData = body.data('initialData'); - if (!templateData || !initialData) + if (templateData == null || !initialData == null) { alert('Error: Initial data did not load correctly.'); } @@ -88,6 +90,11 @@ NanoUpdate = function () } } + if (!templateCount) + { + alert('ERROR: No templates listed!'); + } + // load markup for each template and register it for (var key in templateData) { @@ -121,15 +128,16 @@ NanoUpdate = function () renderTemplates(initialData); } _isInitialised = true; + $('#uiNoJavaScript').hide(); } executeCallbacks(_afterUpdateCallbacks, _data); - - //alert($("#mainTemplate").html()); } catch(error) { - alert('An error occurred while loading the UI: ' + error.message+"\n"+error.stack); + + alert('ERROR: An error occurred while loading the UI: ' + error.message); + return; } }); @@ -165,15 +173,29 @@ NanoUpdate = function () { _earlyUpdateData = updateData; // all templates have not been registered. We set _earlyUpdateData which will be applied after the template is loaded with the initial data } - } + }; // This function renders the template with the latest data // It has to be done recursively as each piece of data is observed individually and needs to be updated individually var renderTemplates = function (data) { - _data = data; - $("#mainTemplate").html(_templates["main"].render(_data)); - } + if (!_templates.hasOwnProperty("main")) + { + alert('Error: Main template not found.'); + } + + _data = data; + + try + { + $("#mainTemplate").html(_templates["main"].render(_data)); + } + catch(error) + { + alert('ERROR: An error occurred while rendering the UI: ' + error.message); + return; + } + }; // Execute all callbacks in the callbacks array/object provided, updateData is passed to them for processing var executeCallbacks = function (callbacks, updateData) @@ -184,7 +206,7 @@ NanoUpdate = function () } return updateData; - } + }; return { init: function ()