diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js index 2cd4adfbc3f5f9bea285cb5ee1109bf386946d87..7c16dcca4eb095925e06d0cd5ff607d52bc07400 100644 --- a/src/core/js/edit_mode.js +++ b/src/core/js/edit_mode.js @@ -42,8 +42,8 @@ var edit_mode = new function() { } } - // TODO: do all these listener need to be part of edit_mode or can they be - // declared with "var" + // TODO: do all these listener need to be part of edit_mode or can they be + // declared with "var" this.scroll_edit_panel = function(e) { $('.caosdb-f-edit').css("top", document.documentElement.scrollTop); } @@ -381,7 +381,7 @@ var edit_mode = new function() { } - this.init_actions_panels = function(){ + this.init_actions_panels = function() { this.reset_actions_panels(); $(".caosdb-entity-actions-panel").each(function(index) { var clone = $(this).clone(true)[0]; @@ -391,7 +391,7 @@ var edit_mode = new function() { }); } - this.reset_actions_panels = function(){ + this.reset_actions_panels = function() { $(".caosdb-f-edit-mode-entity-actions-panel").remove(); $(".caosdb-entity-actions-panel").show(); } @@ -495,7 +495,7 @@ var edit_mode = new function() { /** * @param {HTMLElement} entity property in view mode representation. * @return {undefined} - */ + */ this.make_property_editable = function(element) { if (typeof element == "undefined") { throw Error("parameter `element` was undefined."); @@ -564,7 +564,7 @@ var edit_mode = new function() { } - this.init_dragable = function(){ + this.init_dragable = function() { var props = document.getElementsByClassName("caosdb-f-edit-drag"); for (var pel of props) { pel.addEventListener("dragstart", edit_mode.prop_dragstart); @@ -572,55 +572,55 @@ var edit_mode = new function() { } } - /* - * This function treats the deletion of entities, i.e. when the "delete" - * button is clicked. - */ - this.delete_action = async function(entity){ - var app = edit_mode.app; - // this is the callback of the delete button - // show waiting notification - edit_mode.smooth_replace(entity, app.waiting); - // send delete request - var response = await transaction.deleteEntities([getEntityID(entity)]); - // transform the delete response - var entities = await transformation.transformEntities(response); - // error of delete - // continue with transformed entities - edit_mode.smooth_replace(app.waiting, entities[0]); - app.entity = entities[0]; - // treating error msg of delete - if (edit_mode.has_errors(app.entity)) { - hintMessages.hintMessages(app.entity); - edit_mode.set_entity_dropable(app.entity, - edit_mode.prop_dragover, edit_mode.prop_dragleave, - parent_drop_listener, property_drop_listener - ); - edit_mode.init_actions_panels(); - // only add edit button, because a deletion would fail again - edit_mode.add_start_edit_button(app.entity, () => { - app.startEdit(app.entity) - }); - if (getEntityRole(app.entity) == "RecordType") { - edit_mode.add_new_record_button(app.entity, () => { - edit_mode.create_new_record(getEntityID(app.entity)).then((entity) => { - app.newEntity(entity); - }, edit_mode.handle_error); - }); - } - } else { - // no error msg of delete - // removes trash bin etc - $(app.entity).find('.caosdb-f-edit-mode-entity-actions-panel').remove(); - // creates an ok button, which removes - // deleted entity on click - var closeButton = $(app.entity).find('.alert-info .close'); - closeButton.text("Ok"); - closeButton.click((e) => { - $(app.entity).remove(); - }); - } - } + /* + * This function treats the deletion of entities, i.e. when the "delete" + * button is clicked. + */ + this.delete_action = async function(entity) { + var app = edit_mode.app; + // this is the callback of the delete button + // show waiting notification + edit_mode.smooth_replace(entity, app.waiting); + // send delete request + var response = await transaction.deleteEntities([getEntityID(entity)]); + // transform the delete response + var entities = await transformation.transformEntities(response); + // error of delete + // continue with transformed entities + edit_mode.smooth_replace(app.waiting, entities[0]); + app.entity = entities[0]; + // treating error msg of delete + if (edit_mode.has_errors(app.entity)) { + hintMessages.hintMessages(app.entity); + edit_mode.set_entity_dropable(app.entity, + edit_mode.prop_dragover, edit_mode.prop_dragleave, + parent_drop_listener, property_drop_listener + ); + edit_mode.init_actions_panels(); + // only add edit button, because a deletion would fail again + edit_mode.add_start_edit_button(app.entity, () => { + app.startEdit(app.entity) + }); + if (getEntityRole(app.entity) == "RecordType") { + edit_mode.add_new_record_button(app.entity, () => { + edit_mode.create_new_record(getEntityID(app.entity)).then((entity) => { + app.newEntity(entity); + }, edit_mode.handle_error); + }); + } + } else { + // no error msg of delete + // removes trash bin etc + $(app.entity).find('.caosdb-f-edit-mode-entity-actions-panel').remove(); + // creates an ok button, which removes + // deleted entity on click + var closeButton = $(app.entity).find('.alert-info .close'); + closeButton.text("Ok"); + closeButton.click((e) => { + $(app.entity).remove(); + }); + } + } /* * Initialize the edit mode and create a state machine. */ @@ -866,11 +866,11 @@ var edit_mode = new function() { app.waiting = createWaitingNotification("Please wait."); $(app.waiting).hide(); app.init(); - // TODO: We need some refactoring: there ist the variable editApp which is - // set with this return value. I think app is a bad name as it contains - // the state machine. Alos, the state machine should be either passed - // around or be global (edit_mode.app). - edit_mode.app = app + // TODO: We need some refactoring: there ist the variable editApp which is + // set with this return value. I think app is a bad name as it contains + // the state machine. Alos, the state machine should be either passed + // around or be global (edit_mode.app). + edit_mode.app = app return app; } @@ -881,12 +881,12 @@ var edit_mode = new function() { this.freeze_but = function(element) { $('.caosdb-f-main-entities').children().each(function(index) { edit_mode.freeze_entity(this); - if (element != this){ - console.log("freezing") - edit_mode.freeze_entity(this); - } else { - console.log("Not freezing") - } + if (element != this) { + console.log("freezing") + edit_mode.freeze_entity(this); + } else { + console.log("Not freezing") + } }); edit_mode.unfreeze_entity(element); @@ -1059,7 +1059,9 @@ var edit_mode = new function() { $(entity).find(".caosdb-f-edit-mode-entity-actions-panel").append(button); - $(button).click(() => {edit_mode.delete_action(entity);}); + $(button).click(() => { + edit_mode.delete_action(entity); + }); } this.remove_delete_button = function(entity) { @@ -1072,4 +1074,4 @@ var edit_mode = new function() { */ $(document).ready(function() { edit_mode.init(); -}); +}); \ No newline at end of file