2020-02-16 11:31:32 +01:00
|
|
|
/**
|
2020-02-05 21:48:50 +01:00
|
|
|
* EGroupware eTemplate2 - JS Link 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-02-05 21:48:50 +01:00
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright 2011 Nathan Gray
|
|
|
|
*/
|
|
|
|
|
2020-03-30 18:28:48 +02:00
|
|
|
/*egw:uses
|
|
|
|
/vendor/bower-asset/jquery/dist/jquery.js;
|
|
|
|
/vendor/bower-asset/jquery-ui/jquery-ui.js;
|
|
|
|
et2_core_inputWidget;
|
|
|
|
et2_core_valueWidget;
|
2020-09-11 00:59:34 +02:00
|
|
|
et2_widget_selectbox;
|
2020-03-30 18:28:48 +02:00
|
|
|
|
|
|
|
// Include menu system for list context menu
|
|
|
|
egw_action.egw_menu_dhtmlx;
|
|
|
|
*/
|
|
|
|
|
2020-12-21 21:53:24 +01:00
|
|
|
import {et2_createWidget, et2_register_widget, et2_widget, WidgetConfig} from "./et2_core_widget";
|
2020-03-30 18:28:48 +02:00
|
|
|
import {ClassWithAttributes} from "./et2_core_inheritance";
|
|
|
|
import {et2_inputWidget} from "./et2_core_inputWidget";
|
|
|
|
import {et2_button} from "./et2_widget_button";
|
2022-05-11 22:00:23 +02:00
|
|
|
import {Et2LinkList} from "./Et2Link/Et2LinkList";
|
2022-05-13 11:59:13 +02:00
|
|
|
import type {Et2LinkString} from "./Et2Link/Et2LinkString";
|
|
|
|
import {Et2Link} from "./Et2Link/Et2Link";
|
2022-07-12 09:57:24 +02:00
|
|
|
import type {Et2LinkTo} from "./Et2Link/Et2LinkTo";
|
|
|
|
import type {Et2LinkAppSelect} from "./Et2Link/Et2LinkAppSelect";
|
|
|
|
import type {Et2LinkEntry, Et2LinkEntryReadonly} from "./Et2Link/Et2LinkEntry";
|
2020-02-05 21:48:50 +01:00
|
|
|
|
2020-03-30 18:28:48 +02:00
|
|
|
/**
|
2022-07-12 09:57:24 +02:00
|
|
|
* @deprecated use Et2LinkTo
|
2020-02-05 21:48:50 +01:00
|
|
|
*/
|
2022-07-12 09:57:24 +02:00
|
|
|
export type et2_link_to = Et2LinkTo;
|
2020-02-05 21:48:50 +01:00
|
|
|
|
|
|
|
/**
|
2022-07-12 09:57:24 +02:00
|
|
|
* @deprecated use Et2LinkAppSelect
|
2020-02-05 21:48:50 +01:00
|
|
|
*/
|
2022-07-12 09:57:24 +02:00
|
|
|
export type et2_link_apps = Et2LinkAppSelect;
|
2020-02-05 21:48:50 +01:00
|
|
|
|
|
|
|
/**
|
2022-07-12 09:57:24 +02:00
|
|
|
* @deprecated use Et2LinkEntry
|
2020-02-05 21:48:50 +01:00
|
|
|
*/
|
2022-07-12 09:57:24 +02:00
|
|
|
export type et2_link_entry = Et2LinkEntry;
|
2020-02-05 21:48:50 +01:00
|
|
|
|
2022-05-13 11:59:13 +02:00
|
|
|
/**
|
|
|
|
* @deprecated use Et2Link
|
|
|
|
*/
|
|
|
|
export type et2_link = Et2Link;
|
|
|
|
|
2020-02-05 21:48:50 +01:00
|
|
|
/**
|
2022-07-12 09:57:24 +02:00
|
|
|
* @deprecated use Et2LinkEntryReadonly
|
2020-02-05 21:48:50 +01:00
|
|
|
*/
|
2022-07-12 09:57:24 +02:00
|
|
|
export type et2_link_entry_ro = Et2LinkEntryReadonly;
|
2020-02-05 21:48:50 +01:00
|
|
|
|
|
|
|
/**
|
2022-05-13 11:59:13 +02:00
|
|
|
* @deprecated use Et2LinkString
|
2020-02-05 21:48:50 +01:00
|
|
|
*/
|
2022-05-13 11:59:13 +02:00
|
|
|
export type et2_link_string = Et2LinkString;
|
2020-02-05 21:48:50 +01:00
|
|
|
|
|
|
|
/**
|
2022-05-13 11:59:13 +02:00
|
|
|
* @deprecated use Et2LinkList
|
2020-02-05 21:48:50 +01:00
|
|
|
*/
|
2022-05-13 11:59:13 +02:00
|
|
|
// can't just define as type, as tracker/app.ts uses it with iterateOver()!
|
|
|
|
// export type et2_link_list = Et2LinkList;
|
|
|
|
export class et2_link_list extends Et2LinkList {}
|
2020-02-05 21:48:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export class et2_link_add extends et2_inputWidget
|
|
|
|
{
|
2021-08-12 19:21:49 +02:00
|
|
|
static readonly _attributes: any = {
|
2020-02-05 21:48:50 +01:00
|
|
|
"value": {
|
|
|
|
"description": "Either an array of link information (see egw_link::link()) or array with keys to_app and to_id",
|
|
|
|
"type": "any"
|
|
|
|
},
|
|
|
|
"application": {
|
|
|
|
"name": "Application",
|
|
|
|
"type": "string",
|
|
|
|
"default": "",
|
|
|
|
"description": "Limit to the listed application or applications (comma seperated)"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private span: JQuery;
|
|
|
|
private div: JQuery;
|
|
|
|
private app_select: et2_link_apps;
|
|
|
|
private button: et2_button;
|
2021-08-12 19:21:49 +02:00
|
|
|
|
2020-02-05 21:48:50 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2021-08-12 19:21:49 +02:00
|
|
|
constructor(_parent: et2_widget, _attrs?: WidgetConfig, _child?: object)
|
2020-02-05 21:48:50 +01:00
|
|
|
{
|
2020-02-05 23:27:24 +01:00
|
|
|
super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_link_add._attributes, _child || {}));
|
|
|
|
|
2020-02-05 21:48:50 +01:00
|
|
|
|
|
|
|
this.span = jQuery(document.createElement("span"))
|
2021-08-12 19:21:49 +02:00
|
|
|
.text(this.egw().lang("Add new"))
|
|
|
|
.addClass('et2_link_add_span');
|
2020-02-05 21:48:50 +01:00
|
|
|
this.div = jQuery(document.createElement("div")).append(this.span);
|
|
|
|
this.setDOMNode(this.div[0]);
|
|
|
|
}
|
2021-08-12 19:21:49 +02:00
|
|
|
|
|
|
|
doLoadingFinished()
|
2020-02-05 21:48:50 +01:00
|
|
|
{
|
|
|
|
super.doLoadingFinished.apply(this, arguments);
|
2021-08-12 19:21:49 +02:00
|
|
|
if (this.app_select && this.button)
|
2020-02-05 21:48:50 +01:00
|
|
|
{
|
|
|
|
// Already done
|
|
|
|
return false;
|
|
|
|
}
|
2021-08-12 19:21:49 +02:00
|
|
|
this.app_select = <et2_link_apps>et2_createWidget("link-apps", jQuery.extend({}, this.options, {
|
2020-02-05 21:48:50 +01:00
|
|
|
'id': this.options.id + 'app',
|
|
|
|
value: this.options.application ? this.options.application : this.options.value && this.options.value.add_app ? this.options.value.add_app : null,
|
|
|
|
application_list: this.options.application ? this.options.application : null
|
2021-08-12 19:21:49 +02:00
|
|
|
}), this);
|
2022-07-12 09:57:24 +02:00
|
|
|
this.div.append(this.app_select);
|
2021-08-12 19:21:49 +02:00
|
|
|
this.button = <et2_button>et2_createWidget("button", {
|
|
|
|
id: this.options.id + "_add",
|
|
|
|
label: this.egw().lang("add")
|
|
|
|
}, this);
|
2020-02-05 21:48:50 +01:00
|
|
|
this.button.set_label(this.egw().lang("add"));
|
|
|
|
var self = this;
|
2021-08-12 19:21:49 +02:00
|
|
|
this.button.click = function ()
|
2020-02-05 21:48:50 +01:00
|
|
|
{
|
2022-07-12 09:57:24 +02:00
|
|
|
self.egw().open(self.options.value.to_app + ":" + self.options.value.to_id, self.app_select.value, 'add');
|
2020-02-05 21:48:50 +01:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
this.div.append(this.button.getDOMNode());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-12 19:21:49 +02:00
|
|
|
|
2020-02-05 21:48:50 +01:00
|
|
|
/**
|
|
|
|
* Should be handled client side.
|
|
|
|
* Return null to avoid overwriting other link values, in case designer used the same ID for multiple widgets
|
|
|
|
*/
|
2021-08-12 19:21:49 +02:00
|
|
|
getValue()
|
2020-02-05 21:48:50 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2021-08-12 19:21:49 +02:00
|
|
|
|
change egw.jsonq() and egw.link_title() to return promises
* egw.jsonq() now always returns a promise like egw.request(), still supporting old callback syntax
* egw.link_title(_app, _id, _callback, _context, _force_reload) supports boolean values for _callback (to not break existing code)
- false: just a cache lookup (like current call with just 2 parameters), returning null, if no title is cached, or the title
- true: always return a promise, which might already be resolved, if title was cached
- function: also returns a promise and calls the callback
--> calling egw.link_title(_app, _id) without 3rd parameter is deprecated now (gives a console.trace), to be changed in future to always return a promise, unless called with false, to just return a cache-lookup
* Et2SelectAccountReadonly and et2_link_widget is changed to use the new/updated syntax with promises
2022-05-02 11:27:33 +02:00
|
|
|
et2_register_widget(et2_link_add, ["link-add"]);
|