We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    I have a tree widget on one of my CMPs. The basic functionality is copied from the Gallery component.

    Tariffs.tree.Tariffs = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            id: 'tariffs-tree-tariffs'
            ,url: Tariffs.config.connector_url
            ,action: 'mgr/tariff/getNodes'
            ,root: {
            	nodeType: 'async',
            	leaf: false,
            	text: 'All Tariffs',
            	id: 'root'
            }
            ,tbar: [{
                text: _('tariffs.tariff_create')
                ,handler: function(btn,e) { this.createTariff(btn,e,true); }
                ,scope: this
            },'-',{
                text: _('tariffs.refresh')
                ,handler: this.refresh
                ,scope: this
            }]
            ,rootVisible: true
        })
        Tariffs.tree.Tariffs.superclass.constructor.call(this,config);    
    };
    


    At the lowest level of the tree are Tariff object which I would like to update / delete by right clicking on an entry.

    I added this in the definition of each Tariff node which is assembled by a PHP snippet:

    $node = new TreeNode();
    $node->menu['items'][] = array(
            'text' => $modx->lexicon('tariffs.tariff_update'),
    	'handler' => 'function(itm,e) { this.updateTariff(itm,e); }',);
    $node->menu['items'][] = '-';
    $node->menu['items'][] = array(
    	'text' => $modx->lexicon('tariffs.tariff_remove'),
            'handler' => 'function(itm,e) { this.removeTariff(itm,e); }',);
    


    In the definition of the tree widget I have the following definition for the updateTariff function:

    Ext.extend(Tariffs.tree.Tariffs,MODx.tree.Tree,{
        windows: {}
      
        ,updateTariff: function(btn,e) {
        	alert("about to update a tariff record");
    	}
     ....
    


    Now the menu pops up correctly when a right click a node, however when I select the "Update" option I don’t see the alert as I would expect.

    What am I doing wrong??

    Thanks!
      MODx Revolution / MAMP / OS X
      • 27519
      • 275 Posts
      I found some info which might help to solve this:

      In the the last code snippet I actually have three functions: one for inserting a new object/record, one for updating and one for deleting.

      The insert works fine. It opens a new windows and allows me to enter data for a new instance and save it to the DB.

      The update and the delete generate Javascript exceptions:
      Uncaught TypeError: Object function(itm,e) { this.updateTariff(itm,e); } has no method ’apply’
      Uncaught TypeError: Object function(itm,e) { this.removeTariff(itm,e); } has no method ’apply’

      ... when I click one of the buttons in the popup menu.

      Apparently I’ve not included some "apply" method, however after some experimenting I have not yet found a solution.

      I’ve searched the ExtJs docs and website but do not really understand what I need to do to solve this.
        MODx Revolution / MAMP / OS X