',
+ html: true,
+ showConfirmButton: false,
+ allowEscapeKey: false
+ });
+}
+
function showDomainCreationAlert(justConnected) {
swal({
title: 'Create new domain ID',
@@ -377,14 +403,7 @@ function showDomainCreationAlert(justConnected) {
}
} else {
// we're going to change the alert to a new one with a spinner while we create this domain
- swal({
- title: 'Creating domain ID',
- text: '
',
- html: true,
- showConfirmButton: false,
- allowEscapeKey: false
- });
-
+ showSpinnerAlert('Creating domain ID');
createNewDomainID(inputValue, justConnected);
}
});
@@ -403,7 +422,7 @@ function createNewDomainID(description, justConnected) {
if (data.status == "success") {
// we successfully created a domain ID, set it on that field
var domainID = data.domain.id;
- $("[name='metaverse.id']").val(domainID).change();
+ $(Settings.DOMAIN_ID_SELECTOR).val(domainID).change();
if (justConnected) {
var successText = "We connnected your High Fidelity account and created a new domain ID for this machine."
@@ -458,6 +477,198 @@ function createNewDomainID(description, justConnected) {
});
}
+function setupPlacesTable() {
+ // create a dummy table using our view helper
+ var placesTableSetting = {
+ type: 'table',
+ name: 'places',
+ label: 'Places',
+ html_id: Settings.PLACES_TABLE_ID,
+ help: "The following places currently point to this domain.To point your places to this domain, "
+ + " go to the My Places "
+ + "page in your High Fidelity Metaverse account.",
+ read_only: true,
+ columns: [
+ {
+ "name": "name",
+ "label": "Name"
+ },
+ {
+ "name": "path",
+ "label": "Path"
+ }
+ ]
+ }
+
+ // get a table for the places
+ var placesTableGroup = viewHelpers.getFormGroup('', placesTableSetting, Settings.data.values, false, false);
+
+ // append the places table in the right place
+ $('#places_paths .panel-body').prepend(placesTableGroup);
+
+ // do we have a domain ID?
+ if (Settings.data.values.metaverse.id.length > 0) {
+ // now, ask the API for what places, if any, point to this domain
+ reloadPlacesOrTemporaryName();
+ } else {
+ // we don't have a domain ID - add a button to offer the user a chance to get a temporary one
+ var temporaryPlaceButton = dynamicButton(Settings.GET_TEMPORARY_NAME_ID, 'Get a temporary place name');
+ $('#' + Settings.PLACES_TABLE_ID).after(temporaryPlaceButton);
+ }
+
+}
+
+function placeTableRow(name, path, isTemporary) {
+ if (!isTemporary) {
+ var name_link = "" + name + "";
+ } else {
+ var name_link = name;
+ }
+
+ return "
" + name_link + "
" + path + "
";
+}
+
+function placeTableRowForPlaceObject(place) {
+ var placePathOrIndex = (place.path ? place.path : "/");
+ return placeTableRow(place.name, placePathOrIndex, false);
+}
+
+function reloadPlacesOrTemporaryName() {
+ // we only need to do this if we have a current domain ID
+ var domainID = Settings.data.values.metaverse.id;
+ if (domainID.length > 0) {
+ var domainURL = Settings.METAVERSE_URL + "/api/v1/domains/" + domainID;
+
+ $.getJSON(domainURL, function(data){
+ // check if we have owner_places (for a real domain) or a name (for a temporary domain)
+ if (data.status == "success") {
+ if (data.domain.owner_places) {
+ // add a table row for each of these names
+ _.each(data.domain.owner_places, function(place){
+ $('#' + Settings.PLACES_TABLE_ID + " tbody").append(placeTableRowForPlaceObject(place));
+ });
+ } else if (data.domain.name) {
+ // add a table row for this temporary domain name
+ $('#' + Settings.PLACES_TABLE_ID + " tbody").append(placeTableRow(data.domain.name + " (temporary)", '/', true));
+ }
+ }
+ });
+ }
+}
+
+function appendDomainIDButtons() {
+ var domainIDInput = $(Settings.DOMAIN_ID_SELECTOR);
+
+ var createButton = dynamicButton(Settings.CREATE_DOMAIN_ID_BTN_ID, "Create new domain ID");
+ createButton.css('margin-top', '10px');
+ var chooseButton = dynamicButton(Settings.CHOOSE_DOMAIN_ID_BTN_ID, "Choose from my domains");
+ chooseButton.css('margin', '10px 0px 0px 10px');
+
+ domainIDInput.after(chooseButton);
+ domainIDInput.after(createButton);
+}
+
+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
+ clickedButton.html("Loading domains...")
+ clickedButton.attr('disabled', 'disabled')
+
+ // get a list of user domains from data-web
+ data_web_domains_url = Settings.METAVERSE_URL + "/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.
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
+ })
+
+ // remove the spinner from the choose button
+ clickedButton.html("Choose from my domains")
+ clickedButton.removeAttr('disabled')
+ })
+
+ } 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"
+ })
+ }
+}
+
+function createTemporaryDomain() {
+ swal({
+ title: 'Create temporary place name',
+ text: 'This will create a temporary place name and domain ID so other users can easily connect to your domain.',
+ showCancelButton: true,
+ confirmButtonText: 'Create',
+ closeOnConfirm: false
+ }, function(isConfirm){
+ if (isConfirm) {
+ showSpinnerAlert('Creating temporary place name');
+
+ // make a get request to get a temporary domain
+ $.post(Settings.METAVERSE_URL + '/api/v1/domains/temporary', function(data){
+ if (data.status == "success") {
+ var domain = data.data.domain;
+
+ // we should have a new domain ID - set it on the domain ID value
+ $(Settings.DOMAIN_ID_SELECTOR).val(domain.id).change();
+ swal({
+ type: 'success',
+ title: 'Success!',
+ text: "We have created a temporary name and domain ID for you."
+ + "Your temporary place name is " + domain.name + "."
+ + "Press the button below to save your new settings and restart your domain-server.",
+ confirmButtonText: 'Save',
+ html: true
+ }, function(){
+ saveSettings();
+ });
+ }
+ });
+ }
+ });
+}
+
function reloadSettings() {
$.getJSON('/settings.json', function(data){
_.extend(data, viewHelpers)
@@ -476,6 +687,9 @@ function reloadSettings() {
// call our method to setup the HF account button
setupHFAccountButton();
+ // call our method to setup the place names table
+ setupPlacesTable();
+
// add tooltip to locked settings
$('label.locked').tooltip({
placement: 'right',
@@ -484,17 +698,6 @@ function reloadSettings() {
});
}
-function appendDomainIDButtons() {
- var metaverseInput = $("[name='metaverse.id']");
-
- var createButton = $("");
- var chooseButton = $("");
-
- metaverseInput.after(chooseButton);
- metaverseInput.after(createButton);
-}
var SETTINGS_ERROR_MESSAGE = "There was a problem saving domain settings. Please try again!";
@@ -540,7 +743,7 @@ function makeTable(setting, keypath, setting_value, isLocked) {
}
html += "
"
-
- if (isArray) {
- rowIsObject = setting.columns.length > 1
- colValue = rowIsObject ? row[col.name] : row
- html += colValue
-
- // for arrays we add a hidden input to this td so that values can be posted appropriately
- html += ""
- } else if (row.hasOwnProperty(col.name)) {
- html += row[col.name]
+ if (setting.numbered === true) {
+ html += "
" + row_num + "
"
}
- html += ""
- })
-
- if (!isLocked) {
- if (setting.can_order) {
- html += "
"
+ if (setting.key) {
+ html += "
" + indexOrName + "
"
}
- html += "
"
- }
- html += "
"
+ _.each(setting.columns, function(col) {
+ html += "
"
- row_num++
- });
+ if (isArray) {
+ rowIsObject = setting.columns.length > 1
+ colValue = rowIsObject ? row[col.name] : row
+ html += colValue
+
+ // for arrays we add a hidden input to this td so that values can be posted appropriately
+ html += ""
+ } else if (row.hasOwnProperty(col.name)) {
+ html += row[col.name]
+ }
+
+ html += "
"
+ })
+
+ if (!isLocked && !setting.read_only) {
+ if (setting.can_order) {
+ html += "
"
+ }
+ html += "
"
+ }
+
+ html += ""
+
+ row_num++
+ });
+ }
// populate inputs in the table for new values
- if (!isLocked) {
+ if (!isLocked && !setting.read_only) {
html += makeTableInputs(setting)
}
html += "
"
@@ -926,70 +1131,3 @@ function cleanupFormValues(node) {
function showErrorMessage(title, message) {
swal(title, message)
}
-
-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
- clickedButton.html("Loading domains...")
- clickedButton.attr('disabled', 'disabled')
-
- // get a list of user domains from data-web
- data_web_domains_url = Settings.METAVERSE_URL + "/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.