We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37031
    • 93 Posts
    I'm having an issue with my CMP. I have a grid that's working great. It uses GetList, Create, and Update processors without any issues. I'm trying to add a button to toggle the active status of the record and it makes sense to me to reuse my Update processor and add some functionality to the beforeSet() method. So I updated my Update processor and called it via AJAX but I keep receiving a failure response. My question is:

    • What does my modObjectUpdateProcessor expect when I call it via AJAX and how should I pass it data?

    Here is my extended modObjectUpdateProcessor called scClassLevelCategoryUpdateProcessor where I added logic to the beforeSet() method:

    class scClassLevelCategoryUpdateProcessor extends modObjectUpdateProcessor {
    
        public $classKey = 'scClassLevelCategory';
        public $languageTopics = array('studentcentre:default');
        public $objectType = 'studentcentre.att';
        
        public function beforeSet() {
            $toggleActive = $this->getProperty('toggleActive');
            
            // Do something with $toggleActive
            
            $this->setProperty('active', $newActiveState);
            return parent::beforeSet();
        }
            
    }
    return 'scClassLevelCategoryUpdateProcessor';


    And here is my ExtJS function called toggleActive from my grid definition (I've just included the function):

    toggleActive: function(btn,e) {
        var selRow = this.getSelectionModel().getSelected();
        if (selRow.length <= 0) return false;
        record = JSON.stringify(selRow.data);
    
        MODx.Ajax.request({
            url: this.config.url
            ,params: {
                action: 'mgr/attendance/scClassLevelCategoryUpdate'
                ,data: record
                ,toggleActive: 1
            }
            ,listeners: {
                'success': {fn:function(r) {
                    this.refresh();
                    Ext.getCmp('studentcentre-grid-attendance-level-categories').refresh();
                },scope:this}
                ,'failure': {fn:function(r) {
                    console.log(r);
                },scope:this}
            }
        });
        return true;
    }
    


    Thank everyone and any help would be much appreciated!

    This question has been answered by jeffmiranda. See the first response.

    [ed. note: jeffmiranda last edited this post 12 years, 6 months ago.]
      • 3749
      • 24,544 Posts
      Take a look at this: https://www.markhamstra.com/xpdo/2012/modobjectgetlistprocessor-class-based-processor/

      I think you may need to override prepareQueryBeforeCount() so it will get the object before modifying it.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • discuss.answer
        • 37031
        • 93 Posts
        Thanks for the reply Bob! I did some more testing and discovered that passing the entire record through the data property wasn't allowing the processor to retrieve the record. Instead I tried passing the primary ID and a toggleActive flag like so:

            toggleActive: function(btn,e) {
                var selRow = this.getSelectionModel().getSelected();
                if (selRow.length <= 0) return false;
                MODx.Ajax.request({
                    url: this.config.url
                    ,params: {
                        action: 'mgr/attendance/scClassLevelCategoryUpdate'
                        ,id: selRow.data.id
                        ,toggleActive: 1
                    }
                    ,listeners: {
                        'success': {fn:function(r) {
                            this.refresh();
                            Ext.getCmp('studentcentre-grid-attendance-level-categories').refresh();
                        },scope:this}
                    }
                });
                return true;
            }


        The Update processor was then able to retrieve the record. The key was ensuring that I was passing a property called id which contained the primary key of the record I wanted to update. I then modified my Update processor like so:

        class scClassLevelCategoryUpdateProcessor extends modObjectUpdateProcessor {
        
            public $classKey = 'scClassLevelCategory';
            public $languageTopics = array('studentcentre:default');
            public $objectType = 'studentcentre.att';
            
            public function beforeSet() {
            
                $toggleActive = $this->getProperty('toggleActive');
                if (!empty($toggleActive)) {
        	        if ($this->object->get('active') == 1) {
        		        $this->setProperty('active', 0);
        	        } else {
        		        $this->setProperty('active', 1);
        	        }
                }
                
                return parent::beforeSet();
            }
                
        }
        return 'scClassLevelCategoryUpdateProcessor';
          • 3749
          • 24,544 Posts
          Glad you got it sorted. Thanks for reporting back. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting