2014-10-08 43 views
0

因此,我遵循Will Abson's指南和源代碼在Alfresco中擴展自定義媒體查看器。 雖然我有幾個問題。 我已經使用4.2+ Alfresco,因此不需要使用head.ftl作爲棄用,我使用第二個可擴展性模塊自動添加我自己的配置,但是:BOD: 我如何訪問我的web-preview.get.js中的jsNode?或者更好,有沒有辦法訪問正在顯示的節點的屬性值和方面? 我知道服務器端和客戶端var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef)var jsNode = AlfrescoUtil.getNodeDetails(model.widgets[i].options.nodeRef); 這是在另一個問題here中提到的,但它似乎像默認值,如mimeType,大小,nodeRef除外,我無法使用這些來從文件。 這些都是我的變化:Alfresco媒體查看器web預覽可擴展性

網絡preview.get.js-config文件夾我的自定義媒體觀衆的

//<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js"> 
if (model.widgets) 
{ 
    for (var i = 0; i < model.widgets.length; i++) 
    { 
     var at = "test"; 
     //var jsNode = AlfrescoUtil.getNodeDetails(model.widgets[i].options.nodeRef); 
     //var author = jsNode.properties["cm:author"]; 
     var widget = model.widgets[i]; 
     if (widget.id == "WebPreview") 
     { 
     var conditions = []; 
     // Insert new pluginCondition(s) at start of the chain 
     conditions.push({ 
      attributes: { 
       mimeType: "application/pdf" 
      }, 
      plugins: [{ 
       name: "PDF", 
       attributes: { 
       } 
      }] 
     }); 
     var oldConditions = eval("(" + widget.options.pluginConditions + ")"); 
     // Add the other conditions back in 
     for (var j = 0; j < oldConditions.length; j++) 
     { 
      conditions.push(oldConditions[j]); 
     } 
     // Override the original conditions 
     model.pluginConditions = jsonUtils.toJSONString(conditions); 
     widget.options.pluginConditions = model.pluginConditions; 
     } 
    } 
} 

PDF.js

/** 
* Copyright (C) 2014 Will Abson 
*/ 

/** 
* This is the "PDF" plug-in used to display documents directly in the web browser. 
* 
* Supports the "application/pdf" mime types. 
* 
* @namespace Alfresco.WebPreview.prototype.Plugins 
* @class Alfresco.WebPreview.prototype.Plugins.PDF 
*/ 
(function() 
{ 
    /** 
    * PDF plug-in constructor 
    * 
    * @param wp {Alfresco.WebPreview} The Alfresco.WebPreview instance that decides which plugin to use 
    * @param attributes {Object} Arbitrary attributes brought in from the <plugin> element 
    */ 
    Alfresco.WebPreview.prototype.Plugins.PDF = function(wp, attributes) 
    { 
     this.wp = wp; 
     this.attributes = YAHOO.lang.merge(Alfresco.util.deepCopy(this.attributes), attributes); 
     //this.wp.options.nodeRef = this.wp.nodeRef; 
     return this; 
    }; 

    Alfresco.WebPreview.prototype.Plugins.PDF.prototype = 
    { 
     /** 
     * Attributes 
     */ 
     attributes: 
     { 
      /** 
      * Maximum size to display given in bytes if the node's content is used. 
      * If the node content is larger than this value the image won't be displayed. 
      * Note! This doesn't apply if src is set to a thumbnail. 
      * 
      * @property srcMaxSize 
      * @type String 
      * @default "2000000" 
      */ 
      srcMaxSize: "2000000" 
     }, 

     /** 
     * Tests if the plugin can be used in the users browser. 
     * 
     * @method report 
     * @return {String} Returns nothing if the plugin may be used, otherwise returns a message containing the reason 
     *   it cant be used as a string. 
     * @public 
     */ 
     report: function PDF_report() 
     { 
      // TODO: Detect whether Adobe PDF plugin is installed, or if navigator is Chrome 
      // See https://stackoverflow.com/questions/185952/how-do-i-detect-the-adobe-acrobat-version-installed-in-firefox-via-javascript 
      var srcMaxSize = this.attributes.srcMaxSize; 
      if (!this.attributes.src && srcMaxSize.match(/^\d+$/) && this.wp.options.size > parseInt(srcMaxSize)) 
      { 
      return this.wp.msg("pdf.tooLargeFile", this.wp.options.name, Alfresco.util.formatFileSize(this.wp.options.size), Alfresco.util.formatFileSize(this.attributes.srcMaxSize)); 
      } 
     }, 

     /** 
     * Display the node. 
     * 
     * @method display 
     * @public 
     */ 
     display: function PDF_display() 
     { 
      // TODO: Support rendering the content of the thumbnail specified 
      var src = this.wp.getContentUrl(); 
      var test = this.attributes.author; 
      //var test = this.wp.options.nodeRef; 
      //var jsNode = new Alfresco.util.Node(test); 
      //var jsNode = AlfrescoUtil.getNodeDetails(this.wp.options.nodeRef); 
      //var author = jsNode.properties["cm:author"]; 
      //var test = this.wp.options.author; 
      //var test1 = this.wp.options.mimeType; 
      //var test = this.attributes.author.replace(/[^\w_\-\. ]/g, ""); 
      //.replace(/[^\w_\-\. ]/g, ""); 
      return '<iframe name="' + test + '" src="' + src + '"></iframe>'; 
     } 
    }; 

})(); 

,你可以通過註釋部分來查看我嘗試了不同的方法來訪問節點屬性/值,甚至是簡單的字符串,但我肯定缺少某些東西。 謝謝。

回答

2

如果你看看源代碼,你會看到一個輔助方法是什麼都沒有比做到var url = '/slingshot/doclib2/node/' + nodeRef.replace('://', '/');

遠程調用所以來看看是什麼庫WebScript正在返回EN它匹配你需要的屬性。

我通常不使用這個,我知道肯定/api/metadatareturns的所有屬性。

+0

謝謝Tahir,我只是這麼做的。我創建了一個新的函數,它調用:'var result = remote.connect(proxy).get(「/ api/metadata?nodeRef =」+ nodeRef);'你指出的遠程調用是一個簡單的webscript,幾個屬性。非常感謝。 – Teqnology 2014-10-12 23:51:12