This project is read-only.

How to add custom script in dashboard

Topics: Administration, Customizing Orchard, Writing modules
Oct 12, 2012 at 12:52 PM


I'm building a module for a customer and they want new link in menu in Dashboard.
It's quite simple to add one through INavigationProvider:

    T("UpdateNews"), "2", 
    item => item.Action( "UpdateExternalNews", 
        new { area = "Xxx.News" }), 
    new[] {"update-external-news-link"});

But action take some time and that's why I need something like blockUi.
So my plan is to use jQuery, something like

$(".update-external-news-link").click(function() {
  // block UI
  // version 1: return true (and cause URL call)
  // version 2: (using ajax)
  //  - grab URL from link
  //  - call URL
  //  - handle response 

No problem with all these, but here's the question:
Where should I put script above? 

I cannot use Script.Require("xxxScript") or something similar, because I'm not loading any custom view yet. I just need that script for link in menu, regardless what is on main part of screen.

I tried to serarch for solution here and on web, but I couldn't find anything about adding scrips to dashboard. 

Best regards, Martin



Oct 12, 2012 at 1:33 PM

I think the only way you would be able to achieve that is by modifying TheAdmin theme.

But since that's not advised (it may change overtime) it's probably best you implement a custom Admin theme as seen here

Copy paste the layout.cshtml from TheAdmin into your custom theme and add the required script there.

Hope this helps.



Oct 12, 2012 at 2:52 PM

Thanx, that helped a lot :)
I followed the instructions from link above and created my admin theme (MyAdmin). 

Beside layout.cshtml, I also had to copy admin.js. Now I can add scripts (and any other features) in admin module at will.

Thank you again,
best regards, Martin 

Oct 12, 2012 at 3:18 PM

No problem, glad it helped.