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