Skip to content

Commit f11e0c5

Browse files
committed
Merge pull request #2 from Mcpoowl/master
Added a NoContext widget to the package
2 parents d6741bc + adcccd8 commit f11e0c5

File tree

8 files changed

+159
-3
lines changed

8 files changed

+159
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ This widget adds a string to your page, taking a microflow as datasource.
66
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)
77

88
## 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!
9+
Display a string, composed on the fly by a microflow. Choose whether you want to place the widget in a dataview or not (CustomString (No Context)) Use this widget instead of creating an attribute solely for display purposes. Now an additional attribute to store the string has become superfluous!
1010

1111
## Installation
1212

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.
13+
Import the widget to your project. Add either the Custom String or the Custom String (No Context) to a page. Configure the properties to determine how the widget will behave in your application.
1414

1515
## Properties
1616

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<widget id="CustomStringNoContext.widget.CustomStringNoContext" needsEntityContext="false" xmlns="http://www.mendix.com/widget/1.0/">
3+
<name>CustomString (No Context)</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+
<property key="mfToExecute" type="microflow" required="false">
21+
<caption>On click</caption>
22+
<category>Behavior</category>
23+
<description>The microflow to execute on click.</description>
24+
<returnType type="Boolean" />
25+
</property>
26+
</properties>
27+
</widget>
28+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
CustomString
3+
========================
4+
5+
@file : CustomString.js
6+
@version : 2.0.0
7+
@author : Roeland Salij
8+
@date : Thursday, December 03, 2015
9+
@copyright : Mendix 2015
10+
@license : Apache 2
11+
12+
Documentation
13+
========================
14+
Describe your widget here.
15+
*/
16+
17+
// Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
18+
define([
19+
"dojo/_base/declare",
20+
"mxui/widget/_WidgetBase",
21+
"dijit/_TemplatedMixin",
22+
"dojo/_base/array",
23+
"dojo/_base/lang",
24+
"dojo/text!CustomStringNoContext/widget/template/CustomStringNoContext.html"
25+
], function(declare, _WidgetBase, _TemplatedMixin, dojoArray, dojoLang, widgetTemplate) {
26+
"use strict";
27+
28+
// Declare widget's prototype.
29+
return declare("CustomStringNoContext.widget.CustomStringNoContext", [ _WidgetBase, _TemplatedMixin ], {
30+
// _TemplatedMixin will create our dom node using this HTML template.
31+
templateString: widgetTemplate,
32+
33+
// Parameters configured in the Modeler.
34+
sourceMF: "",
35+
renderHTML: "",
36+
37+
// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
38+
_handles: null,
39+
_alertDiv: null,
40+
41+
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
42+
constructor: function() {
43+
this._handles = [];
44+
},
45+
46+
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
47+
postCreate: function() {
48+
this._setupEvents();
49+
this._render();
50+
},
51+
52+
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
53+
54+
// Attach events to HTML dom elements
55+
_setupEvents: function() {
56+
if(this.mfToExecute){
57+
this.connect(this.customString, "click", this._executeMicroflow)};
58+
},
59+
_render : function () {
60+
mx.data.action({
61+
params : {
62+
actionname : this.sourceMF
63+
},
64+
callback : dojoLang.hitch(this,function(returnedString) {
65+
this.customString.innerHTML = this.checkString(returnedString, this.renderHTML);
66+
}),
67+
error : dojoLang.hitch(this, function(error) {
68+
alert(error.description);
69+
}),
70+
onValidation : dojoLang.hitch(this, function(validations) {
71+
alert("There were " + validations.length + " validation errors");
72+
})
73+
});
74+
},
75+
76+
_executeMicroflow: function () {
77+
if (this.mfToExecute) {
78+
mx.data.action({
79+
store: {
80+
caller: this.mxform
81+
},
82+
params: {
83+
actionname: this.mfToExecute
84+
},
85+
callback: function () {
86+
// ok
87+
},
88+
error: function () {
89+
// error
90+
}
91+
92+
});
93+
}
94+
},
95+
96+
97+
checkString : function (string, htmlBool) {
98+
if(string.indexOf("<script") > -1 || !htmlBool)
99+
string = mxui.dom.escapeHTML(string);
100+
return string;
101+
}
102+
});
103+
});
104+
105+
require(["CustomStringNoContext/widget/CustomStringNoContext"], function() {
106+
"use strict";
107+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<div class="CustomString-container" dojoAttachPoint="customString"></div>
2+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.widgetname {
2+
3+
}
4+
5+
.widgetname-message {
6+
7+
}
8+
9+
.input-group-addon {
10+
clear: both;
11+
padding: 2px 6px;
12+
}
13+
14+
.widgetname-infoTextNode {
15+
padding: 0.8em 1em;
16+
margin-top: 10px;
17+
}

src/package.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
<clientModule name="CustomString" version="2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="CustomString/CustomString.xml" />
6+
<widgetFile path="CustomStringNoContext/CustomStringNoContext.xml" />
67
</widgetFiles>
78
<files>
8-
<file path="CustomString/widget/" />
9+
<file path="CustomString/widget/" />
10+
<file path="CustomStringNoContext/widget/" />
911
</files>
1012
</clientModule>
1113
</package>

test/CustomStringTest.mpr

8 KB
Binary file not shown.

test/widgets/CustomString.mpk

4.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)