We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20380
    • 118 Posts
    There is a button on it hangs Event
    editFiletype : function(btn, e) {
             
            var r = {
                'id' : MODx.request.id,
                'd' : this.menu.record.i,
                'key' : this.menu.record.key,
                'name' : this.menu.record.name,
                'service' : 'MODX'
            };
            if (!this.windows.EditFiletype) {
                this.windows.EditFiletype = MODx.load({
                    xtype : 'advicles-window-filetypeedit',
                    record : r,
                    listeners : {
                        'success' : {
                            fn : function(r) {
                                this.refresh();
                            },
                            scope : this
                        }
                    }
                });
            }
            this.windows.EditFiletype.setValues(r);
            this.windows.EditFiletype.show(e.target);
        },

    Opens a window with the form:
    Advicles.window.EditFiletype = function(config) {
        config = config || {};
        this.ident = config.ident || 'advimp' + Ext.id();
        Ext.applyIf(config, {
            title : "Редактировать тип файлов",
            id : this.ident,
            url : "/assets/components/advicles/filetypelist.php",
            action : 'edit',
            fields : [{
                xtype : 'hidden',
                name : 'id',
                value : MODx.request.id
            }, {
                xtype : 'hidden',
                name : 'd',
                value : MODx.request.d
            }, {
                xtype : 'textfield',
                fieldLabel : "Key",
                name : 'key',
                id : 'modx-filetype-key',
                value : MODx.request.key
            }, {
                xtype : 'textfield',
                fieldLabel : "Name",
                name : 'name',
                id : 'modx-filetype-name',
                value : MODx.request.name
            }]
        });
        Advicles.window.EditFiletype.superclass.constructor.call(this, config);
    };
    Ext.extend(Advicles.window.EditFiletype, MODx.Window, {
        activeOptions : 'advicles-options-MODX',
        changeService : function(cb, s) {
            var nv = cb.getValue();
            var op = Ext.getCmp(this.activeOptions);
     
            var nop = 'advicles-options-' + nv;
            var p = Ext.getCmp(nop);
            if (p) {
                op.hide();
                p.show();
                this.activeOptions = nop;
            }
            return true;
        }
    });
    Ext.reg('advicles-window-filetypeedit', Advicles.window.EditFiletype);

    However, when the store shape in the window, it hangs up. The data in the file is sent, but the response is obtained in the processing error (firefox):
    TypeError: g is undefined
    var g = this.getRoot(a), e = g.length, d = e, k = true;

    File filetypelist.php - I wrote myself, so I can make it any conclusion. Which json should be returned to the error from occurring? Tried {"success": true} - does not work.
    Help me, please.
    PS Sorry for the bad English

    file filetypelist.php:
    $arr = array();
    $arr['success'] = true;
    header('Content-type: text/json; charset=utf-8');
    echo(json_encode($arr));
      • 3749
      • 24,544 Posts
      See if this works:


      function outputArray(array $array,$count = false) {
         if ($count === false) { $count = count($array); }
         return '{"total":"'.$count.'","results":'.$this->modx->toJSON($array).'}';
      }
      
      $arr = array();
      $arr['success'] = true;
      // header('Content-type: text/json; charset=utf-8');
      // echo(json_encode($arr));
      
      return outputArray($arr);



      That function code is from the MODX modProcessor class.

      You might consider using a class-based processor for your list: https://www.markhamstra.com/xpdo/2012/getting-started-with-class-based-processors-2.2/, which will handle a lot of the heavy lifting for you.
        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
        • 20380
        • 118 Posts
        No, just need use
        $arr['data'] = $value;

        not $arr['result']