]> git.mjollnir.org Git - moodle.git/commitdiff
"FORMSLIB,EDITOR/MDL-16698, add filepicker to editor element"
authordongsheng <dongsheng>
Wed, 18 Feb 2009 02:18:06 +0000 (02:18 +0000)
committerdongsheng <dongsheng>
Wed, 18 Feb 2009 02:18:06 +0000 (02:18 +0000)
lib/form/editor.php
lib/javascript.php
repository/javascript.php

index 509b3de298590d01cf42308e6041a77bb5432e4a..46afcae474b35d8990f79f97a00cb98a25af1c24 100644 (file)
@@ -2,7 +2,6 @@
 
 require_once('HTML/QuickForm/element.php');
 
-
 //TODO:
 //  * locking
 //  * freezing
@@ -104,7 +103,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
     }
 
     function toHtml() {
-        global $CFG;
+        global $CFG, $COURSE;
 
         if ($this->_flagFrozen) {
             return $this->getFrozenHtml();
@@ -178,21 +177,36 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
             $str .= '<object type="text/html" data="'.$editorurl.'" height="160" width="600" style="border:1px solid #000">Error</object>'; // TODO: localise, fix styles, etc.
             $str .= '</div>';
 
-       /// TODO: somehow pass 'itemid' to tinymce so that image chooser known where to look for and upload files,
-       //        also include list of expected file types handled by editor array('image', 'video', 'media')
-            // JS code by Dongsheng goes here - uncomment following block when finished
-
-      /// TODO: hide embedded file manager if tinymce used
-/*            if ($editorclass === 'form-textarea-advanced') {
-                $str .= '<script type="text/javascript">
+        require_once($CFG->dirroot.'/repository/lib.php');
+        if(empty($COURSE->context)) {
+            $ctx = get_context_instance(CONTEXT_SYSTEM);
+        } else {
+            $ctx = $COURSE->context;
+        }
+        $ret = repository_get_client($ctx, array('image', 'video', 'media'), '*');
+
+        $suffix = $ret['suffix'];
+        $str .= $ret['css'].$ret['js'];
+        $str .= <<<EOD
+<script type="text/javascript">
+id2suffix['$id']='$suffix';
+id2itemid['$id']='$draftitemid';
+</script>
+EOD;
+
+        /// TODO: hide embedded file manager if tinymce used
+        if ($editorclass === 'form-textarea-advanced') {
+            $str .= <<<EOD
+<script type="text/javascript">
 //<![CDATA[
-    var fileman = document.getElementById("'.$id.'_filemanager");
-    fileman.style.visibility = "hidden";
-    fileman.style.height = "0";
+var fileman = document.getElementById("{$id}_filemanager");
+fileman.style.visibility = "hidden";
+fileman.style.height = "0";
 //]]>
-</script>';
+</script>
+EOD;
 
-            }*/
+            }
         }
 
 
index a691468e363a9a3caa33059e4ac6a39be0c54cb7..776392ce4e36c8a2ccfe5353ed7f8051517502a0 100644 (file)
@@ -29,6 +29,7 @@ setTimeout('fix_column_widths()', 20);
 <script type="text/javascript">
 //<![CDATA[
 var id2suffix = {};
+var id2itemid = {};
 <?php
 if (!empty($focus)) {
     if(($pos = strpos($focus, '.')) !== false) {
index 2e154c7980776b0386ca43fc1126b3378dc8fb92..3f38fddcacb517e086b634c0a9b48d9f8b9d7d2f 100644 (file)
@@ -491,6 +491,12 @@ _client.viewfiles = function() {
         _client.viewthumb();
     }
 }
+_client.print_msg = function(msg) {
+    _client.print_header();
+    var panel = new YAHOO.util.Element('panel-$suffix');
+    panel.get('element').innerHTML += msg;
+    _client.print_footer();
+}
 _client.print_header = function() {
     var panel = new YAHOO.util.Element('panel-$suffix');
     var str = '<div id="fp-header-$suffix">';
@@ -1046,6 +1052,8 @@ success: function(o) {
      _client.ds = data;
      if(!data) {
          return;
+     }else if(data.msg){
+         _client.print_msg(data.msg);
      }else if(data.iframe) {
          _client.viewiframe();
      }else if(data.login) {
@@ -1116,6 +1124,8 @@ function openpicker_$suffix(params) {
         repository_client_$suffix.target = params.target;
         if(params.itemid){
             repository_client_$suffix.itemid = params.itemid;
+        } else if(tinyMCE && id2itemid[tinyMCE.selectedInstance.editorId]){
+            repository_client_$suffix.itemid = id2itemid[tinyMCE.selectedInstance.editorId];
         }
         repository_client_$suffix.instance = new repository_client_$suffix();
         repository_client_$suffix.instance.create_picker();