From 75ea36b68623e448fcd0497fa9c993b3992dc539 Mon Sep 17 00:00:00 2001 From: Roeland Salij Date: Fri, 10 Oct 2014 21:44:04 +0200 Subject: [PATCH] Initial version --- README.md | 18 +++++- src/CustomString/CustomString.xml | 22 +++++++ src/CustomString/widget/CustomString.js | 80 +++++++++++++++++++++++++ src/package.xml | 11 ++++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/CustomString/CustomString.xml create mode 100644 src/CustomString/widget/CustomString.js create mode 100644 src/package.xml diff --git a/README.md b/README.md index d0f60d7..85c1f4e 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/src/CustomString/CustomString.xml b/src/CustomString/CustomString.xml new file mode 100644 index 0000000..52c373f --- /dev/null +++ b/src/CustomString/CustomString.xml @@ -0,0 +1,22 @@ + + + CustomString + + + 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 + + + + Source microflow + Data source + Microflow returning a String + + + + Render value as HTML + Data source + Escapes HTML elements when set to false + + + + diff --git a/src/CustomString/widget/CustomString.js b/src/CustomString/widget/CustomString.js new file mode 100644 index 0000000..98d3104 --- /dev/null +++ b/src/CustomString/widget/CustomString.js @@ -0,0 +1,80 @@ +(function() { + 'use strict'; + + dojo.provide('CustomString.widget.CustomString'); + + dojo.declare('CustomString.widget.CustomString', [ mxui.widget._WidgetBase, dijit._TemplatedMixin ], { + + templateString : '
', + + _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(" -1 || !htmlBool) + string = mxui.dom.escapeHTML(string); + return string; + } + }); +})(); \ No newline at end of file diff --git a/src/package.xml b/src/package.xml new file mode 100644 index 0000000..723cae8 --- /dev/null +++ b/src/package.xml @@ -0,0 +1,11 @@ + + + + + + + + + + +