From d02d1380707bdaf807181c1c1d8f449e3c1b6db2 Mon Sep 17 00:00:00 2001 From: vyshane Date: Tue, 14 Mar 2006 05:32:41 +0000 Subject: [PATCH] Clicking on a template tag e.g. [[field_name]] now adds the template tag to 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 | 3 +- mod/data/field/textarea/field.class.php | 94 ++++++++++++++++++++----- mod/data/templates.php | 31 +++++--- 3 files changed, 98 insertions(+), 30 deletions(-) diff --git a/mod/data/add.php b/mod/data/add.php index 40708234db..d36c7303f6 100755 --- a/mod/data/add.php +++ b/mod/data/add.php @@ -77,7 +77,8 @@ $strdata = get_string('modulenameplural','data'); - print_header_simple($data->name, "", "$strdata -> $data->name", "", "", true, "", navmenu($course, $cm)); + print_header_simple($data->name, '', "$strdata -> $data->name", + '', '', true, '', navmenu($course, $cm), '', ''); print_heading(format_string($data->name)); diff --git a/mod/data/field/textarea/field.class.php b/mod/data/field/textarea/field.class.php index c819d7a4e7..70ff0e0fe7 100755 --- a/mod/data/field/textarea/field.class.php +++ b/mod/data/field/textarea/field.class.php @@ -119,12 +119,12 @@ class data_field_textarea extends data_field_base { if ($usehtmleditor) { if (!empty($courseid) and isteacher($courseid)) { - $output .= ($scriptcount < 1) ? ''."\n" : ''; + $output .= ($scriptcount < 1) ? ''."\n" : ''; } else { - $output .= ($scriptcount < 1) ? ''."\n" : ''; + $output .= ($scriptcount < 1) ? ''."\n" : ''; } - $output .= ($scriptcount < 1) ? ''."\n" : ''; + $output .= ($scriptcount < 1) ? ''."\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 ''."\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); diff --git a/mod/data/templates.php b/mod/data/templates.php index 8f4e0fce43..c81910d8d1 100755 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -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 @@ -71,9 +71,10 @@ /// Print the page header $strdata = get_string('modulenameplural','data'); - - print_header_simple($data->name, "", "$strdata -> $data->name", "", "", true, "", navmenu($course, $cm)); - + + print_header_simple($data->name, '', "$strdata -> $data->name", + '', '', true, '', navmenu($course, $cm), '', ''); + print_heading(format_string($data->name)); ///processing submitted data, i.e updating form @@ -127,7 +128,7 @@ if (empty($data->addtemplate) and empty($data->singletemplate) and empty($data->listtemplate) and empty($data->rsstemplate)){ echo '
'; } - + print_simple_box_start('center','80%'); echo '
'; @@ -135,12 +136,20 @@ echo get_string('availabletags','data'); helpbutton('tags', get_string('tags','data'), 'data'); echo '
'; - echo ''; + + foreach ($fields as $field) { + echo ''; } + //print special tags echo ''; echo ''; @@ -176,7 +185,7 @@ print_simple_box_end(); echo ''; if ($usehtmleditor) { - use_html_editor('template'); + use_html_editor('template'); if ($mode == 'listtemplate'){ use_html_editor('listtemplateheader'); use_html_editor('listtemplatefooter'); -- 2.39.5