cancel
Showing results for 
Search instead for 
Did you mean: 

Aikau Document Picker Save Help

sarah_jordison
Champ in-the-making
Champ in-the-making
Hi Guys,

I am using one of the examples of the Aikau project. Now, I am new to this project and it looks like it's a huge time saver. However, I am being tripped up a little here.

I have the following json model and it displays the document picker and a save and cancel button. All I want to do it console.log() the list of selected document nodeRefs. However, I cannot seem to find the on save callback function, nor can I find the code to grab the list of user selected documents. Does someone have an example of this?

Thanks!

<strong>JSON Model</strong>
<javascript>
model.jsonModel = {
    services: [
        "alfresco/dialogs/AlfDialogService",
        "alfresco/services/DocumentService",
        "alfresco/services/SiteService",
        "alfresco/services/CrudService"
    ],
    widgets: [
        {
           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: "Choose a document",
                          name: "document"
                      }
                  }
               ]
           }
        }
    ]
};
</javascript>

UPDATE:
I am still feeling totally lost in this Aikau code. I have now created a JavaScript widget successfully and altered my model, but cannot seem to get the subscribe to fire. Is there a specific way to do this? I have even changed my model and put the widget inside my own widget. I imagine this would put it into the scope of my widget, but then it doesn't load the document picker UI anymore.

<strong>MyWidget.js<strong>
<javascript>
define(["dojo/_base/declare",
        "dijit/_WidgetBase",
        "alfresco/core/Core"
    ],
    function(declare, _Widget, Core) {
        return declare([_Widget, Core], {
   
           /**
           *  Construct
           */
           constructor: function example_widgets_MyWidget__constructor(args) {
              console.log(args);
           
              this.alfSubscribe("ALF_ITEMS_SELECTED", lang.hitch(this, "getPickedItems"));

                        //this.alfSubscribe("ALF_ITEMS_SELECTED", lang.hitch(this, this.getPickedItems));
           },
           
           /**
            *  Get Picked Items from Picked Items Widget
            */
           getPickedItems: function example_widgets_MyWidget__getPickedItems() {
              var pickedItemsWidget = lang.getObject("verticalWidgets.pickedItemsWidget", false, this);
              
              alert(pickedItemsWidget.currentData.items);
           }
        });
});
</javascript>

2 REPLIES 2

ddraper
World-Class Innovator
World-Class Innovator
Typically there won't be any callback functions - Aikau works over a pub/sub layer so when you select a document and click the "OK" button button in the form it will publish the documents you've selected on the "FORM_CONTENTS" topic that you have configured.

If you want to do something with that publication then you'll need to create a custom service that subscribes to that topic. There are lots of OOTB services that do various things, but none that perform the use-case that you've described (which is to just console.log the selected items).

If you haven't already, I'd suggest working your way through the Aikau tutorial on GitHub to get up to speed with the basics: https://github.com/Alfresco/Aikau/blob/master/tutorial/chapters/Contents.md

Regards,
Dave

I created a JavaScript widget and this is the code that I needed below. It wasn't apparent that I needed to grab the ID for the current scope.


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;
              
//THIS CODE
              this.subscribe(args.pubSubScope + "FORM_CONTENTS", function(args){
                 console.log(args.document.join(','));
              });
           }
        });
});