Skip to content

Commit 74fcc00

Browse files
author
Jelte Lagendijk
committed
Merge branch 'master' of ssh://github.com/mendix/HTMLSnippet
2 parents e232253 + 82e51fa commit 74fcc00

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<widget id="HTMLSnippet.widget.HTMLSnippetContext" needsEntityContext="true" xmlns="http://www.mendix.com/widget/1.0/">
3+
<name>HTMLSnippet with Context</name>
4+
<description>The HTMLSnippet widget can be used to insert a custom piece of HTML or JavaScript in the client</description>
5+
6+
<icon>iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ bWFnZVJlYWR5ccllPAAAAm9JREFUeNqEU01IVFEU/t6bGcfGJq2RYkhKSKdFIGQxRRAR0q6kZuuq hWZY0SZa1EKhRQsTpEVZrVpUVgxGFETgLgorEdPsZ1FizJhJ1Py8N+/d+97p3DcK80Lr8i733HvO 953vnnOfRkRYaVi2QEADQqcmfQE0tEur3GurEUghPHAq1eo7T6fH/SSKYKWJrjd0eZLILuYoa/DB INGmu0TnJthm33JcEP8ZUhJOjgHHk8COGPDd8Pv1f4FjtRyg64jWAAcbgGNNQFujPybY9/AHrUYQ yX7F2GwGyS37UB8BKpMf6Jsh05TlK+xpXlNZZ0iXMNLYhKPdw7iZ7kLLRiDAaV7NAZ2pG+jZfg17 8/PoFU+g9T5YIEWQMyQcFx5YsmE7BCFdnL4w4lN1NtGP/p7PmPoAjE/Fywpcruahligevf6F9t21 CId0JYQ/QvJeB158zONwax2GXy5iZuAEJqaBREIRcI0sKb1M4aAGS7ge+PrzBWjc6SuPs2iIhZCI h7F5QxVqqnTcGnUwcBvovrhUxKIlUVIEIQ0d+2MI6hrUmepxwXLguqpGa5UglDhBoeQg3z6NeF0I 5+/PQS+YxM/Whclz8Ok8bCYzSq4HKHKww0TvZg18yhis0IF6Y6btMBnBtWzov00bJQYrRzkzOLNc 2isFhKvPMljMS0/BukgAQ53NEGyTRdDaLr2nIzvX49tPCzYfWqzAYnalRNlqFd7krnB3hFNu89b6 MEbvfEEwx8xKUrQ6AJvrUC00iDAHSV6lDuGSB3IYzDzc6rLa5X9Q23bmLZX4RZF3J3baylbyHEBd jYHenhV4Ff1r/BFgACiOjHWT8QsmAAAAAElFTkSuQmCC</icon>
7+
8+
<properties>
9+
<!-- content type -->
10+
<property key="contenttype" type="enumeration" defaultValue="html">
11+
<caption>Content Type</caption>
12+
<category>Behavior</category>
13+
<description>Defines whether this widget provides a piece of HTML or a piece of JavaScript.
14+
</description>
15+
<enumerationValues>
16+
<enumerationValue key="html">HTML</enumerationValue>
17+
<enumerationValue key="js">JavaScript</enumerationValue>
18+
<enumerationValue key="jsjQuery">JavaScript with jQuery</enumerationValue>
19+
</enumerationValues>
20+
</property>
21+
22+
<!-- html/js string -->
23+
<property key="contents" type="translatableString" multiline="true" required="false">
24+
<caption>Contents</caption>
25+
<category>Behavior</category>
26+
<description>The HTML or Javascript to embed.</description>
27+
</property>
28+
29+
<!-- html/js file path -->
30+
<property key="contentsPath" type="string" required="false">
31+
<caption>External File</caption>
32+
<category>Behavior</category>
33+
<description>The path to the HTML or Javascript you want to add. The root folder is theme folder. Will override the Contents if used.</description>
34+
</property>
35+
36+
<!-- The onclick microflow -->
37+
<property key="onclickmf" type="microflow" required="false">
38+
<caption> On click microflow </caption>
39+
<category>Behavior</category>
40+
<description>The microflow to execute on click</description>
41+
<returnType type="Void"/>
42+
</property>
43+
44+
<!-- description of what the html/js should do -->
45+
<property key="documentation" type="string" multiline="true" required="false">
46+
<caption>Documentation</caption>
47+
<category>Common</category>
48+
<description>Documentation of this widget. Should explain its purpose.</description>
49+
</property>
50+
51+
<!-- Refresh when the context changes -->
52+
<property key="refreshOnContextChange" type="boolean" defaultValue="false">
53+
<caption>Refresh on context change</caption>
54+
<category>Behavior</category>
55+
<description>Refresh when the context changes</description>
56+
</property>
57+
58+
<!-- Refresh when the context updates -->
59+
<property key="refreshOnContextUpdate" type="boolean" defaultValue="false">
60+
<caption>Refresh on context update</caption>
61+
<category>Behavior</category>
62+
<description>Refresh when the context updates (works only when context change is true)</description>
63+
</property>
64+
</properties>
65+
</widget>

src/HTMLSnippet/widget/HTMLSnippet.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ define([
99
"dojo/dom-construct",
1010
"dojo/_base/lang",
1111
"dijit/layout/LinkPane"
12-
], function(declare, _WidgetBase, dom, domStyle, domAttr, domConstruct, lang, LinkPane) {
12+
], function (declare, _WidgetBase, dom, domStyle, domAttr, domConstruct, lang, LinkPane) {
1313
"use strict";
1414

1515
return declare("HTMLSnippet.widget.HTMLSnippet", [_WidgetBase], {
1616

1717
_objectChangeHandler: null,
18+
contextObj: null,
1819

19-
postCreate: function() {
20+
postCreate: function () {
2021
logger.debug(this.id + ".postCreate");
2122
this._setupEvents();
2223

@@ -25,7 +26,7 @@ define([
2526
}
2627
},
2728

28-
executeCode: function() {
29+
executeCode: function () {
2930
logger.debug(this.id + ".executeCode");
3031
var external = this.contentsPath !== "" ? true : false;
3132
switch (this.contenttype) {
@@ -35,7 +36,7 @@ define([
3536
preload: true,
3637
loadingMessage: "",
3738
href: this.contentsPath,
38-
onDownloadError: function() {
39+
onDownloadError: function () {
3940
console.log("Error loading html path");
4041
}
4142
}).placeAt(this.domNode.id).startup();
@@ -77,8 +78,9 @@ define([
7778
}
7879
},
7980

80-
update: function(obj, callback) {
81+
update: function (obj, callback) {
8182
logger.debug(this.id + ".update");
83+
this.contextObj = obj;
8284
if (this.refreshOnContextChange) {
8385
this.executeCode();
8486

@@ -89,7 +91,7 @@ define([
8991
if (obj) {
9092
this._objectChangeHandler = this.subscribe({
9193
guid: obj.getGuid(),
92-
callback: lang.hitch(this, function() {
94+
callback: lang.hitch(this, function () {
9395
this.executeCode();
9496
})
9597
});
@@ -100,21 +102,32 @@ define([
100102
this._executeCallback(callback, "update");
101103
},
102104

103-
_setupEvents: function() {
105+
_setupEvents: function () {
104106
logger.debug(this.id + "._setupEvents");
105107
if (this.onclickmf) {
106108
this.connect(this.domNode, "click", this._executeMicroflow);
107109
}
108110
},
109111

110-
_executeMicroflow: function() {
112+
_executeMicroflow: function () {
111113
logger.debug(this.id + "._executeMicroflow");
112114
if (this.onclickmf) {
113-
mx.ui.action(this.onclickmf, {}, this);
115+
var params = {
116+
applyto: "selection",
117+
actionname: this.onclickmf
118+
};
119+
if (this.contextObj != null) {
120+
params.guids = [this.contextObj.getGuid()]
121+
}
122+
mx.data.action({
123+
params: params,
124+
callback: function (obj) { },
125+
error: function (error) { }
126+
}, this);
114127
}
115128
},
116129

117-
evalJs: function() {
130+
evalJs: function () {
118131
logger.debug(this.id + ".evalJS");
119132
try {
120133
eval(this.contents + "\r\n//# sourceURL=" + this.id + ".js");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define([
2+
"dojo/_base/declare", "HTMLSnippet/widget/HTMLSnippet"
3+
], function (declare, HTMLSnippet) {
4+
"use strict";
5+
6+
// Declare widget"s prototype.
7+
return declare("HTMLSnippet.widget.HTMLSnippetContext", [HTMLSnippet]);
8+
9+
});
10+
11+
require(["HTMLSnippet/widget/HTMLSnippetContext"]);

src/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<clientModule name="HTMLSnippet" version="3.8.1" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="HTMLSnippet/HTMLSnippet.xml"/>
6+
<widgetFile path="HTMLSnippet/HTMLSnippetContext.xml"/>
67
</widgetFiles>
78
<files>
89
<file path="HTMLSnippet/widget/"/>

test/Test.mpr

8 KB
Binary file not shown.

test/widgets/HTMLSnippet.mpk

-2.06 KB
Binary file not shown.

0 commit comments

Comments
 (0)