Loading images from an array - arrays

I'm trying to load an image from an array, but I can't figure out how to do so...
For text, it's good :
private var textArray:Array = [
{label:"text1", Type:"it's the text1"},
{label:"text2", Type:"it's the text2"}]
and the function setDisplay is showing one of the label in my textField
private function setDisplay(e:Event):void{
var fIndex:int = ac.aIndex;
txtField.htmlText = "<b>Title:</b><br /> " + fruitArray[fIndex].Type;
txtField.setTextFormat(titleFormat);
Now I can't figure out how to do the same thing for images...
I've tried that :
private var possibleSources:Array = [
{label:"Image1", Image: {url:"assets/smiley.jpg"}},
{label:"Image2", Image: {url:"assets/smiley2.jpg"}}];
and add in my SetDisplay function :
txtField.htmlText = "<b>Title:</b><br /> " + textArray[fIndex].Type + "<b>Images:</b><br /> " + possibleSources.Image;
The app is launching and I've got "it's the text1" for text1 and "it's the text2" for text2
But for "Images" I've got "undefined"....
Do you know what's wrong ?
Thank you for your help,
EDIT :
Thank you for your help.
Here's what I got so far :
private var possibleSources:Array = [
{label:"Image1", Image: {url:"assets/smiley1.jpg"}},
{label:"Image2", Image: {url:"assets/smiley2.jpg"}}];
private var textArray:Array = [
{label:"text1", Type:"It's the text1"},
{label:"text2", Type:"It's the text2"}]
private function setDisplay(e:Event):void{
it1.htmlText = "<b>Title :</b><br /> " + textArray[fIndex].Type +"<b>image :</b><br /> " + possibleSources[fIndex].Image.url;
And here's what I got as a result :
The smiley1.jpg is not here...

You have mistake in code where you access data about Image in the possibleSources:
Correct:
trace(possibleSources[0].Image.url);
Also, if you want display image in the text field, url string isn't enough, read about supported html tags, and their format.

Related

obfuscated page content while using output cache in mvc 5

I'm developing a web application using MVC5 and I use output cache attribute on one of my actions.
the problem is after multiple page visits, my page will have binary content that looks like this:
page screenshot
there's my source:
[OutputCache(Duration = 86400, Location = OutputCacheLocation.ServerAndClient,VaryByParam = "ID;slug")]
[SeoOptionsFilter]
public ActionResult CourseDetail(int ID, string slug)
{
var courseComplexObject =
_courseRepository.GetCourseDetail(ID, slug);
var course = courseComplexObject.Model;
TempData["breadcrumb"] = BreadcrumbViewBuilder
.New().Home().Courses()
.AddMore(course.CategoryName, "/Category/" + course.CategoryId.ToString() + "/" + course.CategorySlug)
.AddMore(course.Name, "/CourseDetails/" + course.CourceId.ToString() + "/" + course.Slug + ".aspx",
true)
.Build();
//TODO: What if course is null
SetViewBagIfUserIsRegistered(course, ID);
TempData["CourseVideoCatOn"] = GetCourseVideoCategory(ID);
TempData["CourseID"] = ID;
TempData.Keep();
// Response.Cache.SetOmitVaryStar(true);
return View(courseComplexObject.Model);
}
I commented my custom action filter [SeoOptionsFilter]
but the result already has errors.
this error occurs randomly in page visits

How to replace Pipelet for ExportCustomerGroups in SFCC? (For removing Deprecated API usage)

function abc(){
var Site = require('dw/system/Site');
var utils= require('app_nars/cartridge/scripts/util/utils.js');
var mySite : String = (Site.getCurrent().getID() == "a") ? "" : "-" + Site.getCurrent().getID();
var customerGroupName : String ;
if (mySite == "A") {
customerGroupName = "A";
} else {
customerGroupName = "B";
}
var grpNam= utils.getGroup(customerGroupName);
var grpFileName = 'test';
/* No script api available for pipelet ExportCustomerGroups*/
var Pipelet = require('dw/system/Pipelet');
var PipeletExecutionResponse = new dw.system.Pipelet('ExportCustomerGroups').execute({
CustomerGroups: grpNam.iterator(),
ExportFile : grpFileName,
OverwriteExportFile:true
});
app.getView().render('path/templateName');
}
How can we replace the Pipelet ExportCustomerGroups here , i could see in documentation we can use job steps and there is no script replacement
You have to create with your own code, construct the xml needed while parsing the customers.[enter image description here][1]
Or you can use this step when configuring job if no custom code needed there:
[1]: https://i.stack.imgur.com/s1VQa.png

Azure Search - querying for ampersand character

I'm trying to find all records which contain & symbol, which is reserved. I'm using search, not $filter.
According to documentation, it can not be escaped with \%, and should be escaped as HTML url part to %26.
Trying SDK and Search explorer to find any options on how to search, but with no succeed:
&
*&*
*%26*
%26
\%26
UPD
Document example:
{
"test": "Hello & World"
Search query: search=%26&searchFields=test&$select=test
UPD 2
public class MyType
{
[System.ComponentModel.DataAnnotations.Key]
[IsFilterable]
public string Id { get; set; }
[IsSearchable, IsSortable]
public string Test { get; set; }
}
class Program
{
private static SearchServiceClient CreateSearchServiceClient()
{
string searchServiceName = "XXXXXX";
string adminApiKey = "XXXXXXX";
var serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(adminApiKey));
return serviceClient;
}
static void Main(string[] args)
{
var client = CreateSearchServiceClient();
var def = new Microsoft.Azure.Search.Models.Index
{
Name = "temp-test-reserved1",
Fields = FieldBuilder.BuildForType<MyType>()
};
client.Indexes.Create(def);
var c = client.Indexes.GetClient("temp-test-reserved1");
var actions = new IndexAction<MyType>[]
{
IndexAction.Upload(new MyType{ Id = "1", Test = "Hello & World" }),
IndexAction.Upload(new MyType{ Id = "2", Test = "& test start" }),
IndexAction.Upload(new MyType{ Id = "3", Test = "test end &" })
};
c.Documents.Index(IndexBatch.New(actions));
}
}
search=%26&searchFields=Test&$select=Test
You likely can't find & because it's being removed at indexing and query time, since it's considered to be punctuation by the default analyzer. This article has more details on lexical analysis in Azure Cognitive Search. If you need to preserve ampersands while still tokenizing text on whitespace boundaries, you'll need to create a custom analyzer.
In the search explorer field on the Azure portal try the query &search=%26(as shown below)
In the SDK, only if you have set the UseHttpGetForQueries parameter to true, you would need to think of URL encoding the '&' character. By default, this parameter is set to false in which case you don't need to encode it.
More documentation about escaping/encoding here

how can set parameter values for params string[] parameter

I am required to produce the following address
http://example.com/Content/Details?cid=34&query=%D8%AA%D8%AD&positions%5B0%5D=true&positions%5B0%5D=false&positions%5B1%5D=false&positions%5B2%5D=false
this url after decode is :
http://example.com/Content/Details?cid=32&query=تحلیل&positions[0]=true&positions[0]=false&positions[1]=false&positions[2]=false
My action method contains the following parameters
public ActionResult Details(
string cid, string query, int? page, int id = 0, params string[] positions)
{
if(positions != null)
{
ViewBag.Title = positions[0];
ViewBag.Description = positions[1];
ViewBag.KeyWord = positions[2];
}
}
But when I set the parameters required for the positions parameter I get an error :
In fact i cant use positions[0] , positions[1] and positions[2] !!!
my cshtml page :
#{ title
#Html.CheckBox("positions[0]", ViewBag.Title as string)
description
#Html.CheckBox("positions[1]", ViewBag.Description as string)
keyword
#Html.CheckBox("positions[2]", ViewBag.KeyWord as string)
}
#Html.PagedListPager(Model, page => Url.Action("Details", new {cid = ViewBag.currentFilter, query= ViewBag.currentSearchString , positions[0]=ViewBag.title , positions[1]=ViewBag.Description ,position[2]=ViewBag.KeyWord,page }))
how can i set values for positions parameter in cshtml page ?
How can i set position[0] ,positions[2] and positions[3] ... i want know this just
the rest of my code is correct
please help me
You should read them in your controller and set them in ViewBag or ViewData:
ViewData["positons_0"] = Request.QueryString["positions[0]"];
ViewData["positons_1"] = Request.QueryString["positions[1]"];
// etc ...
Then you will be able to use them in your view also.
But I would suggest that you remove the square brackets from your querystring if possible. These are reserverd characters for IP v6 address literals (see here) and this is why you cannot use them in MVC. Your url should be:
http://example.com/Content/Details?cid=32&query=تحلیل&positions=true&positions=false&positions=false&positions=false
In this way you will be able to use it in both your controller:
public ActionResult Details(string cid, string query, int? page, int id = 0, string[] positions)
{
// ....
}
... and view:
#foreach(string position in Model.positions) // example
{
// ....
}

read zip attachment in visualforce page

Hi all I am developing an app on salesforce.
I want to read the content of the file which is inside the zip attachment in visualforce page but without extracting the zip file.
How can I achieve this? Is there any way to do this?
Update for modified question:
Have a look at Handling Office Files and Zip Files in Apex – Part 2 by Andrew Fawcett.
There is a basic Knowledge Article on how to do this with an image that is stored in an Attachment. See How can I Display Base64 Data on page layout?
In this example the AttachmentID is passed via a query string paramemter, but you could look it up however works best for your requirement.
Visualforce page:
<apex:page controller="ViewImage" cache="true">
<img src="data:{!att.ContentType};base64,{!image}" />
</apex:page>
Controller:
public class ViewImage {
public Attachment att {
get {
if (att == null) {
String id = ApexPages.currentPage().getParameters().get('AttachmentID');
att = [SELECT Body, ContentType, Name FROM Attachment WHERE ID = :id];
}
return att;
}
private set;
}
public String image {
get {
return EncodingUtil.Base64Encode(att.body);
}
}
}
Hi all I have achieved this using JSzip library here is my code --
In apex page I have written javascript function --
function viewContent(){
var zip = null;
var zipFileName = null;
var zipFileNames = null;
data = "{!contentAsText}";
zip = new JSZip(data, {base64:true});
zipFileName = 'files.zip';
zipFileNames = [];
for(var zipfileName in zip.files){
zipFileNames.push(zipfileName);
if(zipfileName == 'index.html'){
var file = zip.files[zipfileName];
var data = file.data;
document.getElementById('contentdiv').innerHTML = data;
//var data = JSZipBase64.encode(file.data);
}
}
In controller --
public String contentAsText {get;set;}
List<Attachment> atts = [Select Id, Body from Attachment where name='files.zip' limit 1];
contentAsText = EncodingUtil.base64Encode(atts[0].Body);
This link will help you --
http://andyinthecloud.com/2012/12/09/handling-office-files-and-zip-files-in-apex-part-2/

Resources