Joachim Werner avatar Joachim Werner committed 4d20571

started working on multiple selection/batch jobs

Comments (0)

Files changed (4)

controllers/DefaultController.php

             $dir = new DDMediaDirectory($basePath.'/'.$defaultPath);
             $files = $dir->listContent();
         }
-		$this->render('index', array('mediaAction'=>$mediaAction, 'basePath'=>$basePath, 'path'=>$path, 'currentPath'=>$currentPath, 'files'=>$files, 'msg'=>$msg));
+        $this->render('index', array(
+            'mediaAction'=>$mediaAction, 
+            'basePath'=>$basePath, 
+            'path'=>$path, 
+            'currentPath'=>$currentPath, 
+            'files'=>$files, 
+            'msg'=>$msg
+        ));
     } // }}}
     // {{{ actionThumbnail
     /**
         fclose ($image);
         die;
     } // }}}
+    // {{{ getFileIconByExtension
+    /**
+     * Returns an icon filename by file extension
+     *
+     * @param string $extension Extension (e.g. 'xls', 'css', 'txt' ...)
+     * @return string Filetype icon name (e.g. 'excel.png')
+     */
     private function getFileIconByExtension($extension)
     {
         $icons = array(
             return $icons[$extension].'.png';
         else
             return 'unknown.png';
-    }
+    } // }}} 
     // }}} End Methods
 }
 // {{{ myPar

models/DDMediaAction.php

     // {{{ *** Members ***
     public $path;
     public $name;
+    public $multipleNames;
     public $oldName;
     public $mediaType;
     public $action;
         return array(
             array('path, mediaType, action','required'),
             array('action','checkActionParams'),
-            array('name, oldName, p1', 'safe'),
+            array('name, multipleNames, oldName, p1', 'safe'),
             array('uploadedFile','file','on'=>'upload'),
         );
     } // }}}
         return array(
             'path'          => Yii::t('main','Path'),
             'name'          => Yii::t('main','Name'),
+            'multipleNames' => Yii::t('main','Multiple Selection'),
             'oldName'       => Yii::t('main','Old Name'),
             'mediaType'     => Yii::t('main','Media Type'),
             'action'        => Yii::t('main','Action'),

views/default/_mediaAction.php

         <?php echo CHtml::activeTextField($model,'name') ?>
     </div>
  
+    <div class="simple" id="multipleNamesRow" style="display:none">
+        <?php echo CHtml::activeLabel($model,'multipleNames'); ?>
+        <?php echo CHtml::activeTextArea($model,'multipleNames', array( 'rows'=>5 )) ?>
+    </div>
+ 
     <div class="simple" id="nameRowDisplayOnly" style="display:none">
         <?php echo CHtml::activeLabel($model,'name'); ?>
         <?php //echo CHtml::activeHiddenField($model,'name') ?>

views/default/index.php

 <table class="media-items">
     <thead>
         <tr>
+            <th><input type="checkbox" value="" onclick="toggleAll(this.checked);" /></th>
             <th><?php echo CHtml::encode(Yii::t('main', 'Icon')); ?></th>
             <th><?php echo CHtml::encode(Yii::t('main', 'Name')); ?></th>
             <th><?php echo CHtml::encode(Yii::t('main', 'Date')); ?></th>
         <?php foreach($files['dirs'] as $dirPath=>$stats) : ?>
         <?php /* $onclick=""; if(!in_array($stats['name'],array('.', '..'))) */ $onclick=' onclick="selectMedia(\'directory\',\''.$dirPath.'\',\''.$stats['name'].'\');"'; ?>
         <tr class="dirsFilesRows"<?php echo $onclick; ?>>
+            <td>
+                <?php if(!in_array($stats['name'], array('.','..'))) : ?>
+                <input type="checkbox" name="chSelectedItem[]" value="<?php echo $stats['name']; ?>" class="chSelectedItems" />
+                <?php endif; ?>
+            </td>
             <td class="folder"><?php echo CHtml::image($this->module->assetsUrl.'/filetypeicons/folder.png',$stats['name']); ?></td>
             <td><?php echo CHtml::link($stats['name'],array('index','p'=>urlencode($path.'/'.$stats['name']))); ?></td>
             <td>&ndash;</td>
         <?php $onclick=""; if(!in_array($stats['name'],array('.', '..'))) $onclick=' onclick="selectMedia(\'file\',\''.$filePath.'\',\''.$stats['name'].'\');"'; ?>
         <tr class="dirsFilesRows"<?php echo $onclick; ?>>
             <td>
+                <?php if(!in_array($stats['name'], array('.','..'))) : ?>
+                <input type="checkbox" name="chSelectedItem[]" value="<?php echo $stats['name']; ?>" onclick="collectChSelectedItems();" class="chSelectedItems" />
+                <?php endif; ?>
+            </td>
+            <td>
 <?php
 if(preg_match("/image\/(.*)/",$stats['mimeType'],$matches))
     echo CHtml::image($this->createUrl('thumbnail',array('path'=>urlencode($stats['path']),'x'=>75)));
         </tr>
         <?php endforeach; ?>
         <!-- }}} -->
+        <!-- {{{ Batch Selection Row -->
+        <tr>
+            <td colspan="7">
+                <input type="text" name="path" value="<?php echo $path; ?>" size="20" />
+                <select name="batchAction" id="batchAction" onchange="if(this.value!=='') { doBatchJob=true; doShowDialog=true; showDialog(this.value); }">
+                    <option value="">(Batch Action)</option>
+                    <option value="move">Move</option>
+                    <option value="delete">Delete</option>
+                </select>
+            </td>
+        </tr>
+        <!-- }}} -->
     </tbody>
 </table>
 
 <!--
     var currentPath = '<?php echo $currentPath; ?>';
     var selectedItem = '.';
+    var doBatchJob=false;
     var doShowDialog=false;
+    var selectedItems=[];
+    function toggleAll(toggle)
+    {
+        $('.chSelectedItems').each( function() {
+            if(this.checked)
+                this.checked=false;
+            else
+                this.checked=true;
+        });
+    }
+    function collectChSelectedItems()
+    {
+        selectedItems = [];
+        $('.chSelectedItems').each( function() {
+            if( this.checked ) {
+                selectedItems.push( this.value );
+            }
+        });
+        jQuery('#DDMediaAction_multipleNames').val(selectedItems.join("\n"));
+    }
     // {{{ selectMedia
     function selectMedia(mediaType, path, name)
     {
         if(doShowDialog==false)
             return;
         jQuery('#mydialog').dialog('open');
-        jQuery('#mydialog').dialog({title:'<?php echo CHtml::encode(Yii::t('main', 'Item: ')); ?>'+selectedItem /* +' &rArr; '+action */ });
+        if(doBatchJob==false) {
+            jQuery('#mydialog').dialog({title:'<?php echo CHtml::encode(Yii::t('main', 'Item: ')); ?>'+selectedItem /* +' &rArr; '+action */ });
+        } else {
+            jQuery('#mydialog').dialog({title:'Multiple Selection'});
+            jQuery('#batchAction').val('');
+        }
         jQuery('#DDMediaAction_action').val(action);
         jQuery('#mediaActionSubmitButton').val('Submit');
         jQuery('.msg').html('').hide();
         jQuery('#selectedItemName').html(selectedItem);
-        jQuery('#nameRow, #nameRowDisplayOnly, #p1Row, #uploadedFileRow').hide();
+        jQuery('#nameRow, #multipleNamesRow, #nameRowDisplayOnly, #p1Row, #uploadedFileRow').hide();
         switch(action)
         {
             case 'rename':
             case 'move':
                 jQuery('#mediaActionSubmitButton').val('<?php echo CHtml::encode(Yii::t('main', 'Move')); ?>');
                 jQuery('.msg').html('<?php echo CHtml::encode(Yii::t('main', 'Enter the new location:')); ?>').show();
-                jQuery('#nameRowDisplayOnly, #p1Row').show();
+                if(doBatchJob==false) {
+                    jQuery('#nameRowDisplayOnly, #p1Row').show();
+                    jQuery('#DDMediaAction_p1').val('./'+selectedItem);
+                } else {
+                    jQuery('#multipleNamesRow, #p1Row').show();
+                    jQuery('#DDMediaAction_p1').val('./');
+                }
                 jQuery('label[for=DDMediaAction_p1]').html('<?php echo CHtml::encode(Yii::t('main', 'Destination')); ?>');
-                jQuery('#DDMediaAction_p1').val('./'+selectedItem);
                 jQuery('#DDMediaAction_p1').focus().select();
                 break;
             case 'delete':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.