cleanup and handle a bug when changing from normal text userdata to another field

This commit is contained in:
James B. Pollack 2016-08-24 14:49:41 -07:00
parent 45e3f926a1
commit 384c3dd543

View file

@ -26,7 +26,7 @@ var ICON_FOR_TYPE = {
var EDITOR_TIMEOUT_DURATION = 1500; var EDITOR_TIMEOUT_DURATION = 1500;
var colorPickers = []; var colorPickers = [];
var lastEntityID=null; var lastEntityID = null;
debugPrint = function(message) { debugPrint = function(message) {
EventBridge.emitWebEvent( EventBridge.emitWebEvent(
JSON.stringify({ JSON.stringify({
@ -333,11 +333,7 @@ function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, d
var properties = {}; var properties = {};
var parsedData = {}; var parsedData = {};
try { try {
if ($('#userdata-editor').css('height') === "0px") { parsedData = JSON.parse(userDataElement.value);
parsedData = editor.getJSON();
} else {
parsedData = JSON.parse(userDataElement.value);
}
} catch (e) {} } catch (e) {}
if (!(groupName in parsedData)) { if (!(groupName in parsedData)) {
@ -393,7 +389,7 @@ function createJSONEditor() {
alert('JSON editor:' + e) alert('JSON editor:' + e)
}, },
onChange: function() { onChange: function() {
var currentJSONString = editor.getText(); var currentJSONString = editor.getText();
if (currentJSONString === '{"":""}') { if (currentJSONString === '{"":""}') {
return; return;
@ -493,7 +489,10 @@ function bindAllNonJSONEditorElements() {
if (e.target.id === "userdata-new-editor" || e.target.id === "userdata-clear") { if (e.target.id === "userdata-new-editor" || e.target.id === "userdata-clear") {
return; return;
} else { } else {
saveJSONUserData(true); if ($('#userdata-editor').css('height') !== "0px") {
saveJSONUserData(true);
}
} }
}) })
} }
@ -703,7 +702,7 @@ function loaded() {
if (data.type == "update") { if (data.type == "update") {
if (data.selections.length == 0) { if (data.selections.length == 0) {
if (editor !== null && lastEntityID!==null) { if (editor !== null && lastEntityID !== null) {
saveJSONUserData(true); saveJSONUserData(true);
deleteJSONEditor(); deleteJSONEditor();
} }
@ -745,7 +744,7 @@ function loaded() {
} else { } else {
properties = data.selections[0].properties; properties = data.selections[0].properties;
if (lastEntityID !== properties.id && lastEntityID!==null && editor!==null) { if (lastEntityID !== properties.id && lastEntityID !== null && editor !== null) {
saveJSONUserData(true); saveJSONUserData(true);
} }
@ -843,11 +842,8 @@ function loaded() {
hideUserDataTextArea(); hideUserDataTextArea();
var json = null; var json = null;
try { try {
json = JSON.parse(properties.userData) json = JSON.parse(properties.userData);
//its json
if (Object.keys(json).length === 0 && json.constructor === Object) {
//it's an empty object
}
if (editor === null) { if (editor === null) {
createJSONEditor(); createJSONEditor();
} }