From b00371c7e145a3ea027c4b83d94d2eec254b81b6 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 14 Jul 2023 15:37:20 +0200 Subject: [PATCH] WIP egw_action copy fixes paste not working --- api/js/egw_action/EgwAction.ts | 30 ++++++++++++------- .../EgwPopupActionImplementation.ts | 4 +-- api/js/egw_action/egw_action_common.ts | 3 ++ filemanager/js/filemanager.ts | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/api/js/egw_action/EgwAction.ts b/api/js/egw_action/EgwAction.ts index 9c1be07dd6..e2f60fa1e9 100644 --- a/api/js/egw_action/EgwAction.ts +++ b/api/js/egw_action/EgwAction.ts @@ -13,8 +13,8 @@ import {IegwAppLocal} from "../jsapi/egw_global"; import {egw_getObjectManager} from "./egw_action"; export class EgwAction { - public readonly id: string; - private caption: string; + public id: string; + public caption: string; group: number; order: number; @@ -22,7 +22,7 @@ export class EgwAction { this.caption = _value; } - private iconUrl: string; + public iconUrl: string; public set_iconUrl(_value) { this.iconUrl = _value; @@ -39,7 +39,7 @@ export class EgwAction { this.allowOnMultiple = _value } - public readonly enabled: EgwFnct; + public enabled: EgwFnct; public set_enabled(_value) { this.enabled.setValue(_value); @@ -62,7 +62,7 @@ export class EgwAction { readonly parent: EgwAction; children: EgwAction[] = []; //i guess - private readonly onExecute = new EgwFnct(this, null, []); + public onExecute = new EgwFnct(this, null, []); /** * Set to either a confirmation prompt, or TRUE to indicate that this action @@ -382,7 +382,7 @@ export class EgwAction { * @param _target egwActionObject object, gets called for every object in _senders * @returns boolean true if none has disableClass, false otherwise */ - private not_disableClass(_action: EgwAction, _senders: any, _target: any) { + public not_disableClass(_action: EgwAction, _senders: any, _target: any) { if (_target.iface.getDOMNode()) { return !(_target.iface.getDOMNode()).classList.contains(_action.data.disableClass); } else if (_target.id) { @@ -404,7 +404,7 @@ export class EgwAction { * @returns boolean true if none has disableClass, false otherwise */ //TODO senders is never used in function body?? - private enableClass(_action: EgwAction, _senders: any[], _target: any) { + public enableClass(_action: EgwAction, _senders: any[], _target: any) { if (typeof _target == 'undefined') { return false; } else if (_target.iface.getDOMNode()) { @@ -428,7 +428,7 @@ export class EgwAction { * @param _target egwActionObject object, gets called for every object in _senders * @returns boolean true if _target.id matches _action.data.enableId */ - private enableId(_action: EgwAction, _senders: any[], _target: any) { + public enableId(_action: EgwAction, _senders: any[], _target: any) { if (typeof _action.data.enableId == 'string') { _action.data.enableId = new RegExp(_action.data.enableId); } @@ -482,7 +482,7 @@ export class EgwAction { * @param {type} _target * @returns {Boolean} */ - private _check_confirm_mass_selections(_senders, _target) { + public _check_confirm_mass_selections(_senders, _target) { const obj_manager: any = egw_getObjectManager(this.getManager().parent.id, false); if (!obj_manager) { return false; @@ -529,7 +529,7 @@ export class EgwAction { /** * Check to see if action needs to be confirmed by user before we do it */ - private _check_confirm(_senders, _target) { + public _check_confirm(_senders, _target) { // check if actions needs to be confirmed first if (this.data && (this.data.confirm || this.data.confirm_multiple) && this.onExecute.functionToPerform != window.nm_action && typeof window.Et2Dialog != 'undefined') // let old eTemplate run its own confirmation from nextmatch_action.js @@ -572,7 +572,7 @@ export class EgwAction { }; - private updateAction(_data: Object) { + public updateAction(_data: Object) { egwActionStoreJSON(_data, this, "data") } @@ -690,6 +690,14 @@ export class EgwAction { set_hint(hint: string) { } + public clone():EgwAction{ + const clone:EgwAction = Object.assign(Object.create(Object.getPrototypeOf(this)), this) + clone.onExecute = this.onExecute.clone() + if(this.enabled){ + clone.enabled = this.enabled.clone() + } + return clone + } } diff --git a/api/js/egw_action/EgwPopupActionImplementation.ts b/api/js/egw_action/EgwPopupActionImplementation.ts index e1fc77f263..f4f0f19704 100644 --- a/api/js/egw_action/EgwPopupActionImplementation.ts +++ b/api/js/egw_action/EgwPopupActionImplementation.ts @@ -697,9 +697,9 @@ export class EgwPopupActionImplementation implements EgwActionImplementation { //replace jQuery with spread operator // set the Prototype of the copy set_onExecute is not available otherwise //TODO is this a valid/elegant way to do this??? give egwAction a methode clone -- make abstract parent class - let drop_clone = {...drop[k].actionObj}; + let drop_clone = drop[k].actionObj.clone()//Object.assign(Object.create(Object.getPrototypeOf(drop[k].actionObj)), drop[k].actionObj) //{...drop[k].actionObj}; //warning This method is really slow - Object.setPrototypeOf(drop_clone, EgwAction.prototype) + //Object.setPrototypeOf(drop_clone, EgwAction.prototype) let parent = paste_action.parent === drop_clone.parent ? paste_action : (paste_action.getActionById(drop_clone.parent.id) || paste_action); drop_clone.parent = parent; drop_clone.onExecute = new EgwFnct(this, null, []); diff --git a/api/js/egw_action/egw_action_common.ts b/api/js/egw_action/egw_action_common.ts index 5eefd2eef3..459804b7bb 100755 --- a/api/js/egw_action/egw_action_common.ts +++ b/api/js/egw_action/egw_action_common.ts @@ -297,6 +297,9 @@ export class EgwFnct this.isDefault = false this.setValue(_default) } + public clone():EgwFnct{ + return new EgwFnct(this.context,this.functionToPerform || this.value, this.acceptedTypes); + } /** * @returns true iff there is a function to perform and is not default diff --git a/filemanager/js/filemanager.ts b/filemanager/js/filemanager.ts index b8fb293a6e..c46ee860eb 100644 --- a/filemanager/js/filemanager.ts +++ b/filemanager/js/filemanager.ts @@ -1130,7 +1130,7 @@ export class filemanagerAPP extends EgwApp }; for(let i = 0; i < actions.length; i++) { - _action.getActionById(actions[i].id).onExecute = jQuery.extend(true, {}, _action.onExecute); + _action.getActionById(actions[i].id).onExecute = _action.onExecute.clone(); _action.getActionById(actions[i].id).set_onExecute(paste_exec); }