Outlook add-in - Insert HTML with background image - html

I have an outlook add-in that should insert HTML into an appointment. This can be done by calling:
item.body.setSelectedDataAsync
My problem is that I'm trying to insert HTML with a background image. This works fine when using Outlook in the browser, but the Outlook client requires workarounds using VML as described here:
https://www.emailonacid.com/blog/article/email-development/emailology_vector_markup_language_and_backgrounds
I guess item.body.setSelectedDataAsync strips the comments needed for VML (like <!--[if gte mso 9]> ) from the HTML passed to insert?
How can I accomplish adding HTML with background image from my add-in that works across different Outlook versions (browser and client)?
Below is example of javascript code used to insert HTML:
let htmlToInsert = '<table cellpadding="0" cellspacing="0" border="0" width="' + imageWidth + '" >';
htmlToInsert += '<tr><td style="text-align: center; font-size: x-large">' + this.props.roomMap.mapTitle + '</td></tr>';
htmlToInsert += '<tr><td valign="top" style="min-height:' + imageHeight + 'px;height:' + imageHeight + 'px; background-repeat: no-repeat; background-position: center bottom; width:' + imageWidth +';min-height:' + imageHeight + 'px;height:' + imageHeight + 'px;" background="' + this.props.roomMap.thumbnailUrl + '">';
htmlToInsert += '<!--[if gte mso 9]>';
htmlToInsert += '<v:rect style="width:' + imageWidth + 'px;height:' + imageHeight + 'px;" strokecolor="none">';
htmlToInsert += '<v:fill type="tile" src="'+ this.props.roomMap.thumbnailUrl +'" /></v:fill>';
htmlToInsert += '</v:rect>';
htmlToInsert += '<v:shape id="NameHere" style="position:absolute;width:' + imageWidth + 'px;height:' + imageHeight + 'px;">';
htmlToInsert += '<![endif]-->';
htmlToInsert += '<img src="https://www.meetingroommap.net/images/marker.png"/ style="margin-left:' + markerX + 'px; margin-top:' + markerY + 'px">';
htmlToInsert += '<!--[if gte mso 9]>';
htmlToInsert += '</v:shape>';
htmlToInsert += '<![endif]-->';
htmlToInsert += '</td></tr>';
htmlToInsert += '<tr><td style="text-align: center; font-size: xx-small">Powered by <a target="_blank" href="https://www.meetingroommap.net" >www.MeetingRoomMap.net</a></td></tr>';
htmlToInsert += '</table>';
console.log(htmlToInsert);
item.body.setSelectedDataAsync(
htmlToInsert,
{ coercionType: Office.CoercionType.Html,
asyncContext: { } },
function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed){
console.log("Error calling item.body.setSelectedDataAsync: " + asyncResult.error.message);
}
else {
// Successfully set data in item body.
}
});

Thank you for your feedback. After further investigation, it appears there's no great workaround to achieve your scenario. We continue to learn about the new requirements add-in developers have, which helps us enable great scenarios on our platform. We track Outlook add-in feature requests on our user-voice page. Please add your request there. Features on user-voice are also considered when we go through our planning process.
Link to user voice: https://officespdev.uservoice.com/forums/224641-general/category/131778-outlook-add-ins.
Thanks again for your feedback,
Outlook Add-ins Engineering Team

Related

How do I display image from api in json?

I am calling betterdoctor api and im getting back data and i am trying to display a image from the json data. But all im getting back is the src of the image.How do i display the image? instead of just the src of image.
for(i=0;i<data.data.length;i++){
list = list +
'<div class="user">' +
'<p>' +data.data[i]['profile']['first_name']+ " " +data.data[i]
['profile']['last_name']+'</p>' +
'<p>' + 'latitude is ' + data.data[i]['practices'][0]['lat']+ '</p>'
+
'<p>' + 'longtitude is ' + data.data[i]['practices'][0]['lon']+
'</p>' +
<img src= data.data[i]['profile']['image_url'] alt="Mountain View">
+
'</div>'
}
As per Robby Cornelissen comment, you probably want to put the URL inside a img tag.
for(i=0;i<data.data.length;i++){
list = list +
'<div class="user">' +
'<p>' +data.data[i]['profile']['first_name']+ " " +data.data[i]
['profile']['last_name']+'</p>' +
'<p>' + 'latitude is ' + data.data[i]['practices'][0]['lat']+ '</p>'
+
'<p>' + 'longtitude is ' + data.data[i]['practices'][0]['lon']+
'</p>' +
'<p><img src="' + data.data[i]['profile']['image_url'] + '"/></p>' +
'</div>'
}

Polymer update route from custom element

Complete Polyer noob here trying to write a simple little Polymer app.
What I'm trying to do is drive navigation of my iron-pages from a custom element (client-table) but can not figure out how to do this.
I've tried various permutations of using attr-for-selected and selected attributes within the table, but that doesn't seem to work. I've also tried setting up an anchor tag around the paper-button, and almost got that working, but it would trigger a full page refresh and not display my #clientInfo section when the page loaded.
Any suggestions on how to accomplish this, links to documentation that better explain routing/navigation in Polymer (esp. in cases of using custom elements), any default Polymer elements I should inspect the source of, etc?
<!-- snippet from index.html -->
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="home">
<paper-material elevation="1">
<h2>Clients</h2>
<client-table></client-table>
<a data-route="clientInfo" href="/">test</a>
</paper-material>
</section>
<section data-route="clientInfo">
<paper-material elevation="1">
<h2></h2>
<p>This is the users section</p>
Rob
</paper-material>
</section>
</iron-pages>
<!-- snipped from client-table.html -->
buildTable: function() {
var domTable = this.$.table;
var tableData = this.parseTableJson(this.buildTableJson());
var tableMarkup = this.buildTable_initTable() + "<tbody>";
for (var index in tableData) {
row = tableData[index];
var rowMarkup = "<tr>";
rowMarkup += "<td>" + row.clientFirstName + "</td>";
rowMarkup += "<td>" + row.clientLastName + "</td>";
rowMarkup += "<td>" + row.clientEmail + "</td>";
rowMarkup += "<td>" + row.clientPhone + "</td>";
rowMarkup += "<td>" + row.clientZipCode + "</td>";
rowMarkup += "<td><paper-button><iron-icon icon='card-membership'></iron-icon></paper-button></td>";
rowMarkup += "</tr>";
tableMarkup += rowMarkup;
}
tableMarkup += "</tbody>";
$(domTable).append(tableMarkup);
}
And then I found routing.html.

body onload is not able to trigger action url in html form

I am using the onload method in the form like below in one of my servlet:
out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> \n");
out.write("<html><body onload=\"document.forms[0].submit()\">\n");
out.write("<form method=\"POST\" action=\"http://ipaddress:8085/internal/Logout\">\n");
out.write("<input type=\"hidden\" name=\"groupId\" value=\"" + groupId
+ "\"/>\n");
out.write("<input type=\"hidden\" name=\"userName\" value=\""
+ userName + "\"/>\n");
out.write("<input type=\"hidden\" name=\"idpServer\" value=\""
+ idpServer + "\"/>\n");
out.write("<input type=\"hidden\" name=\"sessionId\" value=\""
+ sessionId + "\"/>\n");
out.write("<input type=\"hidden\" name=\"targetPage\" value=\""
+ targetPageURL + "\"/>\n");
out.write("<input type=\"hidden\" name=\"locale\" value=\""
+ locale + "\"/>\n");
out.write("<input type=\"hidden\" name=\"logoutPage\" value=\""
+ logoutPage + "\"/>\n");
out.write("</form>\n</body>\n</html>\n");
After the above code i have one more line which is like
deleteExpiredSession(sessionId);
In the first code block we have 'onload' method which will automatically submits the form to action url but in my case it is not happening
the control is going to some other servlet.
In debug mode the code executing along with the second part of code(deleteExpiredSession(sessionId);), I think the second part should
not be executed because the above code is having onload.
Earlier it was working fine but suddenly it is stopped working. I think recently we migrated to tomcat6 - tomcat7. Is this the reason?
Any suggestions would be great.
I tested your application and I found out the problem is about your action address and id is not valid. You doesn't put port word after : in your URL. Change it to following code and it will work:
<form method="get" action="http://ipaddress:8080/internal/Logout" >
...
I replaced 8080 with port.

Asp .Net client side dynamic text

Im learning Asp.Net, after writing a master page, I couldnt make it run on client (to actually see the animation). The thread waiting action is done on server before publishing the web page so animation is not dynamic. It shows only the final state of the page.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body bgcolor="red">
<center>
<h2>Hello w3schools!</h2>
<h4 id="aa">qq</h4>
<h3>
<p><%
for (int i = 0; i < 30; i++)
{
System.Threading.Thread.Sleep(25);
int txtLeft = 300 + (int)(100*Math.Sin(i));
int txtTop = 300+(int)(100*Math.Cos(i));
string theText = "Hello there!";
Response.Write("<div style=\"position:absolute; left: "+ txtLeft + "px; top:" + txtTop + "px; \">" + theText +"</div>");
}
%></p>
</h3>
</center>
</body>
</html>
I tried
runat="client" (near the "p" letter which is in brackets)
but it failed:
Runat must have value Server.
Take a look at this jsFiddle:
$(Start);
function Start() {
var txtLeft, txtTop, theText, theHTML;
theText = "Hello there!";
for (var i = 0; i < 30; i++) {
txtLeft = 300 + (100 * Math.sin(i));
txtTop = 300 + (100 * Math.cos(i));
theHTML = '<div style="position:absolute; left: ' + txtLeft + 'px; top:' + txtTop + 'px;">' + theText + '</div>';
$('#Demo').append(theHTML);
}
}
Basically, there's no need for server-side programming to generate the output you want; use asp.net for server work. What you can do is add this script to the page in a script tag along with the jquery reference and you're done.

Can someone add fundamental reasons why appending html markup to field variables is wrong

html += '<tr style="display:none;"><td class="leftval">ID:</td><td><span id="' + _uniqueId + '-id">' + one + '</span></td></tr>';
html += '<tr><td class="leftval"><label for="' + _uniqueId + '-itemdesc" title="This is the descriptive text that will actually appear in the email.">Description: </label></td>';
html += '<td><input value="' + four + '" class="CDinput" name="itemdesc" id="' + _uniqueId + '-itemdesc" type="text"></td></tr>';
html += '<tr><td class="leftval"><label for="' + _uniqueId + '-title" title="This is the title text that is used in the email. The text usually is used as the anchor text of a link.">Title: </label></td>';
html += '<td><input value="' + five + '" class="CDinput" name="title" id="' + _uniqueId + '-title" type="text"></td></tr>';
html += '<tr><td class="leftval"><label style="color:#f16d44;" for="' + _uniqueId + '-enddate" title="This is the expiration of the offer. The formating here is arbitrary and does not impact how the end date would look in the actual template.">End Date: </label></td>';
html += '<td><input style="width:230px" value="' + six + '" class="CDinput" name="enddate" id="' + _uniqueId + '-itemenddate" type="text">';//I'm overriding the default width for the calendar image
html += '<img style="cursor:pointer;" class="CDdate" id="' + _uniqueId + '-dateselector"src="/images/Calendar_hyperlink.png"></td></tr>';
I can think of 3 reasons:
string connector operands like ' + ' make it harder to read
Indentation is more difficult since it's awkward to indent the field to simulate a properly formatted html snippet.
Display logic is mixed in tightly with business application logic, making diversifying focus difficult.
You have 3 good reasons listed, and are in the top three. Trying to mix the two makes for ugly code, hard to read, hard to maintain, etc.
One other thing, though, that I hadn't thought of until recently, is that some editors, such as Netbeans, will tell you when your HTML is broken. Forgetting to close tags, wrong values, etc. I'm using PHP for my work, and I've gotten into the habit of doing soemthing like this:
<li>
<span class='name'><?php echo _TAG_INDEX ?>:</span>
<span class='value'><?php echo $get_zone_array['DB_ID'] ?></span>
</li>
Using it like this, if I forgot to close a tag, like if I forgot the closing </span> somewhere, it would point it out for me, so I could go in and fix it. However, if I was putting the HTML into a variable, or echoing it directly, like this:
$html = "<li><span class='name'>"._TAG_INDEX.":<span>" // notice missing / in </span>
. "<span class='value'>".$get_zone_array['DB_ID']."</span>"
. "</li>";
echo $html;
then there wouldn't be any HTML-checking from the editor, making finding those nasty little xHTML errors harder to find.
Some of the reasons:
It's butt-ugly!
It's slow. (The += operator in Java is not fast. Sometimes acceptable, but definitely not fast because it has to do a lot of object creation and buffer copying.)
It's too easy to introduce XSS vulnerabilities through strings not being properly quoted.
It's too inflexible; change anything on the layout and you have to change all the code.
Use a templating library instead. So much easier to get right.