blob: 25bc6cc30d6fd4a7b05f925aef68866339d93dd1 [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 */
10
Akron22598cd2019-12-09 14:59:03 +010011define(["view","plugin/service","util"], function (viewClass, serviceClass) {
Akrona6c32b92018-07-02 18:39:42 +020012 "use strict";
13
14 return {
15
16 /**
17 * Create new widget
18 */
Akron7991b192018-07-09 17:28:43 +020019 create : function (name, src, id) {
Akron22598cd2019-12-09 14:59:03 +010020 return Object.create(viewClass)._init(['widget']).upgradeTo(serviceClass)._init(name, src, id).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) {
35 if (this._element)
36 this._element.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
Akrone1c27f62018-07-20 11:42:59 +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
53 window.alert("Basic information about this plugin");
Akron8d646d72018-07-08 13:45:53 +020054 }.bind(this));
55
Akron22598cd2019-12-09 14:59:03 +010056 return obj;
Akrona6c32b92018-07-02 18:39:42 +020057 },
58
59 // Resize iframe
60 resize : function (data) {
Akrone1c27f62018-07-20 11:42:59 +020061 this.show().style.height = data.height + 'px';
Akrona99315e2018-07-03 22:56:45 +020062 },
63
Akron4a703872018-07-26 10:59:41 +020064
65 // On closing the widget view
66 onClose : function () {
67 if (this._mgr) {
Akron22598cd2019-12-09 14:59:03 +010068 this._mgr._closeService(this._id);
Akron4a703872018-07-26 10:59:41 +020069 this._mgr = undefined;
70 };
Akrona6c32b92018-07-02 18:39:42 +020071 }
72 }
73});