blob: 07b1af6794e711ee4b22c42586ec651407cc8f90 [file] [log] [blame]
Akrona6c32b92018-07-02 18:39:42 +02001/**
2 * The plugin system is based
3 * on registered widgets (iframes) from
4 * foreign services.
Akrone1c27f62018-07-20 11:42:59 +02005 * The widget component represents a single iframe and is
6 * implemented as a view object.
Akrona6c32b92018-07-02 18:39:42 +02007 *
8 * @author Nils Diewald
9 */
Akrone51eaa32020-11-10 09:35:53 +010010"use strict";
Akrona6c32b92018-07-02 18:39:42 +020011
Akron22598cd2019-12-09 14:59:03 +010012define(["view","plugin/service","util"], function (viewClass, serviceClass) {
Akrona6c32b92018-07-02 18:39:42 +020013
14 return {
15
16 /**
17 * Create new widget
18 */
Akronbb891982020-10-05 16:07:18 +020019 create : function (data) {
20 return Object.create(viewClass)._init(['widget']).upgradeTo(serviceClass)._init(data).upgradeTo(this)._init();
Akrona6c32b92018-07-02 18:39:42 +020021 },
22
Akrone8e2c952018-07-04 13:43:12 +020023 // Initialize widget
Akron22598cd2019-12-09 14:59:03 +010024 _init : function () {
25 this.isWidget = true;
Akrona6c32b92018-07-02 18:39:42 +020026 return this;
27 },
28
29 /**
Akrone1c27f62018-07-20 11:42:59 +020030 * The element of the widget as embedded in the view
Akrona6c32b92018-07-02 18:39:42 +020031 */
Akrone1c27f62018-07-20 11:42:59 +020032 show : function () {
Akrona6c32b92018-07-02 18:39:42 +020033
Akron3d9ce5e2020-10-01 15:18:36 +020034 if (this._load) {
Akron24aa0052020-11-10 11:00:34 +010035 if (this._el)
36 this._el.classList.add('show');
Akron22598cd2019-12-09 14:59:03 +010037 return this._load;
Akron3d9ce5e2020-10-01 15:18:36 +020038 }
Akron8d646d72018-07-08 13:45:53 +020039
Akron22598cd2019-12-09 14:59:03 +010040 let obj = this.load();
Akron3d9ce5e2020-10-01 15:18:36 +020041 this._load.classList.add("widget", "show");
Akron6f557e32020-09-09 16:11:01 +020042 obj.setAttribute('loading', 'lazy');
Akrona6c32b92018-07-02 18:39:42 +020043
Akrone1c27f62018-07-20 11:42:59 +020044 // Per default there should at least be a button
45 // for settings, if the plugin requires settings.
46 // Otherwise a button indicating this is a plugin
47 // is a nice idea as well.
Akron22598cd2019-12-09 14:59:03 +010048
Akron37ea1192021-07-28 10:40:14 +020049 this.actions().add(
Akron792b1a42020-09-14 18:56:38 +020050 this.name, {'cls':['button-icon', 'plugin']}, function (e) {
Akron8d646d72018-07-08 13:45:53 +020051
Akrone1c27f62018-07-20 11:42:59 +020052 // Temporary
Akron3d013802020-10-07 15:03:38 +020053 let str = this.name;
54 if (this.desc !== undefined) {
55 str += "\n\n" + this.desc;
56 };
57 window.alert(str);
Akron8d646d72018-07-08 13:45:53 +020058 }.bind(this));
59
Akron22598cd2019-12-09 14:59:03 +010060 return obj;
Akrona6c32b92018-07-02 18:39:42 +020061 },
62
63 // Resize iframe
64 resize : function (data) {
Akrone1c27f62018-07-20 11:42:59 +020065 this.show().style.height = data.height + 'px';
Akrona99315e2018-07-03 22:56:45 +020066 },
67
Akron4a703872018-07-26 10:59:41 +020068
69 // On closing the widget view
70 onClose : function () {
71 if (this._mgr) {
Akronfcf89db2020-10-01 17:40:20 +020072 this._mgr._closeService(this.id);
Akron4a703872018-07-26 10:59:41 +020073 this._mgr = undefined;
74 };
Akrona6c32b92018-07-02 18:39:42 +020075 }
76 }
77});