cancel
Showing results for 
Search instead for 
Did you mean: 

How to set value into alfresco/menus/AlfMenuGroup at aikau page load

janaka1984
Star Contributor
Star Contributor

Hi,

I have implemented alfresco/menus/AlfMenuGroup widget on aikau page. when load browser i need to set value into AlfMenuGroup.

currently i try to use "this.widgetsForToolbar2[0].config.widgets[1].config.widgets[1].config.widgets[0].config.widgets" on postCreate() which is successed with aikau dashlet.

but this is not working with aikau page. please give me hints to short out this issue?

Regards

Janaka

1 ACCEPTED ANSWER

ddraper
World-Class Innovator
World-Class Innovator

OK, I see what you're doing now... you're re-using the faceted-search.get.js file ... can I just check whether or not you're importing the file into your WebScript controller or whether you've copy/pasted... if you've copy/pasted the function then you can always just change the code to set the preference directly.

If you're importing then why not just call the function outside of the model declaration and change the value. There's a couple of things you're going to want to change... the default behaviour is to derive the sort data from the URL hash.

That should achieve the result you're after.

View answer in original post

7 REPLIES 7

ddraper
World-Class Innovator
World-Class Innovator

OK, so that definitely looks wrong you really want to avoid configuring something like that. Can you explain the user case you have for implementing something like this?

As it is, AlfMenuGroup is a container for AlfMenuItem so I'm assuming that is what you actually want to be setting? What I don't understand is why you need to be setting a value from the browser on load? Is the value taken from request or hash parameters in the URL? If it's hash parameters then you could consider using the "processHashTokens" processor provided by the ObjectProcessingMixin​.

If the value isn't dynamically derived from the URL then it should be configurable within the JavaScript controller for the WebScript that defines the dashlet. If you're trying to set a value like this then you must be doing it in a custom widget?

If you can provide more context as to what you're trying to do (as in the end goal rather than the implementation path you're using) then I should be able to help.


Regards,

Dave

Hi dave,

In my toolbar, i use following button which is similar to alfresco advance search toolbar.  when i select sortfield , it is stored in preference as last selected value.

after that, if i refresh browser again, i need to set last selected value into middle button instead of default 'Relevance'

toolbar.JPG

Regards

janaka

ddraper
World-Class Innovator
World-Class Innovator

OK... but the user preferences are available within the JavaScript controller of the WebScript that is rendering the dashlet. So ideally you want to be retrieving the user preference for the sort field in the WebScript and setting it in the model - this would be a much simpler and more reliable approach and wouldn't require a client-side XHR request.

You can import the AlfrescoUtil module into the JS controller:

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

...and then access a user preference by calling:

AlfrescoUtil.getPreferences

passing the dot-notation preference to retrieve. You can get the user preference and then configure this in the model passed to the dashlet. I would strongly recommend trying this approach.

i can get user preference at JS controller. problem is how to set that value to following aikau widget as last selected value?

{

                                   id: "FCTSRCH_SORT_MENU",

                                   name: "alfresco/menus/AlfMenuBarSelect",

                                   config: {

                                      title: msg.get("faceted-search.sort-field.title"),

                                      selectionTopic: "ALF_DOCLIST_SORT_FIELD_SELECTION",

                                      widgets: [

                                         {

                                            id: "DOCLIB_SORT_FIELD_SELECT_GROUP",

                                            name: "alfresco/menus/AlfMenuGroup",

                                            config: {

                                               widgets: getSortFieldsFromConfig()

                                            }

                                         }

                                      ]

                                   }

                                }

ddraper
World-Class Innovator
World-Class Innovator

OK, I see what you're doing now... you're re-using the faceted-search.get.js file ... can I just check whether or not you're importing the file into your WebScript controller or whether you've copy/pasted... if you've copy/pasted the function then you can always just change the code to set the preference directly.

If you're importing then why not just call the function outside of the model declaration and change the value. There's a couple of things you're going to want to change... the default behaviour is to derive the sort data from the URL hash.

That should achieve the result you're after.

i have used copy/paste and directly assigned preference. it is working .

thanks dave

ddraper
World-Class Innovator
World-Class Innovator

No problem, happy to help