"MDL-15405, perform filemanager init tasks in one function"
authorDongsheng Cai <unoter@gmail.com>
Mon, 8 Mar 2010 03:37:20 +0000 (03:37 +0000)
committerDongsheng Cai <unoter@gmail.com>
Mon, 8 Mar 2010 03:37:20 +0000 (03:37 +0000)
lib/form/filemanager.php

index b67406b..270b0fc 100644 (file)
@@ -125,35 +125,6 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
         $draftitemid = $this->getValue();
         $accepted_types = $this->_options['accepted_types'];
 
-        // language strings
-        $straddfile  = get_string('add', 'repository') . '...';
-        $strmakedir  = get_string('makeafolder', 'moodle');
-        $strdownload  = get_string('downloadfolder', 'repository');
-
-
-        $PAGE->requires->string_for_js('loading', 'repository');
-        $PAGE->requires->string_for_js('nomorefiles', 'repository');
-        $PAGE->requires->string_for_js('confirmdeletefile', 'repository');
-        $PAGE->requires->string_for_js('add', 'repository');
-        $PAGE->requires->string_for_js('accessiblefilepicker', 'repository');
-        $PAGE->requires->string_for_js('move', 'moodle');
-        $PAGE->requires->string_for_js('cancel', 'moodle');
-        $PAGE->requires->string_for_js('download', 'moodle');
-        $PAGE->requires->string_for_js('ok', 'moodle');
-        $PAGE->requires->string_for_js('emptylist', 'repository');
-        $PAGE->requires->string_for_js('entername', 'repository');
-        $PAGE->requires->string_for_js('enternewname', 'repository');
-        $PAGE->requires->string_for_js('zip', 'editor');
-        $PAGE->requires->string_for_js('unzip', 'moodle');
-        $PAGE->requires->string_for_js('rename', 'moodle');
-        $PAGE->requires->string_for_js('delete', 'moodle');
-        $PAGE->requires->string_for_js('setmainfile', 'resource');
-        $PAGE->requires->string_for_js('cannotdeletefile', 'error');
-        $PAGE->requires->string_for_js('confirmdeletefile', 'repository');
-        $PAGE->requires->string_for_js('nopathselected', 'repository');
-        $PAGE->requires->string_for_js('popupblockeddownload', 'repository');
-        $PAGE->requires->string_for_js('path', 'moodle');
-
         if (empty($draftitemid)) {
             // no existing area info provided - let's use fresh new draft area
             require_once("$CFG->libdir/filelib.php");
@@ -165,14 +136,13 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
         $filecount = $draftareainfo['filecount'];
         $client_id = uniqid();
 
-        $args = new stdclass;
-        // need these three to filter repositories list
-        $args->accepted_types = $accepted_types;
-        $args->return_types = FILE_INTERNAL;
-        $args->context = $PAGE->context;
-        $args->env = 'filemanager';
+        $params = new stdclass;
+        $params->accepted_types = $accepted_types;
+        $params->return_types = FILE_INTERNAL;
+        $params->context = $PAGE->context;
+        $params->env = 'filemanager';
 
-        $filepicker_options = initialise_filepicker($args);
+        $filepicker_options = initialise_filepicker($params);
 
         $filepicker_options->client_id = $client_id;
         $filepicker_options->maxbytes = $this->_options['maxbytes'];
@@ -180,9 +150,6 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
         $filepicker_options->env      = 'filemanager';
         $filepicker_options->itemid   = $draftitemid;
 
-        // Generate file picker
-        $result = new stdclass;
-
         $options = file_get_draft_area_files($draftitemid);
         $options->mainfile  = $this->_options['mainfile'];
         $options->maxbytes  = $this->getMaxbytes();
@@ -196,44 +163,9 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
         $options->target    = $id;
 
         $html = $this->_getTabs();
+        $html .= '<input value="'.$draftitemid.'" name="'.$elname.'" type="hidden" />';
+        $html .= print_filemanager($options, true);
 
-        
-        $module = array('name'=>'form_filemanager', 'fullpath'=>'/lib/form/filemanager.js', 'requires' => array('core_filepicker', 'base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'));
-        $PAGE->requires->js_module($module);
-        $PAGE->requires->js_init_call('M.form_filemanager.init', array($options), true, $module);
-
-        // print out this only once
-        if (empty($CFG->filemanagertemplateloaded)) {
-            $CFG->filemanagertemplateloaded = true;
-            $html .= <<<FMHTML
-<div id="fm-template" style="display:none"><div class="fm-file-menu">___action___</div> <div class="fm-file-name">___fullname___</div></div>
-FMHTML;
-        }
-
-        $html .= <<<FMHTML
-<input value="$draftitemid" name="{$elname}" type="hidden" />
-<div id="filemanager-wrapper-{$client_id}" style="display:none">
-    <div class="fm-breadcrumb" id="fm-path-{$client_id}"></div>
-    <div class="filemanager-toolbar">
-        <button id="btnadd-{$client_id}" onclick="return false">{$straddfile}</button>
-        <button id="btncrt-{$client_id}" onclick="return false">{$strmakedir}</button>
-        <button id="btndwn-{$client_id}" onclick="return false">{$strdownload}</button>
-    </div>
-    <div class="filemanager-container" id="filemanager-{$client_id}">
-        <ul id="draftfiles-{$client_id}">
-            <li>Loading...</li>
-        </ul>
-    </div>
-</div>
-FMHTML;
-        // non-javascript file manager, will be destroied automatically if javascript is enabled.
-        // will be removed if javascript is enabled
-        $editorurl = "$CFG->wwwroot/repository/filepicker.php?env=filemanager&amp;action=embedded&amp;itemid=$draftitemid&amp;subdirs=/&amp;maxbytes=$options->maxbytes&amp;ctx_id=".$PAGE->context->id.'&amp;course='.$PAGE->course->id;
-        $html .= <<<NONJS
-<div id="nonjs-filemanager-$client_id">
-<object type="text/html" data="$editorurl" height="160" width="600" style="border:1px solid #000">Error</object>
-</div>
-NONJS;
         return $html;
     }
 }