blob: 068ced47e25c78d82a7aa725f14c6c033292c5d1 [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
Akron22598cd2019-12-09 14:59:03 +010034 if (this._load)
35 return this._load;
Akron8d646d72018-07-08 13:45:53 +020036
Akron22598cd2019-12-09 14:59:03 +010037 let obj = this.load();
Akron6f557e32020-09-09 16:11:01 +020038 obj.setAttribute('loading', 'lazy');
Akrona6c32b92018-07-02 18:39:42 +020039
Akrone1c27f62018-07-20 11:42:59 +020040 // Per default there should at least be a button
41 // for settings, if the plugin requires settings.
42 // Otherwise a button indicating this is a plugin
43 // is a nice idea as well.
Akron22598cd2019-12-09 14:59:03 +010044
Akrone1c27f62018-07-20 11:42:59 +020045 this.actions.add(
46 this.name, ['button-icon', 'plugin'], function (e) {
Akron8d646d72018-07-08 13:45:53 +020047
Akrone1c27f62018-07-20 11:42:59 +020048 // Temporary
49 window.alert("Basic information about this plugin");
Akron8d646d72018-07-08 13:45:53 +020050 }.bind(this));
51
Akron22598cd2019-12-09 14:59:03 +010052 return obj;
Akrona6c32b92018-07-02 18:39:42 +020053 },
54
55 // Resize iframe
56 resize : function (data) {
Akrone1c27f62018-07-20 11:42:59 +020057 this.show().style.height = data.height + 'px';
Akrona99315e2018-07-03 22:56:45 +020058 },
59
Akron4a703872018-07-26 10:59:41 +020060
61 // On closing the widget view
62 onClose : function () {
63 if (this._mgr) {
Akron22598cd2019-12-09 14:59:03 +010064 this._mgr._closeService(this._id);
Akron4a703872018-07-26 10:59:41 +020065 this._mgr = undefined;
66 };
Akrona6c32b92018-07-02 18:39:42 +020067 }
68 }
69});