Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
RoelandSalij committed Oct 10, 2014
1 parent 50fb985 commit 75ea36b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
FormatStringMicroFlow
CustomString
=====================
This widget adds a string to your page, taking a microflow as datasource.

## Contributing
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)

## Typical usage scenario
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!

## Installation

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.

## Properties

* *Render as HTML* - Determines if HTML elements in the generated string are escaped.
* *Source microflow* - A microflow generating the string to display.
22 changes: 22 additions & 0 deletions src/CustomString/CustomString.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<widget id="CustomString.widget.CustomString" needsEntityContext="true" xmlns="http://www.mendix.com/widget/1.0/">
<name>CustomString</name>
<description></description>

<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>

<properties>
<property key="sourceMF" type="microflow" required="false">
<caption>Source microflow</caption>
<category>Data source</category>
<description>Microflow returning a String</description>
<returnType type="String"></returnType>
</property>
<property key="renderHTML" type="boolean" defaultValue="false">
<caption>Render value as HTML</caption>
<category>Data source</category>
<description>Escapes HTML elements when set to false</description>
</property>
</properties>
</widget>

80 changes: 80 additions & 0 deletions src/CustomString/widget/CustomString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
(function() {
'use strict';

dojo.provide('CustomString.widget.CustomString');

dojo.declare('CustomString.widget.CustomString', [ mxui.widget._WidgetBase, dijit._TemplatedMixin ], {

templateString : '<div class="CustomString-container" dojoAttachPoint="customString"></div>',

_contextGuid : null,
_contextObj : null,
_objSub : null,

// DOJO.WidgetBase -> PostCreate is fired after the properties of the widget are set.
postCreate: function() {
// Setup events

},

update : function (obj, callback) {
if(typeof obj === 'string'){
this._contextGuid = obj;
mx.data.get({
guids : [obj],
callback : dojo.hitch(this, function (objArr) {
if (objArr.length === 1)
this._loadData(objArr[0],this.customString);
else
console.log('Could not find the object corresponding to the received object ID.')
})
});
} else if(obj === null){
// Sorry no data no show!
console.log('Whoops... the customString has no context object passed to it!');
} else {
// Attach to data refresh.
if (this._objSub)
this.unsubscribe(this._objSub);

this._objSub = mx.data.subscribe({
guid : obj.getGuid(),
callback : dojo.hitch(this, this.update)
});
// Load data
this._loadData(obj,this.customString);
}

if(typeof callback !== 'undefined') {
callback();
}
},

_loadData : function (obj,divElement) {
mx.data.action({
params : {
actionname : this.sourceMF,
applyto : "selection",
guids : [obj.getGuid()]

},
callback : dojo.hitch(this,function(returnedString) {
// no MxObject expected
divElement.innerHTML = this.checkString(returnedString, this.renderHTML);
}),
error : dojo.hitch(this, function(error) {
alert(error.description);
}),
onValidation : dojo.hitch(this, function(validations) {
alert("There were " + validation.length + " validation errors");
})
});
},

checkString : function (string, htmlBool) {
if(string.indexOf("<script") > -1 || !htmlBool)
string = mxui.dom.escapeHTML(string);
return string;
}
});
})();
11 changes: 11 additions & 0 deletions src/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="CustomString" version="1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="CustomString/CustomString.xml"/>
</widgetFiles>
<files>
<file path="CustomString/widget/"/>
</files>
</clientModule>
</package>

0 comments on commit 75ea36b

Please sign in to comment.