In basing custom content types on existing content types, I ran into an issue where my drag-and-drop re-ordering wasn’t working. When I checked the drag-and-drop page re-ordering I was basing it on, I discovered that changes in page orders in the contentbox-admin module weren’t being saved, either.
Digging into the issue, I found that two things were happening that were preventing the re-ordering from happening:
- The passed data was not being URLDecoded
- The passed data had an incorrect replace method
The code as it stands is:
contentbox-admin:handlers.pages
function changeOrder( event, rc, prc ){
event.paramValue(“tableID”,“pages”);
event.paramValue(“newRulesOrder”,“”);
rc.newRulesOrder = ReplaceNoCase(rc.newRulesOrder, “&#rc.tableID#=”, “,”, “all”);
rc.newRulesOrder = ReplaceNoCase(rc.newRulesOrder, “#rc.tableID#=,”, “”, “all”);
The adjusted code to enable it to work:
function changeOrder( event, rc, prc ){
event.paramValue(“tableID”,“pages”);
event.paramValue(“newRulesOrder”,“”);
rc.newRulesOrder = urlDecode(rc.newRulesOrder);
rc.newRulesOrder = ReplaceNoCase(rc.newRulesOrder, “&#rc.tableID#=”, “,”, “all”);
rc.newRulesOrder = ReplaceNoCase(rc.newRulesOrder, “#rc.tableID#=”, “”, “all”);
The changes are adding the urlDecode() line and removing the comma after the equal sign in the last line (which caused the replace to not happen since there is no comma there).
So those would be proposed changes to ContentBox. In the interim, you can make use of the methodology in http://www.andyscott.id.au/blog/a-funky-way-to-replacing-captcha-in-contentbox to override the handler to enact this change without modifying the core contentbox application. While the link talks about overriding a plugin, it can work with any cfc loaded by wirebox. You just need to call your overriding cfc appropriately.
Create your object’s cfc file as a cfc that extends the handler you want to override. Then use a switch to target the individual cfc and set the interceptData.target to the appropriate type of object. In this case, you need to get the bean of the handler, which means using the handlerservice.
public void function afterInstanceCreation() {
var handlerService = “”;
// Get object’s name and clean it up so it doesn’t include anything but the module and subsequent namespaces
var objectName = GetMetaData(interceptData.target).name;
objectName = REReplace(objectName,“^(” & [[application.root.NameSpace]] & “)?modules.”,“”);
switch(objectName){
case “contentbox-admin.handlers.pages”:
handlerService = controller.gethandlerService();
interceptData.target = handlerService.gethandler(handlerService.getRegisteredHandler(“[[your override module]]:[[your override handler]].init”),controller.getRequestService().getContext());
break;
default:
return;
}
}
Note that application.root.NameSpace is a value I added to my application scope, along with a few others, to help with navigating the issues that are created when installing your contentbox site somewhere beneath the root of your web server. The structure itself does nothing, of course, but it gives you quick access to variables that you can make use of throughout your application. To do this, I added the following code at the beginning of my site’s application.cfc > onApplicationStart() function:
var serverRoot = ExpandPath(‘/’);
var appRoot = COLDBOX_APP_ROOT_PATH;
var extraFolders = Replace(appRoot,serverRoot,“”);
var extraNameSpaces = Replace(extraFolders,“",”.",“ALL”);
application.root = StructNew();
application.root.Folder = extraFolders;
application.root.WebFolder = Replace(extraFolders,“",”/",“ALL”);
application.root.NameSpace = extraNameSpaces;
So that gives you everything you need to know to:
-
Fix the drag-and-drop re-ordering of pages
-
Override any wireboxed object (thanks to Andrew Scott)
-
Create an application scope structure to help with non-root-level contentbox sites.
Luis, let me know if you want me to create a jira ticket (and in which project: CONTENTBOX or CTBOXUTILITIES) to address the drag-and-drop re-ordering bug.
John