. /** * Rendering of files viewer related widgets. * * @package theme_bootstrap * @copyright 2012 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . "/files/renderer.php"); class theme_bootstrap_core_files_renderer extends core_files_renderer { /** * Returns html for displaying one file manager * * The main element in HTML must have id="filemanager-{$client_id}" and * class="filemanager fm-loading"; * After all necessary code on the page (both html and javascript) is loaded, * the class fm-loading will be removed and added class fm-loaded; * The main element (class=filemanager) will be assigned the following classes: * 'fm-maxfiles' - when filemanager has maximum allowed number of files; * 'fm-nofiles' - when filemanager has no files at all (although there might be folders); * 'fm-noitems' - when current view (folder) has no items - neither files nor folders; * 'fm-updating' - when current view is being updated (usually means that loading icon is to be displayed); * 'fm-nomkdir' - when 'Make folder' action is unavailable (empty($fm->options->subdirs) == true) * * Element with class 'filemanager-container' will be holding evens for dnd upload (dragover, etc.). * It will have class: * 'dndupload-ready' - when a file is being dragged over the browser * 'dndupload-over' - when file is being dragged over this filepicker (additional to 'dndupload-ready') * 'dndupload-uploading' - during the upload process (note that after dnd upload process is * over, the file manager will refresh the files list and therefore will have for a while class * fm-updating. Both waiting processes should look similar so the images don't jump for user) * * If browser supports Drag-and-drop, the body element will have class 'dndsupported', * otherwise - 'dndnotsupported'; * * Element with class 'fp-content' will be populated with files list; * Element with class 'fp-btn-add' will hold onclick event for adding a file (opening filepicker); * Element with class 'fp-btn-mkdir' will hold onclick event for adding new folder; * Element with class 'fp-btn-download' will hold onclick event for download action; * * Element with class 'fp-path-folder' is a template for one folder in path toolbar. * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully. * Parent element will receive class 'empty' when there are no folders to be displayed; * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name; * * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode * can be changed or not; * Inside element with class 'fp-viewbar' there are expected elements with classes * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch * between the view modes, the last clicked element will have the class 'checked'; * * @param form_filemanager $fm * @return string */ private function fm_print_generallayout($fm) { global $OUTPUT; $options = $fm->options; $client_id = $options->client_id; $straddfile = get_string('addfile', 'repository'); $strmakedir = get_string('makeafolder', 'moodle'); $strdownload = get_string('downloadfolder', 'repository'); $strloading = get_string('loading', 'repository'); $strdroptoupload = get_string('droptoupload', 'moodle'); $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).''; $restrictions = $this->fm_print_restrictions($fm); $strdndnotsupported = get_string('dndnotsupported_insentence', 'moodle').$OUTPUT->help_icon('dndnotsupported'); $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle'); $loading = get_string('loading', 'repository'); $html = '
'.$restrictions.' - '.$strdndnotsupported.'
'.$icon_progress.'
'.$strdndenabledinbox.'
'.$strdroptoupload.'
'.$icon_progress.'
'.$icon_progress.'
'; return $html; } /** * FileManager JS template for displaying one file in 'icon view' mode. * * Except for elements described in fp_js_template_iconfilename, this template may also * contain element with class 'fp-contextmenu'. If context menu is available for this * file, the top element will receive the additional class 'fp-hascontextmenu' and * the element with class 'fp-contextmenu' will hold onclick event for displaying * the context menu. * * @see fp_js_template_iconfilename() * @return string */ private function fm_js_template_iconfilename() { $rv = '
'.$this->pix_icon('i/menu', '▶').'
'; return $rv; } /** * FileManager JS template for displaying file name in 'table view' and 'tree view' modes. * * Except for elements described in fp_js_template_listfilename, this template may also * contain element with class 'fp-contextmenu'. If context menu is available for this * file, the top element will receive the additional class 'fp-hascontextmenu' and * the element with class 'fp-contextmenu' will hold onclick event for displaying * the context menu. * * @todo MDL-32736 remove onclick="return false;" * @see fp_js_template_listfilename() * @return string */ private function fm_js_template_listfilename() { $rv = ' '.$this->pix_icon('i/menu', '▶').' '; return $rv; } /** * FileManager JS template for displaying 'Make new folder' dialog. * * Must be wrapped in an element, CSS for this element must define width and height of the window; * * Must have one input element with type="text" (for users to enter the new folder name); * * content of element with class 'fp-dlg-curpath' will be replaced with current path where * new folder is about to be created; * elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events; * * @return string */ private function fm_js_template_mkdir() { $rv = ' '; return $rv; } /** * FileManager JS template for error/info message displayed as a separate popup window. * * @see fp_js_template_message() * @return string */ private function fm_js_template_message() { return $this->fp_js_template_message(); } /** * FileManager JS template for window with file information/actions. * * All content must be enclosed in one element, CSS for this class must define width and * height of the window; * * Thumbnail image will be added as content to the element with class 'fp-thumbnail'; * * Inside the window the elements with the following classnames must be present: * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be * one input element (or select in case of fp-license and fp-path). They may also have labels. * The elements will be assign with class 'uneditable' and input/select element will become * disabled if they are not applicable for the particular file; * * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated', * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if * information is unavailable. If there is information available, the content of embedded * element with class 'fp-value' will be substituted with the value; * * The value of Original ('fp-original') is loaded in separate request. When it is applicable * but not yet loaded the 'fp-original' element receives additional class 'fp-loading'; * * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it * is applicable but not yet loaded the 'fp-original' element receives additional class * 'fp-loading'. The string explaining that XX references exist will replace content of element * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in
  • ; * * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip', * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick * events (there may be several elements with class 'fp-file-cancel'); * * When confirm button is pressed and file is being selected, the top element receives * additional class 'loading'. It is removed when response from server is received. * * When any of the input fields is changed, the top element receives class 'fp-changed'; * When current file can be set as main - top element receives class 'fp-cansetmain'; * When current file is folder/zip/file - top element receives respectfully class * 'fp-folder'/'fp-zip'/'fp-file'; * * @return string */ private function fm_js_template_fileselectlayout() { global $OUTPUT; $strloading = get_string('loading', 'repository'); $iconprogress = $this->pix_icon('i/loading_small', $strloading).''; $rv = '
    '.$OUTPUT->help_icon('setmainfile', 'repository').'
    '.$iconprogress.' '.$strloading.'

    '.$iconprogress.' '.$strloading.'

      '.get_string('lastmodified', 'moodle').':
      '.get_string('datecreated', 'repository').'
      '.get_string('size', 'repository').'
      '.get_string('dimensions', 'repository').'
      '; return $rv; } /** * FileManager JS template for popup confirm dialogue window. * * Must have one top element, CSS for this element must define width and height of the window; * * content of element with class 'fp-dlg-text' will be replaced with dialog text; * elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will * hold onclick events; * * @return string */ private function fm_js_template_confirmdialog() { $rv = '
      '; return $rv; } /** * Returns all FileManager JavaScript templates as an array. * * @return array */ public function filemanager_js_templates() { $class_methods = get_class_methods($this); $templates = array(); foreach ($class_methods as $method_name) { if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches)) $templates[$matches[1]] = $this->$method_name(); } return $templates; } /** * Template for FilePicker with general layout (not QuickUpload). * * Must have one top element containing everything else (recommended
      ), * CSS for this element must define width and height of the filepicker window. Or CSS must * define min-width, max-width, min-height and max-height and in this case the filepicker * window will be resizeable; * * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode * can be changed or not; * Inside element with class 'fp-viewbar' there are expected elements with classes * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch * between the view modes, the last clicked element will have the class 'checked'; * * Element with class 'fp-repo' is a template for displaying one repository. Other repositories * will be attached as siblings (classes first/last/even/odd will be added respectfully). * The currently selected repostory will have class 'active'. Contents of element with class * 'fp-repo-name' will be replaced with repository name, source of image with class * 'fp-repo-icon' will be replaced with repository icon; * * Element with class 'fp-content' is obligatory and will hold the current contents; * * Element with class 'fp-paging' will contain page navigation (will be deprecated soon); * * Element with class 'fp-path-folder' is a template for one folder in path toolbar. * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully. * Parent element will receive class 'empty' when there are no folders to be displayed; * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name; * * Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh', * 'Logout', 'Manage' and 'Help' are unavailable for this repo; * * Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search, * fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have * class 'enabled' or 'disabled' if particular repository has this functionality. * Element with class 'fp-tb-search' must contain empty form inside, it's contents will * be substituted with the search form returned by repository (in the most cases it * is generated with template core_repository_renderer::repository_default_searchform); * Other elements must have either or

      '.get_string('lastmodified', 'moodle').':
      '.get_string('datecreated', 'repository').'
      '.get_string('size', 'repository').'
      '.get_string('license', 'moodle').'
      '.get_string('author', 'repository').'
      '.get_string('dimensions', 'repository').'
      '; return $rv; } /** * FilePicker JS template for 'Upload file' repository * * Content to display when user chooses 'Upload file' repository (will be nested inside * element with class 'fp-content'). * * Must contain form (enctype="multipart/form-data" method="POST") * * The elements with the following classnames must be present: * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have * one input element (or select in case of fp-setlicense). They may also have labels. * * Element with class 'fp-upload-btn' will hold onclick event for uploading the file; * * Please note that some fields may be hidden using CSS if this is part of quickupload form * * @return string */ private function fp_js_template_uploadform() { $rv = '
      '; return $rv; } /** * FilePicker JS template to display during loading process (inside element with class 'fp-content'). * * @return string */ private function fp_js_template_loading() { return '
      '; } /** * FilePicker JS template for error (inside element with class 'fp-content'). * * must have element with class 'fp-error', its content will be replaced with error text * and the error code will be assigned as additional class to this element * used errors: invalidjson, nofilesavailable, norepositoriesavailable * * @return string */ private function fp_js_template_error() { $rv = '
      '; return $rv; } /** * FilePicker JS template for error/info message displayed as a separate popup window. * * Must be wrapped in one element, CSS for this element must define * width and height of the window. It will be assigned with an additional class 'fp-msg-error' * or 'fp-msg-info' depending on message type; * * content of element with class 'fp-msg-text' will be replaced with error/info text; * * element with class 'fp-msg-butok' will hold onclick event * * @return string */ private function fp_js_template_message() { $rv = '

      '; return $rv; } /** * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists. * * Must have one top element, CSS for this element must define width and height of the window; * * content of element with class 'fp-dlg-text' will be replaced with dialog text; * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename', * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will * hold onclick events; * * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string * (Note that it may have long text) * * @return string */ private function fp_js_template_processexistingfile() { $rv = '

      '; return $rv; } /** * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version). * * Must have one top element, CSS for this element must define width and height of the window; * * content of element with class 'fp-dlg-text' will be replaced with dialog text; * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will * hold onclick events; * * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string * (Note that it may have long text) * * @return string */ private function fp_js_template_processexistingfilemultiple() { $rv = ' '; return $rv; } /** * FilePicker JS template for repository login form including templates for each element type * * Must contain one
      element with templates for different input types inside: * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and * 'fp-login-input' are templates for displaying respective login form elements. Inside * there must be exactly one element with type
      '; return $rv; } /** * Returns all FilePicker JavaScript templates as an array. * * @return array */ public function filepicker_js_templates() { $class_methods = get_class_methods($this); $templates = array(); foreach ($class_methods as $method_name) { if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches)) $templates[$matches[1]] = $this->$method_name(); } return $templates; } }