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

    I have a grid and a create window... In the create window I have to select a folder, for this I use x-type 'modx-tree-directory' but at the moment I'm not able to set the folder value with the node selected in the tree...
    When I put a listener 'click' with a msg alert box, it works fine (I have the selected node returned) but how do I use this to save that value in my object (to pass the good value to the createObjectProcessor)?

    {
          xtype:'modx-tree-directory',            
          rootId: 'assets/master/img/',
          name: 'folder',
          hideFiles: true,
          listeners: {
                click: function(n) {
                    var lpath = n.attributes.id;
                    var rem = 'assets/master/img/'
                    var spath = lpath.replace(rem,'');
                    Ext.Msg.alert('Navigation Tree Click', 'selected: "' + spath + '"'); // returns what I want but how to save this value as the value of field ?
                }
    }
    

    Any help would be appreciated, ExtJS is not my cup of tea...
    I tried too with a combo-box as explain in https://forums.modx.com/thread/74929/extjs-modx-combo-brower-to-select-folder-instead-of-file#dis-post-415780 but did not arrive to fill in my combo
    [ed. note: anso last edited this post 14 years, 6 months ago.]
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Your topic title indicates you solved it, can you share how?
        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
        Sure ! I don't use an x-type 'modx-tree-directory' but a combobox that display the list of the folders and subfolders ignoring files.

        The code of the combo in the create window is
        //[...]
        fields: [{
            xtype: 'picman-combo-folders',
            fieldLabel: 'Folder',
            name: 'folder',
            hiddenName: 'folder',
            displayField: 'folder',
            valueField:'folder',
            anchor: '100%'
        }]
        //[...]
        


        The Picman.combo.Folders code is:
        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'
                    },
                    fields: ['folder']            
                })        
            });
            Picman.combo.Folders.superclass.constructor.call(this, config);
        };
        Ext.extend(Picman.combo.Folders,MODx.combo.ComboBox);
        Ext.reg('picman-combo-folders',Picman.combo.Folders);
        


        and the processor picmanGetListFolderProcessor code is
        <?php
        
        class picmanGetListFolderProcessor extends modProcessor {
        
            public $combo = true;
        
            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]}";
                                if (is_file($current_file)) {
                                    $path[] = "";
                                } elseif (is_dir($current_file)) {
                                    $path[] = "{$thisdir}/{$dircont[$i]}";
                                    $stack[] = $current_file;
                                }
                            }
                            $i++;
                        }
                    }
                }
                $lp = count($path);
                for ($x = 0; $x < $lp; $x++) {
                    $suppr = $assetspath . 'master/img/';
                    $fold = $path[$x];
                    if ($fold != '') {
                        $folder = str_replace($suppr, '', $fold);
                        $myArray[] = $folder;
                        $listtmp = array('folder' => $folder);
                        $myArr[] = $listtmp;
                    }
                }
                return $this->toJSON($myArr);
            }
        }
        return 'picmanGetListFolderProcessor';
        


        It should be improved with some checks (folder readable/writable ie) but at the moment it fit my immediate needs
        Cheers
          • 11055 ☆ A M B ☆
          • 3,112 Posts
          Hi Anso,
          Sorry for this unrelated question.

          I've used this part before, but stucked with one problem:
                      if ($dircont = scandir($thisdir)) {
                          $i = 0;
                          while (isset($dircont[$i])) {
                              if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
                                  $current_file = "{$thisdir}/{$dircont[$i]}";
                                  if (is_file($current_file)) {
                                      $path[] = "";
                                  } elseif (is_dir($current_file)) {
                                      $path[] = "{$thisdir}/{$dircont[$i]}";
                                      $stack[] = $current_file;
                                  }
                              }
                              $i++;
                          }
                      }
          


          My question is, how do you sort the contents?
            Rico
            Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
            MODx is great, but knowing how to use it well makes it perfect!

            www.virtudraft.com

            Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

            Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

            Maintainter/contributor of Babel

            Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
            • 1778
            • 659 Posts
            Hi Goldsky,
            To be honest I don't sort it, the scan dir scan the dir as it is 'natively' sorted (generally alphabetically) I don't apply any kind of sort... But it's an interesting question, I did not try but I guess you can 'sort' the table $path once is filled (something like sort($path) )... To be tested...
            Cheers
              • 1778
              • 659 Posts
              Goldsky,

              I made a quick test and a simple "sort($path[])" (or "asort($path[])" if your $path array is indexed - mine is not - and you want to preserve indexes) after the "while" loop and the if do the trick and sort the array...
              Have swing
              Cheers
                • 11055 ☆ A M B ☆
                • 3,112 Posts
                cool, thanks.
                just like what i thought.
                  Rico
                  Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                  MODx is great, but knowing how to use it well makes it perfect!

                  www.virtudraft.com

                  Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                  Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                  Maintainter/contributor of Babel

                  Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Plenty of array sorting functions in PHP you can use.. you can also use usort($array,'nameoffunction') to apply your own logic. Often use that to sort on a specific item in a multi dimensional array.

                  Thanks for sharing Anso!
                    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.