Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Jackson-South 489 posts 1747 karma points c-trib
    Sep 18, 2015 @ 11:29
    James Jackson-South
    1

    Embedding JavaScript in a custom tab in the content dashboard.

    I'm trying to figure out how best to add resources to a custom tab to the content section of an Umbraco 7.2.8 install as I can't seem to find any documentation on the subject.

    I have a tab loaded but getting the JavaScript to load consistently seems impossible. It works in debug mode but not in release.

    I'm including the html and JavaScript as an embedded resource within a class library and referencing them using a combination of routing and a ClientDependency IVirtualFile. The way I'm getting Umbraco to call the code is very hacky since it is designed for use with property editors.

    [PropertyEditor("Deepend.Dashboard", EmbeddedResourceConstants.ResourceRoot + "custom.html" + EmbeddedResourceConstants.ResourceExtension, ValueType = "TEXT")]
    [PropertyEditorAsset(ClientDependencyType.Javascript, EmbeddedResourceConstants.ResourceRoot + "custom.js" + EmbeddedResourceConstants.ResourceExtension)]
    public class DashboardPropertyEditor : PropertyEditor
    {
        // The resource extension should allow the file to pass ClientDependency security.
    }
    

    Obviously a dashboard tab is not a property editor so I know this is the wrong way to go about it. The angular controller referenced gets loaded though in debug mode and my routing works as expected to yield the embedded resources.

    So.....

    What is the correct way to reference scripts in a custom tab? I'm hoping there is a solution that doesn't require me wading through multiple configuration files as I need everything to be in a self contained dll.

  • Robert Foster 459 posts 1820 karma points MVP 2x admin c-trib
    Sep 18, 2015 @ 11:45
    Robert Foster
    0

    When you say custom tab, are you talking about a custom dashboard tab, or a content tab? It sounds though that you're hitting a similar problem to nuPickers with it's embedded resources and ClientDependency - what happens if you whitelist the domain in the ClientDependency.config file?

  • James Jackson-South 489 posts 1747 karma points c-trib
    Sep 18, 2015 @ 12:56
    James Jackson-South
    0

    That's what I thought it was like but the requests all carry an additional extension .umb which as far as I was aware made it safe without having to add the domain to the whitelist.

    I wonder if I simply need to update my ClientDependency version?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 18, 2015 @ 12:01
    Dave Woestenborghs
    0

    I had some issues as well with embedded resources in my OEmbed picker property editor, but I still wanted a single dll for deployment and upgrade ease.

    What I do now is extract the embedded resources at startup and put them in versioned folders.

    But you are still tied to the property editor class for registering them in the backend. Don't know if you can embed the package.manifest json as well. As I remember correctly package manifests are parsed somewhere in startup by Umbraco. If you can extract them before this happens this can be done.

    Have a look here : https://bitbucket.org/dawoe/embed-property-editor/overview

    Dave

  • James Jackson-South 489 posts 1747 karma points c-trib
    Sep 18, 2015 @ 12:58
    James Jackson-South
    0

    Cheers Dave, I'll have a look through the solution to double check against it.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 18, 2015 @ 12:59
    Dave Woestenborghs
    0

    Would like to hear what you come up with.

    Dave

  • James Jackson-South 489 posts 1747 karma points c-trib
    Sep 18, 2015 @ 15:54
    James Jackson-South
    100

    So it turns out that I had an error in my sanitation code for my IVirtualFile implementation and was returning an empty stream from my embedded resources.

    Pulling embedded resources works well. The example code in the nuPicker library is a good place to get started if anyone wants to implement that kind of behaviour.

Please Sign in or register to post replies

Write your reply to:

Draft