Skip to content

Commit afe585a

Browse files
author
Jelte Lagendijk
committed
Cleanup code
1 parent b4a1ef6 commit afe585a

File tree

1 file changed

+130
-130
lines changed

1 file changed

+130
-130
lines changed

src/HTMLSnippet/widget/HTMLSnippet.js

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,135 +2,135 @@
22
/*global mx, mxui, mendix, dojo, require, console, define, module, document*/
33

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

0 commit comments

Comments
 (0)