Form in share simpleDialog

cancel
Showing results for 
Search instead for 
Did you mean: 
ingon
Member II

Form in share simpleDialog

I'm trying to show a full functional form in a simpleDialog called from a documentlibrary action, but I can'f make it work, since it never reaches the onSuccess event.

Here is where the action is defined:


   <config evaluator="string-compare" condition="DocLibCustom">
      <dependencies>
         <js src="/components/import/import-actions.js" />
      </dependencies>
   </config>

   <config evaluator="string-compare" condition="DocLibActions">
      <actions>
         <action id="alfresco_import_permissions" type="javascript" label="action.import.permissions"
            icon="import-permissions">
            <param name="function">onActionOpenForm</param>
         </action>
      </actions>
      <actionGroups>
         <actionGroup id="folder-browse">
            <action index="230" id="alfresco_import_permissions" />
         </actionGroup>
      </actionGroups>
   </config>


Here, the onActionOpenForm implementation in the file import-actions.js:


(function() {

   YAHOO.Bubbling.fire("registerAction", {
      actionName : "onActionOpenForm",
      fn : function onActionOpenForm(record) {
         var actionUrl = YAHOO.lang.substitute(Alfresco.constants.PROXY_URI + "alfresco/importer/{uri}",
               {
                  uri : this.doclistMetadata.parent.nodeRef.replace(":/", "")
               });
         var templateUrl = Alfresco.constants.URL_SERVICECONTEXT + "alfresco/import/uploadcontent";
         var uploadZip = new Alfresco.module.SimpleDialog(this.id + "-uploadContent");
         uploadZip.setOptions({
            width : "50em",
            templateUrl : templateUrl,
            actionUrl : actionUrl,
            onSuccess : {
               fn : function DLTB_onUploadContent_success(response) {
                  alert("hi");
               },
               scope : this
            },
            onFailure : {
               fn : function DLTB_onUploadContent_failure(response) {
                  alert("bye");
               },
               scope : this
            }
         });
         uploadZip.show()
      }
   });

})();


Here, the form that is rendered in the popup:


<#assign el=args.htmlid?html>
<div id="${el}-dialog" class="upload-content">
   <div id="${el}-dialogTitle" class="hd">${msg("page.importZipFile.title")}</div>
   <div class="bd">
      <form id="${el}-form" action="" method="post" enctype="multipart/form-data" accept-charset="utf-8">
         <div class="yui-gd">
            <div class="yui-u first"><label for="${el}-filedata">${msg("label.filedata")}:</label></div>
            <div class="yui-u"><input type="file" id="${el}-filedata" name="filedata" tabindex="0" style="width:100%"/></div>
         </div>
         <div class="bdft">
            <input type="submit" id="${el}-ok" value="${msg("button.ok")}" tabindex="0" />
            <input type="button" id="${el}-cancel" value="${msg("button.cancel")}" tabindex="0" />
         </div>
      </form>
   </div>
</div>


Alfresco websccript that is called in the form action:

XML:


<webscript>
   <shortname>Import permissions</shortname>
   <description>Import permissions</description>
   <url>/alfresco/importer/{nodeRef}</url>
   <authentication>none</authentication>
   <format default="json">argument</format>
   <args>
      <arg>
         <shortname>nodeRef</shortname>
         <description>NodeRef</description>
      </arg>
   </args>   
</webscript>


Java class:


package alfresco.beans.web.scripts;

import java.io.IOException;

import org.alfresco.service.cmr.repository.NodeService;
import org.json.simple.JSONObject;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;

public class ImportPermissions extends AbstractWebScript {

   NodeService nodeService;

   public final NodeService getNodeService() {
      return nodeService;
   }

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

   public ImportPermissions() {
   }

   @SuppressWarnings("unchecked")
   @Override
   public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {

      JSONObject jsonObject = new JSONObject();
      jsonObject.put("value1", "data1");
      jsonObject.put("value2", "data2");

      String jsonString = jsonObject.toString();
      res.getWriter().write(jsonString);

   }

}


When I click ok in the form, I can debug the alfresco webscript and the execute() method is correct, without errors. The problem I have is that the onSuccess event in onActionOpenForm is never reached, even debugging the simple-dialog.js.

Am I doing anytthing wrong? Do I have to add or remove something in my code??

Thanks in advance!!
1 Reply
nenad982
Active Member

Re: Form in share simpleDialog

Hello,

I have the same error with SimpleDialog when it wraps multipart form. In this situation, backed logic is executed correctly and 200 OK is returned but onSuccess callback is never triggered.

If we process with the same code the form with application/json enctype SimpleDialog works correctly and onSuccess or onFailure callbacks are triggered.

Did anybody have solution for this?

Thanks in advance