Removing "undefined" in pre populated url form link (from Modified Google Expense Report script) - url

I've modified the standard google drive expense report system to use it as a competency and experience matrix where the manager can approve/reject a form.
The problem i'm encountering is when a form is rejected by the manager it sends a link back to the employee with a link to a form pre-populated by the url.
However if the employee didn't enter a value in the original form the url populates it as "undefined".
Question, can I pre-populate a form via url removing or replacing the "undefined" values?
Perhaps the code will explain better than I can.
+ "<P><b>" + 'Please re-submit your form <a href=' + USER_FORM_URL +
'&entry_2=' + encodeURIComponent(row.forename) + '&entry_3=' +
encodeURIComponent(row.surname) + '>here</a></b>'
Any help would be much appreciated, struggled to find a solution "out there".
Tom
image link http://s11.postimage.org/dyd1olkoz/url_stack.jpg as i'm a new poster.

Looks like the getObjects() function in the script may skip adding a value to the row object, later used in sendReportToManager(), if the value is empty in the expense report spreadsheet. So, later trying to append something like row.bananas (or something empty in sheet and thus not defined on object) will result in 'undefined' being appended to the string instead. If you look at your querystring for the form with the 'undefined' values, you should see 'undefined' in the url's querystring.
You can avoid this by wrapping your encodeURIComponent(row.XXXX) calls for potentially empty columns to be something like this: row.XXXX ? encodeURIComponent(row.XXXX) : ""
So, replace the likes of:
+ "<P><b>" + 'Please re-submit your form <a href=' + USER_FORM_URL +
'&entry_2=' + encodeURIComponent(row.forename) + '&entry_3=' +
with
+ "<P><b>" + 'Please re-submit your form <a href=' + USER_FORM_URL +
'&entry_2=' + (row.forename ? encodeURIComponent(row.forename) : "") + '&entry_3=' +

Related

AdWords PLACEMENT_PERFORMANCE_REPORT not pulling URLs

This should be extremely simple but for some reason it doesn't seem to work. I'm trying to pull the URLs of display placements using the DISPLAY_PERFORMANCE_REPORT but instead of URLs it's just returning "--".
The code I'm using is:
var report = AdWordsApp.report(
"SELECT CampaignName, Clicks, FinalAppUrls, FinalUrls " +
"FROM PLACEMENT_PERFORMANCE_REPORT " +
"WHERE Clicks > 0 " +
"DURING LAST_30_DAYS");
var rows = report.rows();
while (rows.hasNext()) {
var row = rows.next();
var url = row["FinalUrls"];
Logger.log(url);
}
I've tried logging the CampaignName and clicks and they're working as expected, so can't understand what the issue is here. The only thing I can think of is that in the reference guide it says:
List of final URLs of the main object of this row. UrlList elements
are returned in JSON list format
I'm not entirely sure what JSON list format is, but when I log the typeof url it says it's a string, so thought it shouldn't be an issue.
The FinalAppUrls and FinalUrls list the target URLs that you set on the individual managed placements.
If you're interested in the URL (domain, rather) of the placement itself, you'll have to request either the Criteria or the DisplayName field in your report——they both contain the domain of the placement.

Append to query-string with the same key

I am trying to add some parts to a query-string with the same key.
I have a url like http://server.com/search/result?query=hello with some controls that should add a collaborator to the query-string.
This is done with this:
<g:link action="result" params="${params + ['collaborator': collaborator.id]}">${collaborator.name}</g:link>
Which returns: http://server.com/search/?query=hello&collaborator=<id>.
This is all good, but its possible to choose more collaborators. How do I append another &collaborator=<id> to the query?
I have tried various methods like ${params + [params.collaborator + collaborator.id]}, but this only puts them in one string.
Try this:
gsp:
<g:link action="result" params="${params + ['collaborator': params.list('collaborator') + [collaborator.id]]}">${collaborator.name}</g:link>
action:
List collaboratorList = params.list('collaborator')
//Your operations on this list

How to handle URL relative/absolute "glitch" in contenteditable when copy and pasting

In contenteditable regions, if you paste an element with a URL attribute, in some browsers it converts the URL from relative to absolute.
I've read through some bug reports that claim it's "fixed" in the latest release, but it's not.
I threw together this fiddle to demonstrate: Hurray for Demos!
It's there, it's ugly, and I'm wondering what is the best way to fix it.
The 1st idea that comes to mind is onpaste, find all anchors in the current node and parse it with regex. Not ideal I suppose, but it might be effective.
???
???
I really wish they'd just leave things alone and not create so many browser related issues with contenteditable, but I guess that would make it too easy.
Any thoughts on the best way to address this?
CKEditor, before letting browser break the data, copies all src, name and href attributes to data-cke-saved-src|href attributes. Unfortunately, since data is a string, it has to be done by regexp. You can find the code here: /core/htmldataprocessor.js#L772-L783.
var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi,
// Be greedy while looking for protected attributes. This will let us avoid an unfortunate
// situation when "nested attributes", which may appear valid, are also protected.
// I.e. if we consider the following HTML:
//
// <img data-x="<a href="X"" />
//
// then the "non-greedy match" returns:
//
// 'href' => '"X"' // It's wrong! Href is not an attribute of <img>.
//
// while greedy match returns:
//
// 'data-x' => '<a href="X"'
//
// which, can be easily filtered out (#11508).
protectAttributeRegex = /([\w-]+)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi,
protectAttributeNameRegex = /^(href|src|name)$/i;
function protectAttributes( html ) {
return html.replace( protectElementRegex, function( element, tag, attributes ) {
return '<' + tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName ) {
// Avoid corrupting the inline event attributes (#7243).
// We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)
if ( protectAttributeNameRegex.test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )
return ' data-cke-saved-' + fullAttr + ' data-cke-' + CKEDITOR.rnd + '-' + fullAttr;
return fullAttr;
} ) + '>';
} );
}
Then, while processing HTML taken from editable element, data-cke-saved-* attributes override the original ones.
This looks like a browser bug that's not specific to contenteditable: https://bugzilla.mozilla.org/show_bug.cgi?id=805359
That issue was opened 10 years ago and last updated 6 years ago. Yet it's still open.
You can see the bug here on StackOverflow. Inspecting any SO link shows that the href value is a relative URL. Copying it and pasting it as HTML has the relative link rewritten into an absolute URL.
Example:

Building a URL with ActionLinks from within a Controller in MVC

I'm building a basic flashcard application - a Set contains Cards and other Sets. When navigating to something like Set1 > Set2 > Set3, I want each of the parent "Sets" to link to their respective details page. I'm passing the Details viewModel a string called "breadcrumbs", which contains something like this:
var stringBuilder = "";
var parent = model.ParentSet;
while (parent != null)
{
stringBuilder += "<li><a href=\"#Url.Action('Detail', 'Set', new {SetId = \" + parentSetId + \"}, null)'>" + parent.Name + "</a> <span class='divider'>/</span></li>";
parent = parent.ParentSet;
}
model.Breadcrumbs =
"<li>Home <span class='divider'>/</span></li>" +
stringBuilder + "<li class='active'>New Set</li>";
model.Name = "New Set";
The URLs being generated are literal though - containing "#Url.Action".
Does anyone know how I can get this to work, or if there's a better way to do it?
Just evaluate it:
"<li><a href='" + Url.Action('Index', 'Home') + "'>..."
I think an important question here is, "What does your view look like?"
If your view is using that model.Breadcrumbs field like this:
...
<div id="breadcrumbs">
#model.Breadcrumbs
</div>
...
The #Url.Action call in the string you've built will never be executed. The Razor engine operates on the code it finds in the view file, not on fields within the model.
You need to do one of two things:
Rather put "#Url.Action(...)" into the string you're constructing, figure out what the Url is on the server side using something like Url.Link() and insert that directly.
(and this is better) Pass those parents to the view as part of the view model and loop over them in the view, constructing the tags as you go. Normally you don't want to put html into a model. The model's there to hold data, not presentation code.

context menu demo app not working crossrider

I am generating context menu when user selects some text and right click it. I tried implementing it, problem is even sample application is not working.
http://crossrider.com/apps/10565/ide
appAPI.contextMenu.add("key1", "Display data object", function (data) {
var sAlertText = 'pageUrl: ' + data.pageUrl + '\r\n' +
'linkUrl: ' + data.linkUrl + '\r\n' +
'selectedText:' + data.selectedText + '\r\n' +
'srcUrl:' + data.srcUrl;
alert(sAlertText);
}, ["all"]);
Only data.pageUrl is available rest of all are "undefined". I want selectedText.
Disclaimer: I work at Crossrider.
Indeed there was an issue with the contextMenu due to a change in the Chrome API.
We've fixed this and now the demo app works.
Thank you for reporting this and please feel free to let us know if you encounter any issues!
Amir

Resources