AnsweredAssumed Answered

Aikau Prepopulate AlfList Widget

Question asked by sarah.jordison on Dec 2, 2015
Latest reply on Dec 8, 2015 by ddraper
Hi Folks,

I am building a simple Aikau Share Page, which will manage document associations. I have used the DocumentPicker widget and am using jQuery to do xhr requests back to Alfresco.

So far I have managed to scrape my way through displaying the picker, allow documents to be picked, and then saving those documents as associations. This stuff works fine, but I cannot for the life of me, figure out how to publish the saved associations to the items list on page load.

I am using the debug screen and can see when the user clicks "OK" in the document picker, it publishes to the "ALF_ITEMS_SELECTED" topic. However, I can't see a way to publish my selected nodes in my JSON Model to this list (or what the format is).

The JS webscript code below calls a service I made and returns an array of nodeRefs. The two screen shots I have show the current state and ideal state I want:

<ol>
    <li>Screen one - list of nodeRefs outputted via the ${test} model property</li>
    <li>Screen two - populated list from a user selecting documents via the document picker</li>
</ol>

All I want to do is publish the two selected nodes in the list, when the user load the page. Any help would be great as I am lost!

<strong>Webscript.get.js</strong>

<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">

//Get current associated node refs
var nodeRef = AlfrescoUtil.param('nodeRef', null);
var result = remote.connect("alfresco").get('/node/get-associations?nodeRef=' + nodeRef);

//Print array of nodeRefs
model.test = jsonUtils.toJSONString(result);

model.jsonModel = {
    services: [
        "alfresco/dialogs/AlfDialogService",
        "alfresco/services/DocumentService",
        "alfresco/services/SiteService",
        "alfresco/services/CrudService"
    ],
    widgets: [
      {
          id: "SET_PAGE_TITLE",
          name: "alfresco/header/SetTitle",
          config: {
              title: "Manage Associations"
          }
      },
        {
           id: "MY_DOCUMENT_FINDER",
           name: "alfresco/forms/Form",
           config: {
               okButtonLabel: "Ok",
               okButtonPublishTopic: "FORM_CONTENTS",
               widgets: [
                  {
                      id: "MY_WIDGET",
                      name: "example/widgets/MyWidget"
                  },
                  {
                      name: "alfresco/forms/controls/DocumentPicker",
                      itemKey: "nodeRef",
                      config: {
                          label: "Associated documents",
                          name: "document"
                      }
                  }
               ]
           }
        }
    ]
};


<strong>MyWidget.js</strong>

define(["dojo/_base/declare",
        "dijit/_WidgetBase",
        "alfresco/core/Core"
    ],
    function(declare, _Widget, Core) {
        return declare([_Widget, Core], {

           url : Alfresco.constants.URL_CONTEXT + "proxy/alfresco/node/get-associations",
           nodeRef : Alfresco.util.getQueryStringParameter('nodeRef'),
           
           /**
           *  Construct
           */
           constructor: function example_widgets_MyWidget__constructor(args) {
              
              var _this = this;
              
                        //Subscribe to OK button (see screen shot)
              this.subscribe(args.pubSubScope + "FORM_CONTENTS", function(args){
                 
                                //Temp save by get
                 $.getJSON(_this.url, { nodeRef: _this.nodeRef, assocRef: args.document.join(',') }, function(r){
                                    //Data Saved
                });
              });
           }
        });
});

Outcomes