From 9be073cc12c014c5c636f18c4d18c758eb9268ae Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 25 Aug 2016 16:03:12 -0700 Subject: [PATCH 1/5] handle some more cases --- scripts/system/edit.js | 10 ++++- scripts/system/html/js/entityProperties.js | 44 ++++++++++++++-------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index bcf31726bc..1727857ee8 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1369,7 +1369,12 @@ var PropertiesTool = function (opts) { }); webView.webEventReceived.connect(function (data) { - data = JSON.parse(data); + try{ + data = JSON.parse(data); + } + catch(e){ + return; + } var i, properties, dY, diff, newPosition; if (data.type === "print") { if (data.message) { @@ -1418,7 +1423,8 @@ var PropertiesTool = function (opts) { pushCommandForSelections(); selectionManager._update(); } else if(data.type === 'saveUserData'){ - Entities.editEntity(data.id, data.properties) + var actualID = data.id.split('"')[1] + var success = Entities.editEntity(actualID, data.properties) } else if (data.type === "showMarketplace") { showMarketplace(); } else if (data.type === "action") { diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 41a1266434..6337ef00af 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -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,11 @@ 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); } - lastEntityID = properties.id; + lastEntityID = '"' + properties.id + '"'; elID.innerHTML = properties.id; elType.innerHTML = properties.type; @@ -840,26 +853,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; From ee190db5eb8fa4bbbd416b9a8fe6fde32a633e37 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 25 Aug 2016 16:27:58 -0700 Subject: [PATCH 2/5] some comments --- scripts/system/edit.js | 1 + scripts/system/html/js/entityProperties.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 1727857ee8..84afca4a01 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1423,6 +1423,7 @@ var PropertiesTool = function (opts) { pushCommandForSelections(); selectionManager._update(); } else if(data.type === 'saveUserData'){ + //the event bridge and json parsing handle our avatar id string differently. var actualID = data.id.split('"')[1] var success = Entities.editEntity(actualID, data.properties) } else if (data.type === "showMarketplace") { diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 6337ef00af..8ce3fbbe00 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -758,9 +758,11 @@ function loaded() { } else { properties = data.selections[0].properties; + 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 + '"'; elID.innerHTML = properties.id; From 4c63ad1ac866d0d056e124efd7bb7a11776e3061 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 26 Aug 2016 10:19:31 -0700 Subject: [PATCH 3/5] code cleanup --- scripts/system/edit.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 84afca4a01..bb52637ef5 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1369,10 +1369,10 @@ var PropertiesTool = function (opts) { }); webView.webEventReceived.connect(function (data) { - try{ + try { data = JSON.parse(data); } - catch(e){ + catch(e) { return; } var i, properties, dY, diff, newPosition; @@ -1424,8 +1424,8 @@ var PropertiesTool = function (opts) { selectionManager._update(); } else if(data.type === 'saveUserData'){ //the event bridge and json parsing handle our avatar id string differently. - var actualID = data.id.split('"')[1] - var success = Entities.editEntity(actualID, data.properties) + var actualID = data.id.split('"')[1]; + Entities.editEntity(actualID, data.properties); } else if (data.type === "showMarketplace") { showMarketplace(); } else if (data.type === "action") { From f6bd04780d95f7906581e3bc794dccbf26c7f554 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 26 Aug 2016 11:56:40 -0700 Subject: [PATCH 4/5] add a print to catch errors --- scripts/system/edit.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index bb52637ef5..8dc6e144f7 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1373,6 +1373,7 @@ var PropertiesTool = function (opts) { data = JSON.parse(data); } catch(e) { + print('web event was not valid json.') return; } var i, properties, dY, diff, newPosition; From 53a22819180a37271c5d1bac25fae8c000268fb4 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 26 Aug 2016 11:57:15 -0700 Subject: [PATCH 5/5] better --- scripts/system/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 8dc6e144f7..1a50fb0d8b 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1373,7 +1373,7 @@ var PropertiesTool = function (opts) { data = JSON.parse(data); } catch(e) { - print('web event was not valid json.') + print('Edit.js received web event that was not valid json.') return; } var i, properties, dY, diff, newPosition;