bbo wrote:Hi,
I tried following things:
Controller
public void HandleEvent( AdminTabStripCreated eventMessage )
{
if ( eventMessage.TabStripName == "product-edit" )
{
RouteValueDictionary routeValues = new RouteValueDictionary
{
{ "area", LmisConsts.ADMIN_AREANAME },
{ "id", System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values[ "id" ].ToString() }
};
int? id = Convert.ToInt32( System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values[ "id" ].ToString() );
// EDIT
this.ControllerContext = this.ControllerContext ?? new System.Web.Mvc.ControllerContext( System.Web.HttpContext.Current.Request.RequestContext, this );
this.SaveSelectedTabIndex();
string content = this.RenderPartialViewToString( "_ProductStickersTab", model ).Replace( "\r\n", "" ).Trim();
eventMessage.BlocksToRender.Add( new MvcHtmlString( TabHelper.BuildKendoAdminTab( _logger, eventMessage.TabStripName, this._localizationService.GetResource( ProductStickersConsts.NS_PLUGIN + ".TabProductStickers" ), content, "content" ) ) );
}
}
public static string BuildKendoAdminTab( ILogger logger, string tabStripName, string text, string content, string contentType = "contentUrl", bool encoded = false )
{
return String.Format(
"{5}<script>{5}" +
" $(document).ready(function() {{{5}" +
" $('#{0}').data('kendoTabStrip').append({5}" +
"[{{{5}" +
"text: '{1}',{5}" +
"encoded: {2},{5}" +
"{3}: '{4}'{5}" +
"}}]);{5}" +
"}});{5}" +
"</script>{5}",
tabStripName, text, encoded.ToString().ToLower(), contentType, content, Environment.NewLine
);
}
The content is loading correct, but in the <script>-tag. This is not good.
Using contentUrl the content will load 'onclick'.
I need another way to bind a new tab without changing the original source code.
Any ideas?
Hi,
To solve the bold tab I added a style in the HandleEvent:
if (eventMessage.TabStripName == "product-edit")
{
int productId = Convert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["ID"]);
this.ControllerContext = this.ControllerContext ?? new System.Web.Mvc.ControllerContext(System.Web.HttpContext.Current.Request.RequestContext, this);
string script = @"<style type=""text/css"">
.k-link {
font-weight: bold;
}
</style>
<script language=""javascript"" type=""text/javascript"">
$(document).ready(function () {
var kTabs = $('#product-edit').data('kendoTabStrip');
kTabs.append({ text: ""301 Redirect"", contentUrl: ""/MiscPageRedirect/RedirectProductTab?id=" + productId + @""" });
});
</script>";
eventMessage.BlocksToRender.Add(MvcHtmlString.Create(script));
}
You can render the tab in the controller and add it using the "content" attribute kTabs.append({ text: "301 Redirect", content: "{html here}" }); I went down this route but found that using a tab is actually better as the kendo library is very different from telerik library, there isn't a model to bind to as it's all done in Javascript now, so I had to re-engineer a few bits - I'll be using content loading tabs from now on.