|
2 | 2 | /*global mx, mxui, mendix, dojo, require, console, define, module, document*/
|
3 | 3 |
|
4 | 4 | require([
|
5 |
| - "dojo/_base/declare", |
6 |
| - "mxui/widget/_WidgetBase", |
| 5 | + "dojo/_base/declare", |
| 6 | + "mxui/widget/_WidgetBase", |
7 | 7 |
|
8 |
| - "mxui/dom", |
9 |
| - "dojo/dom-style", |
10 |
| - "dojo/dom-attr", |
11 |
| - "dojo/dom-construct", |
12 |
| - "dojo/_base/lang", |
13 |
| - "dijit/layout/LinkPane" |
14 |
| -], function (declare, _WidgetBase, dom, domStyle, domAttr, domConstruct, lang, linkPane) { |
15 |
| - "use strict"; |
| 8 | + "mxui/dom", |
| 9 | + "dojo/dom-style", |
| 10 | + "dojo/dom-attr", |
| 11 | + "dojo/dom-construct", |
| 12 | + "dojo/_base/lang", |
| 13 | + "dijit/layout/LinkPane" |
| 14 | +], function(declare, _WidgetBase, dom, domStyle, domAttr, domConstruct, lang, linkPane) { |
| 15 | + "use strict"; |
16 | 16 |
|
17 |
| - return declare("HTMLSnippet.widget.HTMLSnippet", [_WidgetBase], { |
| 17 | + return declare("HTMLSnippet.widget.HTMLSnippet", [_WidgetBase], { |
18 | 18 |
|
19 |
| - postCreate: function () { |
20 |
| - var external = this.contentsPath !== "" ? true : false; |
21 |
| - this._setupEvents(); |
| 19 | + postCreate: function() { |
| 20 | + this._setupEvents(); |
22 | 21 |
|
23 |
| - switch (this.contenttype) { |
24 |
| - case "html": |
25 |
| - if (external) { |
26 |
| - new linkPane({ |
27 |
| - preload: true, |
28 |
| - loadingMessage: "", |
29 |
| - href: this.contentsPath, |
30 |
| - onDownloadError: function(){ |
31 |
| - console.log("Error loading html path"); |
32 |
| - } |
33 |
| - }).placeAt(this.domNode.id).startup(); |
34 |
| - } else { |
35 |
| - domStyle.set(this.domNode, { |
36 |
| - "height": "auto", |
37 |
| - "width": "100%", |
38 |
| - "outline": 0 |
39 |
| - }); |
| 22 | + if (!this.refreshOnContextChange) { |
| 23 | + this.executeCode(); |
| 24 | + } |
| 25 | + }, |
40 | 26 |
|
41 |
| - domAttr.set(this.domNode, "style", this.style); // might override height and width |
42 |
| - var domNode = domConstruct.create("div", { innerHTML: this.contents }); |
43 |
| - domConstruct.place(domNode, this.domNode, "only"); |
44 |
| - } |
45 |
| - break; |
| 27 | + executeCode: function() { |
| 28 | + var external = this.contentsPath !== "" ? true : false; |
| 29 | + switch (this.contenttype) { |
| 30 | + case "html": |
| 31 | + if (external) { |
| 32 | + new linkPane({ |
| 33 | + preload: true, |
| 34 | + loadingMessage: "", |
| 35 | + href: this.contentsPath, |
| 36 | + onDownloadError: function() { |
| 37 | + console.log("Error loading html path"); |
| 38 | + } |
| 39 | + }).placeAt(this.domNode.id).startup(); |
| 40 | + } else { |
| 41 | + domStyle.set(this.domNode, { |
| 42 | + "height": "auto", |
| 43 | + "width": "100%", |
| 44 | + "outline": 0 |
| 45 | + }); |
46 | 46 |
|
47 |
| - case "js": |
48 |
| - case "jsjQuery": |
49 |
| - if (external) { |
50 |
| - var scriptNode = document.createElement("script"), |
51 |
| - intDate = +new Date(); |
| 47 | + domAttr.set(this.domNode, "style", this.style); // might override height and width |
| 48 | + var domNode = domConstruct.create("div", { innerHTML: this.contents }); |
| 49 | + domConstruct.place(domNode, this.domNode, "only"); |
| 50 | + } |
| 51 | + break; |
52 | 52 |
|
53 |
| - scriptNode.type = "text/javascript"; |
54 |
| - scriptNode.src = this.contentsPath + "?v=" + intDate.toString(); |
| 53 | + case "js": |
| 54 | + case "jsjQuery": |
| 55 | + if (external) { |
| 56 | + var scriptNode = document.createElement("script"), |
| 57 | + intDate = +new Date(); |
55 | 58 |
|
56 |
| - domConstruct.place(scriptNode, this.domNode, "only"); |
57 |
| - } else { |
58 |
| - if (this.contenttype == "jsjQuery") { |
59 |
| - require(["HTMLSnippet/lib/jquery-1.11.3"], lang.hitch(this, this.evalJs)); |
60 |
| - } else { |
61 |
| - this.evalJs(); |
62 |
| - } |
63 |
| - } |
64 |
| - break; |
65 |
| - } |
66 |
| - }, |
| 59 | + scriptNode.type = "text/javascript"; |
| 60 | + scriptNode.src = this.contentsPath + "?v=" + intDate.toString(); |
67 | 61 |
|
68 |
| - _setupEvents: function () { |
69 |
| - if (this.onclickmf) { |
70 |
| - this.connect(this.domNode, "click", this._executeMicroflow); |
71 |
| - } |
72 |
| - }, |
| 62 | + domConstruct.place(scriptNode, this.domNode, "only"); |
| 63 | + } else { |
| 64 | + if (this.contenttype == "jsjQuery") { |
| 65 | + require(["HTMLSnippet/lib/jquery-1.11.3"], lang.hitch(this, this.evalJs)); |
| 66 | + } else { |
| 67 | + this.evalJs(); |
| 68 | + } |
| 69 | + } |
| 70 | + break; |
| 71 | + } |
| 72 | + }, |
73 | 73 |
|
74 |
| - _executeMicroflow: function () { |
75 |
| - if (this.onclickmf) { |
76 |
| - mx.data.action({ |
77 |
| - store: { |
78 |
| - caller: this.mxform |
79 |
| - }, |
80 |
| - params: { |
81 |
| - actionname: this.onclickmf |
82 |
| - }, |
83 |
| - callback: function () { |
84 |
| - // ok |
85 |
| - }, |
86 |
| - error: function () { |
87 |
| - // error |
88 |
| - } |
89 |
| - }); |
90 |
| - } |
91 |
| - }, |
| 74 | + update: function(obj, callback) { |
| 75 | + if (this.refreshOnContextChange) { |
| 76 | + this.executeCode(); |
| 77 | + } |
| 78 | + callback(); |
| 79 | + }, |
92 | 80 |
|
93 |
| - evalJs: function () { |
94 |
| - try { |
95 |
| - eval(this.contents + "\r\n//# sourceURL=" + this.id + ".js"); |
96 |
| - } catch (e) { |
97 |
| - domConstruct.place("<div class=\"alert alert-danger\">Error while evaluating javascript input: " + e + "</div>", this.domNode, "only"); |
98 |
| - } |
99 |
| - } |
| 81 | + _setupEvents: function() { |
| 82 | + if (this.onclickmf) { |
| 83 | + this.connect(this.domNode, "click", this._executeMicroflow); |
| 84 | + } |
| 85 | + }, |
100 | 86 |
|
101 |
| - }); |
| 87 | + _executeMicroflow: function() { |
| 88 | + if (this.onclickmf) { |
| 89 | + mx.data.action({ |
| 90 | + store: { |
| 91 | + caller: this.mxform |
| 92 | + }, |
| 93 | + params: { |
| 94 | + actionname: this.onclickmf |
| 95 | + }, |
| 96 | + callback: function() { |
| 97 | + // ok |
| 98 | + }, |
| 99 | + error: function() { |
| 100 | + // error |
| 101 | + } |
| 102 | + }); |
| 103 | + } |
| 104 | + }, |
| 105 | + |
| 106 | + evalJs: function() { |
| 107 | + try { |
| 108 | + eval(this.contents + "\r\n//# sourceURL=" + this.id + ".js"); |
| 109 | + } catch (e) { |
| 110 | + domConstruct.place("<div class=\"alert alert-danger\">Error while evaluating javascript input: " + e + "</div>", this.domNode, "only"); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + }); |
102 | 115 | });
|
0 commit comments