From 6d40bc9c2f0fdccccf2b76c499469fda98916192 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 29 Nov 2018 19:41:56 +0100 Subject: [PATCH 1/3] userData error message continues popup fix --- scripts/system/html/css/edit-style.css | 24 +++++ scripts/system/html/js/entityProperties.js | 103 +++++++++++++-------- 2 files changed, 86 insertions(+), 41 deletions(-) diff --git a/scripts/system/html/css/edit-style.css b/scripts/system/html/css/edit-style.css index 415d8e567f..641b9bb5fe 100644 --- a/scripts/system/html/css/edit-style.css +++ b/scripts/system/html/css/edit-style.css @@ -1663,3 +1663,27 @@ input.number-slider { .collapse-icon { cursor: pointer; } + +#property-userData-editor.error { + border: 2px solid red; +} + +#property-userData-editorStatus { + color: white; + background-color: red; + padding: 5px; + display: none; + cursor: pointer; +} + +#property-materialData-editor.error { + border: 2px solid red; +} + +#property-materialData-editorStatus { + color: white; + background-color: red; + padding: 5px; + display: none; + cursor: pointer; +} diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index dc304c6803..bc93a1a9b7 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -1823,7 +1823,7 @@ function createStringProperty(property, elProperty) { type="text" ${propertyData.placeholder ? 'placeholder="' + propertyData.placeholder + '"' : ''} ${propertyData.readOnly ? 'readonly' : ''}> - `) + `); elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); @@ -2359,31 +2359,41 @@ function saveUserData() { saveJSONUserData(true); } +function setJSONError(property, isError) { + $("#property-"+ property + "-editor").toggleClass('error', isError); + var $propertyUserDataEditorStatus = $("#property-"+ property + "-editorStatus"); + $propertyUserDataEditorStatus.css('display', isError ? 'block' : 'none'); + $propertyUserDataEditorStatus.text(isError ? 'Invalid JSON code - look for red X in your code' : ''); +} + function setUserDataFromEditor(noUpdate) { let json = null; + let errorFound = false; try { json = editor.get(); } catch (e) { - alert('Invalid JSON code - look for red X in your code ', +e); + errorFound = true; } - if (json === null) { + + setJSONError('userData', errorFound); + + if (json !== null) { return; + } + + let text = editor.getText(); + if (noUpdate) { + EventBridge.emitWebEvent( + JSON.stringify({ + id: lastEntityID, + type: "saveUserData", + properties: { + userData: text + } + }) + ); } else { - let text = editor.getText(); - if (noUpdate === true) { - EventBridge.emitWebEvent( - JSON.stringify({ - id: lastEntityID, - type: "saveUserData", - properties: { - userData: text - } - }) - ); - return; - } else { - updateProperty('userData', text, false); - } + updateProperty('userData', text, false); } } @@ -2505,9 +2515,10 @@ function hideUserDataSaved() { function showStaticUserData() { if (editor !== null) { - $('#property-userData-static').show(); - $('#property-userData-static').css('height', $('#property-userData-editor').height()); - $('#property-userData-static').text(editor.getText()); + let $propertyUserDataStatic = $('#property-userData-static'); + $propertyUserDataStatic.show(); + $propertyUserDataStatic.css('height', $('#property-userData-editor').height()); + $propertyUserDataStatic.text(editor.getText()); } } @@ -2528,6 +2539,7 @@ function getEditorJSON() { function deleteJSONEditor() { if (editor !== null) { + setJSONError('userData', false); editor.destroy(); editor = null; } @@ -2578,29 +2590,31 @@ function saveMaterialData() { function setMaterialDataFromEditor(noUpdate) { let json = null; + let errorFound = false; try { json = materialEditor.get(); } catch (e) { - alert('Invalid JSON code - look for red X in your code ', +e); + errorFound = true; } + + setJSONError('materialData', errorFound); + if (json === null) { return; + } + let text = materialEditor.getText(); + if (noUpdate) { + EventBridge.emitWebEvent( + JSON.stringify({ + id: lastEntityID, + type: "saveMaterialData", + properties: { + materialData: text + } + }) + ); } else { - let text = materialEditor.getText(); - if (noUpdate === true) { - EventBridge.emitWebEvent( - JSON.stringify({ - id: lastEntityID, - type: "saveMaterialData", - properties: { - materialData: text - } - }) - ); - return; - } else { - updateProperty('materialData', text, false); - } + updateProperty('materialData', text, false); } } @@ -2667,9 +2681,10 @@ function hideMaterialDataSaved() { function showStaticMaterialData() { if (materialEditor !== null) { - $('#property-materialData-static').show(); - $('#property-materialData-static').css('height', $('#property-materialData-editor').height()); - $('#property-materialData-static').text(materialEditor.getText()); + let $propertyMaterialDataStatic = $('#property-materialData-static'); + $propertyMaterialDataStatic.show(); + $propertyMaterialDataStatic.css('height', $('#property-materialData-editor').height()); + $propertyMaterialDataStatic.text(materialEditor.getText()); } } @@ -2955,7 +2970,7 @@ function loaded() { let elServerScriptError = document.getElementById("property-serverScripts-error"); let elServerScriptStatus = document.getElementById("property-serverScripts-status"); elServerScriptError.value = data.errorInfo; - // If we just set elServerScriptError's diplay to block or none, we still end up with + // If we just set elServerScriptError's display to block or none, we still end up with // it's parent contributing 21px bottom padding even when elServerScriptError is display:none. // So set it's parent to block or none elServerScriptError.parentElement.style.display = data.errorInfo ? "block" : "none"; @@ -3314,12 +3329,15 @@ function loaded() { elStaticUserData.setAttribute("id", userDataElementID + "-static"); let elUserDataEditor = document.createElement('div'); elUserDataEditor.setAttribute("id", userDataElementID + "-editor"); + let elUserDataEditorStatus = document.createElement('div'); + elUserDataEditorStatus.setAttribute("id", userDataElementID + "-editorStatus"); let elUserDataSaved = document.createElement('span'); elUserDataSaved.setAttribute("id", userDataElementID + "-saved"); elUserDataSaved.innerText = "Saved!"; elDiv.childNodes[JSON_EDITOR_ROW_DIV_INDEX].appendChild(elUserDataSaved); elDiv.insertBefore(elStaticUserData, elUserData); elDiv.insertBefore(elUserDataEditor, elUserData); + elDiv.insertBefore(elUserDataEditorStatus, elUserData); // Material Data let materialDataProperty = properties["materialData"]; @@ -3330,12 +3348,15 @@ function loaded() { elStaticMaterialData.setAttribute("id", materialDataElementID + "-static"); let elMaterialDataEditor = document.createElement('div'); elMaterialDataEditor.setAttribute("id", materialDataElementID + "-editor"); + let elMaterialDataEditorStatus = document.createElement('div'); + elMaterialDataEditorStatus.setAttribute("id", materialDataElementID + "-editorStatus"); let elMaterialDataSaved = document.createElement('span'); elMaterialDataSaved.setAttribute("id", materialDataElementID + "-saved"); elMaterialDataSaved.innerText = "Saved!"; elDiv.childNodes[JSON_EDITOR_ROW_DIV_INDEX].appendChild(elMaterialDataSaved); elDiv.insertBefore(elStaticMaterialData, elMaterialData); elDiv.insertBefore(elMaterialDataEditor, elMaterialData); + elDiv.insertBefore(elMaterialDataEditorStatus, elMaterialData); // Special Property Callbacks let elParentMaterialNameString = getPropertyInputElement("materialNameToReplace"); From 2771e2862e15e54b6cfa7edf696ef0e18d2f58f7 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 29 Nov 2018 19:55:34 +0100 Subject: [PATCH 2/3] add missing material data json error clear on delete --- scripts/system/html/js/entityProperties.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index bc93a1a9b7..ed03d62e70 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -2705,6 +2705,7 @@ function getMaterialEditorJSON() { function deleteJSONMaterialEditor() { if (materialEditor !== null) { + setJSONError('materialData', false); materialEditor.destroy(); materialEditor = null; } From 4f2289b347db6342006d41f98fdc89604f7525e1 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 6 Dec 2018 23:42:12 +0100 Subject: [PATCH 3/3] CR fixes --- scripts/system/html/js/entityProperties.js | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index ed03d62e70..6f8f2ef4bc 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -1429,13 +1429,13 @@ const TEXTURE_ELEMENTS = { const JSON_EDITOR_ROW_DIV_INDEX = 2; -var elGroups = {}; -var properties = {}; -var colorPickers = {}; -var particlePropertyUpdates = {}; -var selectedEntityProperties; -var lastEntityID = null; -var createAppTooltip = new CreateAppTooltip(); +let elGroups = {}; +let properties = {}; +let colorPickers = {}; +let particlePropertyUpdates = {}; +let selectedEntityProperties; +let lastEntityID = null; +let createAppTooltip = new CreateAppTooltip(); let currentSpaceMode = PROPERTY_SPACE_MODE.LOCAL; function createElementFromHTML(htmlString) { @@ -1689,7 +1689,7 @@ function updateProperty(originalPropertyName, propertyValue, isParticleProperty) } } -var particleSyncDebounce = _.debounce(function () { +let particleSyncDebounce = _.debounce(function () { updateProperties(particlePropertyUpdates); particlePropertyUpdates = {}; }, DEBOUNCE_TIMEOUT); @@ -2361,7 +2361,7 @@ function saveUserData() { function setJSONError(property, isError) { $("#property-"+ property + "-editor").toggleClass('error', isError); - var $propertyUserDataEditorStatus = $("#property-"+ property + "-editorStatus"); + let $propertyUserDataEditorStatus = $("#property-"+ property + "-editorStatus"); $propertyUserDataEditorStatus.css('display', isError ? 'block' : 'none'); $propertyUserDataEditorStatus.text(isError ? 'Invalid JSON code - look for red X in your code' : ''); } @@ -2377,7 +2377,7 @@ function setUserDataFromEditor(noUpdate) { setJSONError('userData', errorFound); - if (json !== null) { + if (errorFound) { return; } @@ -2452,7 +2452,7 @@ function multiDataUpdater(groupName, updateKeyPair, userDataElement, defaults, r updateProperties(propertyUpdate, false); } -var editor = null; +let editor = null; function createJSONEditor() { let container = document.getElementById("property-userData-editor"); @@ -2545,7 +2545,7 @@ function deleteJSONEditor() { } } -var savedJSONTimer = null; +let savedJSONTimer = null; function saveJSONUserData(noUpdate) { setUserDataFromEditor(noUpdate); @@ -2599,7 +2599,7 @@ function setMaterialDataFromEditor(noUpdate) { setJSONError('materialData', errorFound); - if (json === null) { + if (errorFound) { return; } let text = materialEditor.getText(); @@ -2618,7 +2618,7 @@ function setMaterialDataFromEditor(noUpdate) { } } -var materialEditor = null; +let materialEditor = null; function createJSONMaterialEditor() { let container = document.getElementById("property-materialData-editor"); @@ -2711,7 +2711,7 @@ function deleteJSONMaterialEditor() { } } -var savedMaterialJSONTimer = null; +let savedMaterialJSONTimer = null; function saveJSONMaterialData(noUpdate) { setMaterialDataFromEditor(noUpdate);