Announcement

Collapse
No announcement yet.

Action on multiple selected items in list view (HOWTO)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Action on multiple selected items in list view (HOWTO)

    Hi,

    Im trying to implement some custom action (like massAction) on elements selected in Entity list view

    I my case during debugging this.recordView.checkedList is underfined in browser, however the check-marks are in place in UI.

    How can I properly access the IDs of the selected entities ?

    Code:
    /client/custom/src/views/MY_EXTENSION/list.js
    Code:
    Espo.define('custom:views/MY_EXTENSION/list', 'views/list', function (Dep) {
    
        return Dep.extend({
    
            setup: function () {
                Dep.prototype.setup.call(this);
    
                this.menu.actions.push({
            name: 'printPDF',
            label: 'Print PDF (on selected)',
            action: 'printPDF',
            acl: 'view'
                });
            },
    
            actionPrintPDF: function () {
                 this.notify('Loading...');
    
                var count = this.recordView.checkedList.length;
    
                var idList = [];
                for (var i in this.recordView.checkedList) {
                    idList.push(this.recordView.checkedList[i]);
                };
    
                ids_str = JSON.stringify( idList );
    
                window.location = '?entryPoint=PDF&mode=many&ids=' + ids_str;
            }
        });
    });
    Thanks in advance!

    PS. I tried to minic the logic in /record/list.jst but without much success...

  • #2
    Hello

    this.recordView is just a string

    in your function declare own variable and use it
    var recordView = this.getView('list');

    and don't forget about allResultIsChecked

    Comment


    • #3
      It works nicely! Thanks for the advice.

      In case someone need it the updated code follows:

      Code:
              actionPrintPDF: function () {
                  this.notify('Loading...');
      
                  var recordView = this.getView('list');
                  var count = recordView.checkedList.length;
      
                  var idList = [];
                  for (var i in recordView.checkedList) {
                      idList.push(recordView.checkedList[i]);
                  };
      
                  ids_str = JSON.stringify( idList );
                  window.location = '?entryPoint=PDF&mode=many&ids=' + ids_str;
              }

      Comment


      • #4
        igrp This didn't work for me. What have I done wrong?

        Click image for larger version

Name:	2018-02-20_18-43-09.png
Views:	991
Size:	28.7 KB
ID:	34853

        When I go to my Project entity, I don't see anything in the Action menu:

        Click image for larger version

Name:	2018-02-20_18-44-35.png
Views:	937
Size:	15.0 KB
ID:	34854

        Do I need to make more changes? I didn't add any other files because it doesn't look like I need to based on this post, but maybe you did more than what was shown. Do I need to add files or make changes in custom/Espo/Custom?

        Comment


        • #5
          Did you set this view in clientDefs?

          Comment


          • #6
            Originally posted by tanya View Post
            Did you set this view in clientDefs?
            tanya No, I didn't. Thanks for mentioning that. I see where to set it (custom/Espo/Custom/Resources/metadata/clientDefs/<entity>.json), but I can't find an example for the format of the file. Here's how my file looks at the moment:

            Code:
               2     "controller": "controllers/record",
               3     "boolFilterList": [
               4         "onlyMy"
               5     ],
               6     "relationshipPanels": {
               7         "timesheetDatas": {
               8             "rowActionsView": "views/record/row-actions/empty",
               9             "select": false,
              10             "create": false
              11         },
              12         "projectsCopyFromChildren": {
              13             "rowActionsView": "views/record/row-actions/empty",
              14             "select": false,
              15             "create": false
              16         },
              17         "projectsSimilar": {
              18             "rowActionsView": "views/record/row-actions/empty",
              19             "select": false,
              20             "create": true
              21         }
              22     },
              23     "sidePanels": {
                     ...
            would it be "listActionsView" and, if so, where does it go?

            Originally posted by tanya View Post
            and don't forget about allResultIsChecked
            What did you mean when you mentioned this? Are you saying to be careful if the user clicks the box to select everything since it would try to print every entity object to PDF? If that's what you mean, how do you disable the print to PDF button if the box is checked? I agree it would be bad.


            Comment


            • #7
              I got it to use the custom view, but the option to "Print to PDF" is not listed in the Actions menu.

              Code:
                 1 {
                 2     "controller": "controllers/record",
                 3     "views": {
                 4         "list": "custom:views/project/list"
                 5     },
                 6     "boolFilterList": [
                 7         "onlyMy"
                 8     ],
              I added a console statement and I see it when the page loads:

              Click image for larger version

Name:	console.PNG
Views:	711
Size:	60.2 KB
ID:	35015

              but the Actions menu is unchanged.

              Comment


              • #8
                Oh, actually, it did add a menu, but not the right one. How do I get the option to be in the right menu? I was expecting it to be in the Actions menu below the search bar at the far left of my picture.

                Click image for larger version  Name:	menu.PNG Views:	1 Size:	14.3 KB ID:	35017

                The new button also doesn't work:

                Click image for larger version

Name:	404.PNG
Views:	607
Size:	18.0 KB
ID:	35018

                Comment


                • #9
                  Hello
                  if you want to change the menu below the search bar, you need to override the record list view, not list view

                  /////
                  "recordViews": { "list": "custom:views/project/record/list" }, //////

                  as example client/modules/crm/src/views/meeting/record/list.js

                  and read application/Espo/EntryPoints/Pdf.php

                  Comment

                  Working...
                  X