How do I include a custom field client control JS file? - sitefinity

I'm trying to develop a custom field using the steps outlined here: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/controls/types-of-controls/field-controls/building-a-custom-field-control
Unfortunately, I don't know how/where to include the client control js file, and it doesn't seem to say in the documentation. Can anyone explain how I might do this?
I'm very new to Sitefinity dev (as in this is the first thing I've done) and web dev in general, so feel free to suggest things that "should be obvious"
I also asked this question on the Sitefinity forums - I'll be sure to copy the answer here if I get one there.

Ok, got it.
First you need to set the processing options for the js file to Embedded Resource
Then add it to the AssemblyInfo.cs:
[assembly: WebResource("namespace.filename.js", "text/javascript")]
Then override the GetScriptReferences method in the class that inherits from FieldControl:
public override IEnumerable<ScriptReference> GetScriptReferences()
{
var baseReferences = new List<ScriptReference>(base.GetScriptReferences());
var newRef = new ScriptReference(javascriptPath, this.GetType().Assembly.FullName);
baseReferences.Add(newRef);
return baseReferences;
}

Related

Documentation for Xcode Source Editor Extension

I'm looking for some documentation of the new Xcode Source Editor Extensions in Xcode 8.
As far as I can see there is only the "documentation" found in the header file for XcodeKit. Would be great to get something that's more detailed and more official.
Very preliminary XcodeKit reference documentation is now available.
Our WWDC 2016 presentation introducing Xcode Source Editor Extensions remains the best walkthrough.
The very shortest version, however, is: Because App Extensions need to be embedded in an application, you need to first create a new macOS Cocoa Application, and then add a new Xcode Source Editor Extension to that application. Then the XcodeKit reference should help some in implementing that.
Not really a documentation but a good reference also
https://developer.apple.com/videos/play/wwdc2016/414/
Extensions, at the moment, are poorly documented. There are a lot of assumptions made (for example, did you know that you can execute the container app? Yup, it’s really nice for settings GUI - see this How To Execute Container App - Second Answer)
At the moment, there are a lot of things missing: for example, there isn’t a structure that shows the corresponding lines with the data object - though this is quickly created with the following code:
var matches: [NSTextCheckingResult] = []
do {
let regex = try NSRegularExpression(pattern: "\n", options: [])
matches = regex.matches(in: completeBuffer,
options: [],
range: NSMakeRange(0, completeBuffer.count))
}
catch {
}
This gives you the location of all the \n’s - you should be able to fill out the rest to give you starting and ending positions which should match up to the lines.
All in all, there is a lot to like about the extension, but there are quite a few things missing as well.
Currently the only available documentation is in the headers; there's nothing "unofficial" about them. If you have specific questions, please ask.

SilverStripe 3: Can a module extend mysite/code/Page.php?

Good afternoon,
I don't know if what I want to do is possible, so here goes.
I have a module that extends Page_Controller, but I want certain functions to be accessible via the site root.
Eg: getMyDataObjectList();
Currently, they only work if I go through the normal MVC routing structure.
I've found that when I place the function 'getMyDataObjectList' within '/mysite/code/Page.php' it works.The problem is, I don't want to place the code in there. I want it bundled with my Custom Module, but to work the same as though it was in 'mysite/code/Page.php'
[Example Scenario]
site root: http://[somesite].com
By default, the 'Page.ss' template loads.
I would like the theme developer to be able to call my module functions (API) within any template/Layout page, and have the result returned from the site root
Currently, this only works if I move the "API" functions to '/mysite/code/Page.php'
If the code is in my module, then data is only returned when you go to:
http://[somesite].com/[module_controller]
Can this be achieved? If so, how?
Thanks for your assistance.
[Update - Code Solution]
///>MyExtension.php
class MyExtension extends Extension{
public function getMyDataObjectList(){
return 'object list goes here!';
}
}//class
///>[Module] => _config.php
Object::add_extension('Page_Controller', 'MyExtension');
And as always, I do a (/dev/build?flush=1) just in case.
Thanks to: 'simon_w'
Yes, this is relatively straightforward. Simply, create an Extension subclass with your methods in them and then add that to Page_Controller. An Extension subclass is almost exactly the same as a DataExtension, they're just for classes other than DataObjects.

How to customize cluster icon using gmaps4rails

So we're trying to change the default cluster icon using gmaps for rails.
In the wiki
it says
You can customize the pics used by the clusterer by setting the Gmaps.map.customClusterer js function in your code.
Where would we put that function? It says "In the javascript" - but where? Do we straight-up edit the code generated by gmaps4rails? How does gmaps4rails pick up the information?
To do this customization you just need to create js file. Then you can
"require" that js file in your Application.js or otherwise just directly refer in your view file. That's it you need not to do anything else. I have used it and it worked for me. If any questions do let me know.
To understand how it works you can just refer the
gmaps4rails.base.js (see #customClusterer = -> false)
gmaps4rails.googlemaps.js (method - createClusterer)
it is straight forward to understand

Better way to use Velocity's GenericTools in a Standalone app?

I want to use VelocityTool's GenericTools for some standard formatting in a standalone app. e.g. have something like this in my Velocity template to use the GenericTools' NumberTool formatter:
Total: $numberTool.format("#0.00", $totalPnL)
How do I associate the above "$numberTool" with the GenericTool NumberTool. Here's my Velocity code:
Velocity.init();
VelocityContext velocityContext = new VelocityContext();
Template template = Velocity.getTemplate("example.vm");
velocityContext.put("totalPnL", 100);
StringWriter sw = new StringWriter();
template.merge(velocityContext, sw);
Now I know I can do this to get it to work:
velocityContext.put("numberTool", new NumberTool());
But is that how I need to add all the GenericTools to my app? Manually and one at a time (e.g. another line for DateTool ... etc)? Isn't there a way to make all the GenericTools exposed to my template with out this? I know there's a "tools.xml" that comes with VelocityTools that has the GenericTools defined. Can I just add that to my app to expose all the tools? If so, how?
thanks,
David
http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/ToolManager.html
http://velocity.apache.org/tools/devel/standalone.html
The default tool configuration provides all the generic tools already. Though you can create a config if you want to configure those tools. There's even auto loading for configurations, or manual specification.
ToolManager tm = new ToolManager();
tm.setVelocityEngine(yourVelocityEngine);
Context context = tm.createContext();
it is at least the way I do it too.
I'll put for example
context.put("esc", new EscapeTool());
and in the template I simply use then
${esc.h}
to write a "#" in the code so that Velocity does not parse it as "velocity-script".
I think those helper tools are rather utils and only cover some basic signs. They are not intend to be a standard, you rather can include them on-demand.
I've build for example an abstract class that loads the context of velocity and puts the EscapeTool into the context all the time so that I do not have to add it everywhere.
Good luck with your project
Sebastian

MEF + SL4 question

I'm working on an app in the Silverlight 4 RC and i'm taking the oppertunity to learn MEF for handling plugin controls. I've got it working in a pretty basic manor, but it's not exactly tidy and I know there is a better way of importing multiple xap's.
Essentially, in the App.xaml of my host app, I've got the following telling MEF to load my xap's:
AggregateCatalog catalog = new AggregateCatalog();
DeploymentCatalog c1 = new DeploymentCatalog(new Uri("TestPlugInA.xap", UriKind.Relative));
DeploymentCatalog c2 = new DeploymentCatalog(new Uri("TestPlugInB.xap", UriKind.Relative));
catalog.Catalogs.Add(c1);
catalog.Catalogs.Add(c2);
CompositionHost.Initialize(catalog);
c1.DownloadAsync();
c2.DownloadAsync();
I'm sure I'm not using the AggregateCatalog fully here and I need to be able to load any xap's that might be in the directory, not just hardcoding Uri's obviously....
Also, in the MainPage.xaml.cs in the host I have the following collection which MEF puts the plugin's into:
[ImportMany(AllowRecomposition = true)]
public ObservableCollection<IPlugInApp> PlugIns { get; set; }
Again, this works, but I'm pretty sure I'm using ImportMany incorrectly....
Finally, the MainPage.xaml.cs file implements IPartImportsSatisfiedNotification and I have the following for handling the plugin's once loaded:
public void OnImportsSatisfied()
{
sp.Children.Clear();
foreach (IPlugInApp plugIn in PlugIns)
{
if (plugIn != null)
sp.Children.Add(plugIn.GetUserControl());
}
}
This works, but it seems filthy that it runs n times (n being the number of xap's to load). I'm having to call sp.Children.Clear() as if I don't, when loading the 2 plugin's, my stack panel is populated as follows:
TestPlugIn A
TestPlugIn A
TestPlugIn B
I'm clearly missing something here. Can anyone point out what I should be doing?
Thanks!
I think most of what you are doing is fine. Although ObservableCollections do support notifications of individual elements being added and removed, MEF doesn't take advantage of this. In your case it will simply clear the collection and then add all the plugins. Since you are using OnImportsSatisfied for the change notification, you don't even need an ObservableCollection. You could just use an IEnumerable for your import.
To add flexibility in downloading different xaps, I would expose a service in your container that can be imported and that provides the functionality to download a xap given a url. Then any component in your container can trigger a download, and the url to download can come from whatever source you deem appropriate.