Expand AdminTabStripCreated to provide entire page javascript injection

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
I am working on a project where I found the need to add a button to the product edit page.

After considering my options on how to do this it dawned on me that as it is coded and explained now the AdminTabStripCreated event handler functionality could be re-purposed to provide any injected javascript functionality for any page along with id, etc.

After realizing the accepted way of adding a tab to the tab strip is via javascript it wasn't difficult to make the leap that any javascript could be added to manipulate the page. Please see code snippet below as an example, the code adds a button to the save, copy, delete region of the product details page and works flawlessly.


            if (eventMessage.TabStripName == "product-edit")
            {
                var productId = Convert.ToInt32(eventMessage.Helper.ViewContext.RouteData.Values["id"]);


                string url = "/Admin/Plugins/ErpIntegration/ImportErpProductPricing/" + productId;
                var sb = new StringBuilder();
                sb.Append("<script language=\"javascript\" type=\"text/javascript\">");
                sb.Append(Environment.NewLine);
                sb.Append("$(document).ready(function () {");
                sb.Append(Environment.NewLine);
                sb.Append("$('#copyproduct').before('<input type=\"button\" id=\"erppriceimport\" name=\"erppriceimport\" class=\"k-button\" value=\"Import ERP Pricing\">');");
                sb.Append(Environment.NewLine);
                sb.Append("$('#erppriceimport').on('click', function() { $.get(\"" + url + "\", function( data ) { location.reload(); }); });");
                sb.Append(Environment.NewLine);
                sb.Append("});");
                sb.Append(Environment.NewLine);
                sb.Append("</script>");
                sb.Append(Environment.NewLine);
                eventMessage.BlocksToRender.Add(MvcHtmlString.Create(sb.ToString()));
            }
8 years ago
Go through the Mr. Hristian reply in the previuos post  ===>https://www.nopcommerce.com/boards/t/40529/add-extra-tab-to-admin-edit-order-details.aspx#161987
7 years ago
sohel wrote:

Hey Sohel,

I wasn't asking how to create a new tab, rather suggesting that the current implementation of AdminTabStripCreated could be used for a much larger scope and purpose with little effort on the development end.

Does anyone else have an opinion or understand what I was trying to suggest?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.