Overriding the Preview Button in the List view of a module

In the list view of the Leads module, I want to override the action of the preview button next to each record so that clicking on it opens up the preview pane as well as putting the selected row into edit mode.

Platform: Sugar ondemand version 11.1

I am able to override the preview button as below but how do I trigger the 'Edit' action, as if I had clicked on the 'Edit' from the dropdown list next to the preview button?

// custom/modules/Leads/clients/base/views/recordlist.js
*/
({
  extendsFrom: 'RecordlistView',

  initialize: function(options) {
  this._super("initialize", [options]);

  this.context.on('list:preview:fire', this.preview_clicked, this);

},

preview_clicked: function(model) {

  console.log('Preview button clicked');

  //??? trigger/call the editrow action ???

},

Parents
  • Hi,

    As per Franscesca's answer, I have not actually played with what you are trying but I might be able to offer some pointers.

    It seems that instead of opening the Preview in edit mode directly you are trying to open the preview and also put the row in the dashlet into edit mode as if the row's Edit button has also been clicked. So that is what my pointers are based on.

    I think you are probably on the right track with the file you are overriding as the functions do reside in the recordlist.js file as far as I know. If you look in the core version of that file at ./clients/base/views/recordlist/recordlist.js you will find the events that set up the actions in the recordlist.

    I believe that the trigger for the edit function in the row is: list:editrow:fire which calls the function: editClicked so you could try simply calling that function where you have the placeholder in your snippet above. Or you can copy that function into a custom one and attach that to the click event of the preview button. The custom function could fire the preview and then continue with the editrow fire actions.

    As the function has two parameters it may not be straightforward to do that though so another option might be to trigger the actual button click. The function registerShortcuts in that js file also sets up the shortcut keys to fire events on the record. Within there you can see the way these button clicks are simulated and you could try doing that on the list:editrow:fire action. Try looking at the equivalent preview fire which does this: clickButton(this.$('.selected [data-event="list:preview:fire"]:visible')); So you might try adjusting that (and using the proper method) by calling something like:

    this.$('.selected [data-event="list:editrow:fire"]:visible').click();

    Somewhere in there or nearby is likely to be the answer to what you want to do Slight smile

    Good luck.

    Thanks,

    JH.

Reply
  • Hi,

    As per Franscesca's answer, I have not actually played with what you are trying but I might be able to offer some pointers.

    It seems that instead of opening the Preview in edit mode directly you are trying to open the preview and also put the row in the dashlet into edit mode as if the row's Edit button has also been clicked. So that is what my pointers are based on.

    I think you are probably on the right track with the file you are overriding as the functions do reside in the recordlist.js file as far as I know. If you look in the core version of that file at ./clients/base/views/recordlist/recordlist.js you will find the events that set up the actions in the recordlist.

    I believe that the trigger for the edit function in the row is: list:editrow:fire which calls the function: editClicked so you could try simply calling that function where you have the placeholder in your snippet above. Or you can copy that function into a custom one and attach that to the click event of the preview button. The custom function could fire the preview and then continue with the editrow fire actions.

    As the function has two parameters it may not be straightforward to do that though so another option might be to trigger the actual button click. The function registerShortcuts in that js file also sets up the shortcut keys to fire events on the record. Within there you can see the way these button clicks are simulated and you could try doing that on the list:editrow:fire action. Try looking at the equivalent preview fire which does this: clickButton(this.$('.selected [data-event="list:preview:fire"]:visible')); So you might try adjusting that (and using the proper method) by calling something like:

    this.$('.selected [data-event="list:editrow:fire"]:visible').click();

    Somewhere in there or nearby is likely to be the answer to what you want to do Slight smile

    Good luck.

    Thanks,

    JH.

Children