【问题标题】:How to customize the Document List in Alfresco?如何在 Alfresco 中自定义文档列表?
【发布时间】:2014-06-01 23:28:39
【问题描述】:

在存储库中会有不同的文档列表。即会有数据字典、用户主页、访客主页等。当我将视图更改为“详细视图”时,它会显示收藏夹,如 cmets 链接。如果我不想显示它们,我必须在哪里修改。你能告诉我必须在哪个文件中评论不显示这些链接的代码吗?提前谢谢你。

【问题讨论】:

  • 这是在 Alfresco Share 界面中还是在旧的 Alfresco Explorer 界面中?
  • @Gagravarr 它在露天分享。

标签: alfresco


【解决方案1】:

我想要这个问题的“模块化”答案,这个答案是为了展示我是如何处理这个问题的。

上下文: Alfresco 4.2.f,来自 org.alfresco.maven.archetype:alfresco-amp-archetype:1.1.1 原型的 Maven 项目,我尽可能将所有内容放在嵌入式 JAR 中。

为共享创建一个模块扩展(有关详细信息,请参阅this blog)。这是我的扩展文件:

src/main/resources/alfresco/site-data/extensions/my-custom-extension.xml

<extension>
  <modules>
    <module>
      <id>Main module of my custom extension</id>
      <version>${project.version}</version>
      <auto-deploy>true</auto-deploy>
      <customizations>
        <customization>
          <!-- Order matters here! target before source, always! -->
          <targetPackageRoot>org.alfresco</targetPackageRoot>
          <sourcePackageRoot>my-custom.main</sourcePackageRoot>
        </customization>
      </customizations>
    </module>
  </modules>
</extension>

在模块包的documentlibrary 组件中,创建此 FTL 以声明 javascript:

src/main/resources/alfresco/site-webscripts/my-custom/main/components/documentlibrary/documentlist-v2.get.html.ftl

<#-- Add a Javascript declaration -->
<@markup id="my-custom-js"  target="js" action="after">
  <@script type="text/javascript" group="documentlibrary"
      src="${url.context}/res/my-custom/main/components/documentlibrary/documentlist.js"/>
</@>

在资源 (META-INF) 中的documentlibrary 组件下,创建 Javascript:

src/main/resources/META-INF/my-custom/main/components/documentlibrary/documentlist.js

YAHOO.lang.augmentObject(Alfresco.DocumentList.prototype, {

  // Possible values: i18nLabel, lockBanner, syncFailed, syncTransientError
  // date, size, name, version, description, tags, categories
  myCustomDisabledRenderers: ["description", "version", "tags"],

  // Possible values: favourites, likes, comments, quickShare
  myCustomDisabledSocials: ["favourites", "comments", "likes", "quickShare"],

  myCustomIsSocialDisabled: function(propertyName) {
    return Alfresco.util.arrayContains(
        this.myCustomDisabledSocials, propertyName);
  },

  myCustomIsRendererDisabled: function(propertyName) {
    if (Alfresco.util.arrayContains(
        this.myCustomDisabledRenderers, propertyName)) {
      return true;
    }
    // Disable the social renderer when all the social features are
    // disabled
    if (propertyName === "social" && this.myCustomDisabledSocials.length == 4) {
      return true;
    }
    return false;
  },

  /** Helper function to disable socials
   * propertyName must be one of "favourites", "comments", "likes", "quickShare"
   */
  myCustomDisableSocial: function(propertyName) {
    if (!Alfresco.util.arrayContains(
        this.myCustomDisabledSocials, propertyName)) {
      this.myCustomDisabledSocials.push(propertyName);
    }
  },

  // Custom registerRenderer for social features, originally defined in:
  // webapps/share/components/documentlibrary/documentlist.js:2134
  myCustomSocialRegisterRenderer: function(record) {
    var jsNode = record.jsNode;
    var html = "";
    // Current usage of the separator variable allow to change the order
    // of the different social features (the 'if' blocks below) without 
    // changing their content
    var separator = "";
    /* Favourite / Likes / Comments */
    if (!this.myCustomIsSocialDisabled("favourites")) {
      html += '<span class="item item-social' + separator + '">' + 
          Alfresco.DocumentList.generateFavourite(this, record) + 
          '</span>';
      separator = " item-separator";
    }
    if (!this.myCustomIsSocialDisabled("likes")) {
      html += '<span class="item item-social' + separator + '">' + 
          Alfresco.DocumentList.generateLikes(this, record) + 
          '</span>';
      separator = " item-separator";
    }
    if (!this.myCustomIsSocialDisabled("comments") && 
        jsNode.permissions.user.CreateChildren) {
      html += '<span class="item item-social' + separator + '">' + 
          Alfresco.DocumentList.generateComments(this, record) + 
          '</span>';
      separator = " item-separator";
    }
    if (!this.myCustomIsSocialDisabled("quickShare") && !record.node.isContainer && 
        Alfresco.constants.QUICKSHARE_URL) {
      html += '<span class="item' + separator + '">' + 
          Alfresco.DocumentList.generateQuickShare(this, record) + 
          '</span>';
      separator = " item-separator";
    }

    return html;
  },

  // Overwrite registerRenderer which was originally defined in:
  // webapps/share/components/documentlibrary/documentlist.js:1789
  registerRenderer: function DL_registerRenderer(propertyName, renderer) {
    if (Alfresco.util.isValueSet(propertyName) && 
        Alfresco.util.isValueSet(renderer) && 
        !this.myCustomIsRendererDisabled(propertyName)) {
      if (propertyName === "social") {
        this.renderers[propertyName] = this.myCustomSocialRegisterRenderer;
      } else {
        this.renderers[propertyName] = renderer;
      }
      return true;
    }
    return false;
  }


}, true);

然后您可以通过更新myCustomDisabledRenderers 和/或mySocialDisabledRenderers 来禁用链接。

这种方式还允许您创建一个模块,只需 6 个简单的步骤即可独立禁用(例如)“文档上的 cmets”或“文档上的喜欢”功能!

示例,如何制作一个仅在 6 个步骤中禁用文档上的 cmets 的模块

  1. 重要:先去掉主模块documentlist.js中的“评论禁用”。

    myCustomDisabledSocials: ["favourites", "likes", "quickShare"],
    
  2. 创建一个具有相同结构的新模块“my-custom.nocomment”。

    <extension>
      <modules>
        <module>
          <id>Main module of my custom extension</id>
          [...]
        </module>
        <module>
          <id>No comment module of my custom extension</id>
          <version>${project.version}</version>
          <customizations>
            <customization>
              <targetPackageRoot>org.alfresco</targetPackageRoot>
              <sourcePackageRoot>my-custom.nocomment</sourcePackageRoot>
            </customization>
          </customizations>
        </module>
      </modules>
    </extension>
    
  3. 添加 FTL...

    src/main/resources/alfresco/site-webscripts/my-custom/nocomment/components/documentlibrary/documentlist-v2.get.html.ftl

    <#-- Add a Javascript declaration -->
    <@markup id="my-custom-js"  target="js" action="after">
      <@script type="text/javascript" group="documentlibrary"
          src="${url.context}/res/my-custom/nocomment/components/documentlibrary/documentlist.js"/>
    </@>
    
  4. 然后是 Javascript...

    src/main/resources/META-INF/my-custom/nocomment/components/documentlibrary/documentlist.js

    Alfresco.DocumentList.prototype.myCustomDisableSocial("comment");
    
  5. 然后我很高兴,如果你觉得一切都刚刚好,请鼓掌!

  6. 注意事项:

    • nocomment 模块依赖于main 模块。
    • 重要的是要在main 模块(在http://localhost:8080/share/page/modules/deploy 中)之后 加载nocomment 模块。
    • 为了使nocomment 模块完整,您还需要从文档详细信息页面禁用 cmets,见下文。

从文档详细信息页面禁用 cmets

即使这个在其他地方有文档记录,这几天我花了很多时间搜索,我觉得我需要尽可能全面。

src/main/resources/alfresco/site-data/extensions/my-custom-extension.xml

将此添加到您的my-custom.nocomment 模块声明中,您将摆脱文档详细信息页面中的 cmets 表单和列表。

[...]
<module>
  <id>No comment module of my custom extension</id>
  [...]
  <components>
    <component>
      <region-id>comments</region-id>
      <source-id>document-details</source-id>
      <scope>template</scope>
      <sub-components>
        <sub-component id="default">
          <evaluations>
            <evaluation id="guaranteedToHide">
              <render>false</render>
            </evaluation>
          </evaluations>
        </sub-component>
      </sub-components>
    </component>
  </components>
</module>
[...]

src/main/resources/alfresco/site-webscripts/my-custom/nocomment/components/node-details/node-header.get.js

这是为了禁用文档详细信息页面标题上的按钮。

// Disable comments
for (var i = 0; i < model.widgets.length; i++) {
  if (model.widgets[i].id == "NodeHeader") {
    model.widgets[i].options.showComments = false;
  }
}
// And since it does not work, disable comments this way too
model.showComments = "false";

注意:我没有测试这些 sn-ps,它们是在“匿名化”(基本上是重命名模块)之后从我的项目中获取的。如果您发现错误,请告诉我。

【讨论】:

    【解决方案2】:

    您要查找的内容很可能是由客户端 JavaScript 生成的。您应该使用 share-config-custom.xml 将 Share 设置为开发模式,如下所示:

    <alfresco-config>
        <!-- Put Share Client in debug mode -->
        <config replace="true">
            <flags>
                <client-debug>true</client-debug>
                <client-debug-autologging>false</client-debug-autologging>
            </flags>
        </config>
    </alfresco-config>
    

    然后,使用 firebug 或浏览器的开发者控制台来单步执行客户端 JavaScript。您应该能够找到呈现文档库元素的点。

    您可以使用自己的组件覆盖 Alfresco 的客户端 JavaScript 组件。请将它们放在您自己的命名空间中以避免与 Alfresco 的冲突。

    【讨论】:

    • 谢谢兄弟的回答。我需要更多说明 1.我需要将此 share-config-custom.xml 放在共享中的什么位置?是否在以下 share\WEB-INF\classes\alfresco 位置? 2.你能说出要覆盖的客户端javascript是什么吗?
    • 我已将 share-config-custom.xml 放在 share\WEB-INF\classes\alfresco 位置。添加该文件后,一切都是空白的。我也无法查看登录页面。如果我想覆盖我必须做的javascript?提前谢谢你。
    • 它进入 WEB-INF/classes/alfresco/web-extension。如果您想覆盖 JavaScript,您将使用 YUI 来扩展现有组件,并且您的客户端 JavaScript 文件将驻留在 Share WAR 的 Web 根目录中。如果您以前从未自定义过 Share,我强烈建议您从简单的东西开始,例如 Dashlet 或 UI 操作,请参阅 ecmarchitect.com/archives/2012/05/08/1592ecmarchitect.com/images/articles/alfresco-actions/…code.google.com/p/share-extras
    • 谢谢兄弟。我会通过上面的链接。
    【解决方案3】:

    我通过在 share/src/alfresco/share-document-config 中的文件 share-documentlibrary-config.xml 中注释 {social} 行来做到这一点

    ...
    <metadata-templates>
       <!-- Default (fallback) -->
         <template id="default">
            <line index="10" id="date">{date}{size}</line>
            <line index="20" id="description" view="detailed">{description}</line>
            <line index="30" id="tags" view="detailed">{tags}</line>
            <line index="40" id="categories" view="detailed" evaluator="evaluator.doclib.metadata.hasCategories">{categories}</line> -->
       <!-- <line index="50" id="social" view="detailed">{social}</line> -->
         </template>
    ...
    

    有效!

    【讨论】:

      【解决方案4】:

      我不确定我是否理解您的问题 - 您试图在 alfresco explorer 的特定视图中隐藏某些列?如果是这样,您需要编辑 /jsp/browse/browse.jsp 文件,但我认为这不是一个好主意。也许实现你自己的 NodePropertyResolver 应该是更好的方法,看看我关于这个主题的旧博文:http://www.shmoula.cz/adding-columns-to-custom-browse-jsp/

      【讨论】:

      • 我不想隐藏列。我正在研究 Alfresco Share。我正在尝试在文档列表视图中删除一些链接,如 cmets、Favorite 等。我想知道我需要在哪个 .ftl 文件中删除这些链接。我搜索了它,但找不到那个 .ftl 文件。
      • 啊,我明白了,所以不是 Alfresco explorer。我对 Share 不熟悉,但我认为方法是使用 SurfBug 工具找到您要更改的特定组件。
      • 是的,我正在使用 SurfBug 本身。但是对于那个特定的链接,我找不到任何代码。无论如何感谢您的回复。
      • 最好的策略是在 webapps/share 上搜索 SurfBug 找到的 id :-)。我认为您感兴趣的文件位于 /share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary 目录中 - 从 documentlist.* 文件开始并继续...
      【解决方案5】:

      看起来全部都在:\opt\alfresco-4.0.d\tomcat\webapps\share\components\documentlibrary\documentlist.js 我认为诀窍在于 this.registerRenderer("social"...) 在 1981 行之前返回 html(在喜欢之前的收藏之后)假设你想至少保留 faorite

      【讨论】:

        猜你喜欢
        • 2023-03-17
        • 1970-01-01
        • 2017-05-20
        • 2020-10-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多