egroupware_official/api/js/etemplate/et2_widget_link.ts

149 lines
4.0 KiB
TypeScript
Raw Normal View History

/**
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
* @link https://www.egroupware.org
2020-02-05 21:48:50 +01:00
* @author Nathan Gray
* @copyright 2011 Nathan Gray
*/
/*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;
// Include menu system for list context menu
egw_action.egw_menu_dhtmlx;
*/
import {et2_createWidget, et2_register_widget, et2_widget, WidgetConfig} from "./et2_core_widget";
import {ClassWithAttributes} from "./et2_core_inheritance";
import {et2_inputWidget} from "./et2_core_inputWidget";
import {et2_button} from "./et2_widget_button";
import {Et2LinkList} from "./Et2Link/Et2LinkList";
import type {Et2LinkString} from "./Et2Link/Et2LinkString";
import {Et2Link} from "./Et2Link/Et2Link";
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
/**
* @deprecated use Et2LinkTo
2020-02-05 21:48:50 +01:00
*/
export type et2_link_to = Et2LinkTo;
2020-02-05 21:48:50 +01:00
/**
* @deprecated use Et2LinkAppSelect
2020-02-05 21:48:50 +01:00
*/
export type et2_link_apps = Et2LinkAppSelect;
2020-02-05 21:48:50 +01:00
/**
* @deprecated use Et2LinkEntry
2020-02-05 21:48:50 +01:00
*/
export type et2_link_entry = Et2LinkEntry;
2020-02-05 21:48:50 +01:00
/**
* @deprecated use Et2Link
*/
export type et2_link = Et2Link;
2020-02-05 21:48:50 +01:00
/**
* @deprecated use Et2LinkEntryReadonly
2020-02-05 21:48:50 +01:00
*/
export type et2_link_entry_ro = Et2LinkEntryReadonly;
2020-02-05 21:48:50 +01:00
/**
* @deprecated use Et2LinkString
2020-02-05 21:48:50 +01:00
*/
export type et2_link_string = Et2LinkString;
2020-02-05 21:48:50 +01:00
/**
* @deprecated use Et2LinkList
2020-02-05 21:48:50 +01: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
{
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;
2020-02-05 21:48:50 +01:00
/**
* Constructor
*/
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"))
.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]);
}
doLoadingFinished()
2020-02-05 21:48:50 +01:00
{
super.doLoadingFinished.apply(this, arguments);
if (this.app_select && this.button)
2020-02-05 21:48:50 +01:00
{
// Already done
return false;
}
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
}), this);
this.div.append(this.app_select);
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;
this.button.click = function ()
2020-02-05 21:48:50 +01: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;
}
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
*/
getValue()
2020-02-05 21:48:50 +01:00
{
return null;
}
}
et2_register_widget(et2_link_add, ["link-add"]);