From 5b03a445a802020981970b8bdaf5bbbfae753f9f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 30 Sep 2014 10:47:52 -0700 Subject: [PATCH] allow user to choose domain ID from High Fidelity domains --- domain-server/resources/web/js/settings.js | 92 +++++++++++++++++----- 1 file changed, 72 insertions(+), 20 deletions(-) diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index 45638a8b0d..76b2e52078 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -4,7 +4,7 @@ var Settings = { var viewHelpers = { getFormGroup: function(groupName, setting, values, isAdvanced, isLocked) { - setting_id = groupName + "_" + setting.name + setting_name = groupName + "." + setting.name form_group = "
" @@ -24,16 +24,16 @@ var viewHelpers = { if (setting.type === 'checkbox') { form_group += "" form_group += "
" - form_group += ""; form_group += "
" } else { input_type = _.has(setting, 'type') ? setting.type : "text" - form_group += ""; - form_group += "" + setting.label + ""; + form_group += "" form_group += "" + setting.help + "" @@ -88,16 +88,7 @@ $(document).ready(function(){ }) $('#settings-form').on('click', '#choose-domain-btn', function(){ - // setup the modal to help user pick their domain - if (Settings.initialValues.metaverse["access-token"]) { - - } else { - bootbox.alert({ - message: "You must have an access token to query your High Fidelity domains.

" + - "Please follow the instructions on the settings page to add an access token.", - title: "Access token required" - }) - } + chooseFromHighFidelityDomains($(this)) }) var panelsSource = $('#panels-template').html() @@ -118,7 +109,7 @@ function reloadSettings() { $('.nav-stacked').html(Settings.sidebarTemplate(data)) $('#panels').html(Settings.panelsTemplate(data)) - Settings.initialValues = form2js('settings-form', "_", false, cleanupFormValues, true); + Settings.initialValues = form2js('settings-form', ".", false, cleanupFormValues, true); // add tooltip to locked settings $('label.locked').tooltip({ @@ -131,7 +122,7 @@ function reloadSettings() { } function appendDomainSelectionModal() { - var metaverseFormGroup = $('#metaverse_id').parent('.form-group'); + var metaverseFormGroup = $("[name='metaverse.id']").parent('.form-group'); var chooseButton = ""; metaverseFormGroup.append(chooseButton); } @@ -145,7 +136,7 @@ $('body').on('click', '.save-button', function(e){ }); // grab a JSON representation of the form via form2js - var formJSON = form2js('settings-form', "_", false, cleanupFormValues, true); + var formJSON = form2js('settings-form', ".", false, cleanupFormValues, true); // re-enable all inputs $("input").each(function(){ @@ -180,13 +171,13 @@ function badgeSidebarForDifferences(changedInput) { var panelParentID = changedInput.closest('.panel').attr('id') // get a JSON representation of that section - var rootJSON = form2js(panelParentID, "_", false, cleanupFormValues, true); + var rootJSON = form2js(panelParentID, ".", false, cleanupFormValues, true); var panelJSON = rootJSON[panelParentID] var badgeValue = 0 for (var setting in panelJSON) { - if (panelJSON[setting] != Settings.initialValues[panelParentID][ setting]) { + if (panelJSON[setting] != Settings.initialValues[panelParentID][setting]) { badgeValue += 1 } } @@ -238,4 +229,65 @@ function showAlertMessage(message, isSuccess) { alertBox.addClass(isSuccess ? 'alert-success' : 'alert-danger'); alertBox.html(message); alertBox.fadeIn(); +} + +function chooseFromHighFidelityDomains(clickedButton) { + // setup the modal to help user pick their domain + if (Settings.initialValues.metaverse.access_token) { + + // add a spinner to the choose button + + // get a list of user domains from data-web + data_web_domains_url = "https://data.highfidelity.io/api/v1/domains?access_token=" + $.getJSON(data_web_domains_url + Settings.initialValues.metaverse.access_token, function(data){ + + modal_buttons = { + cancel: { + label: 'Cancel', + className: 'btn-default' + } + } + + if (data.data.domains.length) { + // setup a select box for the returned domains + modal_body = "

Choose the High Fidelity domain you want this domain-server to represent.
This will set your domain ID on the settings page.

" + domain_select = $("") + _.each(data.data.domains, function(domain){ + domain_select.append("") + }) + modal_body += "" + domain_select[0].outerHTML + modal_buttons["success"] = { + label: 'Choose domain', + callback: function() { + domainID = $('#domain-name-select').val() + // set the domain ID on the form + $("[name='metaverse.id']").val(domainID).change(); + } + } + } else { + modal_buttons["success"] = { + label: 'Create new domain', + callback: function() { + window.open("https://data.highfidelity.io/domains", '_blank'); + } + } + modal_body = "

You do not have any domains in your High Fidelity account." + + "

Go to your domains page to create a new one. Once your domain is created re-open this dialog to select it.

" + } + + + bootbox.dialog({ + title: "Choose matching domain", + message: modal_body, + buttons: modal_buttons + }) + }) + + } else { + bootbox.alert({ + message: "You must have an access token to query your High Fidelity domains.

" + + "Please follow the instructions on the settings page to add an access token.", + title: "Access token required" + }) + } } \ No newline at end of file