]> git.mjollnir.org Git - moodle.git/commitdiff
Clicking on a template tag e.g. [[field_name]] now adds the template tag to
authorvyshane <vyshane>
Tue, 14 Mar 2006 05:32:41 +0000 (05:32 +0000)
committervyshane <vyshane>
Tue, 14 Mar 2006 05:32:41 +0000 (05:32 +0000)
the HTMLArea editor in the template views. This is not currently working in
source code mode of the editor.

Added equivalent of use_html_editor() and print_editor_config() from
/lib/weblib.php to textarea field class. We use a copy in that class instead of
calling the functions in /lib/weblib.php because we want the data module to be
compatible with Moodle 1.5. This is not ideal, but it is a necessary evil.

Updated the textarea field class to use the correct path to
/lib/editor/htmlarea/htmlarea.php.

mod/data/add.php
mod/data/field/textarea/field.class.php
mod/data/templates.php

index 40708234db20b839e6820dc7eb5f7ca3fc1516f5..d36c7303f69d25a9bba87510ab8049bd9e98a707 100755 (executable)
@@ -77,7 +77,8 @@
 
     $strdata = get_string('modulenameplural','data');
 
-    print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name", "", "", true, "", navmenu($course, $cm));
+    print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
+                        '', '', true, '', navmenu($course, $cm), '', '');
 
     print_heading(format_string($data->name));
 
index c819d7a4e740aa6b7d038633c847af0ca2664175..70ff0e0fe7fd69b3bce769ed44c9adab24629885 100755 (executable)
@@ -119,12 +119,12 @@ class data_field_textarea extends data_field_base {
         
         if ($usehtmleditor) {
             if (!empty($courseid) and isteacher($courseid)) {
-                $output .= ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php?id='. $courseid .'"></script>'."\n" : '';
+                $output .= ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea/htmlarea.php?id='. $courseid .'"></script>'."\n" : '';
             }
             else {
-                $output .= ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php"></script>'."\n" : '';
+                $output .= ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea/htmlarea.php"></script>'."\n" : '';
             }
-            $output .= ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/lang/en.php"></script>'."\n" : '';
+            $output .= ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea/lang/en.php"></script>'."\n" : '';
             $scriptcount++;
         }
 
@@ -155,31 +155,89 @@ class data_field_textarea extends data_field_base {
      * applied to that field - otherwise it will be used
      * on every textarea in the page.
      *
-     * This is basically the same as use_html_editor() in
-     * /lib/weblib.php, except that this function returns a
-     * string instead of echoing out the javascript. The
-     * reasons why /lib/weblib.php has not been modified are:
-     * 
-     * 1) So that the database module is compatible with
-     *    Moodle 1.5.x
-     * 2) The weblib will be reworked in the future use
-     *    smarty
+     * For Moodle 1.6, this is nearly exactly the same as
+     * use_html_editor() in /lib/weblib.php. For Moodle 1.5, this
+     * function is different to that in /lib/weblib.php. The
+     * reason is because we need the database module to be
+     * compatible with 1.5.
      *
      * @param string $name Form element to replace with HTMl editor by name
      */
     function use_html_editor($name='', $editorhidebuttons='') {
-        echo '<script language="javascript" type="text/javascript" defer="defer">' . "\n";
-        echo print_editor_config($editorhidebuttons, false);
+        echo '<script language="javascript" type="text/javascript" defer="defer">'."\n";
+        echo "editor = new HTMLArea('$name');\n";
+
+        echo $this->print_editor_config($editorhidebuttons);
 
         if (empty($name)) {
-            echo "\n".'HTMLArea.replaceAll(config);'."\n";
-        }
-        else {
-            echo "\nHTMLArea.replace('$name', config);\n";
+            echo "\n".'HTMLArea.replaceAll(editor.config);'."\n";
+        } else {
+            echo "\neditor.generate();\n";
         }
         echo '</script>'."\n";
     }
     
+    
+    /**
+     * Versioning issue same as above.
+     */
+     function print_editor_config($editorhidebuttons='', $return=false) {
+         global $CFG;
+
+         $str = "var config = editor.config;\n";
+         $str .= "config.pageStyle = \"body {";
+
+         if (!(empty($CFG->editorbackgroundcolor))) {
+             $str .= " background-color: $CFG->editorbackgroundcolor;";
+         }
+
+         if (!(empty($CFG->editorfontfamily))) {
+             $str .= " font-family: $CFG->editorfontfamily;";
+         }
+
+         if (!(empty($CFG->editorfontsize))) {
+             $str .= " font-size: $CFG->editorfontsize;";
+         }
+
+         $str .= " }\";\n";
+         $str .= "config.killWordOnPaste = ";
+         $str .= (empty($CFG->editorkillword)) ? "false":"true";
+         $str .= ';'."\n";
+         $str .= 'config.fontname = {'."\n";
+
+         $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array();
+         $i = 1;                     // Counter is used to get rid of the last comma.
+
+         foreach ($fontlist as $fontline) {
+             if (!empty($fontline)) {
+                 if ($i > 1) {
+                     $str .= ','."\n";
+                 }
+                 list($fontkey, $fontvalue) = split(':', $fontline);
+                 $str .= '"'. $fontkey ."\":\t'". $fontvalue ."'";
+
+                 $i++;
+             }
+         }
+         $str .= '};';
+
+         if (!empty($editorhidebuttons)) {
+             $str .= "\nconfig.hideSomeButtons(\" ". $editorhidebuttons ." \");\n";
+         } else if (!empty($CFG->editorhidebuttons)) {
+             $str .= "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n";
+         }
+
+         if (!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) {
+             $str .= print_speller_code($usehtmleditor=true, true);
+         }
+
+         if ($return) {
+             return $str;
+         }
+         echo $str;
+     }
+    
+    
 
     function display_edit_field($id, $mode=0) {
         parent::display_edit_field($id, $mode);
index 8f4e0fce43f3fc547e5dc63d5d39a3e90c453d61..c81910d8d1b6ed3c5fed3b5b66a5d120fdee11a0 100755 (executable)
@@ -25,7 +25,7 @@
     require_once('../../config.php');
     require_once('lib.php');
     require_once($CFG->libdir.'/blocklib.php');
-
+    
     require_login();
 
     $id    = optional_param('id', 0, PARAM_INT);  // course module id
 /// Print the page header
 
     $strdata = get_string('modulenameplural','data');
-
-    print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name", "", "", true, "", navmenu($course, $cm));
-
+    
+    print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
+                        '', '', true, '', navmenu($course, $cm), '', '');
+    
     print_heading(format_string($data->name));
     
      ///processing submitted data, i.e updating form
     if (empty($data->addtemplate) and empty($data->singletemplate) and empty($data->listtemplate) and empty($data->rsstemplate)){
         echo '<div align="center"><input type="submit" name="allforms" value="'.get_string('autogenallforms','data').'" /></div>';
     }
-    
+        
     print_simple_box_start('center','80%');
     echo '<table><tr><td colspan="2">';
 
     echo get_string('availabletags','data');
     helpbutton('tags', get_string('tags','data'), 'data');
     echo '</td></tr><tr><td valign="top">';
-    echo '<select name="fields1[]" size="10" onclick="insertAtCursor(document.tempform.template, this.options[selectedIndex].value)">';    //the insertAtCursor thing only works when editting in plain text =(
-    if ($fields = get_records('data_fields','dataid',$data->id)){
-        foreach ($fields as $field) {
-            echo '<option value="[['.$field->name.']]">'.$field->name.' ('. get_string($field->type, 'data'). ')</option>';
-        }
+    
+    echo '<select name="fields1[]" size="10" ';
+    echo 'onclick="';
+    //echo 'alert(editor._editMode); ';
+    echo 'if (editor._editMode == \'wysiwyg\') {';
+    echo '    editor.insertHTML(this.options[selectedIndex].value); ';     // HTMLArea-specific.
+    echo '} else {';
+    echo 'insertAtCursor(\'document.tempform.template\', this.options[selectedIndex].value);';   // Hack for inserting when in HTMLArea code view or for normal textareas.
+    echo '}">';
+    
+    foreach ($fields as $field) {
+        echo '<option value="[['.$field->name.']]">'.$field->name.' ('. get_string($field->type, 'data'). ')</option>';
     }
+    
     //print special tags
     echo '<option value="##edit##">##' .get_string('edit', 'data'). '##</option>';
     echo '<option value="##more##">##' .get_string('more', 'data'). '##</option>';
     print_simple_box_end();
     echo '</form>';
     if ($usehtmleditor) {
-        use_html_editor('template');
+        use_html_editor('template');        
         if ($mode == 'listtemplate'){
             use_html_editor('listtemplateheader');
             use_html_editor('listtemplatefooter');