1

我们的目标是实现一个预填充的文档创建表单,其中包含从PluginService对象中检索到的值。

当用户右键单击文档并选择“从此文档新建文档”时,它会触发一个Action打开AddContentItemDialog. 然后,调用该服务来检索所选文档的属性(也许没有必要,通过 Firefox 开发人员面板,我看到大多数,也许所有自定义属性都已获取)。

我可以填充文本字段属性,但不能填充ChoiceList:它们不会更新,尽管它们可能会在内部填充。

这是一个带注释的代码示例:

require(["dojo/_base/declare",
         "dojo/_base/lang",
         "dojo/aspect", 
         "ecm/model/Request",
         "ecm/widget/dialog/AddContentItemDialog"], 
function(declare, lang, aspect, Request, AddContentItemDialog) {        

    // Parameters passed to the service as HttpServletRequest
    // (Custom function)
    var serviceParams = getServicesParams(items[0]);

    // Object store and parentFolder retrieving (needed below)
    var parentFolder = items[0].parent;
    var objectStore = items[0].objectStore;

    // Retrieving the template to use for the dialog
    // (Custom function)
    var entryTemplate = retrieveTemplate(objectStore, parentFolder); 

    // Service call 
    Request.invokePluginService("FormPlugin", "FormService", {
        requestParams: serviceParams,
        requestCompleteCallback: function(response) {
            // Creating the global dialog  box
            var addContentItemDialog  = new AddContentItemDialog();
            // Box containing the document properties
            var addContentItemPropertiesPane =
                addContentItemDialog.addContentItemPropertiesPane;
            // Box containing general stuff
            var addContentItemGeneralPane =
                addContentItemDialog.addContentItemGeneralPane;

            // Showing the dialog box 
            addContentItemDialog.show(
                repository,
                parentFolder,  /* parent folder       */
                true,          /* document being added*/
                false,         /* not virtual          */
                null,          /* no callback function */
                null,          /* no teamspace */
                true,          /* use an entry template */
                entryTemplate, /* entry template */
                true           /* can't choose directory from another rep */
           );

            // Waiting for complete rendering before filling the properties and general fields
            aspect.after(addContentItemPropertiesPane,
                         "onCompleteRendering",
                         function() {
                             // Setting the destination and lock it
                             var folderSelector = addContentItemGeneralPane.folderSelector;
                             folderSelector.setRoot(parentFolder, objectStore);
                             folderSelector .setDisabled(true);

                             // Property filling - Work :-)
                             addContentItemDialog.setTitle("New document from another");
                             addContentItemDialog.setIntroText("This form allow you to create a document from another one.");
                             addContentItemPropertiesPane.setPropertyValue("DocumentTitle", "Prefilled title");                            
                             // Property filling - Doesn't work :-(
                             addContentItemPropertiesPane.setPropertyValue("A_ChoiceList_Prop",
                                    [ "Value\\1", "Value\\2", "Value\\3"]);

                         }, true);
            }
        });
    });
});

也许我错过了一些神奇的 IBM 代码行来完成它。

4

1 回答 1

2

更新。1) 代码现在正确等待条目模板内容的检索。2)这个答案也应该适用于以前版本的 ICN。3)这个答案定义了全局范围内的函数。要非常小心,您可能会遇到与其他插件和 ICN 代码冲突的名称。而是使用回调函数,或者“强烈”地命名你的函数。

我按照以下步骤编写插件操作:

  1. 检索源文档和父文件夹
  2. 调用插件服务,获取点击文档的属性
  3. 检索条目模板并使用获取的属性填充其默认值
  4. 创建一个AddContentItemDialog对象并通过将条目模板传递给它来显示它。

条目模板EntryTemplate对象描述。它有一个propertiesOptions引用数组的键。该数组的每个元素都代表一个文档属性。每个元素都包含一个名为 的键defaultValue

EntryTemplate {
    addClassDescription: "An Entry Template",
    ​addClassLabel: "An Entry Template",
    ​addClassName: "AnEntryTemplate",
    ​// [...]
    propertiesOptions: [
        {
            dataType: "xs:string",
            id: "a_prop",
            name: "A Property",
            // [...]
            defaultValue: "A default value",
            // [...]
        },
        // [...]
    ],
    // [...]
}

​​ 字符串值作为(显然)字符串传递,日期作为 ISO8601 格式的字符串 ( yyyy-MM-ddTHH:mm:ss) 和列表作为数组传递。

例如,给定n1, n2,n3 propertyOption条目:

// "xs:string" dataType
entryTemplate.propertiesOptions[n1].defaultValue = "Duck";

// "xs:timestamp" dataType
entryTemplate.propertiesOptions[n2].defaultValue = "1938-04-15T00:00:00";

// "xs:string" dataType, "LIST" cardinality
entryTemplate.propertiesOptions[n3].defaultValue = ["Huey", "Dewey", "Louie"]; 

下面是 PluginAction 的 Javascript 客户端代码的实现。我没有提供服务实现,也没有提供填充条目模板的代码,因为它有点跑题了。(有关编写 ICN 插件的更多信息,您可以参考 ICN 红皮书定制和扩展 IBM Content Navigator。)

另请注意,我不认为这个答案是设计动作插件的最佳方式,请不要犹豫,建议优化/良好实践相关的版本。我刚刚发现很难覆盖回调函数,所以我的目标是在顶层定义它们中的大部分,我不喜欢单体代码。

一、主块部分:

require(["dojo/_base/declare",
         "dojo/_base/lang",
         "dojo/aspect", 
         "ecm/model/Request",
         "ecm/widget/dialog/AddContentItemDialog"], 
         function(declare, lang, aspect, Request, AddContentItemDialog) {
    /**
     * Use this function to add any global JavaScript methods your plug-in requires.
     */

    lang.setObject("openFilledCreateDocumentFormAction",
            function(repository, items, callback, teamspace, resultSet, parameterMap) {

                // Parameters passed to the service as HttpServletRequest

                var serviceParams = new Object();
                serviceParams.server = items[0].repository.id;
                serviceParams.serverType = items[0].repository.type;
                serviceParams.id = items[0].id;

                // Object store and parentFolder retrieving (needed below)
                var objectStore = items[0].objectStore;
                var parentFolder = items[0].parent;
                var entryTemplateClassName = null;

                // Service call. "FormService" fetch the source document
                // properties, then put them as JSON in the response.
                // The response will be passed to the function
                // requestCompleteCallback (see below)
                Request.invokePluginService(
                        "FormPlugin",
                        "FormService", {
                            requestParams: serviceParams,
                            // Parameters below are for response callback
                            etClassName:"AnEntryTemplate",
                            repository:repository,
                            objectStore:objectStore,
                            parentFolder:parentFolder,
                            AddContentItemDialog:AddContentItemDialog,
                            aspect:aspect,
                            requestCompleteCallback: processRetrievalResponse
                        });
            });
});

FormService完成时调用processRetrievalResponse()。在这一节中,我们将从检索我们想要的模板开始。

function processRetrievalResponse(response) {
    // Some data passed to the parent object of this callback (see above)
    var etClassName = this.etClassName;
    var repository = this.repository;
    var objectStore = this.objectStore;
    var parentFolder = this.parentFolder;
    var AddContentItemDialog = this.AddContentItemDialog;
    var aspect = this.aspect;

    // First we'll retrieve all the templates
    repository.retrieveEntryTemplates(
            function (entryTemplates, document_ET_count, folder_ET_count) {
                var entryTemplate = null;
                // Then we'll search for the one that we want
                for (var i = 0; i < entryTemplates.length; i++) {
                    if (entryTemplates[i] &&
                            entryTemplates[i].addClassName == etClassName) {
                        entryTemplate = entryTemplates[i];
                        break;
                    }
                }
                // No Entry Template = abort.
                if (!entryTemplate) {
                    alert("The Entry Template " +
                            "\"" + etClassName + "\" " +
                            "was not found. Please contact the administrators");
                    return;
                }

                // Now we got the Entry Template, time to retrieve its content
                // First, we design a "waiter" object.
                // We assume here the PluginService returns the values in
                // the "properties" entry of the object response

                retrievalWaiter =
                    new RetrievalWaiter (repository,
                                         objectStore,
                                         parentFolder,
                                         entryTemplate,
                                         response.properties,
                                         AddContentItemDialog,
                                         aspect);
                // Then a call to retrieve its content
                entryTemplate.retrieveEntryTemplate(null, false, true);

                // We ignite the waiter. When the retrieval will be performed,
                // It will fill its default values and use it to display
                // the creation document dialog.                    
                retrievalWaiter.wait();


            }, "Document", parentFolder.id, null, objectStore);
}

RetrievalWaiter代码。在这里,没有while循环,因为它会像恶心一样消耗。该对象仅依靠 setTimeOut() 来定期检查条目模板内容的检索。

function RetrievalWaiter(repository, objectStore, parentFolder,
                         entryTemplate, properties,
                         AddContentItemDialog, aspect) {
    this.repository = repository;
    this.objectStore = objectStore;
    this.parentFolder = parentFolder;
    this.entryTemplate = entryTemplate;
    this.properties = properties;
    this.aspect = aspect;
    this.wait = 
        function() {
            // If the Entry Template is not yet loaded, wait 500 ms
            // and recheck
            if (!this.entryTemplate.isRetrieved) {
                var _this = this;
                setTimeout(function() {_this.wait();}, 500);                    
                return;
            }
            // Fill the Entry Template with defaults value
            // (got from the PluginServer response, see above)
            fillEntryTemplate(this.entryTemplate, this.properties);

            // Show the document creation dialog with the 
            showDialog(AddContentItemDialog,
                    this.aspect,
                    this.repository, this.objectStore,
                    this.parentFolder, this.entryTemplate);
        }
}

现在,是时候显示对话框了。

function showDialog(AddContentItemDialog, aspect,
                    repository, objectStore,
                    parentFolder,
                    entryTemplate) {
    var addContentItemDialog  = new AddContentItemDialog();
    var addContentItemPropertiesPane =
        addContentItemDialog.addContentItemPropertiesPane;
    var addContentItemGeneralPane =
        addContentItemDialog.addContentItemGeneralPane;

    addContentItemDialog.show(
            repository,
            parentFolder,  // parent folder 
            true,          // document being added
            false,         // not virtual 
            null,          // no callback function 
            null,          // no teamspace 
            true,          // Use an Entry Template 
            entryTemplate, // Entry template 
            true           // don't allow choosing directory
                           // from another repository
    );

    // Use aspect to set the value *after* the complete rendering
    // of the properties pane   
    aspect.after(
            addContentItemPropertiesPane,
            "onCompleteRendering",
            function() {
                addContentItemDialog.setTitle("Duplicate a document");
                addContentItemDialog.setIntroText(
                        "This form is loaded from a right-clicked document.");
                // Removing the help link to make the form looks like
                // the document creation one
                addContentItemDialog.setIntroTextRef("","");
                // Set parent folder and prevent it from being edited.
                addContentItemGeneralPane.folderSelector.setRoot(parentFolder, objectStore);
                addContentItemGeneralPane.folderSelector.setDisabled(true);

            }, true);
}

// This function relies on the PluginService response.
// It takes the Entry Template, a JSON formatted response
function fillEntryTemplate(entryTemplate, jsonResponse) {
    // My mission ends here. :-)
}
于 2018-04-10T13:15:38.147 回答