Merge pull request from imgntn/edit_fix

Fix some edit.js bugs
This commit is contained in:
James B. Pollack 2016-08-26 15:43:14 -07:00 committed by GitHub
commit 44d102d723
2 changed files with 41 additions and 17 deletions
scripts/system

View file

@ -1369,7 +1369,13 @@ var PropertiesTool = function (opts) {
});
webView.webEventReceived.connect(function (data) {
data = JSON.parse(data);
try {
data = JSON.parse(data);
}
catch(e) {
print('Edit.js received web event that was not valid json.')
return;
}
var i, properties, dY, diff, newPosition;
if (data.type === "print") {
if (data.message) {
@ -1418,7 +1424,9 @@ var PropertiesTool = function (opts) {
pushCommandForSelections();
selectionManager._update();
} else if(data.type === 'saveUserData'){
Entities.editEntity(data.id, data.properties)
//the event bridge and json parsing handle our avatar id string differently.
var actualID = data.id.split('"')[1];
Entities.editEntity(actualID, data.properties);
} else if (data.type === "showMarketplace") {
showMarketplace();
} else if (data.type === "action") {

View file

@ -333,7 +333,13 @@ function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, d
var properties = {};
var parsedData = {};
try {
parsedData = JSON.parse(userDataElement.value);
if ($('#userdata-editor').css('height') !== "0px") {
//if there is an expanded, we want to use its json.
parsedData = getEditorJSON();
} else {
parsedData = JSON.parse(userDataElement.value);
}
} catch (e) {}
if (!(groupName in parsedData)) {
@ -441,7 +447,11 @@ function hideUserDataTextArea() {
function showStaticUserData() {
$('#static-userdata').show();
$('#static-userdata').css('height', $('#userdata-editor').height())
$('#static-userdata').text(editor.getText());
if (editor !== null) {
$('#static-userdata').text(editor.getText());
}
};
function removeStaticUserData() {
@ -450,7 +460,10 @@ function removeStaticUserData() {
function setEditorJSON(json) {
editor.set(json)
editor.expandAll();
if (editor.hasOwnProperty('expandAll')) {
editor.expandAll();
}
};
function getEditorJSON() {
@ -745,11 +758,13 @@ function loaded() {
} else {
properties = data.selections[0].properties;
if (lastEntityID !== properties.id && lastEntityID !== null && editor !== null) {
if (lastEntityID !== '"' + properties.id + '"' && lastEntityID !== null && editor !== null) {
saveJSONUserData(true);
}
//the event bridge and json parsing handle our avatar id string differently.
lastEntityID = properties.id;
lastEntityID = '"' + properties.id + '"';
elID.innerHTML = properties.id;
elType.innerHTML = properties.type;
@ -840,26 +855,27 @@ function loaded() {
FIXME: See FIXME for property-script-url.
elScriptTimestamp.value = properties.scriptTimestamp;
*/
hideUserDataTextArea();
var json = null;
try {
json = JSON.parse(properties.userData);
} catch (e) {
//normal text
deleteJSONEditor();
elUserData.value = properties.userData;
showUserDataTextArea();
showNewJSONEditorButton();
hideSaveUserDataButton();
}
if (json !== null) {
if (editor === null) {
createJSONEditor();
}
setEditorJSON(json);
showSaveUserDataButton();
hideUserDataTextArea();
hideNewJSONEditorButton();
} catch (e) {
//normal text
elUserData.value = properties.userData;
showUserDataTextArea();
showNewJSONEditorButton();
hideSaveUserDataButton();
}
elHyperlinkHref.value = properties.href;