blob: 403954c5e2a5eed32ddac989653cf1015e131db9 [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();
Akrona6c32b92018-07-02 18:39:42 +020038
Akrone1c27f62018-07-20 11:42:59 +020039 // Per default there should at least be a button
40 // for settings, if the plugin requires settings.
41 // Otherwise a button indicating this is a plugin
42 // is a nice idea as well.
Akron22598cd2019-12-09 14:59:03 +010043
Akrone1c27f62018-07-20 11:42:59 +020044 this.actions.add(
45 this.name, ['button-icon', 'plugin'], function (e) {
Akron8d646d72018-07-08 13:45:53 +020046
Akrone1c27f62018-07-20 11:42:59 +020047 // Temporary
48 window.alert("Basic information about this plugin");
Akron8d646d72018-07-08 13:45:53 +020049 }.bind(this));
50
Akron22598cd2019-12-09 14:59:03 +010051 return obj;
Akrona6c32b92018-07-02 18:39:42 +020052 },
53
54 // Resize iframe
55 resize : function (data) {
Akrone1c27f62018-07-20 11:42:59 +020056 this.show().style.height = data.height + 'px';
Akrona99315e2018-07-03 22:56:45 +020057 },
58
Akron4a703872018-07-26 10:59:41 +020059
60 // On closing the widget view
61 onClose : function () {
62 if (this._mgr) {
Akron22598cd2019-12-09 14:59:03 +010063 this._mgr._closeService(this._id);
Akron4a703872018-07-26 10:59:41 +020064 this._mgr = undefined;
65 };
Akrona6c32b92018-07-02 18:39:42 +020066 }
67 }
68});