From a5054487ba579fd32c5433d1600ae2473a757060 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Aug 2016 18:18:43 -0700 Subject: [PATCH] save on no selections, select another entity, etc --- scripts/system/edit.js | 5 +- scripts/system/html/js/entityProperties.js | 89 +++++++++++++++++----- 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index a3e5476bf9..51d52367d3 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1427,7 +1427,10 @@ var PropertiesTool = function (opts) { } pushCommandForSelections(); selectionManager._update(); - } else if (data.type === "showMarketplace") { + }else if(data.type==='saveUserData'){ + Entities.editEntity(data.id,data.properties) + } + else if (data.type === "showMarketplace") { showMarketplace(); } else if (data.type === "action") { if (data.action === "moveSelectionToGrid") { diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index a6cf84b230..82706c073d 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -26,7 +26,7 @@ var ICON_FOR_TYPE = { var EDITOR_TIMEOUT_DURATION = 1500; var colorPickers = []; - +var lastEntityID=null; debugPrint = function(message) { EventBridge.emitWebEvent( JSON.stringify({ @@ -84,7 +84,7 @@ function showElements(els, show) { function createEmitCheckedPropertyUpdateFunction(propertyName) { return function() { EventBridge.emitWebEvent( - '{ "type":"update", "properties":{"' + propertyName + '":' + this.checked + '}}' + '{"id":' + lastEntityID + ', "type":"update", "properties":{"' + propertyName + '":' + this.checked + '}}' ); }; } @@ -106,6 +106,7 @@ function createEmitGroupCheckedPropertyUpdateFunction(group, propertyName) { properties[group][propertyName] = this.checked; EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: properties }) @@ -119,7 +120,7 @@ function createEmitNumberPropertyUpdateFunction(propertyName, decimals) { var value = parseFloat(this.value).toFixed(decimals); EventBridge.emitWebEvent( - '{ "type":"update", "properties":{"' + propertyName + '":' + value + '}}' + '{"id":' + lastEntityID + ', "type":"update", "properties":{"' + propertyName + '":' + value + '}}' ); }; } @@ -131,6 +132,7 @@ function createEmitGroupNumberPropertyUpdateFunction(group, propertyName) { properties[group][propertyName] = this.value; EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: properties, }) @@ -145,6 +147,7 @@ function createEmitTextPropertyUpdateFunction(propertyName) { properties[propertyName] = this.value; EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: properties, }) @@ -159,6 +162,7 @@ function createEmitGroupTextPropertyUpdateFunction(group, propertyName) { properties[group][propertyName] = this.value; EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: properties, }) @@ -169,6 +173,7 @@ function createEmitGroupTextPropertyUpdateFunction(group, propertyName) { function createEmitVec3PropertyUpdateFunction(property, elX, elY, elZ) { return function() { var data = { + id: lastEntityID, type: "update", properties: {} }; @@ -184,6 +189,7 @@ function createEmitVec3PropertyUpdateFunction(property, elX, elY, elZ) { function createEmitGroupVec3PropertyUpdateFunction(group, property, elX, elY, elZ) { return function() { var data = { + id: lastEntityID, type: "update", properties: {} }; @@ -200,6 +206,7 @@ function createEmitGroupVec3PropertyUpdateFunction(group, property, elX, elY, el function createEmitVec3PropertyUpdateFunctionWithMultiplier(property, elX, elY, elZ, multiplier) { return function() { var data = { + id: lastEntityID, type: "update", properties: {} }; @@ -220,6 +227,7 @@ function createEmitColorPropertyUpdateFunction(property, elRed, elGreen, elBlue) function emitColorPropertyUpdate(property, red, green, blue, group) { var data = { + id: lastEntityID, type: "update", properties: {} }; @@ -244,6 +252,7 @@ function emitColorPropertyUpdate(property, red, green, blue, group) { function createEmitGroupColorPropertyUpdateFunction(group, property, elRed, elGreen, elBlue) { return function() { var data = { + id: lastEntityID, type: "update", properties: {} }; @@ -273,6 +282,7 @@ function updateCheckedSubProperty(propertyName, propertyValue, subPropertyElemen EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: _properties }) @@ -280,7 +290,7 @@ function updateCheckedSubProperty(propertyName, propertyValue, subPropertyElemen } -function setUserDataFromEditor() { +function setUserDataFromEditor(noUpdate) { var json = null; try { json = editor.get(); @@ -291,20 +301,35 @@ function setUserDataFromEditor() { return; } else { var text = editor.getText() - EventBridge.emitWebEvent( - JSON.stringify({ - type: "update", - properties: { - userData: text - }, - }) - ); + console.log('saving as text:', text) + if (noUpdate === true) { + EventBridge.emitWebEvent( + JSON.stringify({ + id: lastEntityID, + type: "saveUserData", + properties: { + userData: text + }, + }) + ); + return; + } else { + EventBridge.emitWebEvent( + JSON.stringify({ + id: lastEntityID, + type: "update", + properties: { + userData: text + }, + }) + ); + } + } } - function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, defaultValue) { var properties = {}; var parsedData = {}; @@ -337,6 +362,7 @@ function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, d EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: properties, }) @@ -368,11 +394,12 @@ function createJSONEditor() { alert('JSON editor:' + e) }, onChange: function() { + var currentJSONString = editor.getText(); + if (currentJSONString === '{"":""}') { return; } $('#userdata-save').attr('disabled', false) - var currentJSONString = editor.getText(); } @@ -444,8 +471,9 @@ function deleteJSONEditor() { var savedJSONTimer = null; -function saveJSONUserData() { - setUserDataFromEditor(); +function saveJSONUserData(noUpdate) { + console.log('start saving userdata') + setUserDataFromEditor(noUpdate); $('#userdata-saved').show(); $('#userdata-save').attr('disabled', true) if (savedJSONTimer !== null) { @@ -453,7 +481,7 @@ function saveJSONUserData() { } savedJSONTimer = setTimeout(function() { $('#userdata-saved').hide(); - + }, 1500) } @@ -467,12 +495,23 @@ function bindAllNonJSONEditorElements() { if (e.target.id === "userdata-new-editor" || e.target.id === "userdata-clear") { return; } else { - saveJSONUserData(); + console.log('save on focus',e) + saveJSONUserData(true); } }) } } +function unbindAllInputs() { + var inputs = $('input'); + var i; + for (i = 0; i < inputs.length; i++) { + var input = inputs[i]; + var field = $(input); + field.unbind(); + } +} + function loaded() { openEventBridge(function() { var allSections = []; @@ -667,7 +706,9 @@ function loaded() { if (data.type == "update") { if (data.selections.length == 0) { - if (editor !== null) { + if (editor !== null && lastEntityID!==null) { + console.log('save on no selections') + saveJSONUserData(true); deleteJSONEditor(); } elTypeIcon.style.display = "none"; @@ -707,9 +748,13 @@ function loaded() { disableProperties(); } else { - properties = data.selections[0].properties; + if (lastEntityID !== properties.id && lastEntityID!==null) { + console.log('save on init') + saveJSONUserData(true); + } + lastEntityID = properties.id; elID.innerHTML = properties.id; elType.innerHTML = properties.type; @@ -1112,6 +1157,7 @@ function loaded() { properties['userData'] = elUserData.value; EventBridge.emitWebEvent( JSON.stringify({ + id: lastEntityID, type: "update", properties: properties, }) @@ -1122,7 +1168,8 @@ function loaded() { elSaveUserData.addEventListener("click", function() { - saveJSONUserData(); + console.log('save on click') + saveJSONUserData(true); }); elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData'));