How to set ActionLink as an image - asp.net-mvc-2

I have a little question. How to set ActionLink as an image for something like this:
<%= Html.ActionLink("English", "ChangeCulture", "Account",
new {lang = "en", returnUrl = this.Request.RawUrl }, null)%>
For other ActionLink i did something like this:
Html.ActionLink(" ", "About", "Home", new
{style = "background: url('../../Content/images/img03.jpg')no-repeat center
right;display:block; height:24px; width:24px;"})
But for this example it doesn't work. I want to add localization to my site in the form of images of flags. Thanks in advance.

I see a few issues here...
Firstly, you are setting the routeValues paramater of ActionLink with your Html style. Add a null object between them:
Html.ActionLink(" ", "About", "Home", null, new
{style = "background: url('../../Content/images/img03.jpg')no-repeat center
right;display:block; height:24px; width:24px;"})
Secondly, you will want to check the url of the image is correct as you are using a relative path. Try using Url.Content to get the correct path instead.
Thirdly, the lack of a space between the url and the no-repeat flag might be affecting your browser output.

I have solved this using html helper
tho i would recomend using TagBuilder for this.
/// <summary>
/// Create image representation of boolean in form of
/// </summary>
/// <param name="html">The HTML.</param>
/// <param name="boolValue">if set to <c>true</c> [bool value].</param>
/// <param name="path">The path.</param>
/// <param name="alt">The alt.</param>
/// <returns>
/// html img tag
/// </returns>
public static string ImageForBool(this HtmlHelper html, bool boolValue, string path,ImageAlt alt)
{
string trueVal = "tick";
string falseVal = "x";
string img = "<img src=\"{0}\" {1}/>";
string altTag = string.Empty;
path += "Content/Actions/";
if (boolValue)
{
altTag = (alt == null) ? "" : "alt=\"" + alt.trueOption + "\"";
return string.Format(img, Path.Combine(path, trueVal) + ".png", altTag);
}
else
{
altTag = (alt == null) ? "" : "alt=\"" + alt.falseOption + "\"";
return string.Format(img, Path.Combine(path, falseVal) + ".png", altTag);
}
}
this option is possibly the best for you
Alternative way
use html action link and use string.replace
using your code:
string tag = Html.ActionLink("[toReplaceWithImage]", "ChangeCulture", "Account",
new {lang = "en", returnUrl = this.Request.RawUrl }, null).ToString()
tag.Replace("[toReplaceWithImage]", "<img src=\"path\">");

Related

How to filter tags in a component dialog. Adobe CQ

I am trying to filter the tags in a component dialog. I know that I can filter it by namespace, however that applies only to root level. Can I filter the tag selection one level deeper?
for example:
etc
tags
namespace
article-type
blog
news
asset-type
image
video
I want to filter the tags in the component dialog so the user can only select the tags under 'article-type'.
Thanks,
Yes and no. Officially you can go deeper according to the widget API, but there is a "bug" in the Widget JavaScript file that prevents it to work. I had the same issue and I just overwrite this JavaScript file.
Widget definition:
<article jcr:primaryType="cq:Widget"
fieldLabel="Article Type"
name="./cq:tags"
tagsBasePath="/etc/tags/namespace"
xtype="tags">
<namespaces jcr:primaryType="cq:WidgetCollection">
<ns1 jcr:primaryType="nt:unstructured" maximum="1" name="article-type" />
</namespaces>
</article>
<asset jcr:primaryType="cq:Widget"
fieldLabel="Asset Type"
name="./cq:tags"
namespaces="[asset-type]"
tagsBasePath="/etc/tags/offering"
xtype="tags"/>
In this case only one Tag below article-type can be selected; you can limit the number with the maximum attribute. The asset-type has no limits. So choose the option that suits your need.
JavaScript overwrite:
To make this work, you need to change the method CQ.tagging.parseTag in /libs/cq/tagging/widgets/source/CQ.tagging.js:
// private - splits tagID into namespace and local (also works for title paths)
CQ.tagging.parseTag = function(tag, isPath) {
var tagInfo = {
namespace: null,
local: tag,
getTagID: function() {
return this.namespace + ":" + this.local;
}
};
var tagParts = tag.split(':');
if (tagParts[0] == 'article-type' || tagParts[0] == 'asset-type') {
var realTag = tagParts[1];
var pos = realTag.indexOf('/');
tagInfo.namespace = realTag.substring(0, pos).trim();
tagInfo.local = realTag.substring(pos + 1).trim();
}
else {
// parse tag pattern: namespace:local
var colonPos = tag.indexOf(isPath ? '/' : ':');
if (colonPos > 0) {
// the first colon ":" delimits a namespace
// don't forget to trim the strings (in case of title paths)
tagInfo.namespace = tag.substring(0, colonPos).trim();
tagInfo.local = tag.substring(colonPos + 1).trim();
}
}
return tagInfo;
};

how to change GWT/SmartGWT theme at run time

I want to change the theme of my SmartGWT application at run time from the code
I can see this functionally in SmartGWT showcase , but I can't see any code for this in SmartGWT showcase.
What I am doing right now is
This is my XML class
<?xml version="1.0" encoding="UTF-8"?>
<inherits name="com.smartgwt.SmartGwtNoTheme"/>
<inherits name="com.smartclient.theme.graphite.Graphite"/>
<inherits name="com.smartclient.theme.blackops.BlackOps"/>
<inherits name="com.smartclient.theme.enterprise.Enterprise"/>
<inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlue"/>
This is my HTML class snippet
<title>My Web</title>
<script>
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for ( var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}
// Determine what skin file to load
var currentSkin = readCookie('skin');
if (currentSkin == null){
currentSkin = "Enterprise";
}
alert(currentSkin);
</script>
<script type="text/javascript">
document.write("<" + "script src=testtheme/sc/skins/"
+ currentSkin + "/load_skin.js><"+"/script>");
</script>
This is my Java class
SelectItem selectItem = new SelectItem("skin", "Choose Skin");
DynamicForm df = new DynamicForm();
hpnlMain.add(df);
df.setItems(selectItem);
selectItem.setWidth(130);
java.util.LinkedHashMap<String, String> valueMap = new java.util.LinkedHashMap<String, String>();
valueMap.put("Enterprise", "Enterprise");
valueMap.put("EnterpriseBlue", "EnterpriseBlue");
valueMap.put("TreeFrog", "TreeFrog");
valueMap.put("BlackOps", "BlackOps");
valueMap.put("Graphite", "Graphite");
selectItem.setValueMap(valueMap);
String currentSkin = Cookies.getCookie("skin");
if (currentSkin == null) {
currentSkin = "Enterprise";
}
selectItem.setDefaultValue(currentSkin);
selectItem.addChangedHandler(new ChangedHandler() {
#Override
public void onChanged(ChangedEvent event) {
// TODO Auto-generated method stub
Cookies.setCookie("skin", event.getValue().toString());
Window.Location.reload();
}
});
The expected outcome is that when I select any skin form my SelectItem, that skin should be applied, but I am having no Effect .
Please look into this line in my HTML file
<script type="text/javascript">
document.write("<" + "script src=testtheme/sc/skins/"
+ currentSkin + "/load_skin.js><"+"/script>");
Here I'm not sure what will be the exact path ,
I have the smatgwt-skins.jar in my class path
Thanks
What does the 'alert(currentSkin)' line in your html file display when you change the skin and the application gets reloaded? Does it show the newly selected skin name?
It looks like you are using code from the SmartGWT showcase, or it just happens to appear almost identical to it.
http://code.google.com/p/smartgwt/source/browse/trunk/samples/showcase/src/com/smartgwt/sample/showcase/client/Showcase.java
Maybe this could help: Here
Check the Smartclient forum for this situation, there is plenty information on it.

Extjs quicktip display empty box

I am trying to implement a tool tip (QuickTip) functionality on a GXT grid cell.It seems to work most of the time, but some times I get an empty tooltip box while mousing over the column header. I found some articles stating the tooltip is only applicable to the data and not on header,but thats not the case I guess. I made the toolTip/text null by default, still I see empty box on header-mouse over.Am I doing something wrong?
This is my code:
ColumnConfig columnTitle = new ColumnConfig();
columnTitle.setId("subject");
columnTitle.setHeader("<B>Title</B>")
columnTitle.setRenderer(new GridCellRenderer<ModelData>()
{
#Override
public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<ModelData> store, Grid<ModelData> grid)
{
SystemUserMessage msg = ((BeanModel)model).getBean();
String text = null;
text = msg.getSubject();
String content = model.get("content").toString();
String toolTip = null;
toolTip = " qtip='" + content + "'";
String style = null;
if(msg.getPriority().equals("High"))
{
style = " style='color: red;'";
}
String html = "<span" + toolTip + style + ">" + text + "</span>";
return html;
}
});
new QuickTip(messageCenterGrid); //register the tooltip
Try replacing qtip= with data-qtip= . You can also add data-qtitle=
Edit helpful link per Juan : http://docs.sencha.com/ext-js/4-1/#!/api/Ext.tip.QuickTipManager

How to change tinymce editor font style and size on the fly?

tinymce's FAQ explains how to change the editor's default font style by referencing a custom content_css file.
But I'd like to change the editor's font style on the fly programmatically. Any ideas? Thanks.
This is possible, but requires some knowledge.
You will need to call something like
self.switchStyle(url, ed);
where switchStyle is
// url is the url to the stylesheet file to be added to the editor iframes head
// ed is the editor object or editor id
switchStyle: function(url, ed) {
if (typeof ed != 'object') {
ed = tinymce.get(ed);
}
//replace the custom content_css if set
var url_to_replace = ed.getParam('content_css');
var doc = ed.getDoc();
var $doc = $(doc);
var sheets_urls = [];
if (url_to_replace){
sheets_urls.push(url_to_replace);
}
// remove all stylesheets from sheets_urls
$doc.find('link').each(function() {
if (tinymce.inArray(sheets_urls, $(this).attr('href').split('?')[0]) !== -1) {
$(this).remove();
}
});
var link = doc.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
// setstylesheet
$doc.find('head:first').append(link);
},

how to ask for new value before showing to the user?

I found this sample code where i can replace something automatically in the page
// If content-type is HTML, then remove all DIV tags
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Replace all instances of the DIV tag with an empty string
var oRegEx = /<div[^>]*>(.*?)<\/div>/gi;
oBody = oBody.replace(oRegEx, "");
// Set the response body to the div-less string
oSession.utilSetResponseBody(oBody);
}
But how can i ask for the new value, instead of replacing it automatically?
See if this works for you
if (oSession.uriContains("/yoururl/here")) {
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
var oRegEx = /this text will be replaced everywhere/gi;
var mydefaulttext = 'new text';
var mymsgbox = FiddlerScript.prompt('Lets change something', mydefaulttext);
oBody = oBody.replace(oRegEx, mymsgbox);
oSession.utilSetResponseBody(oBody);
}
OnBeforeResponse