Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 1 | /** |
| 2 | * The plugin system is based |
| 3 | * on registered widgets (iframes) from |
| 4 | * foreign services. |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 5 | * The widget component represents a single iframe and is |
| 6 | * implemented as a view object. |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 7 | * |
| 8 | * @author Nils Diewald |
| 9 | */ |
Akron | e51eaa3 | 2020-11-10 09:35:53 +0100 | [diff] [blame^] | 10 | "use strict"; |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 11 | |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 12 | define(["view","plugin/service","util"], function (viewClass, serviceClass) { |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 13 | |
| 14 | return { |
| 15 | |
| 16 | /** |
| 17 | * Create new widget |
| 18 | */ |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 19 | create : function (data) { |
| 20 | return Object.create(viewClass)._init(['widget']).upgradeTo(serviceClass)._init(data).upgradeTo(this)._init(); |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 21 | }, |
| 22 | |
Akron | e8e2c95 | 2018-07-04 13:43:12 +0200 | [diff] [blame] | 23 | // Initialize widget |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 24 | _init : function () { |
| 25 | this.isWidget = true; |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 26 | return this; |
| 27 | }, |
| 28 | |
| 29 | /** |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 30 | * The element of the widget as embedded in the view |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 31 | */ |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 32 | show : function () { |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 33 | |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 34 | if (this._load) { |
| 35 | if (this._element) |
| 36 | this._element.classList.add('show'); |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 37 | return this._load; |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 38 | } |
Akron | 8d646d7 | 2018-07-08 13:45:53 +0200 | [diff] [blame] | 39 | |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 40 | let obj = this.load(); |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 41 | this._load.classList.add("widget", "show"); |
Akron | 6f557e3 | 2020-09-09 16:11:01 +0200 | [diff] [blame] | 42 | obj.setAttribute('loading', 'lazy'); |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 43 | |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 44 | // 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. |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 48 | |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 49 | this.actions.add( |
Akron | 792b1a4 | 2020-09-14 18:56:38 +0200 | [diff] [blame] | 50 | this.name, {'cls':['button-icon', 'plugin']}, function (e) { |
Akron | 8d646d7 | 2018-07-08 13:45:53 +0200 | [diff] [blame] | 51 | |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 52 | // Temporary |
Akron | 3d01380 | 2020-10-07 15:03:38 +0200 | [diff] [blame] | 53 | let str = this.name; |
| 54 | if (this.desc !== undefined) { |
| 55 | str += "\n\n" + this.desc; |
| 56 | }; |
| 57 | window.alert(str); |
Akron | 8d646d7 | 2018-07-08 13:45:53 +0200 | [diff] [blame] | 58 | }.bind(this)); |
| 59 | |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 60 | return obj; |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 61 | }, |
| 62 | |
| 63 | // Resize iframe |
| 64 | resize : function (data) { |
Akron | e1c27f6 | 2018-07-20 11:42:59 +0200 | [diff] [blame] | 65 | this.show().style.height = data.height + 'px'; |
Akron | a99315e | 2018-07-03 22:56:45 +0200 | [diff] [blame] | 66 | }, |
| 67 | |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 68 | |
| 69 | // On closing the widget view |
| 70 | onClose : function () { |
| 71 | if (this._mgr) { |
Akron | fcf89db | 2020-10-01 17:40:20 +0200 | [diff] [blame] | 72 | this._mgr._closeService(this.id); |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 73 | this._mgr = undefined; |
| 74 | }; |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | }); |