cancel
Showing results for 
Search instead for 
Did you mean: 

Aikau Prepopulate AlfList Widget

sarah_jordison
Champ in-the-making
Champ in-the-making
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
                });
              });
           }
        });
});
6 REPLIES 6

sarah_jordison
Champ in-the-making
Champ in-the-making
I have seen publishOnReady being used in a few places. But I don't know the format I need to use with this. Assuming it needs to be in the form definition, I am not sure if it is in the correct place, or where to find out what object it is expecting for the payload:


    {
        id: "MY_DOCUMENT_FINDER",
   name: "alfresco/forms/Form",
   config: {
             publishOnReady : [{
                 publishTopic: "ALF_ITEMS_SELECTED",
                 publishPayload : {
                          //Not sure if this is even correct, or what object it's expecting here
                 }
             }]
               …
        }
                …

ddraper
World-Class Innovator
World-Class Innovator
Hi,

"publishOnReady" can only be configured at the root of the page. The structure that you've defined is correct, but it can't be placed inside the Form widget like that. If your WebScript defining the page already has access to the existing associations, why not just set them as value in the form (or directly on the DocumentPicker). It would be the array of nodeRefs that have been selected.

Regards,
Dave

Hi Dave,

I have tried using value as you suggested but doesn't seem to be displaying anything. It doesn't throw any errors either. Here is the format I am using



{
              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: " +  metadata.name,
                             name: "document",
                            
                             //Not working 😞
                             value: associations //Array of nodeRefs
                         }
                     }
                  ]
              }
           }

ddraper
World-Class Innovator
World-Class Innovator
Are those an array of nodeRefs as in ["node1","node2", "node3"], etc (Note: not representative of real nodeRefs)… or are they an array of *objects* where each object has an "nodeRef" attribute (because "nodeRef" is the configured "itemKey").

It needs to be the latter.

Hi Dave,

I have tried the following for the property "value" and it doesn't seem to populate the list. I have attached screenshots of the results and javascript (screens have printed value of associations)


["workspace:\/\/SpacesStore\/5007099b-1aad-4ceb-99c5-a0f558593dc7", "workspace:\/\/SpacesStore\/c0008b93-d189-4e2d-a35d-bb9ba1e1b160"]


AND


value = [
{"name": "One.pdf", "nodeRef": "workspace:\/\/SpacesStore\/5007099b-1aad-4ceb-99c5-a0f558593dc7", "fileType": "pdf", "modified": "2015-08-22 19:46:34", "modifier": "admin", "size": "1014 KB", "sitetitle": "Something", "siteid": "something"},
{"name": "Two.pdf", "nodeRef": "workspace:\/\/SpacesStore\/c0008b93-d189-4e2d-a35d-bb9ba1e1b160", "fileType": "pdf", "modified": "2015-08-21 23:22:57", "modifier": "admin", "size": "1014 KB", "sitetitle": "Something", "siteid": "something"}]


Any ideas what this could be?

ddraper
World-Class Innovator
World-Class Innovator
We do have an example in our unit tests that verify that it is possible to pre-populate selection of pickers, try viewing http://localhost:8089/aikau/page/tp/ws/DocumentPickerSingleItem in the Aikau unit test application. You can find the WebScript controller source here: https://github.com/Alfresco/Aikau/blob/74d632daf1ebb496e7e1240e563a654566853e43/aikau/src/test/resou...

It's not a complete match, but it does show that in principle it is possible for items to be pre-selected. However, we may need to improve the existing unit test for the multiple item document pickers and verify whether or not there is an issue with the picker.

I'd suggest that you raise an issue for this on the Aikau GitHub project (https://github.com/Alfresco/Aikau) however, to set your expectations I don't think that this would be fixed until the new year… normally we have a release once per week, but for internal reasons we've just started a 2 week sprint that will complete on the 22nd Dec… your bug would go into the next sprint and the fix (if we find that there is a problem) would be in the following release.

Regards,
Dave