blob: b8aa49e49da8896a4ac83cca1f1915d943970b29 [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
Akrone1c27f62018-07-20 11:42:59 +020011define(["view","util"], function (viewClass) {
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) {
Akrone1c27f62018-07-20 11:42:59 +020020 return Object.create(viewClass)._init(['widget']).upgradeTo(this)._init(name, src, id);
Akrona6c32b92018-07-02 18:39:42 +020021 },
22
Akrone8e2c952018-07-04 13:43:12 +020023 // Initialize widget
Akron7991b192018-07-09 17:28:43 +020024 _init : function (name, src, id) {
Akron56a11af2018-07-27 18:28:45 +020025 if (!name || !src || !id)
26 throw Error("Widget not well defined");
Akron7991b192018-07-09 17:28:43 +020027 this.name = name;
Akrona6c32b92018-07-02 18:39:42 +020028 this.src = src;
29 this.id = id;
30 return this;
31 },
32
33 /**
Akrone1c27f62018-07-20 11:42:59 +020034 * The element of the widget as embedded in the view
Akrona6c32b92018-07-02 18:39:42 +020035 */
Akrone1c27f62018-07-20 11:42:59 +020036 show : function () {
Akrona6c32b92018-07-02 18:39:42 +020037
Akrone1c27f62018-07-20 11:42:59 +020038 if (this._show)
39 return this._show;
Akron8d646d72018-07-08 13:45:53 +020040
Akrona6c32b92018-07-02 18:39:42 +020041 // Spawn new iframe
Akrone1c27f62018-07-20 11:42:59 +020042 var i = document.createElement('iframe');
Akrona6c32b92018-07-02 18:39:42 +020043 i.setAttribute('allowTransparency',"true");
44 i.setAttribute('frameborder', 0);
45 i.setAttribute('sandbox','allow-scripts');
Akrone8e2c952018-07-04 13:43:12 +020046 i.style.height = '0px';
Akrona6c32b92018-07-02 18:39:42 +020047 i.setAttribute('name', this.id);
48 i.setAttribute('src', this.src);
Akrona6c32b92018-07-02 18:39:42 +020049
Akrone1c27f62018-07-20 11:42:59 +020050 // Per default there should at least be a button
51 // for settings, if the plugin requires settings.
52 // Otherwise a button indicating this is a plugin
53 // is a nice idea as well.
Akron8d646d72018-07-08 13:45:53 +020054
Akrone1c27f62018-07-20 11:42:59 +020055 this.actions.add(
56 this.name, ['button-icon', 'plugin'], function (e) {
Akron8d646d72018-07-08 13:45:53 +020057
Akrone1c27f62018-07-20 11:42:59 +020058 // Temporary
59 window.alert("Basic information about this plugin");
Akron8d646d72018-07-08 13:45:53 +020060 }.bind(this));
61
Akrone1c27f62018-07-20 11:42:59 +020062 this._show = i;
63 return i;
Akrona6c32b92018-07-02 18:39:42 +020064 },
65
66 // Resize iframe
67 resize : function (data) {
Akrone1c27f62018-07-20 11:42:59 +020068 this.show().style.height = data.height + 'px';
Akrona99315e2018-07-03 22:56:45 +020069 },
70
Akron4a703872018-07-26 10:59:41 +020071
72 // On closing the widget view
73 onClose : function () {
74 if (this._mgr) {
75 this._mgr._closeWidget(this._id);
76 this._mgr = undefined;
77 };
Akrona6c32b92018-07-02 18:39:42 +020078 }
79 }
80});