cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Datalist Page - Association with other datalist items.

rohit_chakrabor
Champ on-the-rise
Champ on-the-rise
I am creating a custom page for listing and performing CRUD operations on datalists. For this I am following http://blogs.alfresco.com/wp/developer/2014/10/01/aikau-mini-examples-data-list-part-2/.
Issue I am facing is with one of my custom datalists.
Let's say there are 5 custom datalists A, B, C, D and E. Item of A has associations with items of B, C, D and E. While creating item of A, I should select the items of B, C, D and E. I am using Picker but am not getting the desired result. If I pick an item for an association, the same item is rendered to all other associations. Any help will be appreciated.
2 REPLIES 2

ddraper
World-Class Innovator
World-Class Innovator
To help me understand this question better… is this asking how to create or customize the picker for working with associations? It's worth remembering that the blog post was just to provide some examples of how to use Aikau widgets, it wasn't intended to be a complete replacement for production data lists - hopefully we'll work through that use case at some point in the future.

Regards,
Dave

I want to create an item of custom datalist called Artifact in this custom page. I am using the AlfDynamicPayloadButton to create the item of Artifact.
I am using a custom picker called DemoPicker to pick the association items.


define(["alfresco/forms/controls/BaseFormControl",
        "alfresco/core/CoreWidgetProcessing",
        "dojo/_base/declare",
        "dojo/_base/lang",
        "dojo/_base/array"],
        function(BaseFormControl, CoreWidgetProcessing, declare, lang, array) {
  
   return declare([BaseFormControl, CoreWidgetProcessing], {
     
      /**
       * The value to use as a key for each item. Each picked item should have an attribute with the name defined.
       *
       * @instance
       * @type {string}
       * @default "name"
       */
      itemKey: "name",

      /**
       * @instance
       */
      getWidgetConfig: function alfresco_forms_controls_Picker__getWidgetConfig() {
         // Return the configuration for the widget
         return {
            id : this.id + "_CONTROL",
            name: this.name,
            value: (this.value != null) ? this.value : []
         };
      },
     
      /**
       * @instance
       */
      createFormControl: function alfresco_forms_controls_Picker__createFormControl(config, domNode) {
         this.alfSubscribe(this + "ALF_ITEMS_SELECTED", lang.hitch(this, "onItemsSelected"));
        
         // Update the model to set the main picked items display and the overall picker config
         var clonedWidgetsForControl = lang.clone(this.widgetsForControl);
         this.setModelPickedItemsConfig(lang.clone(this.configForPickedItems), config.value, clonedWidgetsForControl);
         this.setModelPickerConfig(lang.clone(this.configForPicker), clonedWidgetsForControl);
        
//         // Set the value…
         this.setModelPickerWidgetValue(config.value, clonedWidgetsForControl);
         return this.processWidgets(clonedWidgetsForControl, this.domNode);
      },

      /**
       * Updates the model to set a value of the currently selected items. It is necessary to do this because
       * the model cannot contain variable information (at least none that can be defined when the widget is
       * instantiated) so it is necessary to perform this before the [processWidgets]{@link module:alfresco/core/Core#processWidgets}
       * function is called.
       *
       * @instance
       * @param {object} config The configuration to use
       * @param {array} value The value to set
       * @param {object} widgetsForControl A cloned copy of the defined widgets for the picked items
       */
      setModelPickedItemsConfig: function alfresco_forms_controls_Picker__setModelPickedItemsConfig(config, value, widgetsForControl) {
         lang.setObject("0.config.widgets.0.config", config, widgetsForControl);
         lang.setObject("0.config.widgets.0.config.value", value, widgetsForControl);
      },

      /**
       * Updates the model to set a value of the currently selected items. It is necessary to do this because
       * the model cannot contain variable information (at least none that can be defined when the widget is
       * instantiated) so it is necessary to perform this before the [processWidgets]{@link module:alfresco/core/Core#processWidgets}
       * function is called.
       *
       * @instance
       * @param {object} value The value to set
       */
      setModelPickerConfig: function alfresco_forms_controls_Picker__setModelPickerConfig(value, widgetsForControl) {
         lang.setObject("0.config.widgets.1.config.widgets.1.config", value, widgetsForControl);
      },

      /**
       * The value returned is an array where each element is the value of the [itemKey]{@link module:alfresco/forms/controls/Picker#itemKey}
       * of each item returned by calling the [getPickedItemsWidget function]{@link module:alfresco/forms/controls/Picker#getPickedItemsWidget}.
       *
       * @instance
       * @returns {object}pickedItemsWidget
       */
      getValue: function alfresco_forms_controls_Picker__getValue() {
         var processedItems = [];
         var items = this.getPickedItemsWidget().currentData.items;
         array.forEach(items, function(item, index) {
            processedItems.push(item[this.itemKey]);
         }, this);
         return processedItems;
       //  return items;
      },
     
      /**
       * Calls the [setModelPickerWidgetValue]{@link module:alfresco/forms/controls/DocumentPicker#setModelPickerWidgetValue}
       * function.
       *
       * @instance
       * @param {object} value
       */
      setValue: function alfresco_forms_controls_Picker__setValue(value) {
         this.setModelPickerWidgetValue(value);
      },

      /**
       * Updates the model to set a value of the currently selected items. It is necessary to do this because
       * the model cannot contain variable information (at least none that can be defined when the widget is
       * instantiated) so it is necessary to perform this before the [processWidgets]{@link module:alfresco/core/Core#processWidgets}
       * function is called.
       *
       * @instance
       * @param {object} value The value to set
       */
      setModelPickerWidgetValue: function alfresco_forms_controls_Picker__setModelPickerWidgetValue(value, widgetsForControl) {
         lang.setObject("0.config.widgets.1.config.widgets.1.config.value", value, widgetsForControl);
      },

      /**
       * When items are picked it is necessary to update the [AlfFormDialogButton]{@link module:alfresco/buttons/AlfFormDialogButton}
       * that generates the [form]{@link module:alfresco/forms/Form} containing the [Picker]{@link module:alfresco/pickers/Picker} because
       * the [AlfDialogService]{@link module:alfresco/dialogs/AlfDialogService} will destroy the dialog when it is closed.
       *
       * @instance
       * @param {object} value The items to set.
       */
      updateFormDialogButton: function alfresco_forms_controls_Picker__updateFormDialogButton(value) {
         var button = lang.getObject("verticalWidgets.formDialogButton", false, this);
         if (button != null)
         {
            lang.setObject("widgets.1.config.value", value, button);
         }
         else
         {
            this.alfLog("warn", "The button to request a form does not exist", this);
         }
      },

      /**
       * This is called when the [form]{@link module:alfresco/forms/Form} generated by the [AlfFormDialogButton]{@link module:alfresco/buttons/AlfFormDialogButton}
       * is submitted. The payload will contain the picked items captured by the [Picker]{@link module:alfresco/pickers/Picker}
       * widget. The items should then be rendered in the local [PickedItems]{@link module:alfresco/pickers/PickedItems} widget.
       *
       * @instance
       * @param {object} payload The details of the selected items
       */
      onItemsSelected: function alfresco_forms_controls_Picker__onItemsSelected(payload) {
         var pickedItemsWidget = this.getPickedItemsWidget();
         if (pickedItemsWidget != null)
         {
            if (payload.pickedItems != null)
            {
               pickedItemsWidget.currentData.items = payload.pickedItems;
               pickedItemsWidget.renderView();
               this.updateFormDialogButton(payload.pickedItems);
            }
            else
            {
               this.alfLog("warn", "No items provided to assign to PickedItems widget, nothing will be set", payload, this);
            }
            this.validate();
         }
         else
         {
            this.alfLog("warn", "PickedItems widget is not created, it is not possible to set items", this);
         }
      },

      /**
       * Retrieves the [PickedItems widget]{@link module:alfresco/pickers/PickedItems} defined in the
       * [widgetsForControl]{@link module:alfresco/forms/controls/DocumentPicker#widgetsForControl} model.
       * This is defined in a separate function to support functions that override the model and need to
       * obtain the widget by a different means.
       *
       * @instance
       * @returns {object} The [PickedItems widget]{@link module:alfresco/pickers/PickedItems}
       */
      getPickedItemsWidget: function alfresco_forms_controls_Picker__getPickedItemsWidget() {
         var widget = lang.getObject("verticalWidgets.pickedItemsWidget", false, this);
         return widget;
      },

      /**
       * This should be overridden to define the widget model for rendering the picked items.
       *
       * @instance
       * @type {object}
       * @default []
       */
      configForPickedItems: null,

      /**
       * This should be overridden to define the widget model for rendering the picker that appears within the
       * dialog.
       *
       * @instance
       * @type {object}
       * @default []
       */
      configForPicker: null,

      /**
       *
       * @instance
       * @type {object}
       * @default
       */
      widgetsForControl: [
         {
            name: "alfresco/layout/VerticalWidgets",
            assignTo: "verticalWidgets",
            config: {
               widgets: [
                  {
                     name: "alfresco/pickers/PickedItems",
                     assignTo: "pickedItemsWidget"                          
                  },
                  {
                     name: "alfresco/buttons/AlfFormDialogButton",
                     assignTo: "formDialogButton",
                     config: {
                       label: "select",
                        dialogTitle: "Select…",
                        dialogConfirmationButtonTitle : "OK",
                        dialogCancellationButtonTitle : "Cancel",
                        formSubmissionTopic: this + "ALF_ITEMS_SELECTED",
                        formSubmissionGlobal: false,
                        formSubmissionToParent: false,
                        additionalCssClasses: "confirmationButton",
                        widgets: [
                                  {
                                     name: "alfresco/buttons/AlfButton",
                                     config: {
                                        label: "Go to parent folder",
                                        iconClass: "alf-folder-up-icon",
                                        publishTopic: "ALF_DOCLIST_PARENT_NAV"
                                     }
                                  },
                                  {
                                     name: "alfresco/pickers/Picker",
                                     config: {}
                           }
                        ]
                     }
                  }
               ]
            }
         }
      ]
   });
});


Here I am able to render the association to the PickedItem widget in AlfDynamicPayloadButton.publishPayload.widgets.
The problem I am facing is that when I try to create the Artifact item, the following exception is thrown:

2015-03-19 15:39:04,963 ERROR node.integrity.IntegrityChecker http-bio-8080-exec-7 Found 5 integrity violations:
The association target multiplicity has been violated:
Source Node: workspace://SpacesStore/b007dfb6-aa39-466f-8b6d-47a52d46a1a3
Association: Association[ class=ClassDef[name=
{http://essg/model}
artifactDatalist], name=
{http://essg/model}
serviceAssociation, target class=
{http://essg/model}
serviceDataList, source role=null, target role=null]
Required target Multiplicity: 1..1
Actual target Multiplicity: 0

It is the same for the other 4 associations.

Thanks,
Rohit