diff --git a/src/core/js/ext_prop_display.js b/src/core/js/ext_prop_display.js index 92df5949ad85f2bfc9890ad063103b8ed1136956..4a94173e93a2819ce5cf030b0cff65fda39afc56 100644 --- a/src/core/js/ext_prop_display.js +++ b/src/core/js/ext_prop_display.js @@ -25,7 +25,7 @@ * @requires log (singleton from loglevel library) * @requires load_config (function from webcaosdb.js) */ -var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, getPropertyElements, getPropertyName, getUserName, getUserRoles, logger, load_config, query) { +var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, getPropertyElements, getPropertyName, getUserName, getUserRoles, logger, load_config, preview, query) { /** * Return the property-display config file; `ext_prop_display.json` by @@ -210,29 +210,34 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get this.displayProperties(entities, conf, allTypes, userName, userRoles); // If we are in the edit mode, (un)hide properties after ending // the editing of an entity - for (let event_t of [edit_mode.start_edit.type, preview.showPreviewEvent.type]) { - document.body.addEventListener(event_t, (e) => { - edit_mode.app.onAfterShowResults = this._displayPropertiesWrapper(edit_mode.app.onAfterShowResults, conf, allTypes); - }, true); - } + document.body.addEventListener(edit_mode.start_edit.type, (e) => { + edit_mode.app.onAfterShowResults = this._displayPropertiesWrapper(edit_mode.app.onAfterShowResults, conf, allTypes); + }, true); + // After showing a preview for the first time, its entity card is + // added to the dom tree, so the properties have to be (un)hidden + // afterwards. + document.body.addEventListener(preview.previewReadyEvent.type, (e) => { + let newEntities = $(".caosdb-entity-preview"); + this.displayProperties(newEntities, conf, allTypes, userName, userRoles); + console.log("unhiding properties in preview"); + }, true); } else { // There are no properties to be hidden, so make this clear in HTML body - $("body").attr("data-hidden-properties", "false") + $("body").attr("data-hidden-properties", "false"); this.unhideAllProperties(); - for (let event_t of [edit_mode.start_edit.type, preview.showPreviewEvent.type]) { - document.body.addEventListener(edit_mode.start_edit.type, (e) => { - // also unhide properties when leaving the edit mode - // TODO(fspreck): We're lacking a proper state/event here in the - // edit mode, so do this on "init", since this is the state to which - // the state machine returns after either successfully saving an - // entity or canceling the edit. - edit_mode.app.onAfterShowResults = this._unhideAllPropertiesWrapper(edit_mode.app.onAfterShowResults); - }, true); - } + document.body.addEventListener(edit_mode.start_edit.type, (e) => { + // also unhide properties when leaving the edit mode + // TODO(fspreck): We're lacking a proper state/event here in the + // edit mode, so do this on "init", since this is the state to which + // the state machine returns after either successfully saving an + // entity or canceling the edit. + edit_mode.app.onAfterShowResults = this._unhideAllPropertiesWrapper(edit_mode.app.onAfterShowResults); + }, true); + document.body.addEventListener(preview.previewReadyEvent.type, (e) => this.unhideAllProperties(), true); } } -}($, edit_mode, getEntityName, getEntityRole, getPropertyElements, getPropertyName, getUserName, getUserRoles, log.getLogger("ext_prop_display"), load_config, query); +}($, edit_mode, getEntityName, getEntityRole, getPropertyElements, getPropertyName, getUserName, getUserRoles, log.getLogger("ext_prop_display"), load_config, preview, query); $(document).ready(() => { if ("${BUILD_MODULE_EXT_PROPERTY_DISPLAY}" == "ENABLED") {