简体   繁体   中英

Alfresco - Approve task in a workflow

I'm integrating an applet on a workflow in the Alfresco. I created a new button org/alfresco/components/form/controls/workflow/activiti-transitions.ftl here

  ...

    <button onclick="changePDF(); this.disabled=true; return false;"> Change </button>
    <div id="pdfTexto" style="width:1000px;height:1000px"></div>
        <div class="applet">
            <script type="text/javascript">
                deploy();
            </script>
        </div>
    </#if>

And this button change (through the javascript of the applet) calls the functionality of the applet that is make changes in the file of the respective workflow. After this, I want to put "Approved" like the button accept standard does. But, I only want to make this after the changes make effect. My applet returns a "ok" when the changes are completed (the POST request is completed), after this, I want to put "Approved" and redirect to the same page that "accept" button redirects. In resume, after "ok", make what the accept button does.

My applet updates the content of an exiting document with: http://localhost:8080/share/proxy/alfresco/api/upload ...

How can I make this? Any hints for a better solution then the below?

Evolution: I'm trying to make this:

 var form = new FormData();
     form.append("prop_wf_reviewOutcome","Approve");
     form.append("prop_bpm_comment","good");
     form.append("prop_transitions","Next");
     var requestTask = new XMLHttpRequest();
         requestTask[Alfresco.util.CSRFPolicy.getHeader()] = Alfresco.util.CSRFPolicy.getToken();
         requestTask.open("POST", "http://localhost:8080/share/proxy/alfresco/api/task/"+ taskidVar+ "/formprocessor" + "?" + Alfresco.util.CSRFPolicy.getParameter() + "=" + encodeURIComponent(Alfresco.util.CSRFPolicy.getToken()));
         requestTask.send(form);

But lack redirect the page as the "Approve" button.

First of all, you need to define your behaviour:

package com.someco.alfresco.policy;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DocumentUpdatePolicy implements ContentServicePolicies.OnContentUpdatePolicy {
    private final Log logger = LogFactory.getLog(getClass());

    private PolicyComponent policyComponent;    
    private NodeService nodeService;    

    public void init() {
        this.policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"),
                ContentModel.TYPE_CONTENT,
                new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.EVERY_EVENT));
    }

    @Override
    public void onContentUpdate(NodeRef nodeRef, boolean newContent) {

        logger.debug("Called on: " + nodeRef);
        if (null == nodeRef || !nodeService.exists(nodeRef)) {
            logger.error("Wrong nodeRef");
            /* This can happen in some circumstances */
            /* Do you want to just ignore it or do something ? You decide */
            return;
        }

        /* Here goes the code to update the task */
    }

    public void setPolicyComponent(final PolicyComponent policyComponent) {
        this.policyComponent = policyComponent;
    }

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }


}

Than you need to initialise it in your custom Spring context:

<bean id="onDocumentUpdatePolicy" class="com.someco.alfresco.policy.DocumentUpdatePolicy">
    <property name="policyComponent">
        <ref bean="policyComponent" />
    </property>
    <property name="nodeService">
        <ref bean="NodeService" />
    </property>
</bean>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM