oh cool, I didn't know this.

thanks,

By the way. I just created a (horrible, but nevertheless) solution for
our problem with dam support and having only one handler
(http://jira.magnolia-cms.com/browse/MGNLSTK-564). My solution was to
attach a save handler to the dam dialog control class, and do the
buisiness there.

Because it's a bit hard to understand what really happens with the
dialog controls (and I assume it's a temporary fix and i don't have
much time) i didn't get it quite right: I'm setting a hidden field
that i don't need, only to attach the save handler. Also do i indulge
in some gruesome hardcoding of the dam handler name (which should be
obtained dynamically).
But perhaps this approach is in itself valid, so i send it to you.

Ernst

2010/2/2 Grégory Joseph <[email protected]>:
>
>
> On Feb 2, 2010, at 1:55 PM, Ernst Bunders wrote:
>
>>
>> hello Grégory
>> Maybe it would be nice to include a 'site' instance in the freemarker
>> context.
>
> Agreed.
>
>> At this point it is at least not entirely clear how to obtain
>> an instance.
>
> You can do ${stk.site}, which is 
> info.magnolia.module.templatingkit.util.STKUtil#getSite(), or ${model.site}, 
> if your model is (a subclass of) STKTemplateModel
>
> -g
>
>> 2010/1/29 Grégory Joseph <[email protected]>:
>>>
>>>
>>> On Jan 29, 2010, at 3:33 PM, Nils Breunese wrote:
>>>
>>>>
>>>> Please see http://jira.magnolia-cms.com/browse/MGNLSTK-575
>>>
>>> Yep, seen it earlier; excellent, thanks. We'll probably apply that soon on 
>>> the trunk, as soon as we get a moment. We probably want to do the same 
>>> "magic" wrapping we did for templates/paragraphs, where you could do 
>>> ${site.myParam} instead of ${site.parameters.myParam}. We'll probably also 
>>> want to have an example with the default config (or at least an empty 
>>> "parameters" node). Do you have a very concrete use-case we could reuse for 
>>> samples ? :)
>>>
>>> Cheers,
>>>
>>> -g
>>> ----------------------------------------------------------------
>>> For list details see
>>> http://www.magnolia-cms.com/home/community/mailing-lists.html
>>> To unsubscribe, E-mail to: <[email protected]>
>>> ----------------------------------------------------------------
>>>
>>>
>>
>>
>>
>> --
>> Ernst Bunders
>> Ontwikkelaar VPRO
>>
>> ----------------------------------------------------------------
>> For list details see
>> http://www.magnolia-cms.com/home/community/mailing-lists.html
>> To unsubscribe, E-mail to: <[email protected]>
>> ----------------------------------------------------------------
>
>
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------
>
>



-- 
Ernst Bunders
Ontwikkelaar VPRO

----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------
package nl.vpro.magnolia.module.images.dam;

import info.magnolia.cms.beans.runtime.MultipartForm;
import info.magnolia.cms.core.Content;
import info.magnolia.cms.security.AccessDeniedException;
import info.magnolia.context.MgnlContext;
import info.magnolia.module.admininterface.FieldSaveHandler;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.value.StringValue;

import javax.jcr.RepositoryException;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 */
public class DamBugfixSaveHandler implements FieldSaveHandler {
    public void save(Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType, int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException {
        HttpServletRequest request = MgnlContext.getWebContext().getRequest();
        String mediaUUID = request.getParameter("imageMediaUUID");

        if (StringUtils.isBlank(mediaUUID)) {
            //mediaUUID not set:
            if (parentNode.hasNodeData("image")) {
                delete(parentNode, true);
            }
        } else {
            //mediaUUID set.
            if (parentNode.hasNodeData("image")) {
                if (!"media".equals(parentNode.getNodeData("image").getString())) {
                    //property found with wrong value
                    delete(parentNode, false);
                    create(parentNode);
                }
            } else {
                //no property found
                create(parentNode);
            }
        }
    }

    private void delete(Content node, boolean save) {
        try {
            node.deleteNodeData("image");
            if (save) node.save();
        } catch (RepositoryException e) {
        }
    }

    private void create(Content node) {
        try {
            node.setNodeData("image", new StringValue("media"));
            node.save();
        } catch (RepositoryException e) {
        }
    }
}
package nl.vpro.magnolia.module.images.dam;

import info.magnolia.cms.beans.config.ContentRepository;
import info.magnolia.cms.core.Content;
import info.magnolia.cms.gui.dialog.DialogHidden;
import info.magnolia.cms.util.ContentUtil;
import info.magnolia.module.templatingkit.dam.DAMHandler;
import info.magnolia.module.templatingkit.dam.DAMSupport;
import info.magnolia.module.templatingkit.dam.dialog.DialogDAM;
import info.magnolia.module.templatingkit.util.STKUtil;

import javax.jcr.RepositoryException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;

/**
 * This class is ment to fix the dam-support bug that when there is only one dam handler
 * The property 'image' with the handler name as value is not set.
 * When there are multiple handlers this property created by a radio group that makes you select the
 * preffered handler.
 * When there is only one handler, it should be created by a hidden field.
 */
public class DialogDamSingleHandlerBugfix extends DialogDAM {

    private Collection<DAMHandler> handlers = null;

    @Override
    public void init(HttpServletRequest request, HttpServletResponse response, Content storageNode, Content configNode) throws RepositoryException {
        super.init(request, response, storageNode, configNode);
        this.handlers = getDamSupport().getHandlers().values();

    }

    protected void drawSubs(Writer out) throws IOException {

        super.drawSubs(out);
        if (handlers.size() == 1) {
            String currentValue = getConfigValue("image");
            DialogHidden dialog = new DialogHidden();

            //eigenlijk hebben we alleen maar de savehandler nodig, maar goed
            dialog.setName("image");
            dialog.setValue("media");
            dialog.setSaveInfo(true);
            dialog.setConfig("saveHandler", "nl.vpro.magnolia.module.images.dam.DamBugfixSaveHandler");
            this.addSub(dialog);
            dialog.drawHtml(out);
            dialog.drawHtmlPost(out);
        }
    }

    private DAMSupport getDamSupport() {
        try {
            Content websiteNode = this.getStorageNode();
            if (websiteNode == null) {
                String websitePath = this.getRequest().getParameter("mgnlPath");
                websiteNode = ContentUtil.getContent(ContentRepository.WEBSITE, websitePath);
            }
            return STKUtil.getSite(websiteNode).getDamSupport();
        } catch (Exception e) {
            //ignore
        }
        return null;
    }
}

Reply via email to