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.
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?
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?
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.
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.
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.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.
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?
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?
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
Cheers Dave, I'll have a look through the solution to double check against it.
Would like to hear what you come up with.
Dave
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.
is working on a reply...