activiti dynamic table reset content - alfresco

Good day to all.
I created a dynamic table on the forms area.
I would like to reset the content of the table if i selected an item in the dropdown list that will trigger the resetting of the contents (via javascript).
A sample and snippet would be appreciated.
Thank you.

you can refer this example or you can use your custom ftl
<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />
<#if field.control.params.optionSeparator??>
<#assign optionSeparator=field.control.params.optionSeparator>
<#else>
<#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
<#assign labelSeparator=field.control.params.labelSeparator>
<#else>
<#assign labelSeparator="|">
</#if>
<#assign fieldValue=field.value>
<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
<#if context.properties[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
<#elseif args[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
</#if>
</#if>
<div class="form-field">
<#if form.mode == "view">
<div class="viewmode-field">
<#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
<span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
</#if>
<span class="viewmode-label">${field.label?html}:</span>
<#if fieldValue?string == "">
<#assign valueToShow=msg("form.control.novalue")>
<#else>
<#assign valueToShow=fieldValue>
<#if field.control.params.options?? && field.control.params.options != "">
<#list field.control.params.options?split(optionSeparator) as nameValue>
<#if nameValue?index_of(labelSeparator) == -1>
<#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
<#assign valueToShow=nameValue>
<#break>
</#if>
<#else>
<#assign choice=nameValue?split(labelSeparator)>
<#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
<#assign valueToShow=msgValue(choice[1])>
<#break>
</#if>
</#if>
</#list>
</#if>
</#if>
<span class="viewmode-value">${valueToShow?html}</span>
</div>
<#else>
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<#if field.control.params.options?? && field.control.params.options != "">
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
<#if field.description??>title="${field.description}"</#if>
<#if field.indexTokenisationMode??>class="non-tokenised"</#if>
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
<#if field.control.params.style??>style="${field.control.params.style}"</#if>
<#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
<#list field.control.params.options?split(optionSeparator) as nameValue>
<#if nameValue?index_of(labelSeparator) == -1>
<option value="${nameValue?html}"<#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)> selected="selected"</#if>>${nameValue?html}</option>
<#else>
<#assign choice=nameValue?split(labelSeparator)>
<option value="${choice[0]?html}" <#if choice[0] == fieldValue?string || (fieldValue?is_number && ((fieldValue - choice[0]?number)?string == "0"))> selected="selected"</#if>>${msgValue(choice[1])?html}</option>
</#if>
</#list>
</select>
<#formLib.renderFieldHelp field=field />
<#else>
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
<#if field.description??>title="${field.description}"</#if>
<#if field.indexTokenisationMode??>class="non-tokenised"</#if>
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
<#if field.control.params.style??>style="${field.control.params.style}"</#if>
<#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
</select>
<#formLib.renderFieldHelp field=field />
<!-- <div id="${fieldHtmlId}" class="missing-options">Hello ${msg("form.control.selectone.missing-options")}</div> -->
</#if>
</#if>
</div>
<script type="text/javascript">//<![CDATA[
//var abcd =
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
console.log("type name "+"${fieldHtmlId}");
Alfresco.util.Ajax.jsonGet({
url: encodeURI(Alfresco.constants.PROXY_URI + 'url'),
successCallback:
{
fn: function loadWebscript_successCallback(response, config)
{
var obj = eval('(' + response.serverResponse.responseText + ')');
var allResults = obj.values;
function sorting(json_object, key_to_sort_by) {
function sortByKey(a, b) {
var x = a[key_to_sort_by];
var y = b[key_to_sort_by];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
json_object.sort(sortByKey);
}
if (obj)
{
sorting(allResults, 'value');
for (i = 0; i < allResults.length; i++) {
var newOption = document.createElement('option');
newOption.value = allResults[i].value;
newOption.text = (allResults[i].desc == "")?allResults[i].value:allResults[i].value +" - "+ allResults[i].desc;
YAHOO.util.Dom.get("${fieldHtmlId}").options.add(newOption);
}
if("${fieldValue}" != null && "${fieldValue}" != "" && "${fieldValue}" != undefined){
YAHOO.util.Dom.get("${fieldHtmlId}").value = "${fieldValue}";
}
}
}
}
});
}, this);
</script>
This is simple select ftl to get dynamic data from repository.
Based on value selection you can execute your js code on onChange event.

Good day guys.
I just found the answer.
I'm using activiti 6.0 community.
There is also a condition resetting the required columns to false and also a visibility condition.
I'll show the snippet after cleaning and organizing the script.
Thanks for your effort.

Related

If - else condition in XML View UI5 application

In my XML view for one of the fields I want to display "Yes" if value from Model parts is "S" or "P" and for rest of all the values want to display "No".
text="{= ${order>/parts} === 'S' ? "Yes" : ${order>/parts} === 'P' ? "Yes" : "No} }"/>
Also, how to write -
if ${order>/parts} has "S" AND ${order>/stock} has "A" then display Yes else No in the similar notion like above?
You should read about formatters, which are exactly what you require
I tried this small example and it works just fine. Maybe because you use double quotes in both opening the text property and at the values ("Yes" and "No"). Try replacing the " with ' in your values. If that doesn't work, you should check if {order>/parts} is not undefined.
View
<Input value="{= ${test1} === 'S' ? 'Yes' : ${test1} === 'P' ? 'Yes' : 'No'}" />
<Input value="{= ${test1} === 'S' ? ${test2} === 'P' ? 'Yes' : 'No' : 'No' }" />
or
<Input value="{= ${test1} === 'S' || ${test1} === 'P' ? 'Yes' : 'No'}" />
<Input value="{= ${test1} === 'S' && ${test2} === 'P' ? 'Yes' : 'No'}"/>
Controller
onInit: function() {
var oModel = new sap.ui.model.json.JSONModel({
test1: "S",
test2: "P"
});
var bindingContext = new sap.ui.model.Context();
bindingContext.oModel = oModel;
bindingContext.sPath = "/";
this.getView().setBindingContext(bindingContext);
this.getView().setModel(oModel);
}
Hope this will help you
<Input value="{= (${order>/parts} === 'S' || ${order>/parts} === 'P') ? 'Yes' : 'No' }" />
<Input value="{= (${order>/parts} === 'S' && ${order>/stock} === 'A') ? 'Yes' : 'No' }" />
It helped me too.
In my case it was using icons:
<Button icon="{= ${Approved} === true ? 'sap-icon://accept' : 'sap-icon://approve'}" press="onApproveProduct" />

add dynamic class with css binding

I want to add a class behind payment-method by function with the knockout css binding (in Magento 2.1).
So this is the current code:
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method-title field choice">
<input type="radio"
name="payment[method]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
The class is returned by getCode() which works above with the id and value.
So I thought I could do just:
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked()), getCode()}">
But then it fails with:
knockout.js:2624 Uncaught SyntaxError: Unable to parse bindings.
Bindings value: css: {'_active': (getCode() == isChecked()), getCode() }
Message: Unexpected token }
<div class="payment-method" data-bind="css: getCode()">
This works.
<div class="payment-method" data-bind="css: {getCode()}">
This doesn't.
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}, attr: {'class': getCode()}">
This works too but will overwrite the payment-method class and the _active class isn't set either initally anymore.
How do I set that dynamic class?
This piece of code is redundant, as the css data-bind is getting overwrite with your attr binding.
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}, attr: {'class': getCode()}">
This is how you can do your dynamic class (assumption these properties are observable):
<div class="payment-method" data-bind="css: CSS">
self.CSS = ko.computed(function() {
var code = self.getCode();
var isChecked = self.isChecked();
return code + ' ' + (code == isChecked ? '_active' : '');
}, viewModel);
The comment from #tyler_mitchell helped me find the solution myself through this thread: https://stackoverflow.com/a/21528681/928666
I can do:
<div class="payment-method" data-bind="attr: { 'class': 'payment-method ' + getCode() }, css: {'_active': (getCode() == isChecked())}">
Not brilliant but well...
Another example should anyone need it
<div data-bind="attr: { 'class': 'mainClass' + (dynamicClassSetOnce ? ' ' + dynamicClassSetOnce : '' }, css: { 'mainClass--focussed': isFocussed }">
...
</div>

How to upload image to an existing image src in angularjs, css

I have a table and have a upload picture. I also have a picture that is already displayed. What I want to do is when I upload a new picture it will overwrite the already displayed picture. In my fiddle I have a duck pic and when I upload new pic it display as another image. How can I hide the duck pic when the user upload new pic?
Link in my fiddle: http://jsfiddle.net/DharkRoses/m2qagzzk/6/
sample code:
angular.module('test', []);
angular.module('test').controller('UploadCtrl', function ($scope, $timeout) {
$scope.thumbnail = {
dataUrl: []
};
$scope.fileReaderSupported = window.FileReader != null;
$scope.photoChanged = function (files, index) {
if (files != null) {
var file = files[0];
var index = this.$index;
if ($scope.fileReaderSupported && file.type.indexOf('image') > -1) {
$timeout(function () {
var fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = function (e) {
$timeout(function () {
$scope.thumbnail[index] = {dataUrl: e.target.result};
});
}
Use this code:: demo
<img ng-if="!thumbnail[$index].dataUrl"ng-src="http://s13.postimg.org/w0v662g93/pink_04.png" height="50px" />
AngularJS views support binary operators
condition && true || false
You can use ng-src with conditions:
<img ng-src="{{thumbnail[$index].dataUrl.length !== 0 && thumbnail[$index].dataUrl || 'http://s13.postimg.org/w0v662g93/pink_04.png'}}" height="50px" />
HTML:
<tr ng-repeat="i in [1, 2, 3, 4]">
<td>{{i}}</td>
<td>
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)" /> </td>
<td>
<img ng-src="{{thumbnail[$index].dataUrl.length !== 0 && thumbnail[$index].dataUrl || 'http://s13.postimg.org/w0v662g93/pink_04.png'}}" height="50px" />
</td>
</tr>
fiddle

How to get the inner text from an xml document using XDocument and extension methods

I am trying to get the "NAME" and "EMAIL" texts from the following html file:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<ol>
<li>
<font class="normal">
<b>NAME</b> <img src="/images/mailbox.gif" border="0" alt="Send Mail" /> <img src="/images/icons/member_photos.gif" border="0" alt="View Photos" /> <br />
ADDRESS<br />
PHONE<br />
EMAIL<br />
<br />
</font>
</li>
</body>
</html>
Here is the code that I am using:
// Load the xml document
XDocument xDoc = XDocument.Load(#"..\..\Directory.html");
// Parse document
var names = xDoc.Root.DescendantsAndSelf()
.Where(x => x.Name.LocalName == "ol").DescendantsAndSelf()
.Where(x => x.Name.LocalName == "li").DescendantsAndSelf()
.Select(x => new
{
name = x.Elements().Where(y => y.Name.LocalName == "b").Select(y => y.Value),
email = x.DescendantsAndSelf().Where(y => y.Name.LocalName == "a" && x.FirstAttribute.Name == "href" && x.Attribute("href").Value.Contains("mailto")).Select(y => y.Value ?? "No Email")
}
);
// Print text to console
for (int i = 0; i < names.Count(); i++)
{
Console.WriteLine("{0}: {1}", names.ElementAt(i).name, names.ElementAt(i).email);
}
Somehow, the above code is printing this:
System.Linq.Enumerable+WhereSelectEnumerableIterator2[System.Xml.Linq.XElement,
System.String]:
System.Linq.Enumerable+WhereSelectEnumerableIterator2[System.Xm
l.Linq.XElement,System.String]
Could someone please tell me why this is happening? Also, if there is a better way of doing this, suggestions would be very welcome.
Without checks for null (note most of the places I use FirstorDefault can potentially thrrow NullExceptions since I do not check for null in the solution.
var htmlToProcess =
#"<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta charset='utf-8' />
<title></title>
</head>
<body>
<ol>
<li>
<font class='normal'>
<b>NAME</b> <a href='/member/mail_compose.aspx?id=name'><img src='/images/mailbox.gif' border='0' alt='Send Mail' /></a> <a href='/photos/member_viewphoto.aspx?id=name'><img src='/images/icons/member_photos.gif' border='0' alt='View Photos' /></a> <br />
ADDRESS<br />
PHONE<br />
<a href='mailto:email#hotmail.com' class='redlink'>EMAIL</a><br />
<br />
</font>
</li>
</ol>
</body>
</html>";
var body = dataSet1Tree.Nodes()
.OfType<XElement>()
.FirstOrDefault(x=> x.Name.LocalName.ToLower() =="body");
if (body != null)
{
var oi = body.Descendants()
.FirstOrDefault(x => x.Name.LocalName.ToLower() == "ol");
if (oi != null)
{
var lis = oi.Elements()
.Where(x=> x.Name.LocalName.ToLower()=="li");
var listContainingInfo =from font in lis.Select(li => body.Descendants()
.FirstOrDefault(x => x.Name.LocalName.ToLower() == "font"))
.Where(font => font != null)
select font.Nodes().OfType<XElement>();
var listOfUsers = listContainingInfo.Select(nodes => new
{
Name = nodes.FirstOrDefault(innerNode => innerNode.Name.LocalName.ToLower() == "b").Value,
Email = nodes.FirstOrDefault(innerNode => innerNode.Value == "EMAIL")
.Attributes("href")
.FirstOrDefault()
.Value
});
foreach (var user in listOfUsers)
Console.WriteLine(user.Name +" "+ user.Email);
}
}
To answer your first question (which is probably more important to you than the code I have to get it working for that sample HTML), you have .Select for your name and email fields. That's why you're returning a collection when you loop over names. If that is actually what you want, then do a SelectMany instead of a Select when you create your anonymous object.
Without a schema, I don't know how to better your XML traversing before the ".Select"
Another issue is that for the href attribute, you need to compare to FirstAttribute.Name.LocalName instead of just the FirstAttribute.Name
var names = xDoc.Root.DescendantsAndSelf()
.Where(x => x.Name.LocalName == "ol").DescendantsAndSelf()
.Where(x => x.Name.LocalName == "li").DescendantsAndSelf()
.Where(x => x.Name.LocalName == "font")
.Select(x => new
{
name = x.Descendants().Where(y => y.Name.LocalName == "b").Select(y => y.Value).Single(),
email = x.Descendants().Where(y => y.Name.LocalName == "a" && y.FirstAttribute.Name.LocalName == "href" && y.Attribute("href").Value.Contains("mailto")).Select(y => y.Value).Single()
});
Some notes:
y.Value ?? "No Email"
needs to be redone because the y.Value will never be null
also you were missing an ol tag in your html :)

Merging maps in Freemarker

I'm unable to find any documentation on how to merge two hash maps. This is what I am trying to acheive
<select
<#render_attrs commonattrs.merge({"class":"select"}) /> > ....
<#macro render_attrs attrs>
<#list attrs?keys as key>
<#if attrs[key]!="">
${key}="${attrs[key]}"
</#if>
</#list>
commonattrs + {"class": "select"}
It's documented here: http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_hashop

Resources