Announcement

Collapse
No announcement yet.

HELP - Filter/Hide Inactive Contacts in Side Panel

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

  • HELP - Filter/Hide Inactive Contacts in Side Panel

    So, I have a client that wants to automatically HIDE inactive accounts in the small list panel. I can see that you can use the FILTER tool to do this, but she wants it to be done automatically.
    Here's the code I found that needs to be modified:

    namespace Espo\Modules\Crm\AclPortal;

    use \Espo\Entities\User;
    use \Espo\ORM\Entity;

    class Contact extends \Espo\Core\AclPortal\Base
    {
    public function checkIsOwnContact(User $user, Entity $entity)
    {
    $contactId = $user->get('contactId');
    if ($contactId) {
    if ($entity->id === $contactId) {
    return true;
    }
    ***** INSERT CODE HERE*****
    }
    return false;
    }
    }

    I'm thinking that this will work:

    *********
    if ($contactNotActive === true) {
    return false;
    }
    ***********

    Do I need to change any other code? Maximus , you have been my rock, does this look right to you???

  • #2
    You could create filter based on status field. I think it's much forward-looking approach.
    I've created same thing but with tasks. Basically when someone don't paid an invoice before deadline, invoice status will change to overdue. Based on that also status of client will change to blocked. And filter will hide all open tasks from this client in module Tasks.

    Comment


    • item
      item commented
      Editing a comment
      Hi emillod, like your idea, solution
      You have do that without developement ? just use out-of-box solution ? (AdvancedPack certainly)
      I need to do something like this for ours customs module.

  • #3


    This is the area that she wants automatically filtered.

    Comment


    • #4
      Hi PhotoMommie.

      You just need to create a custom view for the contact field in the Case entity.
      1. Create the file /client/custom/src/views/case/fields/contacts.js with this code:
      HTML Code:
      Espo.define('custom:views/case/fields/contacts', 'views/fields/link-multiple-with-primary', function (Dep) {
      
          return Dep.extend({
      
              primaryLink: 'contact',
      
              getSelectFilters: function () {
                  if (this.model.get('accountId')) {
                      return {
                          'account': {
                              type: 'equals',
                              attribute: 'accountId',
                              value: this.model.get('accountId'),
                              data: {
                                  type: 'is',
                                  nameValue: this.model.get('accountName')
                              }
                          },
                          'notActive': {
                              type: 'isFalse',
                              attribute: 'notActive'
                          }
                      };
                  }
              },
      
              getCreateAttributes: function () {
                  if (this.model.get('accountId')) {
                      return {
                          accountId: this.model.get('accountId'),
                          accountName: this.model.get('accountName')
                      }
                  }
              }
      
          });
      });
      2. In the file /custom/Espo/Custom/Resources/metadata/entityDefs/Case.json define the view for the "contacts" field with this way
      Code:
      {
          "fields": {
      [COLOR=#c0392b]        "contacts": {
                  "view": "custom:views/case/fields/contacts"
              },[/COLOR]
              .........
          }
      }
      3. Administration -> Clear Cache
      4. Refresh a web page
      5. Test the filter

      Notes:
      1. I used the boolean type field called 'notActive'.
      2. The filter depends on the linked account. You can change these dependencies by changing the filter in the contacts.js file.

      Comment


      • #5


        Perfect! This worked for the popup side panel!

        Comment


        • #6
          Hey Maximus , I am attempting to use the model to create a pre-filtered list of vendors allowed in a selected jurisdiction.
          I am running into the issue that the filter is not selecting the jurisdiction. I think I got my wires crossed on how to do this.

          PHP Code:
          Espo.define('custom:views/salePubEstimator/fields/vendor''views/fields/link-multiple-with-primary', function (Dep) {

          return 
          Dep.extend({

          primaryLink'vendor',

          getSelectFilters: function () {
          if (
          this.model.get('jurisdictionId')) {
          return {
          'jurisdiction': {
          type'equals',
          attribute'jurisdictionId',
          valuethis.model.get('jurisdictionId'),
          data: {
          type'is',
          nameValuethis.model.get('jurisdictionName')
          }
          },
          'vendorType': {
          attribute'Newspaper'
          }
          };
          }
          },

          getCreateAttributes: function () {
          if (
          this.model.get('jurisdictionId')) {
          return {
          vendorIdthis.model.get('vendorId'),
          vendorNamethis.model.get('vendorName')
          }
          }
          }

          });
          }); 
          Attached Files

          Comment


          • #7
            Originally posted by Maximus View Post
            Hi PhotoMommie.

            You just need to create a custom view for the contact field in the Case entity.
            1. Create the file /client/custom/src/views/case/fields/contacts.js with this code:
            HTML Code:
            Espo.define('custom:views/case/fields/contacts', 'views/fields/link-multiple-with-primary', function (Dep) {
            
            return Dep.extend({
            
            primaryLink: 'contact',
            
            getSelectFilters: function () {
            if (this.model.get('accountId')) {
            return {
            'account': {
            type: 'equals',
            attribute: 'accountId',
            value: this.model.get('accountId'),
            data: {
            type: 'is',
            nameValue: this.model.get('accountName')
            }
            },
            'notActive': {
            type: 'isFalse',
            attribute: 'notActive'
            }
            };
            }
            },
            
            getCreateAttributes: function () {
            if (this.model.get('accountId')) {
            return {
            accountId: this.model.get('accountId'),
            accountName: this.model.get('accountName')
            }
            }
            }
            
            });
            });
            2. In the file /custom/Espo/Custom/Resources/metadata/entityDefs/Case.json define the view for the "contacts" field with this way
            Code:
            {
            "fields": {
            [COLOR=#c0392b] "contacts": {
            "view": "custom:views/case/fields/contacts"
            },[/COLOR]
            .........
            }
            }
            3. Administration -> Clear Cache
            4. Refresh a web page
            5. Test the filter

            Notes:
            1. I used the boolean type field called 'notActive'.
            2. The filter depends on the linked account. You can change these dependencies by changing the filter in the contacts.js file.
            That works great.
            Now if we need to do the same thing but using the bottom panel, and clicking on select?

            Comment

            Working...
            X