I'm pulling in a xml-file with just one result in it. One of the nodes is picture, which contains a link to a picture. This is the xml-file:
<artist>
<id>502</id>
<name>Bad Religion</name>
<picture>http://userserve-ak.last.fm/serve/500/46612615/Bad Religion BR 2010.jpg</picture>
<twitter></twitter>
</artist>
I've tested the url, and it's correct. This is how I try to bind the url to the image instance (artistPic), but it's not working. Displaying the artist name does work.
var artist:XMLList = new XMLList(event.result);
artistPic.source = artist.picture;
lblArtistName.text = artist.name;
That's because artist.picture returns an XMLList object. Try the following code :
var artist:XML = new XML(event.result);
artistPic.source = String(artist.picture[0]);
lblArtistName.text = artist.name; // This one is probably transtyped automagically by Flex.
Related
This questions has been posed and answered several places on SO, specifically here : Issue with Gmail - Embedded images using MailKit
and handles my exact query, yet the answer doesn't seem to work for my case.
I've tried to build a simple mailer that embeds images in an HTML email, yet in several clients, all images still end up as attachments.
I suspect the fault to be in the way I handle the image attachments (one .gif and several .png) to be:
// Add pictures to embedded resources and replace links to pictures in the message
foreach (string imgpath in ImgPaths)
{
var image = builder.LinkedResources.Add(imgpath);
image.ContentId = MimeUtils.GenerateMessageId();
image.ContentDisposition = new ContentDisposition() { Disposition = ContentDisposition.Inline };
HtmlFormat = HtmlFormat.Replace(Path.GetFileName(imgpath), string.Format("cid:{0}", image.ContentId));
}
builder.HtmlBody = HtmlFormat;
message.Body = builder.ToMessageBody();
I can see from the emails (received in Gmail, for instance), do show that the images are being listed as:
src="images/cid:TPSXHQUDSAU4.JJRKUIEGLTZ5#Loralei"
All images are attached as attachments in both clients I've tried (gmail and roundcube). I've walked through your tutorials and checked out everything here: https://stackoverflow.com/search?q=Mailkit+Embed
Sadly, I just can't seem to find my error. Hopefully #jstedfast could see where I make my mistake?
UPDATE
As mentioned by #jstedfast, the corrected code should be (for my case anyway):
foreach (string imgpath in ImgPaths)
{
var test = Path.GetFileName(imgpath);
var image = builder.LinkedResources.Add(imgpath);
image.ContentId = MimeUtils.GenerateMessageId();
image.ContentDisposition = new ContentDisposition() { Disposition = ContentDisposition.Inline };
//HtmlFormat = HtmlFormat.Replace(Path.GetFileName(imgpath), string.Format("cid:{0}", image.ContentId));
HtmlFormat = HtmlFormat.Replace($"images/{test}", string.Format("cid:{0}", image.ContentId)); //use images/filename
}
This is a great guide to follow too, https://programming.vip/docs/5dac3983f0cd5.html
This looks like the problem:
<img src="images/cid:TPSXHQUDSAU4.JJRKUIEGLTZ5#Loralei" .../>
That needs to be:
<img src="cid:TPSXHQUDSAU4.JJRKUIEGLTZ5#Loralei" .../>
My guess is that in order to fix this, you'd change the following line of code:
HtmlFormat = HtmlFormat.Replace(Path.GetFileName(imgpath), string.Format("cid:{0}", image.ContentId));
to this:
HtmlFormat = HtmlFormat.Replace(imgpath, string.Format("cid:{0}", image.ContentId));
Hope that helps!
I've got an API (https://datatank.stad.gent/4/cultuursportvrijetijd/kunstenplan.json)
I have a list of art spot names that I got from that API displayed on a page. (actually different lists each filtered by category)
What I want is when you click on a name, you get more information about that art spot on a separate page. How do I do this?
Here's a snippet of my code that will display a list of museums.
var list_museums='';
var list_galleries='';
var list_centers='';
var list_offspaces='';
var list_search='';
var item_name='';
var item_location='';
var item_site='';
var item_category='';
var item_info='';
for(var i=0;i<this.cultuurUtilities.length;i++)
{
var cultuur=this.cultuurUtilities[i];
var museums = cultuur.categorie=="Museum";
var galleries = cultuur.categorie=="galerie";
var centers = cultuur.categorie=="Centrum voor beeldende kunst";
var offspaces = cultuur.categorie=="Off-Spaces";
console.log("cultuur for loop");
if(museums==true){
list_museums+='<div class="museum-item"><li class="li-museums"><img class="museum-img"></img><div class="museum-link"><a href="detailpagina.html">'+cultuur.Naam;
list_museums+='</a></div></li></div>';
What I want is when you click on a name, you get more information about that art spot on a separate page
I think you mean opening a new window/tab? You can accomplish this in different ways:
1) Adding the "onclick" listener on your clickable element and write the function to be called. Inside it, you can open a new window using the "window.open" function (it opens a new window by default, so you can pass a second parameter to specify the frame where the new window/tab must be handled, because you might wanted to open the page in a new tab, not a new window. Check the docs here). It returns its handle, so you can write into it, just like you do usually in your page.
For example:
var mywindow = window.open("path_to_follow");
// The first parameter is optional. By removing it, it will give you a blank page
mywindow.document.write("<h3>My Selected Museum</h3>");
<< bunch of other instructions >>
2) Using a anchor tag with "href" attribute and the selected item identifier passed as a GET parameter. For example:
<a target="_blank" href="path_to_follow/display_page?museum_id=dinamically_set_id">Click Here to open</a>
In your "display_page" (you can name it as you like) you manage to use some server-side language (like PHP, Java, etc...) to prepare a "stub" of your page, and filling with the selected museum informations, using the museum identifier we said before.
If you need further information, just comment!
I have a JSON that looks like this, it comes from a knockout array and has been converted. I simply want to content this to a single object to send to a service.
[{\"NotePadID\":-1,\"UserID\":\"NIGOV\\\\\\\\dard-lytts\",\"DateInput\":\"08/28/2014\",\"CategoryID\":6,\"SubCategoryName\":\"Active Farmer\",\"DateCreated\":\"08/28/2014\",\"Note\":\"test\"}]
This comes as an array how would I get the first, ie
var test = jsonConverted[0]['CategoryID'];
Always returns undifined. What I actually want to do is just pass a single object to my ajax, should be simple but not working.
using javascript you can do it like
var a = '[{\"NotePadID\":-1,\"UserID\":\"NIGOV\\\\\\\\dard-lytts\",\"DateInput\":\"08/28/2014\",\"CategoryID\":6,\"SubCategoryName\":\"Active Farmer\",\"DateCreated\":\"08/28/2014\",\"Note\":\"test\"}]'
return JSON.parse(a)[0]['CategoryID']
you can try this and follow the "Demo"
var stringiFiedArray = "[{\"NotePadID\":-1,\"UserID\":\"NIGOV\\\\\\\\dard-lytts\",\"DateInput\":\"08/28/2014\",\"CategoryID\":6,\"SubCategoryName\":\"Active Farmer\",\"DateCreated\":\"08/28/2014\",\"Note\":\"test\"}]";
var javasArrar = JSON.parse(stringiFiedArray);
alert(javasArrar[0]["CategoryID"]);
you can click here to see Demo
I'm working on a Spotify app and trying to create a views.List object from some stored information in our database. On initial load, a POST is made to get the necessary info. I store this in localstorage so each subsequent request can avoid hitting the database and retrieve the object locally. What's happening though is the List objects I create from localstorage data come up blank, while the POST requests work just fine.
Here is the snippet I'm using to create the list:
var temp_playlist = models.Playlist.fromURI(playlist.uri);
var tempList = new views.List(temp_playlist, function (track) {
return new views.Track(track, views.Track.FIELD.STAR |
views.Track.FIELD.NAME |
views.Track.FIELD.ARTIST |
views.Track.FIELD.DURATION);
});
document.getElementById("tracklist").appendChild(tempList.node);
playlist.uri in the first line is what I'm retrieving either from a POST or from localstorage. The resulting views.List object (tempList) looks identical in both cases except for tempList.node. The one retrieved from localstorage shows these values for innerHTML, innerText, outerHTML, and outerText in console.log:
innerHTML: "<div style="height: 400px; "></div>"
innerText: ""
outerHTML: "<div style="height: 400px; "></div>"
outerText: ""
Whereas the one retrieved via POST has the full data:
innerHTML: "<div style="height: 400px; "><a href="spotify:track:07CnMloaACYeFpwgZ9ihfg" class="sp-item sp-track sp-track-availability-0" title="Boss On The Boat by Tosca" data-itemindex="0" data-viewindex="0" style="-webkit-transform: translateY(0px); ">....
innerText: "3Boss On The BoatTosca6:082....
and so forth..
Any help would be greatly appreciated
Solved this.
I am using hide() and show() to render the tabs in my app. I was constructing the tracklist and then show()ing the div which led to a blank tracklist. If I simply show() the div and then construct the tracklist it works fine.
The reason (I think) it was working for POSTs is because the tracklist was retrieved from the database and the slightly longer loading time probably meant the tracklist was constructed after the div's show() executed. With localStorage I guess the tracklist was constructed before the div was even shown, leading to the error.
Using, the local storage, I did it this way :
sp = getSpotifyApi(1);
var m = sp.require("sp://import/scripts/api/models");
var v = sp.require("sp://import/scripts/api/views");
var pl;
pl = m.Playlist.fromURI(uri);
var player = new v.Player();
player.track = pl.get(0);
player.context = pl;
var list = new v.List(pl);
XXXXX.append($(list.node));
Hope, it will help, as it's working for me
I think I've actually managed to solve this and I think it's bulletproof.
Basically I was trying to solve this by trying to convince the API that it needed to redraw the playlist by hiding things/scrolling things/moving things which worked occasionally but never consistently. It never occurred to me to change the playlist itself. Or at least make the API think the playlist has changed.
You can do so by firing an event on the Playlist object.
var models = sp.require('$api/models');
...
// playlist is your Playlist object. Usually retrieved from models.Playlist.fromURI
playlist.notify(models.EVENT.CHANGE, playlist);
These are just standard Spotify functions and the list updates because it thinks something has changed in the playlist. Hope this helps someone!
I am currently using an Ajax tool; HTMLEditorExtender to turn a textbox into a WYSIWYG editor, in a C# ASP.NET project. On the initial page load I place a large amount of formated text and tables into the editor which appears fine; even the tables.
The data is loaded into an asp:panel and the items/display from the panel is what is actually loaded into the extender and displayed.
However, if I want to have a button that saves all of the data that is in the editor to a Session and after the button press still display everything in the WYSIWG editor on the page postback everything that loads in the the textbox is fine except for the tables. They come up with the tags. Is there anyway around this?
The code I am using to initially load the page is this:
ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlContent.RenderControl(hw);
txtPN.Text = sb.ToString();
pnlContent.Visible = false;
On the button click I am having this saved:
string strHTMLText = txtPN.Text;
Session["ProgressNoteHTML"] = strHTMLText;
And I am loading it on the postback like this:
txtPN.Text = (string)Session["ProgressNoteHTML"];
ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
pnlContent.Visible = false;
Any ideas as to why any postbacks would make the tags appear and in the original page load they do not?
The solution offered by Erik won't work for table tags containing property values. For instance: <table align="right"> will not be decoded. I have also found that <img> tags are encoded by the HTMLEditorExtender as well.
The easier solution is to use the Server.HTMLDecode() method.
TextBox_Editor.Text = Server.HtmlDecode(TextBox_Editor.Text) 'fixes encoding bug in ajax:HTMLEditor
I have the same problem, It seems to have something to do with the default sanitizing that the extension performs on the HTML content. I haven't found a way to switch it off, but the workaround is pretty simple.
Write an Anti-Sanitizing function that replaces the cleansed tags with proper tags. Below is mine written in VB.Net. A C# version would look very similar:
Protected Function FixTableTags(ByVal input As String) As String
'find all the matching cleansed tags and replace them with correct tags.
Dim output As String = input
'replace Cleansed table tags.
output = output.Replace("<table>", "<table>")
output = output.Replace("</table>", "</table>")
output = output.Replace("<tbody>", "<tbody>")
output = output.Replace("</tbody>", "</tbody>")
output = output.Replace("<tr>", "<tr>")
output = output.Replace("<td>", "<td>")
output = output.Replace("</td>", "</td>")
output = output.Replace("</tr>", "</tr>")
Return output
End Function