Alfresco · Asynchronous POST transaction using YUI

Once a file is uploaded to Alfresco, additional actions can be performed by invoking a WebScript before the completion of this upstream action.

Following code assigns an aspect with its properties to the document already uploaded by the component Drag & Drop (dnd-upload.js).

...
      /**
       * Called from show when an upload complete event fires.
       *
       * @param fileInfo {object} An entry from the fileStore array contains the information about the file that has uploaded.
       * @method _processUploadCompletion
       * @private
       */
      _processUploadCompletion: function DND__processUploadCompletion(fileInfo)
      {
         if (fileInfo.request.status == "200")
         {
            var response = Alfresco.util.parseJSON(fileInfo.request.responseText);

            // update noderef and filename from response
            fileInfo.nodeRef = response.nodeRef;
            fileInfo.fileName = response.fileName;
            fileInfo.state = this.STATE_SUCCESS;

            // Add the label "Successful" after the filename, updating the fileName from the response
            Dom.addClass(fileInfo.progressStatusIncomplete, "hidden");
            Dom.removeClass(fileInfo.progressStatusComplete, "hidden");

            // Change the style of the progress bar
            Dom.removeClass(fileInfo.progress, "fileupload-progressSuccess-span");
            Dom.addClass(fileInfo.progress, "fileupload-progressFinished-span");

            // Move the progress bar to "full" progress
            Dom.setStyle(fileInfo.progress, "left", 0 + "px");
            fileInfo.progressPercentage.innerHTML = "100%";
            this.noOfSuccessfulUploads++;
            this._updateAggregateProgress(fileInfo, fileInfo.uploadData.filedata.size);
            
            var that = this;
            var setAddAspectCallback = {
                success: function(o) {
                  
                    // Adjust the rest of the gui
                    that._updateStatus();
                    that._adjustGuiIfFinished();

                    // Upload remaining files
                    that._spawnUploads();
                    
                },
                failure: function(o) {
                    Alfresco.logger.error("WARN: NodeRef " + fileInfo.nodeRef + " not updated!");
                }
              };
            
            // Custom webscript URL - Not included in this sample (!)
            var addAspectUrl = Alfresco.constants.PROXY_URI + "mycompany/addCustomAspect";

            // JSON data based on form fields
            var jsonData = {
                "nodeRef" : unescape(encodeURIComponent(fileInfo.nodeRef)),
                "aspect"  : unescape(encodeURIComponent(this.aspect)),
                "properties" : {
                  "caracter" : unescape(encodeURIComponent(this.caracter.value)),
                  "procedimiento" : unescape(encodeURIComponent(this.procedimiento.value)),
                  "resolucion" : unescape(encodeURIComponent(this.resolucion.value))
                }
            }
            var data = YAHOO.lang.JSON.stringify(jsonData);
              
            // Required to avoid default form content type
            YAHOO.util.Connect.setDefaultPostHeader(false);

            // POST action before upload completion
            var transaction = YAHOO.util.Connect.asyncRequest('POST', addAspectUrl, setAddAspectCallback, data);

         }
         else
         {
            // Process the upload failure...
            this._processUploadFailure(fileInfo, fileInfo.request.status);
         }
      },
...

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s