2020-01-15 08:47:33 +01:00
|
|
|
/**
|
|
|
|
* EGroupware clientside Application javascript base object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
2021-06-07 17:33:53 +02:00
|
|
|
* @link https://www.egroupware.org
|
2020-01-15 08:47:33 +01:00
|
|
|
* @author Ralf Becker <rb@egroupware.org>
|
|
|
|
* @author Hadi Nategh <hn@groupware.org>
|
|
|
|
* @author Nathan Gray <ng@groupware.org>
|
|
|
|
*/
|
|
|
|
|
2020-05-10 14:52:47 +02:00
|
|
|
import {etemplate2} from "../etemplate/etemplate2";
|
2021-06-07 17:33:53 +02:00
|
|
|
import type {et2_container} from "../etemplate/et2_core_baseWidget";
|
2020-07-21 23:32:13 +02:00
|
|
|
import {et2_nextmatch} from "../etemplate/et2_extension_nextmatch";
|
|
|
|
import {et2_createWidget} from "../etemplate/et2_core_widget";
|
2021-06-07 17:33:53 +02:00
|
|
|
import type {IegwAppLocal} from "./egw_global";
|
2021-08-11 19:28:01 +02:00
|
|
|
import Sortable from 'sortablejs/modular/sortable.complete.esm.js';
|
2021-12-07 21:35:25 +01:00
|
|
|
import {et2_valueWidget} from "../etemplate/et2_core_valueWidget";
|
2022-03-17 23:18:39 +01:00
|
|
|
import {nm_action} from "../etemplate/et2_extension_nextmatch_actions";
|
|
|
|
import {Et2Dialog} from "../etemplate/Et2Dialog/Et2Dialog";
|
2022-08-07 12:09:02 +02:00
|
|
|
import {Et2Favorites} from "../etemplate/Et2Favorites/Et2Favorites";
|
2023-07-10 16:02:30 +02:00
|
|
|
import {EgwAction} from "../egw_action/EgwAction";
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2020-01-24 13:31:56 +01:00
|
|
|
/**
|
|
|
|
* Type for push-message
|
|
|
|
*/
|
|
|
|
export interface PushData
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
type : "add" | "edit" | "update" | "delete" | "unknown";
|
|
|
|
app : string; // app-name, can include a subtype eg. "projectmanager-element"
|
|
|
|
id : string | number;
|
|
|
|
acl? : any; // app-specific acl data, eg. the owner, or array of participants
|
|
|
|
account_id : number; // user that caused the change
|
|
|
|
[propName : string] : any; // arbitrary more parameters
|
2020-01-24 13:31:56 +01:00
|
|
|
}
|
|
|
|
|
2020-01-15 08:47:33 +01:00
|
|
|
/**
|
|
|
|
* Common base class for application javascript
|
|
|
|
* Each app should extend as needed.
|
|
|
|
*
|
|
|
|
* All application javascript should be inside. Intitialization goes in init(),
|
|
|
|
* clean-up code goes in destroy(). Initialization is done once all js is loaded.
|
|
|
|
*
|
|
|
|
* var app.appname = AppJS.extend({
|
|
|
|
* // Actually set this one, the rest is example
|
|
|
|
* appname: appname,
|
|
|
|
*
|
|
|
|
* internal_var: 1000,
|
|
|
|
*
|
|
|
|
* init: function()
|
|
|
|
* {
|
|
|
|
* // Call the super
|
|
|
|
* this._super.apply(this, arguments);
|
|
|
|
*
|
|
|
|
* // Init the stuff
|
|
|
|
* if ( egw.preference('dateformat', 'common') )
|
|
|
|
* {
|
|
|
|
* // etc
|
|
|
|
* }
|
|
|
|
* },
|
|
|
|
* _private: function()
|
|
|
|
* {
|
|
|
|
* // Underscore private by convention
|
|
|
|
* }
|
|
|
|
* });
|
|
|
|
*/
|
|
|
|
export abstract class EgwApp
|
|
|
|
{
|
|
|
|
/**
|
2020-07-21 23:32:13 +02:00
|
|
|
* Internal application name - pass this in constructor
|
2020-01-15 08:47:33 +01:00
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
readonly appname : string;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal reference to the most recently loaded etemplate2 widget tree
|
|
|
|
*
|
|
|
|
* NOTE: This variable can change which etemplate it points to as the user
|
|
|
|
* works. For example, loading the home or admin apps can cause
|
|
|
|
* et2_ready() to be called again with a different template. this.et2 will
|
|
|
|
* then point to a different template. If the user then closes that tab,
|
|
|
|
* this.et2 will point to a destroyed object, and trying to use it will fail.
|
|
|
|
*
|
|
|
|
* If you need a reference to a certain template you can either store a local
|
|
|
|
* reference or access it through etemplate2.
|
|
|
|
*
|
|
|
|
* @example <caption>Store a local reference</caption>
|
|
|
|
* // in et2_ready()
|
|
|
|
* if(name == 'index') this.index_et2 = et2.widgetContainer;
|
|
|
|
*
|
|
|
|
* // Remember to clean up in destroy()
|
|
|
|
* delete this.index_et2;
|
|
|
|
*
|
|
|
|
* // Instead of this.et2, using a local reference
|
|
|
|
* this.index_et2 ...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @example <caption>Access via etemplate2 object</caption>
|
2022-10-24 17:57:35 +02:00
|
|
|
* // Instead of this.et2, using its unique ID
|
2020-07-21 23:32:13 +02:00
|
|
|
* var et2 = etemplate2.getById("myapp-index")
|
2020-01-15 08:47:33 +01:00
|
|
|
* if(et2)
|
|
|
|
* {
|
|
|
|
* et2.widgetContainer. ...
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @var {et2_container}
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
et2 : et2_container;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal reference to egw client-side api object for current app and window
|
|
|
|
*
|
|
|
|
* @var {egw}
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
egw : IegwAppLocal;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
sidebox : JQuery;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
viewContainer : JQuery;
|
|
|
|
viewTemplate : JQuery;
|
|
|
|
et2_view : any;
|
2020-01-15 08:47:33 +01:00
|
|
|
favorite_popup : JQuery | any;
|
|
|
|
|
|
|
|
dom_id : string;
|
|
|
|
|
|
|
|
mailvelopeSyncHandlerObj : any;
|
|
|
|
|
2020-04-21 23:36:17 +02:00
|
|
|
/**
|
|
|
|
* In some cases (CRM) a private, disconnected app instance is created instead of
|
|
|
|
* using the global. We want to be able to access them for observer() & push(), so
|
|
|
|
* we track all instances.
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
static _instances : EgwApp[] = [];
|
2020-04-21 23:36:17 +02:00
|
|
|
|
2021-02-24 17:18:42 +01:00
|
|
|
/**
|
|
|
|
* If pushData.acl has fields that can help filter based on ACL grants, list them
|
|
|
|
* here and we can check them and ignore push messages if there is no ACL for that entry
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
protected push_grant_fields : string[];
|
2021-02-24 17:18:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If pushData.acl has fields that can help filter based on current nextmatch filters,
|
|
|
|
* list them here and we can check and ignore push messages if the nextmatch filters do not exclude them
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
protected push_filter_fields : string[];
|
2021-02-24 17:18:42 +01:00
|
|
|
|
2020-01-15 08:47:33 +01:00
|
|
|
/**
|
|
|
|
* Initialization and setup goes here, but the etemplate2 object
|
|
|
|
* is not yet ready.
|
|
|
|
*/
|
2022-09-08 11:27:02 +02:00
|
|
|
constructor(appname : string, _wnd? : Window)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2020-03-20 18:38:38 +01:00
|
|
|
this.appname = appname;
|
2022-09-08 11:27:02 +02:00
|
|
|
this.egw = egw(this.appname, _wnd || window);
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// Initialize sidebox for non-popups.
|
|
|
|
// ID set server side
|
|
|
|
if(!this.egw.is_popup())
|
|
|
|
{
|
2020-03-20 18:38:38 +01:00
|
|
|
var sidebox = jQuery('#favorite_sidebox_' + this.appname);
|
2020-01-15 08:47:33 +01:00
|
|
|
if(sidebox.length == 0 && egw_getFramework() != null)
|
|
|
|
{
|
|
|
|
var egw_fw = egw_getFramework();
|
2021-12-07 21:35:25 +01:00
|
|
|
sidebox = jQuery('#favorite_sidebox_' + this.appname, egw_fw.sidemenuDiv);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
// Make sure we're running in the top window when we init sidebox
|
|
|
|
//@ts-ignore
|
2020-05-18 20:55:57 +02:00
|
|
|
if(window.app[this.appname] === this && egw.top.app[this.appname] !== this && egw.top.app[this.appname])
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
//@ts-ignore
|
2020-05-18 20:55:57 +02:00
|
|
|
egw.top.app[this.appname]._init_sidebox(sidebox);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._init_sidebox(sidebox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mailvelopeSyncHandlerObj = this.mailvelopeSyncHandler();
|
2020-04-21 23:36:17 +02:00
|
|
|
|
|
|
|
// Keep track of this instance
|
|
|
|
EgwApp._register_instance(this);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up any created objects & references
|
|
|
|
* @param {object} _app local app object
|
|
|
|
*/
|
|
|
|
destroy(_app)
|
|
|
|
{
|
|
|
|
delete this.et2;
|
2021-12-07 21:35:25 +01:00
|
|
|
if(this.sidebox)
|
2020-01-15 08:47:33 +01:00
|
|
|
this.sidebox.off();
|
|
|
|
delete this.sidebox;
|
|
|
|
if (!_app) delete app[this.appname];
|
2020-04-21 23:36:17 +02:00
|
|
|
let index = -1;
|
|
|
|
if((index = EgwApp._instances.indexOf(this)) >= 0)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
EgwApp._instances.splice(index, 1);
|
2020-04-21 23:36:17 +02:00
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is called when the etemplate2 object is loaded
|
|
|
|
* and ready. If you must store a reference to the et2 object,
|
|
|
|
* make sure to clean it up in destroy(). Note that this can be called
|
|
|
|
* several times, with different et2 objects, as templates are loaded.
|
|
|
|
*
|
|
|
|
* @param {etemplate2} et2
|
|
|
|
* @param {string} name template name
|
|
|
|
*/
|
2020-05-10 14:52:47 +02:00
|
|
|
et2_ready(et2 : etemplate2, name : string)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
if(this.et2 !== null)
|
|
|
|
{
|
|
|
|
egw.debug('log', "Changed et2 object");
|
|
|
|
}
|
|
|
|
this.et2 = et2.widgetContainer;
|
|
|
|
this._fix_iFrameScrolling();
|
2021-12-07 21:35:25 +01:00
|
|
|
if(this.egw && this.egw.is_popup())
|
2021-01-27 12:26:37 +01:00
|
|
|
{
|
|
|
|
this._set_Window_title();
|
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// Highlights the favorite based on initial list state
|
|
|
|
this.highlight_favorite();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Observer method receives update notifications from all applications
|
|
|
|
*
|
|
|
|
* App is responsible for only reacting to "messages" it is interested in!
|
|
|
|
*
|
|
|
|
* @param {string} _msg message (already translated) to show, eg. 'Entry deleted'
|
|
|
|
* @param {string} _app application name
|
|
|
|
* @param {(string|number)} _id id of entry to refresh or null
|
|
|
|
* @param {string} _type either 'update', 'edit', 'delete', 'add' or null
|
|
|
|
* - update: request just modified data from given rows. Sorting is not considered,
|
|
|
|
* so if the sort field is changed, the row will not be moved.
|
|
|
|
* - edit: rows changed, but sorting may be affected. Requires full reload.
|
|
|
|
* - delete: just delete the given rows clientside (no server interaction neccessary)
|
|
|
|
* - add: requires full reload for proper sorting
|
|
|
|
* @param {string} _msg_type 'error', 'warning' or 'success' (default)
|
|
|
|
* @param {object|null} _links app => array of ids of linked entries
|
|
|
|
* or null, if not triggered on server-side, which adds that info
|
|
|
|
* @return {false|*} false to stop regular refresh, thought all observers are run
|
|
|
|
*/
|
|
|
|
observer(_msg, _app, _id, _type, _msg_type, _links)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-23 19:03:29 +01:00
|
|
|
* Handle a push notification about entry changes from the websocket
|
2020-01-15 08:47:33 +01:00
|
|
|
*
|
2022-10-24 17:57:35 +02:00
|
|
|
* Gets called for data of all apps, but should only handle data of apps it displays,
|
|
|
|
* which is by default only its own, but can be for multiple apps eg. for calendar.
|
2020-01-24 13:31:56 +01:00
|
|
|
*
|
2020-01-23 19:03:29 +01:00
|
|
|
* @param pushData
|
|
|
|
* @param {string} pushData.app application name
|
|
|
|
* @param {(string|number)} pushData.id id of entry to refresh or null
|
|
|
|
* @param {string} pushData.type either 'update', 'edit', 'delete', 'add' or null
|
2020-01-15 08:47:33 +01:00
|
|
|
* - update: request just modified data from given rows. Sorting is not considered,
|
|
|
|
* so if the sort field is changed, the row will not be moved.
|
|
|
|
* - edit: rows changed, but sorting may be affected. Requires full reload.
|
|
|
|
* - delete: just delete the given rows clientside (no server interaction neccessary)
|
|
|
|
* - add: requires full reload for proper sorting
|
2020-01-23 19:03:29 +01:00
|
|
|
* @param {object|null} pushData.acl Extra data for determining relevance. eg: owner or responsible to decide if update is necessary
|
|
|
|
* @param {number} pushData.account_id User that caused the notification
|
2020-01-15 08:47:33 +01:00
|
|
|
*/
|
2020-01-24 13:31:56 +01:00
|
|
|
push(pushData : PushData)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2020-01-24 13:31:56 +01:00
|
|
|
// don't care about other apps data, reimplement if your app does care eg. calendar
|
2021-12-07 21:35:25 +01:00
|
|
|
if(pushData.app !== this.appname)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-01-24 13:31:56 +01:00
|
|
|
|
2021-02-24 17:18:42 +01:00
|
|
|
// handle delete, for simple case of uid === "$app::$id"
|
2021-12-07 21:35:25 +01:00
|
|
|
if(pushData.type === 'delete' && egw.dataHasUID(this.uid(pushData)))
|
2020-01-23 11:26:44 +01:00
|
|
|
{
|
2020-08-05 18:26:40 +02:00
|
|
|
egw.refresh('', pushData.app, pushData.id, 'delete');
|
2021-02-24 17:18:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we know about it and it's an update, just update.
|
|
|
|
// This must be before all ACL checks, as responsible might have changed and entry need to be removed
|
|
|
|
// (server responds then with null / no entry causing the entry to disappear)
|
2021-12-07 21:35:25 +01:00
|
|
|
if(pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData)) && this.et2)
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
|
|
|
return this.et2.getInstanceManager().refresh("", pushData.app, pushData.id, pushData.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check grants to see if we know we aren't supposed to show it
|
|
|
|
if(typeof this.push_grant_fields !== "undefined" && this.push_grant_fields.length > 0
|
|
|
|
&& !this._push_grant_check(pushData, this.push_grant_fields)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nextmatch does the hard part of updating. Try to find one.
|
2021-03-04 21:53:52 +01:00
|
|
|
let nm = <et2_nextmatch>this.et2?.getDOMWidgetById('nm');
|
2021-02-24 17:18:42 +01:00
|
|
|
if(!nm)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter what's allowed down to those we can see / care about based on nm filters
|
|
|
|
if(typeof this.push_filter_fields !== "undefined" && this.push_filter_fields.length > 0 &&
|
|
|
|
!this._push_field_filter(pushData, nm, this.push_filter_fields)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass actual refresh on to just nextmatch
|
|
|
|
nm.refresh(pushData.id, pushData.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check grants to see if we can quickly tell if this entry is not for us
|
|
|
|
*
|
|
|
|
* Override this method if the app has non-standard access control.
|
|
|
|
*
|
|
|
|
* @param pushData
|
|
|
|
* @param grant_fields List of fields in pushData.acl with account IDs that might grant access eg: info_responsible
|
2021-03-04 19:27:35 +01:00
|
|
|
* @param appname Optional, to check against the grants for a different application. Defaults to this.appname.
|
|
|
|
*
|
|
|
|
* @return boolean Entry has ACL access
|
2021-02-24 17:18:42 +01:00
|
|
|
*/
|
2021-03-04 19:27:35 +01:00
|
|
|
_push_grant_check(pushData : PushData, grant_fields : string[], appname? : string) : boolean
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
2021-03-04 19:27:35 +01:00
|
|
|
let grants = egw.grants(appname || this.appname);
|
2021-02-24 17:18:42 +01:00
|
|
|
|
2021-02-24 22:28:17 +01:00
|
|
|
// No grants known
|
2021-12-07 21:35:25 +01:00
|
|
|
if(!grants)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-24 22:28:17 +01:00
|
|
|
|
2021-02-24 17:18:42 +01:00
|
|
|
// check user has a grant from owner or something
|
|
|
|
for(let i = 0; i < grant_fields.length; i++)
|
|
|
|
{
|
2021-02-24 22:28:17 +01:00
|
|
|
let grant_field = pushData.acl[grant_fields[i]];
|
2021-12-07 21:35:25 +01:00
|
|
|
if(["number", "string"].indexOf(typeof grant_field) >= 0 && grants[grant_field] !== 'undefined')
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
|
|
|
// ACL access
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(!Object.keys(grants).filter(function(grant_account)
|
|
|
|
{
|
2021-02-24 22:28:17 +01:00
|
|
|
return grant_field.indexOf(grant_account) >= 0 ||
|
|
|
|
grant_field.indexOf(parseInt(grant_account)).length
|
|
|
|
}))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-24 17:18:42 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check pushData.acl values against a list of fields to see if we care about this entry based on current nextmatch
|
|
|
|
* filter values. This is not a definitive yes or no (the server will tell us when we ask), we just want to cheaply
|
|
|
|
* avoid a server call if we know it won't be in the list.
|
|
|
|
*
|
|
|
|
* @param pushData
|
|
|
|
* @param filter_fields List of filter field names eg: [owner, cat_id]
|
|
|
|
* @return boolean True if the nextmatch filters might include the entry, false if not
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
_push_field_filter(pushData : PushData, nm : et2_nextmatch, filter_fields : string[]) : boolean
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
|
|
|
let filters = {};
|
|
|
|
for(let i = 0; i < filter_fields.length; i++)
|
|
|
|
{
|
|
|
|
filters[filter_fields[i]] = {
|
|
|
|
col: filter_fields[i],
|
|
|
|
filter_values: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get current filter values
|
2021-02-25 21:59:32 +01:00
|
|
|
let value = nm.getValue();
|
|
|
|
if(!value || !value.col_filter) return false;
|
2021-02-24 17:18:42 +01:00
|
|
|
|
2021-02-25 21:59:32 +01:00
|
|
|
for(let field_filter of Object.values(filters))
|
|
|
|
{
|
|
|
|
let val = value.col_filter[field_filter.col];
|
|
|
|
if(val && (
|
2021-06-08 21:31:32 +02:00
|
|
|
typeof val == "string" && val.trim().length > 0
|
2021-02-25 21:59:32 +01:00
|
|
|
))
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
2021-02-25 21:59:32 +01:00
|
|
|
field_filter.filter_values.push(val);
|
2021-02-24 17:18:42 +01:00
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(val && typeof val == "object" && !jQuery.isEmptyObject(val))
|
2021-06-08 21:31:32 +02:00
|
|
|
{
|
|
|
|
field_filter.filter_values = field_filter.filter_values.concat(Object.values(val))
|
|
|
|
}
|
2021-02-24 17:18:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check filters against pushData.acl data
|
|
|
|
for(let field_filter of Object.values(filters))
|
|
|
|
{
|
|
|
|
// no filter set
|
|
|
|
if (field_filter.filter_values.length == 0) continue;
|
|
|
|
|
|
|
|
// acl value is a scalar (not array) --> check contained in filter
|
2021-12-07 21:35:25 +01:00
|
|
|
if(pushData.acl && typeof pushData.acl[field_filter.col] !== 'object')
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
if(field_filter.filter_values.indexOf(pushData.acl[field_filter.col]) < 0)
|
2021-02-24 17:18:42 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// acl value is an array (eg. tr_assigned) --> check intersection with filter
|
|
|
|
if(!field_filter.filter_values.filter(account => pushData.acl[field_filter.col].indexOf(account) >= 0).length)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-24 13:31:56 +01:00
|
|
|
}
|
2021-02-24 17:18:42 +01:00
|
|
|
return true;
|
2020-01-24 13:31:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get (possible) app-specific uid
|
|
|
|
*
|
|
|
|
* @param {object} pushData see push method for individual attributes
|
|
|
|
*/
|
|
|
|
uid(pushData)
|
|
|
|
{
|
|
|
|
return pushData.app + '::' + pushData.id;
|
|
|
|
}
|
|
|
|
|
2020-01-15 08:47:33 +01:00
|
|
|
/**
|
|
|
|
* Open an entry.
|
|
|
|
*
|
|
|
|
* Designed to be used with the action system as a callback
|
|
|
|
* eg: onExecute => app.<appname>.open
|
|
|
|
*
|
|
|
|
* @param _action
|
|
|
|
* @param _senders
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
open(_action, _senders)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var id_app = _senders[0].id.split('::');
|
|
|
|
egw.open(id_app[1], this.appname);
|
|
|
|
}
|
|
|
|
|
|
|
|
_do_action(action_id : string, selected : [])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A generic method to action to server asynchronously
|
|
|
|
*
|
|
|
|
* Designed to be used with the action system as a callback.
|
|
|
|
* In the PHP side, set the action
|
|
|
|
* 'onExecute' => 'javaScript:app.<appname>.action', and
|
|
|
|
* implement _do_action(action_id, selected)
|
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {egwActionObject[]} _elems
|
|
|
|
*/
|
|
|
|
action(_action, _elems)
|
|
|
|
{
|
|
|
|
// let user confirm select-all
|
|
|
|
var select_all = _action.getManager().getActionById("select_all");
|
|
|
|
var confirm_msg = (_elems.length > 1 || select_all && select_all.checked) &&
|
2021-12-07 21:35:25 +01:00
|
|
|
typeof _action.data.confirm_multiple != 'undefined' ?
|
|
|
|
_action.data.confirm_multiple : _action.data.confirm;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
if(typeof confirm_msg != 'undefined')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
var that = this;
|
|
|
|
var action_id = _action.id;
|
2022-03-17 23:18:39 +01:00
|
|
|
Et2Dialog.show_dialog(function(button_id, value)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-03-17 23:18:39 +01:00
|
|
|
if(button_id != Et2Dialog.NO_BUTTON)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
that._do_action(action_id, _elems);
|
|
|
|
}
|
2022-03-17 23:18:39 +01:00
|
|
|
}, confirm_msg, 'Confirmation required', null, Et2Dialog.BUTTONS_YES_NO, Et2Dialog.QUESTION_MESSAGE);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(typeof this._do_action == 'function')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
this._do_action(_action.id, _elems);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If this is a nextmatch action, do an ajax submit setting the action
|
|
|
|
var nm = null;
|
|
|
|
var action = _action;
|
|
|
|
while(nm == null && action.parent != null)
|
|
|
|
{
|
|
|
|
if(action.data.nextmatch) nm = action.data.nextmatch;
|
|
|
|
action = action.parent;
|
|
|
|
}
|
|
|
|
if(nm != null)
|
|
|
|
{
|
|
|
|
var value = {};
|
|
|
|
value[nm.options.settings.action_var] = _action.id;
|
|
|
|
nm.set_value(value);
|
|
|
|
nm.getInstanceManager().submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the application's state to the given state.
|
|
|
|
*
|
|
|
|
* While not pretending to implement the history API, it is patterned similarly
|
|
|
|
* @link http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html
|
|
|
|
*
|
|
|
|
* The default implementation works with the favorites to apply filters to a nextmatch.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {{name: string, state: object}|string} state Object (or JSON string) for a state.
|
|
|
|
* Only state is required, and its contents are application specific.
|
|
|
|
* @param {string} template template name to check, instead of trying all templates of current app
|
|
|
|
* @return {boolean} false - Returns false to stop event propagation
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
setState(state, template? : string) : string | false | void
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
// State should be an object, not a string, but we'll parse
|
|
|
|
if(typeof state == "string")
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
if(state.indexOf('{') != -1 || state == 'null')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
state = JSON.parse(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(typeof state != "object")
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
egw.debug('error', 'Unable to set state to %o, needs to be an object', state);
|
2020-01-15 08:47:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(state == null)
|
|
|
|
{
|
|
|
|
state = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for egw.open() parameters
|
|
|
|
if(state.state && state.state.id && state.state.app)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
return egw.open(state.state, undefined, undefined, {}, '_self');
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try and find a nextmatch widget, and set its filters
|
|
|
|
var nextmatched = false;
|
|
|
|
var et2 = template ? etemplate2.getByTemplate(template) : etemplate2.getByApplication(this.appname);
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
et2[i].widgetContainer.iterateOver(function(_widget)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
// Firefox has trouble with spaces in search
|
|
|
|
if(state.state && state.state.search) state.state.search = unescape(state.state.search);
|
|
|
|
|
|
|
|
// Apply
|
|
|
|
if(state.state && state.state.sort && state.state.sort.id)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
_widget.sortBy(state.state.sort.id, state.state.sort.asc, false);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2020-11-16 18:57:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not using resetSort() to avoid the extra applyFilters() call
|
2021-12-07 21:35:25 +01:00
|
|
|
_widget.sortBy(undefined, undefined, false);
|
2020-11-16 18:57:04 +01:00
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
if(state.state && state.state.selectcols)
|
|
|
|
{
|
|
|
|
// Make sure it's a real array, not an object, then set cols
|
2021-12-07 21:35:25 +01:00
|
|
|
_widget.set_columns(jQuery.extend([], state.state.selectcols));
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
_widget.applyFilters(state.state || state.filter || {});
|
|
|
|
nextmatched = true;
|
|
|
|
}, this, et2_nextmatch);
|
|
|
|
if(nextmatched) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'blank' is the special name for no filters, send that instead of the nice translated name
|
2021-12-07 21:35:25 +01:00
|
|
|
var safe_name = jQuery.isEmptyObject(state) || jQuery.isEmptyObject(state.state || state.filter) ? 'blank' : state.name.replace(/[^A-Za-z0-9-_]/g, '_');
|
|
|
|
var url = '/' + this.appname + '/index.php';
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// Try a redirect to list, if app defines a "list" value in registry
|
2021-12-07 21:35:25 +01:00
|
|
|
if(egw.link_get_registry(this.appname, 'list'))
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
url = egw.link('/index.php', jQuery.extend({'favorite': safe_name}, egw.link_get_registry(this.appname, 'list')));
|
|
|
|
}
|
|
|
|
// if no list try index value from application
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(egw.app(this.appname)?.index)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
url = egw.link('/index.php', 'menuaction=' + egw.app(this.appname).index + '&favorite=' + safe_name);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
egw.open_link(url, undefined, undefined, this.appname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the current state of the application for future restoration
|
|
|
|
*
|
|
|
|
* The state can be anything, as long as it's an object. The contents are
|
|
|
|
* application specific. The default implementation finds a nextmatch and
|
|
|
|
* returns its value.
|
|
|
|
* The return value of this function cannot be passed directly to setState(),
|
|
|
|
* since setState is expecting an additional wrapper, eg:
|
|
|
|
* {name: 'something', state: getState()}
|
|
|
|
*
|
|
|
|
* @return {object} Application specific map representing the current state
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
getState() : { [propName : string] : any }
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
var state = {};
|
|
|
|
|
|
|
|
// Try and find a nextmatch widget, and set its filters
|
|
|
|
var et2 = etemplate2.getByApplication(this.appname);
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
et2[i].widgetContainer.iterateOver(function(_widget)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
state = _widget.getValue();
|
|
|
|
}, this, et2_nextmatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to load selected row from nm into a template view
|
|
|
|
*
|
|
|
|
* @param {object} _action
|
|
|
|
* @param {object} _senders
|
|
|
|
* @param {boolean} _noEdit defines whether to set edit button or not default is false
|
|
|
|
* @param {function} et2_callback function to run after et2 is loaded
|
|
|
|
*/
|
2020-03-09 16:12:49 +01:00
|
|
|
viewEntry(_action, _senders, _noEdit?, et2_callback?)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
//full id in nm
|
|
|
|
var id = _senders[0].id;
|
|
|
|
// flag for edit button
|
|
|
|
var noEdit = _noEdit || false;
|
|
|
|
// nm row id
|
|
|
|
var rowID = '';
|
|
|
|
// content to feed to etemplate2
|
2021-12-07 21:35:25 +01:00
|
|
|
var content : any = {};
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
if(id)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var parts = id.split('::');
|
|
|
|
rowID = parts[1];
|
|
|
|
content = egw.dataGetUIDdata(id);
|
|
|
|
if (content.data) content = content.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a new app object with just constructors for our new etemplate2 object
|
2021-12-07 21:35:25 +01:00
|
|
|
var app = {classes: window.app.classes};
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
/* destroy generated etemplate for view mode in DOM*/
|
2021-12-07 21:35:25 +01:00
|
|
|
var destroy = function()
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
self.viewContainer.remove();
|
|
|
|
delete self.viewTemplate;
|
|
|
|
delete self.viewContainer;
|
|
|
|
delete self.et2_view;
|
|
|
|
// we need to reference back into parent context this
|
2021-12-07 21:35:25 +01:00
|
|
|
for(var v in self)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
this[v] = self[v];
|
|
|
|
}
|
|
|
|
app = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
// view container
|
|
|
|
this.viewContainer = jQuery(document.createElement('div'))
|
2021-12-07 21:35:25 +01:00
|
|
|
.addClass('et2_mobile_view')
|
|
|
|
.css({
|
|
|
|
"z-index": 102,
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
background: "white",
|
|
|
|
display: 'block',
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
overflow: 'auto'
|
|
|
|
})
|
|
|
|
.attr('id', 'popupMainDiv')
|
|
|
|
.appendTo('body');
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// close button
|
|
|
|
var close = jQuery(document.createElement('span'))
|
2021-12-07 21:35:25 +01:00
|
|
|
.addClass('egw_fw_mobile_popup_close loaded')
|
|
|
|
.click(function()
|
|
|
|
{
|
|
|
|
destroy.call(app[self.appname]);
|
|
|
|
//disable selected actions after close
|
|
|
|
egw_globalObjectManager.setAllSelected(false);
|
|
|
|
})
|
|
|
|
.appendTo(this.viewContainer);
|
|
|
|
if(!noEdit)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
// edit button
|
|
|
|
var edit = jQuery(document.createElement('span'))
|
2021-12-07 21:35:25 +01:00
|
|
|
.addClass('mobile-view-editBtn')
|
|
|
|
.click(function()
|
|
|
|
{
|
|
|
|
egw.open(rowID, self.appname);
|
|
|
|
})
|
|
|
|
.appendTo(this.viewContainer);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
// view template main container (content)
|
|
|
|
this.viewTemplate = jQuery(document.createElement('div'))
|
2021-12-07 21:35:25 +01:00
|
|
|
.attr('id', this.appname + '-view')
|
|
|
|
.addClass('et2_mobile-view-container popupMainDiv')
|
|
|
|
.appendTo(this.viewContainer);
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
var mobileViewTemplate = (_action.data.mobileViewTemplate || 'edit').split('?');
|
2020-01-15 08:47:33 +01:00
|
|
|
var templateName = mobileViewTemplate[0];
|
|
|
|
var templateTimestamp = mobileViewTemplate[1];
|
2021-12-07 21:35:25 +01:00
|
|
|
var templateURL = egw.webserverUrl + '/' + this.appname + '/templates/mobile/' + templateName + '.xet' + '?' + templateTimestamp;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
'content': content,
|
2021-12-07 21:35:25 +01:00
|
|
|
'readonlys': {'__ALL__': true, 'link_to': false},
|
2020-01-15 08:47:33 +01:00
|
|
|
'currentapp': this.appname,
|
|
|
|
'langRequire': this.et2.getArrayMgr('langRequire').data,
|
|
|
|
'sel_options': this.et2.getArrayMgr('sel_options').data,
|
|
|
|
'modifications': this.et2.getArrayMgr('modifications').data,
|
|
|
|
'validation_errors': this.et2.getArrayMgr('validation_errors').data
|
|
|
|
};
|
|
|
|
|
|
|
|
// etemplate2 object for view
|
2021-12-07 21:35:25 +01:00
|
|
|
this.et2_view = new etemplate2(this.viewTemplate[0], '');
|
2020-01-15 08:47:33 +01:00
|
|
|
framework.pushState('view');
|
|
|
|
if(templateName)
|
|
|
|
{
|
2021-09-29 01:00:55 +02:00
|
|
|
this.et2_view.load(this.appname + '.' + templateName, templateURL, data, typeof et2_callback == 'function' ? et2_callback : function() {}, app);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// define a global close function for view template
|
|
|
|
// in order to be able to destroy view on action
|
|
|
|
this.et2_view.close = destroy;
|
|
|
|
}
|
|
|
|
|
2023-07-11 13:38:09 +02:00
|
|
|
/**
|
|
|
|
* Opens _menuaction in an Et2Dialog
|
|
|
|
*
|
2023-07-14 00:18:11 +02:00
|
|
|
* Equivalent to egw.openDialog, though this one works in popups too.
|
2023-07-13 15:22:21 +02:00
|
|
|
*
|
2023-07-11 13:38:09 +02:00
|
|
|
* @param _menuaction
|
2023-07-14 00:18:11 +02:00
|
|
|
* @return Promise<Et2Dialog>
|
2023-07-11 13:38:09 +02:00
|
|
|
*/
|
2023-07-14 08:54:07 +02:00
|
|
|
openDialog(_menuaction : string) : Promise<Et2Dialog>
|
2023-07-11 13:38:09 +02:00
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
let resolver;
|
|
|
|
let rejector;
|
|
|
|
const dialog_promise = new Promise((resolve, reject) =>
|
|
|
|
{
|
|
|
|
resolver = value => resolve(value);
|
|
|
|
rejector = reason => reject(reason);
|
|
|
|
});
|
|
|
|
let request = this.egw.json(_menuaction.match(/^([^.:]+)/)[0] + '.jdots_framework.ajax_exec.template.' + _menuaction,
|
2023-07-13 15:22:21 +02:00
|
|
|
['index.php?menuaction=' + _menuaction, true], _response =>
|
2023-07-11 13:38:09 +02:00
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
if(Array.isArray(_response) && typeof _response[0] === 'string')
|
2023-07-11 13:38:09 +02:00
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
let dialog = jQuery(_response[0]).appendTo(document.body);
|
|
|
|
if(dialog.length > 0 && dialog.get(0))
|
|
|
|
{
|
|
|
|
resolver(dialog.get(0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log("Unable to add dialog with dialogExec('" + _menuaction + "')", _response);
|
|
|
|
rejector(new Error("Unable to add dialog"));
|
|
|
|
}
|
2023-07-11 13:38:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
console.log("Invalid response to dialogExec('" + _menuaction + "')", _response);
|
|
|
|
rejector(new Error("Invalid response to dialogExec('" + _menuaction + "')"));
|
2023-07-11 13:38:09 +02:00
|
|
|
}
|
2023-07-13 15:22:21 +02:00
|
|
|
}).sendRequest();
|
2023-07-14 00:18:11 +02:00
|
|
|
return dialog_promise;
|
2023-07-11 13:38:09 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 01:00:55 +02:00
|
|
|
/**
|
|
|
|
* Merge selected entries into template document
|
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {egwActionObject[]} _selected
|
|
|
|
*/
|
|
|
|
merge(_action : egwAction, _selected : egwActionObject[])
|
|
|
|
{
|
|
|
|
// Find what we need
|
|
|
|
let nm = null;
|
|
|
|
let action = _action;
|
2021-10-18 17:42:12 +02:00
|
|
|
let as_pdf = null;
|
2021-09-29 01:00:55 +02:00
|
|
|
|
|
|
|
// Find Select all
|
2021-10-18 17:42:12 +02:00
|
|
|
while(nm == null && action.parent != null)
|
2021-09-29 01:00:55 +02:00
|
|
|
{
|
|
|
|
if(action.data != null && action.data.nextmatch)
|
|
|
|
{
|
|
|
|
nm = action.data.nextmatch;
|
|
|
|
}
|
2021-10-18 17:42:12 +02:00
|
|
|
if(as_pdf === null && action.getActionById('as_pdf') !== null)
|
|
|
|
{
|
|
|
|
as_pdf = action.getActionById('as_pdf').checked;
|
|
|
|
}
|
2021-09-29 01:00:55 +02:00
|
|
|
action = action.parent;
|
|
|
|
}
|
|
|
|
let all = nm?.getSelection().all || false;
|
|
|
|
|
2021-10-18 17:42:12 +02:00
|
|
|
as_pdf = as_pdf || false;
|
2021-09-29 01:00:55 +02:00
|
|
|
|
|
|
|
// Get list of entry IDs
|
|
|
|
let ids = [];
|
|
|
|
for(let i = 0; !all && i < _selected.length; i++)
|
|
|
|
{
|
|
|
|
let split = _selected[i].id.split("::");
|
|
|
|
ids.push(split[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
let vars = {
|
|
|
|
..._action.data.merge_data,
|
|
|
|
pdf: as_pdf,
|
|
|
|
select_all: all,
|
|
|
|
id: JSON.stringify(ids)
|
|
|
|
};
|
|
|
|
egw.open_link(egw.link('/index.php', vars), '_blank');
|
|
|
|
}
|
|
|
|
|
2020-01-15 08:47:33 +01:00
|
|
|
/**
|
|
|
|
* Initializes actions and handlers on sidebox (delete)
|
|
|
|
*
|
|
|
|
* @param {jQuery} sidebox jQuery of DOM node
|
|
|
|
*/
|
|
|
|
_init_sidebox(sidebox)
|
|
|
|
{
|
2022-09-12 13:24:00 +02:00
|
|
|
|
2020-01-15 08:47:33 +01:00
|
|
|
if(sidebox.length)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
if(this.sidebox) this.sidebox.off();
|
|
|
|
this.sidebox = sidebox;
|
|
|
|
sidebox
|
|
|
|
.off()
|
|
|
|
// removed .on("mouse(enter|leave)" (wrapping trash icon), as it stalls delete in IE11
|
2021-12-07 21:35:25 +01:00
|
|
|
.on("click.sidebox", "div.ui-icon-trash", this, this.delete_favorite)
|
2020-01-15 08:47:33 +01:00
|
|
|
// need to install a favorite handler, as we switch original one off with .off()
|
2021-12-07 21:35:25 +01:00
|
|
|
.on('click.sidebox', 'li[data-id]', this, function(event)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var li = jQuery(this);
|
|
|
|
li.siblings().removeClass('ui-state-highlight');
|
|
|
|
|
|
|
|
var state = {};
|
|
|
|
var pref = egw.preference('favorite_' + this.dataset.id, self.appname);
|
|
|
|
if(pref)
|
|
|
|
{
|
|
|
|
// Extend, to prevent changing the preference by reference
|
|
|
|
jQuery.extend(true, state, pref);
|
|
|
|
}
|
|
|
|
if(this.dataset.id != 'add')
|
|
|
|
{
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
self.setState.call(self, state);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.addClass("ui-helper-clearfix");
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
let el = document.getElementById('favorite_sidebox_' + this.appname)?.getElementsByTagName('ul')[0];
|
|
|
|
if(el && el instanceof HTMLElement)
|
2021-08-18 11:15:38 +02:00
|
|
|
{
|
|
|
|
let sortablejs = Sortable.create(el, {
|
|
|
|
ghostClass: 'ui-fav-sortable-placeholder',
|
|
|
|
draggable: 'li:not([data-id$="add"])',
|
|
|
|
delay: 25,
|
2021-12-07 21:35:25 +01:00
|
|
|
dataIdAttr: 'data-id',
|
|
|
|
onSort: function(event)
|
|
|
|
{
|
2021-08-18 11:15:38 +02:00
|
|
|
let favSortedList = sortablejs.toArray();
|
2021-12-07 21:35:25 +01:00
|
|
|
self.egw.set_preference(self.appname, 'fav_sort_pref', favSortedList);
|
2021-08-18 11:15:38 +02:00
|
|
|
self._refresh_fav_nm();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// Bind favorite de-select
|
|
|
|
var egw_fw = egw_getFramework();
|
|
|
|
if(egw_fw && egw_fw.applications[this.appname] && egw_fw.applications[this.appname].browser
|
|
|
|
&& egw_fw.applications[this.appname].browser.baseDiv)
|
|
|
|
{
|
|
|
|
jQuery(egw_fw.applications[this.appname].browser.baseDiv)
|
|
|
|
.off('.sidebox')
|
2021-12-07 21:35:25 +01:00
|
|
|
.on('change.sidebox', function()
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
self.highlight_favorite();
|
|
|
|
});
|
2023-02-10 00:47:59 +01:00
|
|
|
egw_fw.applications[this.appname].browser.baseDiv.addEventListener("change", (e) =>
|
|
|
|
{
|
|
|
|
if(e.target.localName == "et2-favorites")
|
|
|
|
{
|
|
|
|
sidebox[0].querySelectorAll("li:not([data-id='add']) > a > div:first-child").forEach(f =>
|
|
|
|
{
|
|
|
|
f.classList.add("sideboxstar");
|
|
|
|
f.classList.remove('ui-icon', 'ui-heart');
|
|
|
|
});
|
|
|
|
const new_pref = sidebox[0].querySelector("li[data-id='" + e.target.preferred + "'] > a > div:first-child");
|
|
|
|
if(new_pref)
|
|
|
|
{
|
|
|
|
new_pref.classList.add('ui-icon', 'ui-icon-heart');
|
|
|
|
new_pref.classList.remove("sideboxstar");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new favorite
|
|
|
|
*
|
|
|
|
* Fetches the current state from the application, then opens a dialog to get the
|
|
|
|
* name and other settings. If user proceeds, the favorite is saved, and if possible
|
|
|
|
* the sidebox is directly updated to include the new favorite
|
|
|
|
*
|
|
|
|
* @param {object} [state] State settings to be merged into the application state
|
|
|
|
*/
|
|
|
|
add_favorite(state)
|
|
|
|
{
|
|
|
|
// Get current state
|
|
|
|
// Make sure it's an object - deep copy to prevent references in sub-objects (col_filters)
|
2022-08-25 18:13:32 +02:00
|
|
|
state = jQuery.extend(true, {}, this.getState(), state || {});
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2022-08-25 18:13:32 +02:00
|
|
|
this._create_favorite_popup(state);
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// Stop the normal bubbling if this is called on click
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update favorite items in nm fav. menu
|
|
|
|
*
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
_refresh_fav_nm()
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if(etemplate2 && etemplate2.getByApplication)
|
|
|
|
{
|
|
|
|
var et2 = etemplate2.getByApplication(self.appname);
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
et2[i].widgetContainer.iterateOver(function(_widget)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
_widget.stored_filters = _widget.load_favorites(self.appname);
|
2022-08-07 12:09:02 +02:00
|
|
|
}, self, Et2Favorites);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
throw new Error("_refresh_fav_nm():Either et2 is not ready/ not there yet. Make sure that etemplate2 is ready before call this method.");
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the "Add new" popup dialog
|
|
|
|
*/
|
2022-08-25 18:13:32 +02:00
|
|
|
_create_favorite_popup(state)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-08-25 18:13:32 +02:00
|
|
|
const favorite_prefix = 'favorite_';
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
// Clear old, if existing
|
|
|
|
if(this.favorite_popup && this.favorite_popup.group)
|
|
|
|
{
|
2020-05-15 17:50:38 +02:00
|
|
|
this.favorite_popup.group.destroy();
|
2020-01-15 08:47:33 +01:00
|
|
|
delete this.favorite_popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add some controls if user is an admin
|
2022-08-25 18:13:32 +02:00
|
|
|
const apps = this.egw.user('apps');
|
|
|
|
const is_admin = (typeof apps['admin'] != "undefined");
|
|
|
|
|
|
|
|
// Setup data
|
|
|
|
let data = {
|
|
|
|
content: {
|
|
|
|
state: state || [],
|
|
|
|
current_filters: []
|
|
|
|
},
|
|
|
|
readonlys: {
|
|
|
|
group: !is_admin
|
|
|
|
}
|
|
|
|
};
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
|
2022-08-25 18:13:32 +02:00
|
|
|
// Show current set filters (more for debug than user)
|
|
|
|
let filter_list = [];
|
|
|
|
let add_to_popup = function(arr, inset = "")
|
|
|
|
{
|
|
|
|
jQuery.each(arr, function(index, filter)
|
|
|
|
{
|
|
|
|
filter_list.push({
|
|
|
|
label: inset + index.toString(),
|
|
|
|
value: (typeof filter != "object" ? "" + filter : "")
|
|
|
|
});
|
|
|
|
if(typeof filter == "object" && filter != null)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-08-25 18:13:32 +02:00
|
|
|
add_to_popup(filter, inset + " ");
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2022-08-25 18:13:32 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
add_to_popup(data.content.state);
|
|
|
|
data.content.current_filters = filter_list;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2022-08-25 18:13:32 +02:00
|
|
|
let save_callback = (button, value) =>
|
|
|
|
{
|
|
|
|
if(button !== Et2Dialog.OK_BUTTON)
|
|
|
|
{
|
|
|
|
return;
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2022-08-25 18:13:32 +02:00
|
|
|
|
|
|
|
if(value.name)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
2022-08-25 18:13:32 +02:00
|
|
|
// Add to the list
|
|
|
|
value.name = (<string>value.name).replace(/(<([^>]+)>)/ig, "");
|
|
|
|
let safe_name = (<string>value.name).replace(/[^A-Za-z0-9-_]/g, "_");
|
|
|
|
let favorite = {
|
|
|
|
name: value.name,
|
|
|
|
group: value.group || false,
|
|
|
|
state: data.content.state
|
|
|
|
};
|
|
|
|
|
|
|
|
let favorite_pref = favorite_prefix + safe_name;
|
|
|
|
|
|
|
|
// Save to preferences
|
|
|
|
if(typeof value.group != "undefined" && value.group != '')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-08-25 18:13:32 +02:00
|
|
|
// Admin stuff - save preference server side
|
|
|
|
this.egw.jsonq('EGroupware\\Api\\Framework::ajax_set_favorite',
|
|
|
|
[
|
|
|
|
this.appname,
|
|
|
|
value.name,
|
|
|
|
"add",
|
|
|
|
value.group,
|
|
|
|
data.content.state
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal user - just save to preferences client side
|
|
|
|
this.egw.set_preference(this.appname, favorite_pref, favorite);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
|
2022-08-25 18:13:32 +02:00
|
|
|
// Add to list immediately
|
|
|
|
if(this.sidebox)
|
|
|
|
{
|
|
|
|
// Remove any existing with that name
|
|
|
|
jQuery('[data-id="' + safe_name + '"]', this.sidebox).remove();
|
|
|
|
|
|
|
|
// Create new item
|
|
|
|
var html = "<li data-id='" + safe_name + "' data-group='" + favorite.group + "' class='ui-menu-item' role='menuitem'>\n";
|
|
|
|
var href = 'javascript:app.' + this.appname + '.setState(' + JSON.stringify(favorite) + ');';
|
|
|
|
html += "<a href='" + href + "' class='ui-corner-all' tabindex='-1'>";
|
|
|
|
html += "<div class='" + 'sideboxstar' + "'></div>" +
|
|
|
|
favorite.name;
|
|
|
|
html += "<div class='ui-icon ui-icon-trash' title='" + this.egw.lang('Delete') + "'/>";
|
|
|
|
html += "</a></li>\n";
|
|
|
|
jQuery(html).insertBefore(jQuery('li', this.sidebox).last());
|
|
|
|
this._init_sidebox(this.sidebox);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to update nextmatch favorites too
|
|
|
|
this._refresh_fav_nm();
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2022-08-25 18:13:32 +02:00
|
|
|
};
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2022-08-25 18:13:32 +02:00
|
|
|
|
|
|
|
// Create popup
|
|
|
|
this.favorite_popup = new Et2Dialog(this.egw);
|
|
|
|
this.favorite_popup.transformAttributes({
|
|
|
|
callback: save_callback,
|
|
|
|
title: this.egw.lang("New favorite"),
|
|
|
|
buttons: Et2Dialog.BUTTONS_OK_CANCEL,
|
|
|
|
width: 400,
|
|
|
|
value: data,
|
|
|
|
template: this.egw.webserverUrl + '/api/templates/default/add_favorite.xet'
|
|
|
|
});
|
|
|
|
document.body.appendChild(this.favorite_popup);
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a favorite from the list and update preferences
|
|
|
|
* Registered as a handler on the delete icons
|
|
|
|
*
|
|
|
|
* @param {jQuery.event} event event object
|
|
|
|
*/
|
|
|
|
delete_favorite(event)
|
|
|
|
{
|
|
|
|
// Don't do the menu
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
|
|
|
var app = event.data;
|
|
|
|
var id = jQuery(this).parentsUntil('li').parent().attr("data-id");
|
|
|
|
var group = jQuery(this).parentsUntil('li').parent().attr("data-group") || '';
|
2021-12-07 21:35:25 +01:00
|
|
|
var line = jQuery('li[data-id="' + id + '"]', app.sidebox);
|
2020-01-15 08:47:33 +01:00
|
|
|
var name = line.first().text();
|
|
|
|
var trash = this;
|
|
|
|
line.addClass('loading');
|
|
|
|
|
|
|
|
// Make sure first
|
|
|
|
var do_delete = function(button_id)
|
|
|
|
{
|
2022-03-17 23:18:39 +01:00
|
|
|
if(button_id != Et2Dialog.YES_BUTTON)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
line.removeClass('loading');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide the trash
|
|
|
|
jQuery(trash).hide();
|
|
|
|
|
|
|
|
// Delete preference server side
|
|
|
|
var request = egw.json("EGroupware\\Api\\Framework::ajax_set_favorite",
|
|
|
|
[app.appname, id, "delete", group, ''],
|
2021-12-07 21:35:25 +01:00
|
|
|
function(result)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
// Got the full response from callback, which we don't want
|
|
|
|
if(result.type) return;
|
|
|
|
|
|
|
|
if(result && typeof result == 'boolean')
|
|
|
|
{
|
|
|
|
// Remove line from list
|
|
|
|
line.slideUp("slow", function() { });
|
|
|
|
|
|
|
|
app._refresh_fav_nm();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Something went wrong server side
|
|
|
|
line.removeClass('loading').addClass('ui-state-error');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
jQuery(trash).parentsUntil("li").parent(),
|
|
|
|
true,
|
|
|
|
jQuery(trash).parentsUntil("li").parent()
|
|
|
|
);
|
|
|
|
request.sendRequest(true);
|
|
|
|
};
|
2022-03-17 23:18:39 +01:00
|
|
|
Et2Dialog.show_dialog(do_delete, (egw.lang("Delete") + " " + name + "?"),
|
|
|
|
"Delete", null, Et2Dialog.BUTTONS_YES_NO, Et2Dialog.QUESTION_MESSAGE);
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the favorite closest matching the current state
|
|
|
|
*
|
|
|
|
* Closest matching takes into account not set values, so we pick the favorite
|
|
|
|
* with the most matching values without a value that differs.
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
highlight_favorite()
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
if(!this.sidebox) return;
|
|
|
|
|
|
|
|
var state = this.getState();
|
2021-12-07 21:35:25 +01:00
|
|
|
var best_match : any = false;
|
2020-01-15 08:47:33 +01:00
|
|
|
var best_count = 0;
|
|
|
|
var self = this;
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
jQuery('li[data-id]', this.sidebox).removeClass('ui-state-highlight');
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
jQuery('li[data-id]', this.sidebox).each(function(i, href)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var favorite : any = {};
|
2021-12-07 21:35:25 +01:00
|
|
|
if(this.dataset.id && egw.preference('favorite_' + this.dataset.id, self.appname))
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
favorite = egw.preference('favorite_' + this.dataset.id, self.appname);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
if(!favorite || jQuery.isEmptyObject(favorite)) return;
|
|
|
|
|
|
|
|
// Handle old style by making it like new style
|
|
|
|
if(favorite.filter && !favorite.state)
|
|
|
|
{
|
|
|
|
favorite.state = favorite.filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
var match_count = 0;
|
|
|
|
var extra_keys = Object.keys(favorite.state);
|
|
|
|
for(var state_key in state)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
extra_keys.splice(extra_keys.indexOf(state_key), 1);
|
|
|
|
if(typeof favorite.state != 'undefined' && typeof state[state_key] != 'undefined' && typeof favorite.state[state_key] != 'undefined' && (state[state_key] == favorite.state[state_key] || !state[state_key] && !favorite.state[state_key]))
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
match_count++;
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(state_key == 'selectcols' && typeof favorite.state.selectcols == "undefined")
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-03-24 17:21:02 +01:00
|
|
|
// Skip, not set in favorite
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(typeof state[state_key] != 'undefined' && state[state_key] && typeof state[state_key] === 'object'
|
|
|
|
&& typeof favorite.state != 'undefined' && typeof favorite.state[state_key] != 'undefined' && favorite.state[state_key] && typeof favorite.state[state_key] === 'object')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
if((typeof state[state_key].length !== 'undefined' || typeof state[state_key].length !== 'undefined')
|
2021-12-07 21:35:25 +01:00
|
|
|
&& (state[state_key].length || Object.keys(state[state_key]).length) != (favorite.state[state_key].length || Object.keys(favorite.state[state_key]).length))
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
// State or favorite has a length, but the other does not
|
|
|
|
if((state[state_key].length === 0 || Object.keys(state[state_key]).length === 0) &&
|
|
|
|
(favorite.state[state_key].length == 0 || Object.keys(favorite.state[state_key]).length === 0))
|
|
|
|
{
|
|
|
|
// Just missing, or one is an array and the other is an object
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// One has a value and the other doesn't, no match
|
|
|
|
return;
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(state[state_key].length !== 'undefined' && typeof favorite.state[state_key].length !== 'undefined' &&
|
2020-01-15 08:47:33 +01:00
|
|
|
state[state_key].length === 0 && favorite.state[state_key].length === 0)
|
|
|
|
{
|
|
|
|
// Both set, but both empty
|
|
|
|
match_count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Consider sub-objects (column filters) individually
|
|
|
|
for(var sub_key in state[state_key])
|
|
|
|
{
|
|
|
|
if(state[state_key][sub_key] == favorite.state[state_key][sub_key] || !state[state_key][sub_key] && !favorite.state[state_key][sub_key])
|
|
|
|
{
|
|
|
|
match_count++;
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(state[state_key][sub_key] && favorite.state[state_key][sub_key] &&
|
2020-01-15 08:47:33 +01:00
|
|
|
typeof state[state_key][sub_key] === 'object' && typeof favorite.state[state_key][sub_key] === 'object')
|
|
|
|
{
|
|
|
|
// Too deep to keep going, just string compare for perfect match
|
|
|
|
if(JSON.stringify(state[state_key][sub_key]) === JSON.stringify(favorite.state[state_key][sub_key]))
|
|
|
|
{
|
|
|
|
match_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(typeof state[state_key][sub_key] !== 'undefined' && state[state_key][sub_key] != favorite.state[state_key][sub_key])
|
|
|
|
{
|
|
|
|
// Different values, do not match
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(typeof state[state_key] !== 'undefined'
|
|
|
|
&& typeof favorite.state != 'undefined' && typeof favorite.state[state_key] !== 'undefined'
|
|
|
|
&& state[state_key] != favorite.state[state_key])
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
// Different values, do not match
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check for anything set that the current one does not have
|
|
|
|
for(var i = 0; i < extra_keys.length; i++)
|
|
|
|
{
|
|
|
|
if(favorite.state[extra_keys[i]]) return;
|
|
|
|
}
|
|
|
|
if(match_count > best_count)
|
|
|
|
{
|
|
|
|
best_match = this.dataset.id;
|
|
|
|
best_count = match_count;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(best_match)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
jQuery('li[data-id="' + best_match + '"]', this.sidebox).addClass('ui-state-highlight');
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fix scrolling iframe browsed by iPhone/iPod/iPad touch devices
|
|
|
|
*/
|
|
|
|
_fix_iFrameScrolling()
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
if(/iPhone|iPod|iPad/.test(navigator.userAgent))
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
jQuery("iframe").on({
|
|
|
|
load: function()
|
|
|
|
{
|
|
|
|
var body = this.contentWindow.document.body;
|
|
|
|
|
|
|
|
var div = jQuery(document.createElement("div"))
|
2021-12-07 21:35:25 +01:00
|
|
|
.css({
|
|
|
|
'height': jQuery(this.parentNode).height(),
|
|
|
|
'width': jQuery(this.parentNode).width(),
|
|
|
|
'overflow': 'scroll'
|
|
|
|
});
|
|
|
|
while(body.firstChild)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
div.append(body.firstChild);
|
|
|
|
}
|
|
|
|
jQuery(body).append(div);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set document title, uses getWindowTitle to get the correct title,
|
|
|
|
* otherwise set it with uniqueID as default title
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
_set_Window_title()
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
var title = this.getWindowTitle();
|
2021-12-07 21:35:25 +01:00
|
|
|
if(title)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
document.title = this.et2._inst.uniqueId + ": " + title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window title getter function in order to set the window title
|
|
|
|
* this can be overridden on each application app.js file to customize the title value
|
|
|
|
*
|
|
|
|
* @returns {string} window title
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
getWindowTitle()
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
var titleWidget = <et2_valueWidget>this.et2.getWidgetById('title');
|
|
|
|
if(titleWidget)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-08-15 18:40:13 +02:00
|
|
|
return titleWidget.get_value ? titleWidget.get_value() : (titleWidget.value || "");
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.et2._inst.uniqueId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for drag and drop when dragging nextmatch rows from mail app
|
|
|
|
* and dropped on a row in the current application. We copy the mail into
|
|
|
|
* the filemanager to link it since we can't link directly.
|
|
|
|
*
|
|
|
|
* This doesn't happen automatically. Each application must indicate that
|
2022-10-24 17:57:35 +02:00
|
|
|
* it will accept dropped mail by its nextmatch actions:
|
2020-01-15 08:47:33 +01:00
|
|
|
*
|
|
|
|
* $actions['info_drop_mail'] = array(
|
|
|
|
* 'type' => 'drop',
|
|
|
|
* 'acceptedTypes' => 'mail',
|
|
|
|
* 'onExecute' => 'javaScript:app.infolog.handle_dropped_mail',
|
|
|
|
* 'hideOnDisabled' => true
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* This action, when defined, will not affect the automatic linking between
|
|
|
|
* normal applications.
|
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {egwActionObject[]} _selected Dragged mail rows
|
|
|
|
* @param {egwActionObject} _target Current application's nextmatch row the mail was dropped on
|
|
|
|
*/
|
|
|
|
handle_dropped_mail(_action, _selected, _target)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Mail doesn't support link system, so we copy it to VFS
|
|
|
|
*/
|
|
|
|
var ids = _target.id.split("::");
|
|
|
|
if(ids.length != 2 || ids[0] == 'mail') return;
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
var vfs_path = "/apps/" + ids[0] + "/" + ids[1];
|
2020-01-15 08:47:33 +01:00
|
|
|
var mail_ids = [];
|
|
|
|
|
|
|
|
for(var i = 0; i < _selected.length; i++)
|
|
|
|
{
|
|
|
|
mail_ids.push(_selected[i].id);
|
|
|
|
}
|
|
|
|
if(mail_ids.length)
|
|
|
|
{
|
|
|
|
egw.message(egw.lang("Please wait..."));
|
2021-12-07 21:35:25 +01:00
|
|
|
this.egw.json('filemanager.filemanager_ui.ajax_action', ['mail', mail_ids, vfs_path], function(data)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
// Trigger an update (minimal, no sorting changes) to display the new link
|
2021-12-07 21:35:25 +01:00
|
|
|
egw.refresh(data.msg || '', ids[0], ids[1], 'update');
|
2020-01-15 08:47:33 +01:00
|
|
|
}).sendRequest(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if Mailvelope is available, open (or create) "egroupware" keyring and call callback with it
|
|
|
|
*
|
|
|
|
* @param {function} _callback called if and only if mailvelope is available (context is this!)
|
|
|
|
*/
|
|
|
|
mailvelopeAvailable(_callback)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var callback = jQuery.proxy(_callback, this);
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
if(typeof mailvelope !== 'undefined')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
this.mailvelopeOpenKeyring().then(callback);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jQuery(window).on('mailvelope', function()
|
|
|
|
{
|
|
|
|
self.mailvelopeOpenKeyring().then(callback);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mailvelope object contains SyncHandlers
|
|
|
|
*
|
|
|
|
* @property {function} descriptionuploadSync function called by Mailvelope to upload encrypted private key backup
|
|
|
|
* @property {function} downloadSync function called by Mailvelope to download encrypted private key backup
|
|
|
|
* @property {function} backup function called by Mailvelope to upload a public keyring backup
|
|
|
|
* @property {function} restore function called by Mailvelope to restore a public keyring backup
|
|
|
|
*/
|
|
|
|
private mailvelopeSyncHandler()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* function called by Mailvelope to upload a public keyring
|
|
|
|
* @param {UploadSyncHandler} _uploadObj
|
|
|
|
* @property {string} etag entity tag for the uploaded encrypted keyring, or null if initial upload
|
|
|
|
* @property {AsciiArmored} keyringMsg encrypted keyring as PGP armored message
|
|
|
|
* @returns {Promise.<UploadSyncReply, Error>}
|
|
|
|
*/
|
|
|
|
uploadSync: function(_uploadObj)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
return new Promise(function(_resolve, _reject) {});
|
2020-01-15 08:47:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function called by Mailvelope to download a public keyring
|
|
|
|
*
|
|
|
|
* @param {object} _downloadObj
|
|
|
|
* @property {string} etag entity tag for the current local keyring, or null if no local eTag
|
|
|
|
* @returns {Promise.<DownloadSyncReply, Error>}
|
|
|
|
*/
|
|
|
|
downloadSync: function(_downloadObj)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
return new Promise(function(_resolve, _reject) {});
|
2020-01-15 08:47:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function called by Mailvelope to upload an encrypted private key backup
|
|
|
|
*
|
|
|
|
* @param {BackupSyncPacket} _backup
|
|
|
|
* @property {AsciiArmored} backup an encrypted private key as PGP armored message
|
|
|
|
* @returns {Promise.<undefined, Error>}
|
|
|
|
*/
|
|
|
|
backup: function(_backup)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
// Store backup sync packet into .PGP-Key-Backup file in user directory
|
|
|
|
jQuery.ajax({
|
2021-12-07 21:35:25 +01:00
|
|
|
method: 'PUT',
|
|
|
|
url: egw.webserverUrl + '/webdav.php/home/' + egw.user('account_lid') + '/.PGP-Key-Backup',
|
2020-01-15 08:47:33 +01:00
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify(_backup),
|
2021-12-07 21:35:25 +01:00
|
|
|
success: function()
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
_resolve(_backup);
|
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
error: function(_err)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
_reject(_err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function called by Mailvelope to restore an encrypted private key backup
|
|
|
|
*
|
|
|
|
* @returns {Promise.<BackupSyncPacket, Error>}
|
|
|
|
* @todo
|
|
|
|
*/
|
|
|
|
restore: function()
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
jQuery.ajax({
|
2021-12-07 21:35:25 +01:00
|
|
|
url: egw.webserverUrl + '/webdav.php/home/' + egw.user('account_lid') + '/.PGP-Key-Backup',
|
2020-01-15 08:47:33 +01:00
|
|
|
method: 'GET',
|
2021-12-07 21:35:25 +01:00
|
|
|
success: function(_backup)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
resolve(JSON.parse(_backup));
|
|
|
|
egw.message('Your key has been restored successfully.');
|
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
error: function(_err)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
//Try with old back file name
|
2021-12-07 21:35:25 +01:00
|
|
|
if(_err.status == 404)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
jQuery.ajax({
|
2021-12-07 21:35:25 +01:00
|
|
|
method: 'GET',
|
|
|
|
url: egw.webserverUrl + '/webdav.php/home/' + egw.user('account_lid') + '/.PK_PGP',
|
|
|
|
success: function(_backup)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
resolve(JSON.parse(_backup));
|
|
|
|
egw.message('Your key has been restored successfully.');
|
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
error: function(_err)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
_reject(_err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_reject(_err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for backup file operations
|
|
|
|
*
|
|
|
|
* @param {type} _url Url of the backup file
|
|
|
|
* @param {type} _cmd command to operate
|
|
|
|
* - PUT: to store backup file
|
|
|
|
* - GET: to read backup file
|
|
|
|
* - DELETE: to delete backup file
|
|
|
|
*
|
|
|
|
* @param {type} _successCallback function called when the operation is successful
|
|
|
|
* @param {type} _errorCallback function called when the operation fails
|
|
|
|
* @param {type} _data data which needs to be stored in file via PUT command
|
|
|
|
*/
|
|
|
|
_mailvelopeBackupFileOperator(_url, _cmd, _successCallback, _errorCallback, _data?)
|
|
|
|
{
|
|
|
|
var ajaxObj = {
|
2021-12-07 21:35:25 +01:00
|
|
|
url: _url || egw.webserverUrl + '/webdav.php/home/' + egw.user('account_lid') + '/.PGP-Key-Backup',
|
2020-01-15 08:47:33 +01:00
|
|
|
method: _cmd,
|
|
|
|
success: _successCallback,
|
|
|
|
error: _errorCallback
|
|
|
|
};
|
2021-12-07 21:35:25 +01:00
|
|
|
switch(_cmd)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
case 'PUT':
|
2021-12-07 21:35:25 +01:00
|
|
|
jQuery.extend({}, ajaxObj, {
|
2020-01-15 08:47:33 +01:00
|
|
|
data: JSON.stringify(_data),
|
|
|
|
contentType: 'application/json'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'GET':
|
2021-12-07 21:35:25 +01:00
|
|
|
jQuery.extend({}, ajaxObj, {
|
2020-01-15 08:47:33 +01:00
|
|
|
dataType: 'json'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'DELETE':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
jQuery.ajax(ajaxObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create backup dialog
|
|
|
|
* @param {string} _selector DOM selector to attach backupDialog
|
2022-10-24 17:57:35 +02:00
|
|
|
* @param {boolean} _initSetup determine whether it's an initialization backup or restore backup
|
2020-01-15 08:47:33 +01:00
|
|
|
*
|
|
|
|
* @returns {Promise.<backupPopupId, Error>}
|
|
|
|
*/
|
|
|
|
mailvelopeCreateBackupDialog(_selector?, _initSetup?)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var selector = _selector || 'body';
|
|
|
|
var initSetup = _initSetup;
|
|
|
|
jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]').remove();
|
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring : any)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
_keyring.addSyncHandler(self.mailvelopeSyncHandlerObj);
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
initialSetup: initSetup
|
|
|
|
};
|
|
|
|
_keyring.createKeyBackupContainer(selector, options).then(function(_popupId)
|
|
|
|
{
|
|
|
|
var $backup_selector = jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]');
|
|
|
|
$backup_selector.css({position: 'absolute', "z-index": 1});
|
|
|
|
_popupId.isReady().then(function(result)
|
|
|
|
{
|
|
|
|
egw.message('Your key has been backedup into .PGP-Key-Backup successfully.');
|
|
|
|
jQuery(selector).empty();
|
|
|
|
});
|
|
|
|
resolve(_popupId);
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
2020-01-15 08:47:33 +01:00
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
function(_err)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
reject(_err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete backup key from filesystem
|
|
|
|
*/
|
|
|
|
mailvelopeDeleteBackup()
|
|
|
|
{
|
|
|
|
var self = this;
|
2022-03-17 23:18:39 +01:00
|
|
|
Et2Dialog.show_dialog(function(_button_id)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-03-17 23:18:39 +01:00
|
|
|
if(_button_id == Et2Dialog.YES_BUTTON)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
self._mailvelopeBackupFileOperator(undefined, 'DELETE', function()
|
|
|
|
{
|
|
|
|
self.egw.message(self.egw.lang('The backup key has been deleted.'));
|
|
|
|
}, function(_err)
|
|
|
|
{
|
|
|
|
self.egw.message(self.egw.lang('Was not able to delete the backup key because %1', _err));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-03-17 23:18:39 +01:00
|
|
|
'Are you sure, you would like to delete the backup key?',
|
|
|
|
'Delete backup key',
|
|
|
|
{}, Et2Dialog.BUTTONS_YES_NO_CANCEL, Et2Dialog.QUESTION_MESSAGE, undefined, self.egw);
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create mailvelope restore dialog
|
|
|
|
* @param {string} _selector DOM selector to attach restorDialog
|
|
|
|
* @param {boolean} _restorePassword if true, will restore key password too
|
|
|
|
*
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
mailvelopeCreateRestoreDialog(_selector, _restorePassword)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var restorePassword = _restorePassword;
|
|
|
|
var selector = _selector || 'body';
|
|
|
|
//Clear the
|
|
|
|
jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]').remove();
|
2021-12-07 21:35:25 +01:00
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
_keyring.addSyncHandler(self.mailvelopeSyncHandlerObj);
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
restorePassword: restorePassword
|
|
|
|
};
|
|
|
|
_keyring.restoreBackupContainer(selector, options).then(function(_restoreId)
|
|
|
|
{
|
|
|
|
var $restore_selector = jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]');
|
|
|
|
$restore_selector.css({position: 'absolute', "z-index": 1});
|
|
|
|
resolve(_restoreId);
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
2020-01-15 08:47:33 +01:00
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
function(_err)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
reject(_err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dialog to show all backup/restore options
|
|
|
|
*
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
mailvelopeCreateBackupRestoreDialog()
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var appname = egw.app_name();
|
|
|
|
var menu = [
|
|
|
|
// Header row should be empty item 0
|
|
|
|
{},
|
|
|
|
// Restore Keyring item 1
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
label: "Restore key",
|
|
|
|
image: "lock",
|
|
|
|
onclick: "app." + appname + ".mailvelopeCreateRestoreDialog('#_mvelo')"
|
|
|
|
},
|
2020-01-15 08:47:33 +01:00
|
|
|
// Restore pass phrase item 2
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
label: "Restore password",
|
|
|
|
image: "password",
|
|
|
|
onclick: "app." + appname + ".mailvelopeCreateRestoreDialog('#_mvelo', true)"
|
|
|
|
},
|
2020-01-15 08:47:33 +01:00
|
|
|
// Delete backup Key item 3
|
2021-12-07 21:35:25 +01:00
|
|
|
{label: "Delete backup", image: "delete", onclick: "app." + appname + ".mailvelopeDeleteBackup"},
|
2020-01-15 08:47:33 +01:00
|
|
|
// Backup Key item 4
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
label: "Backup Key",
|
|
|
|
image: "save",
|
|
|
|
onclick: "app." + appname + ".mailvelopeCreateBackupDialog('#_mvelo', false)"
|
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
var dialog = function(_content, _callback?)
|
|
|
|
{
|
2022-03-23 20:28:15 +01:00
|
|
|
let dialog = new Et2Dialog(this.egw);
|
|
|
|
dialog.transformAttributes({
|
2021-12-07 21:35:25 +01:00
|
|
|
callback: function(_button_id, _value)
|
|
|
|
{
|
|
|
|
if(typeof _callback == "function")
|
|
|
|
{
|
|
|
|
_callback.call(this, _button_id, _value.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title: egw.lang('Backup/Restore'),
|
|
|
|
buttons: [{
|
|
|
|
"button_id": 'close',
|
2022-03-23 20:28:15 +01:00
|
|
|
"label": egw.lang('Close'),
|
2021-12-07 21:35:25 +01:00
|
|
|
id: 'dialog[close]',
|
|
|
|
image: 'cancelled',
|
|
|
|
"default": true
|
|
|
|
}],
|
|
|
|
value: {
|
|
|
|
content: {
|
|
|
|
menu: _content
|
|
|
|
}
|
|
|
|
},
|
|
|
|
template: egw.webserverUrl + '/api/templates/default/pgp_backup_restore.xet',
|
|
|
|
class: "pgp_backup_restore",
|
|
|
|
modal: true
|
2020-01-15 08:47:33 +01:00
|
|
|
});
|
2022-03-23 20:28:15 +01:00
|
|
|
return dialog;
|
2020-01-15 08:47:33 +01:00
|
|
|
};
|
2021-12-07 21:35:25 +01:00
|
|
|
if(typeof mailvelope != 'undefined')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
self._mailvelopeBackupFileOperator(undefined, 'GET', function(_data)
|
|
|
|
{
|
|
|
|
dialog(menu);
|
|
|
|
},
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
// Remove delete item
|
|
|
|
menu.splice(3, 1);
|
|
|
|
menu[3]['onclick'] = "app." + appname + ".mailvelopeCreateBackupDialog('#_mvelo', true)";
|
|
|
|
dialog(menu);
|
|
|
|
});
|
2020-01-15 08:47:33 +01:00
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
function()
|
|
|
|
{
|
|
|
|
mailvelope.createKeyring('egroupware').then(function() {dialog(menu);});
|
2020-01-15 08:47:33 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.mailvelopeInstallationOffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dialog and offers installation option for installing mailvelope plugin
|
|
|
|
* plus it offers a video tutorials to get the user morte familiar with mailvelope
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
mailvelopeInstallationOffer()
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
var buttons = [
|
2021-12-07 21:35:25 +01:00
|
|
|
{"text": egw.lang('Install'), id: 'install', image: 'check', "default": true},
|
|
|
|
{"text": egw.lang('Close'), id: 'close', image: 'cancelled'}
|
2020-01-15 08:47:33 +01:00
|
|
|
];
|
|
|
|
var dialog = function(_content, _callback)
|
|
|
|
{
|
|
|
|
return et2_createWidget("dialog", {
|
2021-12-07 21:35:25 +01:00
|
|
|
callback: function(_button_id, _value)
|
|
|
|
{
|
|
|
|
if(typeof _callback == "function")
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
_callback.call(this, _button_id, _value.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title: egw.lang('PGP Encryption Installation'),
|
|
|
|
buttons: buttons,
|
|
|
|
dialog_type: 'info',
|
|
|
|
value: {
|
|
|
|
content: _content
|
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
template: egw.webserverUrl + '/api/templates/default/pgp_installation.xet',
|
2020-01-15 08:47:33 +01:00
|
|
|
class: "pgp_installation",
|
|
|
|
modal: true
|
|
|
|
//resizable:false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var content = [
|
|
|
|
// Header row should be empty item 0
|
|
|
|
{},
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
domain: this.egw.lang('Add your domain as "%1" in options to list of email providers and enable API.',
|
|
|
|
'*.' + this._mailvelopeDomain()), video: "test", control: "true"
|
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
];
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
dialog(content, function(_button)
|
|
|
|
{
|
|
|
|
if(_button == 'install')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
if(typeof chrome != 'undefined')
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
// ATM we are not able to trigger mailvelope installation directly
|
|
|
|
// since the installation should be triggered from the extension
|
|
|
|
// owner validate website (mailvelope.com), therefore, we just redirect
|
|
|
|
// user to chrome webstore to install mailvelope from there.
|
|
|
|
window.open('https://chrome.google.com/webstore/detail/mailvelope/kajibbejlbohfaggdiogboambcijhkke');
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
else if(typeof InstallTrigger != 'undefined' && InstallTrigger.enabled())
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
InstallTrigger.install({mailvelope: "https://download.mailvelope.com/releases/latest/mailvelope.firefox.xpi"},
|
|
|
|
function(_url, _status)
|
|
|
|
{
|
|
|
|
if(_status == 0)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2022-03-17 23:18:39 +01:00
|
|
|
Et2Dialog.alert(egw.lang('Mailvelope addon installation succeded. Now you may configure the options.'));
|
2020-01-15 08:47:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-17 23:18:39 +01:00
|
|
|
Et2Dialog.alert(egw.lang('Mailvelope addon installation failed! Please try again.'));
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PGP begin and end tags
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
readonly begin_pgp_message : string = '-----BEGIN PGP MESSAGE-----';
|
|
|
|
readonly end_pgp_message : string = '-----END PGP MESSAGE-----';
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mailvelope "egroupware" Keyring
|
|
|
|
*/
|
|
|
|
mailvelope_keyring : any = undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery selector for Mailvelope iframes in all browsers
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
readonly mailvelope_iframe_selector : string = 'iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]';
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open (or create) "egroupware" keyring and call callback with it
|
|
|
|
*
|
|
|
|
* @returns {Promise.<Keyring, Error>} Keyring or Error with message
|
|
|
|
*/
|
|
|
|
mailvelopeOpenKeyring()
|
|
|
|
{
|
2022-09-08 11:27:02 +02:00
|
|
|
let self = this;
|
|
|
|
let mailvelope = this.egw.window.mailvelope; // use Mailvelope of correct window
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
|
|
|
if (self.mailvelope_keyring) _resolve(self.mailvelope_keyring);
|
|
|
|
|
2022-09-08 11:27:02 +02:00
|
|
|
let resolve = _resolve;
|
|
|
|
let reject = _reject;
|
2020-01-15 08:47:33 +01:00
|
|
|
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
|
|
|
{
|
|
|
|
self.mailvelope_keyring = _keyring;
|
|
|
|
|
|
|
|
resolve(_keyring);
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
mailvelope.createKeyring('egroupware').then(function(_keyring)
|
|
|
|
{
|
|
|
|
self.mailvelope_keyring = _keyring;
|
|
|
|
var mvelo_settings_selector = self.mailvelope_iframe_selector
|
|
|
|
.split(',').map(function(_val) {return 'body>' + _val;}).join(',');
|
|
|
|
|
|
|
|
mailvelope.createSettingsContainer('body', _keyring, {
|
|
|
|
email: self.egw.user('account_email'),
|
|
|
|
fullName: self.egw.user('account_fullname')
|
|
|
|
}).then(function()
|
|
|
|
{
|
|
|
|
// make only Mailvelope settings dialog visible
|
|
|
|
jQuery(mvelo_settings_selector).css({position: 'absolute', top: 0});
|
|
|
|
// add a close button, so we know when to offer storing public key to AB
|
|
|
|
jQuery('<button class="et2_button et2_button_text" id="mailvelope_close_settings">' + self.egw.lang('Close') + '</button>')
|
|
|
|
.css({position: 'absolute', top: 8, right: 8, "z-index": 2})
|
|
|
|
.click(function()
|
|
|
|
{
|
|
|
|
// try fetching public key, to check user created onw
|
|
|
|
self.mailvelope_keyring.exportOwnPublicKey(self.egw.user('account_email')).then(function(_pubKey)
|
|
|
|
{
|
|
|
|
// CreateBackupDialog
|
|
|
|
self.mailvelopeCreateBackupDialog().then(function(_popupId)
|
|
|
|
{
|
|
|
|
jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]').css({
|
|
|
|
position: 'absolute',
|
|
|
|
"z-index": 1
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
egw.message(_err);
|
|
|
|
});
|
|
|
|
|
|
|
|
// if yes, hide settings dialog
|
|
|
|
jQuery(mvelo_settings_selector).each(function(index, item : any)
|
|
|
|
{
|
2022-09-08 11:27:02 +02:00
|
|
|
if (!item.src.match(/keyBackupDialog.html/,'ig')) item.remove();
|
2021-12-07 21:35:25 +01:00
|
|
|
});
|
|
|
|
jQuery('button#mailvelope_close_settings').remove();
|
|
|
|
|
|
|
|
// offer user to store his public key to AB for other users to find
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
button_id: 2,
|
2022-03-17 23:18:39 +01:00
|
|
|
label: 'Yes',
|
2021-12-07 21:35:25 +01:00
|
|
|
id: 'dialog[yes]',
|
|
|
|
image: 'check',
|
|
|
|
default: true
|
|
|
|
},
|
2022-03-17 23:18:39 +01:00
|
|
|
{button_id: 3, label: 'No', id: 'dialog[no]', image: 'cancelled'}
|
2021-12-07 21:35:25 +01:00
|
|
|
];
|
|
|
|
if(egw.user('apps').admin)
|
|
|
|
{
|
|
|
|
buttons.unshift({
|
|
|
|
button_id: 5,
|
2022-03-17 23:18:39 +01:00
|
|
|
label: 'Yes and allow non-admin users to do that too (recommended)',
|
2021-12-07 21:35:25 +01:00
|
|
|
id: 'dialog[yes_allow]',
|
|
|
|
image: 'check',
|
|
|
|
default: true
|
|
|
|
});
|
|
|
|
delete buttons[1].default;
|
|
|
|
}
|
2022-03-17 23:18:39 +01:00
|
|
|
Et2Dialog.show_dialog(function(_button_id)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
2022-03-17 23:18:39 +01:00
|
|
|
if(_button_id != Et2Dialog.NO_BUTTON)
|
2021-12-07 21:35:25 +01:00
|
|
|
{
|
|
|
|
var keys = {};
|
|
|
|
keys[self.egw.user('account_id')] = _pubKey;
|
|
|
|
self.egw.json('addressbook.addressbook_bo.ajax_set_pgp_keys',
|
2022-03-17 23:18:39 +01:00
|
|
|
[keys, _button_id != Et2Dialog.YES_BUTTON ? true : undefined]).sendRequest()
|
2021-12-07 21:35:25 +01:00
|
|
|
.then(function(_data)
|
|
|
|
{
|
|
|
|
self.egw.message(_data.response['0'].data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-03-17 23:18:39 +01:00
|
|
|
'It is recommended to store your public key in addressbook, so other users can write you encrypted mails.',
|
|
|
|
'Store your public key in Addressbook?',
|
|
|
|
{}, buttons, Et2Dialog.QUESTION_MESSAGE, undefined, self.egw);
|
2021-12-07 21:35:25 +01:00
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
self.egw.message(_err.message + "\n\n" +
|
|
|
|
self.egw.lang("You will NOT be able to send or receive encrypted mails before completing that step!"), 'error');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.appendTo('body');
|
|
|
|
});
|
|
|
|
resolve(_keyring);
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
2020-01-15 08:47:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mailvelope uses Domain without first part: eg. "stylite.de" for "egw.stylite.de"
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_mailvelopeDomain()
|
|
|
|
{
|
|
|
|
var parts = document.location.hostname.split('.');
|
|
|
|
if (parts.length > 1) parts.shift();
|
|
|
|
return parts.join('.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we have a key for all recipients
|
|
|
|
*
|
|
|
|
* @param {Array} _recipients
|
|
|
|
* @returns {Promise.<Array, Error>} Array of recipients or Error with recipients without key
|
|
|
|
*/
|
|
|
|
mailvelopeGetCheckRecipients(_recipients)
|
|
|
|
{
|
|
|
|
// replace rfc822 addresses with raw email, as Mailvelop does not like them and lowercase all email
|
|
|
|
var rfc822_preg = /<([^'" <>]+)>$/;
|
|
|
|
var recipients = _recipients.map(function(_recipient)
|
|
|
|
{
|
|
|
|
var matches = _recipient.match(rfc822_preg);
|
|
|
|
return matches ? matches[1].toLowerCase() : _recipient.toLowerCase();
|
|
|
|
});
|
|
|
|
|
|
|
|
// check if we have keys for all recipients
|
|
|
|
var self = this;
|
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
self.mailvelopeOpenKeyring().then(function(_keyring : any)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
var keyring = _keyring;
|
|
|
|
_keyring.validKeyForAddress(recipients).then(function(_status)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
var no_key = [];
|
|
|
|
for(var email in _status)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
if (!_status[email]) no_key.push(email);
|
2021-12-07 21:35:25 +01:00
|
|
|
}
|
|
|
|
if(no_key.length)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
// server addressbook on server for missing public keys
|
|
|
|
self.egw.json('addressbook.addressbook_bo.ajax_get_pgp_keys', [no_key]).sendRequest().then(function(_data)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
var data = _data.response['0'].data;
|
|
|
|
var promises = [];
|
|
|
|
for(var email in data)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
promises.push(keyring.importPublicKey(data[email]).then(function(_result)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
if(_result == 'IMPORTED' || _result == 'UPDATED')
|
|
|
|
{
|
|
|
|
no_key.splice(no_key.indexOf(email), 1);
|
|
|
|
}
|
|
|
|
}));
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
Promise.all(promises).then(function()
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
if(no_key.length)
|
|
|
|
{
|
|
|
|
reject(new Error(self.egw.lang('No key for recipient:') + ' ' + no_key.join(', ')));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resolve(recipients);
|
|
|
|
}
|
|
|
|
});
|
2020-01-15 08:47:33 +01:00
|
|
|
});
|
2021-12-07 21:35:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resolve(recipients);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
2020-01-15 08:47:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the share action is enabled for this entry
|
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {egwActionObject[]} _entries
|
|
|
|
* @param {egwActionObject} _target
|
|
|
|
* @returns {boolean} if action is enabled
|
|
|
|
*/
|
|
|
|
is_share_enabled(_action, _entries, _target)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
|
2020-01-15 08:47:33 +01:00
|
|
|
/**
|
|
|
|
* create a share-link for the given entry
|
|
|
|
*
|
|
|
|
* @param {egwAction} _action egw actions
|
|
|
|
* @param {egwActionObject[]} _senders selected nm row
|
|
|
|
* @param {egwActionObject} _target Drag source. Not used here.
|
|
|
|
* @param {Boolean} _writable Allow edit access from the share.
|
|
|
|
* @param {Boolean} _files Allow access to files from the share.
|
|
|
|
* @param {Function} _callback Callback with results
|
2020-03-25 03:34:04 +01:00
|
|
|
* @param {Object} _extra Additional (app-specific or special) parameters
|
2020-01-15 08:47:33 +01:00
|
|
|
* @returns {Boolean} returns false if not successful
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
share_link(_action, _senders, _target, _writable?, _files?, _callback?, _extra?)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var path = _senders[0].id;
|
|
|
|
if(!path)
|
|
|
|
{
|
|
|
|
return this.egw.message(this.egw.lang('Missing share path. Unable to create share.'), 'error');
|
|
|
|
}
|
|
|
|
switch(_action.id)
|
|
|
|
{
|
|
|
|
case 'shareFilemanager':
|
|
|
|
// Sharing a link to just files in filemanager
|
|
|
|
var id = path.split('::');
|
2021-12-07 21:35:25 +01:00
|
|
|
path = '/apps/' + id[0] + '/' + id[1];
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
|
|
|
if(typeof _writable === 'undefined' && _action.parent && _action.parent.getActionById('shareWritable'))
|
|
|
|
{
|
|
|
|
_writable = _action.parent.getActionById('shareWritable').checked || false;
|
|
|
|
}
|
|
|
|
if(typeof _files === 'undefined' && _action.parent && _action.parent.getActionById('shareFiles'))
|
|
|
|
{
|
|
|
|
_files = _action.parent.getActionById('shareFiles').checked || false;
|
|
|
|
}
|
2020-03-31 18:21:26 +02:00
|
|
|
if(typeof _extra === 'undefined')
|
|
|
|
{
|
|
|
|
_extra = {};
|
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
|
2020-03-25 03:34:04 +01:00
|
|
|
return egw.json('EGroupware\\Api\\Sharing::ajax_create', [_action.id, path, _writable, _files, _extra],
|
2020-01-15 08:47:33 +01:00
|
|
|
_callback ? _callback : this._share_link_callback, this, true, this).sendRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
share_merge(_action, _senders, _target)
|
|
|
|
{
|
|
|
|
var parent = _action.parent.parent;
|
|
|
|
var _writable = false;
|
|
|
|
var _files = false;
|
|
|
|
if(parent && parent.getActionById('shareWritable'))
|
|
|
|
{
|
|
|
|
_writable = parent.getActionById('shareWritable').checked || false;
|
|
|
|
}
|
|
|
|
if(parent && parent.getActionById('shareFiles'))
|
|
|
|
{
|
|
|
|
_files = parent.getActionById('shareFiles').checked || false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Share only works on one at a time
|
|
|
|
var promises = [];
|
|
|
|
for(var i = 0; i < _senders.length; i++)
|
|
|
|
{
|
2021-12-07 21:35:25 +01:00
|
|
|
promises.push(new Promise(function(resolve, reject)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
this.share_link(_action, [_senders[i]], _target, _writable, _files, resolve);
|
|
|
|
}.bind(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// But merge into email can handle several
|
2021-12-07 21:35:25 +01:00
|
|
|
Promise.all(promises.map(function(p) {p.catch(function(e) {console.log(e)})}))
|
|
|
|
.then(function(values)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
// Process document after all shares created
|
|
|
|
return nm_action(_action, _senders, _target);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Share-link callback
|
|
|
|
* @param {object} _data
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
_share_link_callback(_data)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
if (_data.msg || _data.share_link) window.egw_refresh(_data.msg, this.appname);
|
|
|
|
|
2021-12-07 21:35:25 +01:00
|
|
|
var copy_link_to_clipboard = function(evt)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var $target = jQuery(evt.target);
|
|
|
|
$target.select();
|
2021-12-07 21:35:25 +01:00
|
|
|
try
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
var successful = document.execCommand('copy');
|
2021-12-07 21:35:25 +01:00
|
|
|
if(successful)
|
2020-01-15 08:47:33 +01:00
|
|
|
{
|
|
|
|
egw.message('Share link copied into clipboard');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
}
|
2020-01-15 08:47:33 +01:00
|
|
|
egw.message('Failed to copy the link!');
|
|
|
|
};
|
|
|
|
jQuery("body").on("click", "[name=share_link]", copy_link_to_clipboard);
|
|
|
|
et2_createWidget("dialog", {
|
2021-12-07 21:35:25 +01:00
|
|
|
callback: function(button_id, value)
|
|
|
|
{
|
2020-01-15 08:47:33 +01:00
|
|
|
jQuery("body").off("click", "[name=share_link]", copy_link_to_clipboard);
|
|
|
|
return true;
|
|
|
|
},
|
2021-12-07 21:35:25 +01:00
|
|
|
title: _data.title ? _data.title : egw.lang("%1 Share Link", _data.writable ? egw.lang("Writable") : egw.lang("Readonly")),
|
2020-01-15 08:47:33 +01:00
|
|
|
template: _data.template,
|
|
|
|
width: 450,
|
2021-12-07 21:35:25 +01:00
|
|
|
value: {content: {"share_link": _data.share_link}}
|
2020-01-15 08:47:33 +01:00
|
|
|
});
|
|
|
|
}
|
2020-04-21 23:36:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep a list of all EgwApp instances
|
|
|
|
*
|
|
|
|
* This is not just the globals available in window.app, it also includes private instances as well
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param app_obj
|
|
|
|
*/
|
2021-12-07 21:35:25 +01:00
|
|
|
private static _register_instance(app_obj : EgwApp)
|
2020-04-21 23:36:17 +02:00
|
|
|
{
|
|
|
|
// Reject improper objects
|
|
|
|
if(!app_obj.appname) return;
|
|
|
|
|
|
|
|
EgwApp._instances.push(app_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterator over all app instances
|
|
|
|
*
|
|
|
|
* Use for(const app of EgwApp) {...} to iterate over all app objects.
|
|
|
|
*/
|
|
|
|
static [Symbol.iterator]()
|
|
|
|
{
|
|
|
|
return EgwApp._instances[Symbol.iterator]();
|
|
|
|
}
|
2023-07-10 16:02:30 +02:00
|
|
|
|
|
|
|
//TODO check if this makes any sense
|
|
|
|
confirm:(param: EgwAction, _senders:any, _target:any)=>any=undefined
|
2020-01-15 08:47:33 +01:00
|
|
|
}
|
2021-12-07 21:35:25 +01:00
|
|
|
|
2021-06-11 15:21:18 +02:00
|
|
|
// EgwApp need to be global on window, as it's used to iterate through all EgwApp instances
|
|
|
|
window.EgwApp = EgwApp;
|