Skip to content

Commit 75ea36b

Browse files
committed
Initial version
1 parent 50fb985 commit 75ea36b

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
FormatStringMicroFlow
1+
CustomString
22
=====================
3+
This widget adds a string to your page, taking a microflow as datasource.
4+
5+
## Contributing
6+
For more information on contributing to this repository visit [Contributing to a GitHub repository] (https://world.mendix.com/display/howto50/Contributing+to+a+GitHub+repository)
7+
8+
## Typical usage scenario
9+
Display a string, composed on the fly by a microflow, in a dataview. Use this widget instead of creating an attribute solely for display purposes. Now an additional attribute to store the string has become superfluous!
10+
11+
## Installation
12+
13+
Import the widget to your project and add the Format String to a dataview on a page. Configure the properties to determine how the widget will behave in your application.
14+
15+
## Properties
16+
17+
* *Render as HTML* - Determines if HTML elements in the generated string are escaped.
18+
* *Source microflow* - A microflow generating the string to display.

src/CustomString/CustomString.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<widget id="CustomString.widget.CustomString" needsEntityContext="true" xmlns="http://www.mendix.com/widget/1.0/">
3+
<name>CustomString</name>
4+
<description></description>
5+
6+
<icon>iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjExR/NCNwAAAnVJREFUOE+tkt1LU3EYxyf2QjeKS8VUpC4WFPRyUzfdFmgimBBhdDMXNq3my3Q60yk2czo9Lac7s9zm3Kab5nxbviu+oR0tdhElQeRFUH/AwJkOvz1bRyOmdNMXPjznd3i+3+c8h5/gvygiIuISlQ0Ch7BBPZepHqoLxDJRQSiJ78QP/lxOrBAXiYNF6VFUrv4+CUTEOvGZOBt8QbpCPdH88z8VCoiMPLIhLnhqUTa7vHJNt6+43uErbezxKpt7GYXWFew5VKJjx098i4qJ9Svq2mF1z8E9tYq+cQ6scwbV+gHI1HauSONM5/v/1rXrmTeihfH++IQkdDgG4Zl7j8Hpd3g9sQbn2FvYhldQ0zaE3Oou7kGNLfxLcgrV5riEZCQlp4C1ujEwvQb/1jZWP3yFdWgZHf1LYF2LkNU7IansYnjbH+XIGz+dSkpBIgXozX00lcPuLrC9E8Dk8jpanfN4bp+DUjeM7FKTl7ft6+gtcfmm8GQcYoSxqHimh8m9gJ1AAEEFQzwLH6ExTaPSMI4sWbuP9+3rfFzi6QDV0AU6IzoHdUt3yLgXMLv2BTXGSSh0HmQ8ZMMCBLI6u7e5c5ImL8HYuwh9zzytsIutnzuhFaposrJlDLm1vRRgDFtBUFDfzSia+mBwLUBHu2o7Z7Hp3w6Zn7SOo+zFKIoZD27LLch49DL8J+bXOkSSKisn1/ajwTID9aspqNgJKPWjKNG9QWGTB9nlXUiTslxanvHgC3VfZUu/V2bmJCo7Hmv6IWdGIGsYhljlRFaRGalSA3cz33jwRdrTXYVFdKfExGTK2r3peQZfqrTNR1O9ZGRSpSw/WSD4BZFEYar4S8lzAAAAAElFTkSuQmCC</icon>
7+
8+
<properties>
9+
<property key="sourceMF" type="microflow" required="false">
10+
<caption>Source microflow</caption>
11+
<category>Data source</category>
12+
<description>Microflow returning a String</description>
13+
<returnType type="String"></returnType>
14+
</property>
15+
<property key="renderHTML" type="boolean" defaultValue="false">
16+
<caption>Render value as HTML</caption>
17+
<category>Data source</category>
18+
<description>Escapes HTML elements when set to false</description>
19+
</property>
20+
</properties>
21+
</widget>
22+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
(function() {
2+
'use strict';
3+
4+
dojo.provide('CustomString.widget.CustomString');
5+
6+
dojo.declare('CustomString.widget.CustomString', [ mxui.widget._WidgetBase, dijit._TemplatedMixin ], {
7+
8+
templateString : '<div class="CustomString-container" dojoAttachPoint="customString"></div>',
9+
10+
_contextGuid : null,
11+
_contextObj : null,
12+
_objSub : null,
13+
14+
// DOJO.WidgetBase -> PostCreate is fired after the properties of the widget are set.
15+
postCreate: function() {
16+
// Setup events
17+
18+
},
19+
20+
update : function (obj, callback) {
21+
if(typeof obj === 'string'){
22+
this._contextGuid = obj;
23+
mx.data.get({
24+
guids : [obj],
25+
callback : dojo.hitch(this, function (objArr) {
26+
if (objArr.length === 1)
27+
this._loadData(objArr[0],this.customString);
28+
else
29+
console.log('Could not find the object corresponding to the received object ID.')
30+
})
31+
});
32+
} else if(obj === null){
33+
// Sorry no data no show!
34+
console.log('Whoops... the customString has no context object passed to it!');
35+
} else {
36+
// Attach to data refresh.
37+
if (this._objSub)
38+
this.unsubscribe(this._objSub);
39+
40+
this._objSub = mx.data.subscribe({
41+
guid : obj.getGuid(),
42+
callback : dojo.hitch(this, this.update)
43+
});
44+
// Load data
45+
this._loadData(obj,this.customString);
46+
}
47+
48+
if(typeof callback !== 'undefined') {
49+
callback();
50+
}
51+
},
52+
53+
_loadData : function (obj,divElement) {
54+
mx.data.action({
55+
params : {
56+
actionname : this.sourceMF,
57+
applyto : "selection",
58+
guids : [obj.getGuid()]
59+
60+
},
61+
callback : dojo.hitch(this,function(returnedString) {
62+
// no MxObject expected
63+
divElement.innerHTML = this.checkString(returnedString, this.renderHTML);
64+
}),
65+
error : dojo.hitch(this, function(error) {
66+
alert(error.description);
67+
}),
68+
onValidation : dojo.hitch(this, function(validations) {
69+
alert("There were " + validation.length + " validation errors");
70+
})
71+
});
72+
},
73+
74+
checkString : function (string, htmlBool) {
75+
if(string.indexOf("<script") > -1 || !htmlBool)
76+
string = mxui.dom.escapeHTML(string);
77+
return string;
78+
}
79+
});
80+
})();

src/package.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<package xmlns="http://www.mendix.com/package/1.0/">
3+
<clientModule name="CustomString" version="1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
4+
<widgetFiles>
5+
<widgetFile path="CustomString/CustomString.xml"/>
6+
</widgetFiles>
7+
<files>
8+
<file path="CustomString/widget/"/>
9+
</files>
10+
</clientModule>
11+
</package>

0 commit comments

Comments
 (0)