如何在Alfresco表单上添加文件上传选择器

Dmi*_*kin 1 components webclient alfresco customizing alfresco-share

如何在Alfresco Share中的表单上添加文件/数据上传选择器?我需要点击我的按钮,然后应该出现文件选择器.有人可以帮忙吗?

Wil*_*son 6

查看users.js中定义的Manage Users控制台代码,该代码具有上载包含用户详细信息的CSV文件的功能.

首先,您需要定义一个HTML按钮控件,然后添加一些客户端脚本以将其绑定到上载控件

在组件的HTML模板中定义按钮

<span class="yui-button yui-push-button" id="${args.htmlid?html}-uploadusers-button">
   <span class="first-child"><button>${msg("button.uploaduser")}</button></span>
</span>
Run Code Online (Sandbox Code Playgroud)

然后在客户端代码中创建YUI按钮(例如在您的onReady()函数中)

var uploadUsersButton = Alfresco.util.createYUIButton(this, "uploadusers-button", this.onUploadUsersClick);
Run Code Online (Sandbox Code Playgroud)

然后定义按钮单击处理程序作为你的组件原型的新功能-下面的例子是从功能ConsoleUsers_onUploadUsersClick()users.js,您将需要修改,按您的需求

onUploadUsersClick: function onUploadUsersClick()
{
   // Force the use of the HTML (rather than Flash) uploader because there are issues with the
   // Flash uploader in these circumstances when Sharepoint is being used. The Flash uploader
   // picks up the wrong JSESSIONID cookie which causes the upload to fail.
   if (!this.fileUpload)
   {
      this.fileUpload = Alfresco.util.ComponentManager.findFirst("Alfresco.HtmlUpload") 
   }

   // Show uploader for single file select - override the upload URL to use appropriate upload service
   var uploadConfig =
   {
      uploadURL: "api/people/upload.html",
      mode: this.fileUpload.MODE_SINGLE_UPLOAD,
      onFileUploadComplete:
      {
         fn: this.onUsersUploadComplete,
         scope: this
      }
   };

   this.fileUpload.show(uploadConfig);

   // Make sure the "use Flash" tip is hidden just in case Flash is enabled...
   var singleUploadTip = Dom.get(this.fileUpload.id + "-singleUploadTip-span");
   Dom.addClass(singleUploadTip, "hidden");
   Event.preventDefault(e);
}
Run Code Online (Sandbox Code Playgroud)

请注意uploadURL在config对象中使用参数.您应该将其设置为您创建的自定义存储库Web脚本的URL,该脚本知道如何处理上载文件的内容.

用户上载示例还定义了onUsersUploadComplete()您将看到引用的方法.您可以在此处实现自己的组件方法,以采取适当的操作,例如根据上载结果更新UI.