SAP UI5 binding by reference to another value - data-binding

I have a large model with many levels and attributes and I want to have one Input in my XML view which will always edit 1 attribute from the model, but every time it will be a different attribute.
I want to edit for example attributes on following paths:
myModel>/user/0/surname
myModel>/user/1/name
myModel>/user/2/nickname
myModel>/user/3/email
Let's say that now I am interested in editing the nickname of user nr2 so I will save its path to a variable:
myModel.setProperty("currentlyEditedPath", "myModel>/user/2/nickname");
And I want to define my Input like this:
<Input value="{myModel>/currentlyEditedPath}" >
And what happens is that UI5 will allow me to edit the string "myModel>/user/2/nickname" it self. But its wrong. I only want to use the string as a reference to some other value deep in the model which should be modified and updated. I should probably write something like this, but I cannot find the correct way:
<Input value="{ ${myModel> ${myModel>/currentlyEditedPath} } } " >
Any ideas, please? .. as simple as possible. Best inline.

I think the Element binding is the good way. Feel free to comment on this:
var oInput = sap.ui.core.Fragment.byId("myFragmentID","myInputID");
oInput.bindElement("myModel>/user/2");
oInput.bindProperty("value", "myModel>nickname");
Or I can also place the value to the XML:
<Input value="{myModel>nickname}" >

Related

How to extract information to Google Tag Manager

<input type="hidden" name="formid" class="Field FieldDescriptor" value="777">
I would like to return 777 as "formid" variable in Google Tag Manager. When I test it, it returns as undefined.
What do I need to do to have GTM pull "777" as the "formid" value?
Thanks in advance
You have formid as a data layer variable. To get it as a data layer variable, you first have to push it into the dataLayer array from the global scope.
But that's not what you want. Now, how do you get a formID value? depends on when you need it. The simplest way would be just pulling it through a JS variable that would look like so:
function(){
return document.querySelector('input[type="hidden"][name="formid"][class="Field FieldDescriptor"]').value;
}
Note that it depends on certain input attributes and their values. The selector may be adjusted depending to your needs, but that would be a separate issue.

mvcgrid.net unable to use toolbar

I'm working on a website with a feature that can sort users.
I'm using mvcgrid.net libs but I can't figure it out. the toolbar doesn't work.
I used most of the basic source codes from mvcgrid.net but when i press something in the search bar it doesn't work or the items per page selection.
If you have specific code to take a look at, please post. Otherwise, here are a few things you can check:
(1) Be sure you've applied the mvcgrid data attributes needed. For example, for a search field you might have these attributes:
<input
type="search"
data-mvcgrid-apply-additional="change"
data-mvcgrid-type="additionalQueryOption"
data-mvcgrid-option="search"
data-mvcgrid-name="ContactGrid">
(2) Be sure the value you chose for mvcgrid-option (in this example, "search") is then added when you configure the grid. For example:
MVCGridDefinitionTable.Add("ContactGrid", new MVCGridBuilder<ContactViewModel>(defaults)
.WithAdditionalQueryOptionNames("Search")
...
(3) You then need to read the attribute (again in the grid config) in your .WithRetrieveDataMethod()
string search = options.GetAdditionalQueryOptionString("search");
I've forgotten step 2 in the past -- that's generally what has tripped me up.

Adding fields dynamically to Share form

I want to add a text field for each file that is added to the attached package items in alfresco to write notes regarding each file, is it possible to do?
I have implemented something that could be reused for your use case.
You can define a property with multiple values that will contain the list of notes associated with each attachment.
There is a simple trick to post a property with multiple values: add "[]" to the name of the property. For example:
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_0"
name="prop_someco_notes[]"
tabindex="0"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_1"
name="prop_someco_notes[]"
tabindex="1"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
As you can see, the name of the input ends with []. Both input textfields have the same name.
The Alfresco Form Engine will consider these two inputs as the value for the property with multiple values: "someco:notes".
The bigger problem is that you need to generate this html with some smart javascript and free marker template.
You can write a custom free marker template to render the initial html: if a user opens a task on which documents have been already attached, you will need to generate the list of inputs using a custom control (you can of course start from textfield.ftl).
It won't be easy to generate the initial list because unfortunately Alfresco returns the list of values as a single comma separated value.
You can customise the webscript that injects the model in the free marker template "org.alfresco.web.scripts.forms.FormUIGet" to pass an array instead of a csv.
A quicker and dirtier solution is to split the csv value. In share-config-custom.xml, you can specify what textfield.ftl show use as a separator instead of the comma.
When a user adds/remove elements from the package, you can intercept the update and add/remove the correspondent note. Notice that I have added the filed "noderef" to each input so it is possible to know the relation between the notes and the nodes in the package.
UPDATE:
For the associations (used for example to define the package in a workflow task), Share uses a javascript library called "object finder" (or "object picker"). This library fires an event called "formValueChanged" that you can intercept:
YAHOO.Bubbling.fire("formValueChanged",
{
eventGroup: this,
addedItems: addedItems,
removedItems: removedItems,
selectedItems: selectedItems,
selectedItemsMetaData: Alfresco.util.deepCopy(this.selectedItems)
});

TAPi18n: how to construct the key to be translated dynamically?

I'm trying to add a prefix to the keys to be translated. This is one of my attempts:
<label for="{{n}}">{{_ 'input_label_{{n}}' }}</label>
<input name="{{n}}" placeholder="{{_ 'input_placeholder_{{n}}' }}">
Obviously it does not work because you can't nest {{ ... }}'s.
I've also tried creating a helper:
{{tr 'input_label' n}}
tr: function(prefix, fieldName) {
return TAPi18next.t(prefix + '_' + fieldName);
}
But it comes back untranslated. I assume because I'm calling TAPi18n as a static and not an instance of it, but I don't know how else to do it.
These are just two of many attempts.
I will have hundreds of inputs, and I want to avoid sending all the translation keys to the input template, since it's redundant information. The key variations can easily be made by adding prefixes.
Can you think of any way to generate the key values dynamically?
Use the second approach, but with TAPi18n.__ rather than TAPi18next.t.
Unlike TAPi18next.t, TAPi18n.__ reactively updates when the user's language choice is changed and the language has finished downloading. I'm guessing the problem is that the language choice hasn't quite come through when the template is first rendered, so TAP18next.t returns the strings in the default language (English), and doesn't update when the language changes. Using TAPi18n.__ instead fixes this.

.NET frameworks for formatting e-mail messages?

Are there any open source/free frameworks available that take some of the pain out of building HTML e-mails in C#?
I maintain a number of standalone ASP.NET web forms whose main function is to send an e-mail. Most of these are in plain text format right now, because doing a nice HTML presentation is just too tedious.
I'd also be interested in other approaches to tackling this same problem.
EDIT: To be clear, I'm interested in taking plain text form input (name, address, phone number) and dropping it into an HTML e-mail template. That way the receipient would see a nicely formatted message instead of the primitive text output we're currently giving them.
EDIT 2: As I'm thinking more about this and about the answers the question has generated so far, I'm getting a clearer picture of what I'm looking for. Ideally I'd like a new class that would allow me to go:
HtmlMessage body = new HtmlMessage();
body.Header(imageLink);
body.Title("Some Text That Will Display as a Header");
body.Rows.Add("First Name", FirstName.Text);
The HtmlMessage class builds out a table, drops the images in place and adds new rows for each field that I add. It doesn't seem like it would be that hard to write, so if there's nothing out there, maybe I'll go that route
Andrew Davey created Postal which lets you do templated emails using any of the ASP.NET MVC view engines. Here's a video where he talks about how to use it.
His examples:
public class HomeController : Controller {
public ActionResult Index() {
dynamic email = new Email("Example");
email.To = "webninja#example.com";
email.FunnyLink = DB.GetRandomLolcatLink();
email.Send();
return View();
}
}
And the template using Razor:
To: #ViewBag.To From: lolcats#website.com Subject: Important Message
Hello, You wanted important web links right? Check out this:
#ViewBag.FunnyLink
<3
The C# port of StringTemplate worked well for me. I highly recommend it. The template file can have a number of named tokens like this:
...
<b>
Your information to login is as follows:<br />
Username: $username$<br />
Password: $password$<br />
</b>
...
...and you can load this template and populate it like this:
notificationTemplate.SetAttribute("username", Username);
notificationTemplate.SetAttribute("password", Password);
At the end, you get the ToString() of the template and assign it to the MailMessage.Body property.
I recently implemented what you're describing using MarkDownSharp. It was pretty much painless.
It's the same framework (minus a few tweaks) that StackOverflow uses to take plain-text-formatted posts and make them look like nice HTML.
Another option would be to use something like TinyMCE to give your users a WYWIWYG HTML editor. This would give them more power over the look and feel of their emails, but it might just overcomplicate things.
Bear in mind that there are also some security issues with user-generated HTML. Regardless of which strategy you use, you need to make sure you sanitize the user's input so they can't include scary things like script tags in their input.
Edit
Sorry, I didn't realize you were looking for an email templating solution. The simplest solution I've come up with is to enable text "macros" in user-generated content emails. So, for example, the user could input:
Dear {RecipientFirstName},
Thank you for your interest in {ClientCompanyName}. The position you applied for has the following minimum requirements:
- B.S. or greater in Computer Science or related field
- ...
And then we'd do some simple parsing to break this down to:
Dear {0},
Thank you for your interest in {1}. The position you applied for has the following minimum requirements:
- B.S. or greater in Computer Science or related field
- ...
... and ...
0 = "RecipientFirstName"
1 = "ClientCompanyName"
...
We store these two components in our database, and whenever we're ready to create a new instance from this template, we evaluate the values of the given property names, and use a standard format string call to generate the actual content.
string.Format(s, macroCodes.Select(c => EvaluateMacroCode(c, obj)).ToArray());
Then I use MarkdownSharp, along with some HTML sanitizing methods, to produce a nicely-formatted HTML email message:
Dear John,
Thank you for your interest in Microsoft. The position you applied for has the following minimum requirements:
B.S. or greater in Computer Science or related field
...
I'd be curious to know if there's something better out there, but I haven't found anything yet.

Resources