//calls edit method from super class that returns parent folder
super._editWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT);
//This can't be done on the WebAsset so it needs to be done here.
Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_EDIT);
// *********************** BEGIN GRAZIANO issue-12-dnd-template
if(cmd.equals(Constants.DESIGN))
template.setDrawed(true);
// *********************** END GRAZIANO issue-12-dnd-template
if(UtilMethods.isSet(template.getTheme())) {
Folder themeFolder = APILocator.getFolderAPI().find(template.getTheme(), user, false);
template.setThemeName(themeFolder.getName());
}
if(InodeUtils.isSet(template.getInode())) {
_checkReadPermissions(template, user, httpReq);
}
//gets image file --- on the image field on the template we store the image's identifier
//Identifier imageIdentifier = (Identifier) InodeFactory.getInode(template.getImage(), Identifier.class);
File imageFile = new File();
Boolean fileAsContent = false;
Contentlet imageContentlet = new Contentlet();
if(InodeUtils.isSet(template.getImage())){
Identifier imageIdentifier = APILocator.getIdentifierAPI().find(template.getImage());
if(imageIdentifier!=null && UtilMethods.isSet(imageIdentifier.getAssetType())) {
if(fileAsContent = imageIdentifier.getAssetType().equals("contentlet")) {
imageContentlet = APILocator.getContentletAPI().findContentletByIdentifier(imageIdentifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), APILocator.getUserAPI().getSystemUser(), false);
} else {
imageFile = (File) APILocator.getVersionableAPI().findWorkingVersion(imageIdentifier,APILocator.getUserAPI().getSystemUser(),false);
}
}
}
TemplateForm cf = (TemplateForm) form;
//gets the template host
HttpSession session = httpReq.getSession();
TemplateAPI templateAPI = APILocator.getTemplateAPI();
Host templateHost = templateAPI.getTemplateHost(template);
if(templateHost == null) {
String hostId= (String)session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID);
if(!hostId.equals("allHosts")) {
//Setting the default host = the selected crumbtrail host if it is a new container
Host crumbHost = hostAPI.find(hostId, user, false);
if(crumbHost != null && permissionAPI.doesUserHavePermission(crumbHost, PermissionAPI.PERMISSION_CAN_ADD_CHILDREN, user, false))
cf.setHostId(hostId);
}
} else {
cf.setHostId(templateHost.getIdentifier());
}
ActivityLogger.logInfo(this.getClass(), "Edit Template action", "User " + user.getPrimaryKey() + " edit template " + cf.getTitle(), HostUtil.hostNameUtil(req, _getUser(req)));
cf.setImage(fileAsContent?imageContentlet.getIdentifier():imageFile.getIdentifier());
// *********************** BEGIN GRAZIANO issue-12-dnd-template
req.setAttribute(WebKeys.TEMPLATE_IS_DRAWED, template.isDrawed());
// *********************** END GRAZIANO issue-12-dnd-template
}