We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hi all
    Probably a basic question but can't find how to solve it...

    xtype 'modx-combo-browser' allows to choose a file... But I need to select a FOLDER instead of a file ...
    Any clue on how to do that ?
    Cheers [ed. note: anso last edited this post 14 years, 6 months ago.]
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      That's a very interesting question actually. Don't think there's a simple configuration option for that, but it would make a nice feature request.

      There's the modx-tree-directory xtype which may be better for your needs, as you could add a listener for click (or select may be more appropriate) taking it's first "node" variable to get the path.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 1778
        • 659 Posts
        Hi Mark,
        Thanks for answering...
        modx-tree-directory does not fit what I want because it shows files inside directories... I just want to show the folders/subfolders not the files inside them....

        I desperatly try to fill a combo with a JSON array return by a processor extending modProcessor, I get the list of folders as I want in my processor but can't figure out how to display it in my combo...

        Maybe you have some ideas...

        code in the window
               [...]
               {  
                   xtype: 'picman-combo-folders',
                    fieldLabel: 'Folder',
                    name: 'name',
                    hiddenName: 'name',
                    anchor: '100%'     
                }     
        
        


        code of combo
        Picman.combo.Folders = function(config){
            config = config || {};
            Ext.applyIf(config,{
                id: 'picman-combo-folders',   
                url: Picman.config.connectorUrl,
                baseParams: {
                    action: 'mgr/images/getListFolder'
                },
                store: new Ext.data.JsonStore({
                    autoLoad: true,
                    url: Picman.config.connectorUrl,
                    baseParams: {
                        action: 'mgr/images/getListFolder'
                    },
                    id:0,  // these lines are my problem what is the 'field' I call regarding my processor ? 
                    fields: ['name'],
                    displayField: 'name',
                    valueField: 'name'
                    // 
                })
        
                
            });
            Picman.combo.Folders.superclass.constructor.call(this, config);
        };
        Ext.extend(Picman.combo.Folders,MODx.combo.ComboBox);
        Ext.reg('picman-combo-folders',Picman.combo.Folders);
        


        processor code
        class picmanGetListFolderProcessor extends modProcessor {
            public function process() {
                $assetspath = $this->modx->config['assets_path'];
                $dir = $assetspath . 'master/img';
                $stack[] = $dir;
                while ($stack) {
                    $thisdir = array_pop($stack);
                    if ($dircont = scandir($thisdir)) {
                        $i = 0;
                        while (isset($dircont[$i])) {
                            if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
                                $current_file = "{$thisdir}/{$dircont[$i]}";
                                //$this->modx->log(modX::LOG_LEVEL_ERROR, ' - curfile :' . $current_file);
                                if (is_file($current_file)) {
                                    $path[] = "";
                                } elseif (is_dir($current_file)) {
                                    $path[] = "{$thisdir}/{$dircont[$i]}";
                                    $stack[] = $current_file;
                                }
                            }
                            $i++;
                        }
                    }
                }
        
                $lp = count($path);
                $this->modx->log(modX::LOG_LEVEL_ERROR, 'lp :' . $lp);
                for ($x = 0; $x < $lp; $x++) {
                    $suppr = $assetspath . master/img/';
                    $this->modx->log(modX::LOG_LEVEL_ERROR, $x . ' - path :' . $path[$x]);
                    $fold = $path[$x];
                    $this->modx->log(modX::LOG_LEVEL_ERROR, $x . ' - fold :' . $fold);
                    if ($fold != '') {
                        $folder = str_replace($suppr, '', $fold);
                        $this->modx->log(modX::LOG_LEVEL_ERROR, $x . ' - folder :' . $folder);
                        $myArray[] = $folder;
                    }
                }
        
                $this->modx->log(modX::LOG_LEVEL_ERROR, 'path ' . print_r($myArray));
        //        Prints :
        //        Array
        //        (
        //            [0] => abc
        //            [1] => def
        //            [2] => ghij
        //            [3] => klm
        //            [4] => mnop
        //            [5] => mnop/abcd
        //            [6] => mnop/efgh
        //            [7] => mnop/ijkl
        //        )
        
                return $this->toJSON($myArray);
        //        in FF it gives (which is correct I think):
        //        ["abc","def","ghij","klm","mnop","mnop\/abcd","mnop\/efgh","mnop\/ijkl"]
        
            }
        }
        return 'picmanGetListFolderProcessor';
        

        And my combo still empty...
        Any help would be appreciated...
        Cheers [ed. note: anso last edited this post 14 years, 6 months ago.]
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Try extending the modObjectGetListProcessor instead and specifying a public var $combo = true.

          Also I think you can define hideFiles: true on the tree so it just shows the files.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 1778
            • 659 Posts
            I'll try
            Thanks ^_^
              • 1778
              • 659 Posts
              Extending modObjectGetListProcessor doesn't work better...

              But hideFiles: true, works fine with xtype modx-tree-directory... I have to had a listener now... Not sure how to do that, but it's too late now, I need a rest... Tomorrow is another day ...
              Thanks for your help
              Have a good day/evening/night (depends where you are located)
              Cheers [ed. note: anso last edited this post 14 years, 6 months ago.]