mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:58:27 +02:00
Update wizard to make request for domain info
This commit is contained in:
parent
9a0a74c9b9
commit
8401aecef5
3 changed files with 227 additions and 174 deletions
|
@ -146,187 +146,255 @@ function sendUpdatePlaceRequest(id, path, domainID, clearDomainID, onSuccess, on
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pendingDomainRequest = null;
|
||||||
|
function getDomainFromAPI(callback) {
|
||||||
|
if (pendingDomainRequest !== null) {
|
||||||
|
pendingDomainRequest.success(callback);
|
||||||
|
pendingDomainRequest.error(function() { callback({ status: 'fail' }) });
|
||||||
|
return pendingDomainRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback === undefined) {
|
||||||
|
callback = function() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
var domainID = Settings.data.values.metaverse.id;
|
||||||
|
if (domainID === null || domainID === undefined || domainID === '') {
|
||||||
|
callback({ status: 'fail' });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingDomainRequest = $.ajax({
|
||||||
|
url: "/api/domains/" + domainID,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
pendingDomainRequest = null;
|
||||||
|
|
||||||
|
if (data.status === 'success') {
|
||||||
|
DomainInfo = data.domain;
|
||||||
|
} else {
|
||||||
|
DomainInfo = null;
|
||||||
|
}
|
||||||
|
callback(data);
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
pendingDomainRequest = null;
|
||||||
|
|
||||||
|
DomainInfo = null;
|
||||||
|
callback({ status: 'fail' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return pendingDomainRequest;
|
||||||
|
}
|
||||||
|
|
||||||
function chooseFromHighFidelityPlaces(accessToken, forcePathTo, onSuccessfullyAdded) {
|
function chooseFromHighFidelityPlaces(accessToken, forcePathTo, onSuccessfullyAdded) {
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
|
|
||||||
var loadingDialog = showLoadingDialog(Strings.ADD_PLACE_LOADING_DIALOG);
|
var loadingDialog = showLoadingDialog(Strings.ADD_PLACE_LOADING_DIALOG);
|
||||||
|
|
||||||
$.ajax("/api/places", {
|
function loadPlaces() {
|
||||||
dataType: 'json',
|
$.ajax("/api/places", {
|
||||||
jsonp: false,
|
dataType: 'json',
|
||||||
success: function(data) {
|
jsonp: false,
|
||||||
if (data.status == 'success') {
|
success: function(data) {
|
||||||
var modal_buttons = {
|
if (data.status == 'success') {
|
||||||
cancel: {
|
var modal_buttons = {
|
||||||
label: Strings.ADD_PLACE_CANCEL_BUTTON,
|
cancel: {
|
||||||
className: 'add-place-cancel-button btn-default'
|
label: Strings.ADD_PLACE_CANCEL_BUTTON,
|
||||||
}
|
className: 'add-place-cancel-button btn-default'
|
||||||
};
|
|
||||||
|
|
||||||
var dialog;
|
|
||||||
var modal_body;
|
|
||||||
|
|
||||||
if (data.data.places.length) {
|
|
||||||
var places_by_id = {};
|
|
||||||
|
|
||||||
modal_body = $('<div>');
|
|
||||||
|
|
||||||
modal_body.append($("<p>Choose a place name that you own or <a href='" + URLs.METAVERSE_URL + "/user/places' target='_blank'>register a new place name</a></p>"));
|
|
||||||
|
|
||||||
var currentDomainIDType = getCurrentDomainIDType();
|
|
||||||
if (currentDomainIDType === DOMAIN_ID_TYPE_TEMP) {
|
|
||||||
var warning = "<div class='domain-loading-error alert alert-warning'>";
|
|
||||||
warning += "If you choose a place name it will replace your current temporary place name.";
|
|
||||||
warning += "</div>";
|
|
||||||
modal_body.append(warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup a select box for the returned places
|
|
||||||
modal_body.append($("<label for='place-name-select'>Places</label>"));
|
|
||||||
place_select = $("<select id='place-name-select' class='form-control'></select>");
|
|
||||||
_.each(data.data.places, function(place) {
|
|
||||||
places_by_id[place.id] = place;
|
|
||||||
place_select.append("<option value='" + place.id + "'>" + place.name + "</option>");
|
|
||||||
})
|
|
||||||
modal_body.append(place_select);
|
|
||||||
modal_body.append($("<p id='place-name-warning' class='warning-text' style='display: none'>This place name already points to a place or path. Saving this would overwrite the previous settings associated with it.</p>"));
|
|
||||||
|
|
||||||
if (forcePathTo === undefined || forcePathTo === null) {
|
|
||||||
var path = "<div class='form-group'>";
|
|
||||||
path += "<label for='place-path-input' class='control-label'>Path</label>";
|
|
||||||
path += "<input type='text' id='place-path-input' class='form-control' value='/'>";
|
|
||||||
path += "</div>";
|
|
||||||
modal_body.append($(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var place_select = modal_body.find("#place-name-select")
|
|
||||||
place_select.change(function(ev) {
|
|
||||||
var warning = modal_body.find("#place-name-warning");
|
|
||||||
var place = places_by_id[$(this).val()];
|
|
||||||
if (place === undefined || place.pointee === null) {
|
|
||||||
warning.hide();
|
|
||||||
} else {
|
|
||||||
warning.show();
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
place_select.trigger('change');
|
|
||||||
|
|
||||||
modal_buttons["success"] = {
|
var dialog;
|
||||||
label: Strings.ADD_PLACE_CONFIRM_BUTTON,
|
var modal_body;
|
||||||
className: 'add-place-confirm-button btn btn-primary',
|
|
||||||
callback: function() {
|
|
||||||
var placeID = $('#place-name-select').val();
|
|
||||||
// set the place ID on the form
|
|
||||||
$(Settings.place_ID_SELECTOR).val(placeID).change();
|
|
||||||
|
|
||||||
if (forcePathTo === undefined || forcePathTo === null) {
|
if (data.data.places.length) {
|
||||||
var placePath = $('#place-path-input').val();
|
var places_by_id = {};
|
||||||
|
|
||||||
|
modal_body = $('<div>');
|
||||||
|
|
||||||
|
modal_body.append($("<p>Choose a place name that you own or <a href='" + URLs.METAVERSE_URL + "/user/places' target='_blank'>register a new place name</a></p>"));
|
||||||
|
|
||||||
|
var currentDomainIDType = getCurrentDomainIDType();
|
||||||
|
if (currentDomainIDType === DOMAIN_ID_TYPE_TEMP) {
|
||||||
|
var warning = "<div class='domain-loading-error alert alert-warning'>";
|
||||||
|
warning += "If you choose a place name it will replace your current temporary place name.";
|
||||||
|
warning += "</div>";
|
||||||
|
modal_body.append(warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup a select box for the returned places
|
||||||
|
modal_body.append($("<label for='place-name-select'>Places</label>"));
|
||||||
|
place_select = $("<select id='place-name-select' class='form-control'></select>");
|
||||||
|
_.each(data.data.places, function(place) {
|
||||||
|
places_by_id[place.id] = place;
|
||||||
|
place_select.append("<option value='" + place.id + "'>" + place.name + "</option>");
|
||||||
|
})
|
||||||
|
modal_body.append(place_select);
|
||||||
|
modal_body.append($("<p id='place-name-warning' class='warning-text' style='display: none'>This place name already points to a place or path. Saving this would overwrite the previous settings associated with it.</p>"));
|
||||||
|
|
||||||
|
if (forcePathTo === undefined || forcePathTo === null) {
|
||||||
|
var path = "<div class='form-group'>";
|
||||||
|
path += "<label for='place-path-input' class='control-label'>Path</label>";
|
||||||
|
path += "<input type='text' id='place-path-input' class='form-control' value='/'>";
|
||||||
|
path += "</div>";
|
||||||
|
modal_body.append($(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
var place_select = modal_body.find("#place-name-select")
|
||||||
|
place_select.change(function(ev) {
|
||||||
|
var warning = modal_body.find("#place-name-warning");
|
||||||
|
var place = places_by_id[$(this).val()];
|
||||||
|
if (place === undefined || place.pointee === null) {
|
||||||
|
warning.hide();
|
||||||
} else {
|
} else {
|
||||||
var placePath = forcePathTo;
|
warning.show();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
place_select.trigger('change');
|
||||||
|
|
||||||
$('.add-place-confirm-button').attr('disabled', 'disabled');
|
modal_buttons["success"] = {
|
||||||
$('.add-place-confirm-button').html(Strings.ADD_PLACE_CONFIRM_BUTTON_PENDING);
|
label: Strings.ADD_PLACE_CONFIRM_BUTTON,
|
||||||
$('.add-place-cancel-button').attr('disabled', 'disabled');
|
className: 'add-place-confirm-button btn btn-primary',
|
||||||
|
callback: function() {
|
||||||
|
var placeID = $('#place-name-select').val();
|
||||||
|
// set the place ID on the form
|
||||||
|
$(Settings.place_ID_SELECTOR).val(placeID).change();
|
||||||
|
|
||||||
function finalizeSaveDomainID(domainID) {
|
if (forcePathTo === undefined || forcePathTo === null) {
|
||||||
var jsonSettings = {
|
var placePath = $('#place-path-input').val();
|
||||||
metaverse: {
|
} else {
|
||||||
id: domainID
|
var placePath = forcePathTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.add-place-confirm-button').attr('disabled', 'disabled');
|
||||||
|
$('.add-place-confirm-button').html(Strings.ADD_PLACE_CONFIRM_BUTTON_PENDING);
|
||||||
|
$('.add-place-cancel-button').attr('disabled', 'disabled');
|
||||||
|
|
||||||
|
function finalizeSaveDomainID(domainID) {
|
||||||
|
var jsonSettings = {
|
||||||
|
metaverse: {
|
||||||
|
id: domainID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var dialog = showLoadingDialog("Waiting for Domain Server to restart...");
|
||||||
|
$.ajax('/settings.json', {
|
||||||
|
data: JSON.stringify(jsonSettings),
|
||||||
|
contentType: 'application/json',
|
||||||
|
type: 'POST'
|
||||||
|
}).done(function(data) {
|
||||||
|
if (data.status == "success") {
|
||||||
|
waitForDomainServerRestart(function() {
|
||||||
|
dialog.modal('hide');
|
||||||
|
if (onSuccessfullyAdded) {
|
||||||
|
onSuccessfullyAdded(places_by_id[placeID].name, domainID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
bootbox.alert("Failed to add place");
|
||||||
|
}
|
||||||
|
}).fail(function() {
|
||||||
|
bootbox.alert("Failed to add place");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function finishSettingUpPlace(domainID) {
|
||||||
|
sendUpdatePlaceRequest(
|
||||||
|
placeID,
|
||||||
|
placePath,
|
||||||
|
domainID,
|
||||||
|
false,
|
||||||
|
function(data) {
|
||||||
|
$(Settings.DOMAIN_ID_SELECTOR).val(domainID).change();
|
||||||
|
dialog.modal('hide')
|
||||||
|
if (domainID) {
|
||||||
|
finalizeSaveDomainID(domainID);
|
||||||
|
} else {
|
||||||
|
if (onSuccessfullyAdded) {
|
||||||
|
onSuccessfullyAdded(places_by_id[placeID].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(data) {
|
||||||
|
$('.add-place-confirm-button').removeAttr('disabled');
|
||||||
|
$('.add-place-confirm-button').html(Strings.ADD_PLACE_CONFIRM_BUTTON);
|
||||||
|
$('.add-place-cancel-button').removeAttr('disabled');
|
||||||
|
bootbox.alert(Strings.ADD_PLACE_UNKNOWN_ERROR);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function maybeCreateNewDomainID() {
|
||||||
|
console.log("Maybe creating domain id", currentDomainIDType)
|
||||||
|
if (currentDomainIDType === DOMAIN_ID_TYPE_FULL) {
|
||||||
|
finishSettingUpPlace();
|
||||||
|
} else {
|
||||||
|
sendCreateDomainRequest(function(domainID) {
|
||||||
|
console.log("Created domain", domainID);
|
||||||
|
finishSettingUpPlace(domainID);
|
||||||
|
}, function() {
|
||||||
|
$('.add-place-confirm-button').removeAttr('disabled');
|
||||||
|
$('.add-place-confirm-button').html(Strings.ADD_PLACE_CONFIRM_BUTTON);
|
||||||
|
$('.add-place-cancel-button').removeAttr('disabled');
|
||||||
|
bootbox.alert(Strings.ADD_PLACE_UNKNOWN_ERROR);
|
||||||
|
bootbox.alert("FAIL");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var dialog = showLoadingDialog("Waiting for Domain Server to restart...");
|
|
||||||
$.ajax('/settings.json', {
|
|
||||||
data: JSON.stringify(jsonSettings),
|
|
||||||
contentType: 'application/json',
|
|
||||||
type: 'POST'
|
|
||||||
}).done(function(data) {
|
|
||||||
if (data.status == "success") {
|
|
||||||
waitForDomainServerRestart(function() {
|
|
||||||
dialog.modal('hide');
|
|
||||||
if (onSuccessfullyAdded) {
|
|
||||||
onSuccessfullyAdded(places_by_id[placeID].name, domainID);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
bootbox.alert("Failed to add place");
|
|
||||||
}
|
|
||||||
}).fail(function() {
|
|
||||||
bootbox.alert("Failed to add place");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function finishSettingUpPlace(domainID) {
|
maybeCreateNewDomainID();
|
||||||
sendUpdatePlaceRequest(
|
|
||||||
placeID,
|
|
||||||
placePath,
|
|
||||||
domainID,
|
|
||||||
false,
|
|
||||||
function(data) {
|
|
||||||
$(Settings.DOMAIN_ID_SELECTOR).val(domainID).change();
|
|
||||||
dialog.modal('hide')
|
|
||||||
if (domainID) {
|
|
||||||
finalizeSaveDomainID(domainID);
|
|
||||||
} else {
|
|
||||||
if (onSuccessfullyAdded) {
|
|
||||||
onSuccessfullyAdded(places_by_id[placeID].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
function(data) {
|
|
||||||
$('.add-place-confirm-button').removeAttr('disabled');
|
|
||||||
$('.add-place-confirm-button').html(Strings.ADD_PLACE_CONFIRM_BUTTON);
|
|
||||||
$('.add-place-cancel-button').removeAttr('disabled');
|
|
||||||
bootbox.alert(Strings.ADD_PLACE_UNKNOWN_ERROR);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentDomainIDType === DOMAIN_ID_TYPE_FULL) {
|
return false;
|
||||||
finishSettingUpPlace();
|
|
||||||
} else {
|
|
||||||
sendCreateDomainRequest(function(domainID) {
|
|
||||||
console.log("Created domain", domainID);
|
|
||||||
finishSettingUpPlace(domainID);
|
|
||||||
}, function() {
|
|
||||||
$('.add-place-confirm-button').removeAttr('disabled');
|
|
||||||
$('.add-place-confirm-button').html(Strings.ADD_PLACE_CONFIRM_BUTTON);
|
|
||||||
$('.add-place-cancel-button').removeAttr('disabled');
|
|
||||||
bootbox.alert(Strings.ADD_PLACE_UNKNOWN_ERROR);
|
|
||||||
bootbox.alert("FAIL");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
modal_buttons["success"] = {
|
||||||
|
label: Strings.ADD_PLACE_NO_PLACES_BUTTON,
|
||||||
|
callback: function() {
|
||||||
|
window.open(URLs.METAVERSE_URL + "/user/places", '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modal_body = Strings.ADD_PLACE_NO_PLACES_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog = bootbox.dialog({
|
||||||
|
title: Strings.ADD_PLACE_TITLE,
|
||||||
|
message: modal_body,
|
||||||
|
closeButton: false,
|
||||||
|
buttons: modal_buttons
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
modal_buttons["success"] = {
|
bootbox.alert(Strings.ADD_PLACE_UNABLE_TO_LOAD_ERROR);
|
||||||
label: Strings.ADD_PLACE_NO_PLACES_BUTTON,
|
|
||||||
callback: function() {
|
|
||||||
window.open(URLs.METAVERSE_URL + "/user/places", '_blank');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modal_body = Strings.ADD_PLACE_NO_PLACES_MESSAGE;
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
dialog = bootbox.dialog({
|
error: function() {
|
||||||
title: Strings.ADD_PLACE_TITLE,
|
|
||||||
message: modal_body,
|
|
||||||
closeButton: false,
|
|
||||||
buttons: modal_buttons
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
bootbox.alert(Strings.ADD_PLACE_UNABLE_TO_LOAD_ERROR);
|
bootbox.alert(Strings.ADD_PLACE_UNABLE_TO_LOAD_ERROR);
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
loadingDialog.modal('hide');
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
error: function() {
|
}
|
||||||
bootbox.alert(Strings.ADD_PLACE_UNABLE_TO_LOAD_ERROR);
|
|
||||||
},
|
var domainType = getCurrentDomainIDType();
|
||||||
complete: function() {
|
if (domainType !== DOMAIN_ID_TYPE_UNKNOWN) {
|
||||||
loadingDialog.modal('hide');
|
loadPlaces();
|
||||||
}
|
} else {
|
||||||
});
|
getDomainFromAPI(function(data) {
|
||||||
|
if (data.status === 'success') {
|
||||||
|
var domainType = getCurrentDomainIDType();
|
||||||
|
loadPlaces();
|
||||||
|
} else {
|
||||||
|
loadingDialog.modal('hide');
|
||||||
|
bootbox.confirm("We were not able to load your domain information from the Metaverse. Would you like to retry?", function(response) {
|
||||||
|
if (response) {
|
||||||
|
chooseFromHighFidelityPlaces(accessToken, forcePathTo, onSuccessfullyAdded);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bootbox.alert({
|
bootbox.alert({
|
||||||
|
|
|
@ -980,20 +980,6 @@ function placeTableRowForPlaceObject(place) {
|
||||||
return placeTableRow(place.name, placePathOrIndex, false, place.id);
|
return placeTableRow(place.name, placePathOrIndex, false, place.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDomainFromAPI(callback) {
|
|
||||||
var domainID = Settings.data.values.metaverse.id;
|
|
||||||
$.ajax({
|
|
||||||
url: "/api/domains/" + domainID,
|
|
||||||
dataType: 'json',
|
|
||||||
success: function(data) {
|
|
||||||
callback(data);
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
callback({ status: 'fail' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function reloadDomainInfo() {
|
function reloadDomainInfo() {
|
||||||
$('#' + Settings.PLACES_TABLE_ID + " tbody tr").not('.headers').remove();
|
$('#' + Settings.PLACES_TABLE_ID + " tbody tr").not('.headers').remove();
|
||||||
|
|
||||||
|
@ -1010,7 +996,6 @@ function reloadDomainInfo() {
|
||||||
// check if we have owner_places (for a real domain) or a name (for a temporary domain)
|
// check if we have owner_places (for a real domain) or a name (for a temporary domain)
|
||||||
if (data.status == "success") {
|
if (data.status == "success") {
|
||||||
$('.domain-loading-hide').show();
|
$('.domain-loading-hide').show();
|
||||||
DomainInfo = data.domain;
|
|
||||||
if (data.domain.owner_places) {
|
if (data.domain.owner_places) {
|
||||||
// add a table row for each of these names
|
// add a table row for each of these names
|
||||||
_.each(data.domain.owner_places, function(place){
|
_.each(data.domain.owner_places, function(place){
|
||||||
|
@ -1043,7 +1028,6 @@ function reloadDomainInfo() {
|
||||||
appendAddButtonToPlacesTable();
|
appendAddButtonToPlacesTable();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DomainInfo = null;
|
|
||||||
$('.domain-loading-error').show();
|
$('.domain-loading-error').show();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -58,6 +58,7 @@ $(document).ready(function(){
|
||||||
|
|
||||||
reloadSettings(function(success) {
|
reloadSettings(function(success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
getDomainFromAPI();
|
||||||
setupWizardSteps();
|
setupWizardSteps();
|
||||||
updatePlaceNameDisplay();
|
updatePlaceNameDisplay();
|
||||||
updateUsernameDisplay();
|
updateUsernameDisplay();
|
||||||
|
|
Loading…
Reference in a new issue