/
edit_easyonamejs_form.php
109 lines (108 loc) · 5.29 KB
/
edit_easyonamejs_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the editing form for the easyonamejs question type.
*
* @package qtype
* @subpackage easyonamejs
* @copyright 2014 and onward Carl LeBlond
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/type/shortanswer/edit_shortanswer_form.php');
class qtype_easyonamejs_edit_form extends qtype_shortanswer_edit_form {
protected function definition_inner($mform) {
global $PAGE, $CFG;
$PAGE->requires->css('/question/type/easyonamejs/easyonamejs_styles.css');
$marvinjsconfig = get_config('qtype_easyonamejs_options');
$marvinjspath = $marvinjsconfig->path;
$protocol = (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off') ? 'http://' : 'https://';
$PAGE->requires->js(new moodle_url($protocol . $_SERVER['HTTP_HOST'] . $marvinjspath . '/js/promise-0.1.1.min.js'));
$PAGE->requires->js(new moodle_url($protocol . $_SERVER['HTTP_HOST'] . $marvinjspath . '/js/marvinjslauncher.js'));
$mform->addElement('static', 'answersinstruct',
get_string('correctanswers', 'qtype_easyonamejs'), get_string('filloutoneanswer', 'qtype_easyonamejs'));
$mform->closeHeaderBefore('answersinstruct');
$mform->addElement('html', html_writer::start_tag('div', array(
// 'style' => 'width:650px;',
'class' => 'easyonamejs resizable',
'id' => 'appletdiv'
)));
$mform->addElement('html', html_writer::start_tag('div', array(
'style' => 'float: left;font-style: italic ;'
)));
$mform->addElement('html', html_writer::start_tag('small'));
$easyonamejshomeurl = 'http://www.chemaxon.com';
$mform->addElement('html', html_writer::link($easyonamejshomeurl, get_string('easyonamejseditor', 'qtype_easyonamejs')));
$mform->addElement('html', html_writer::empty_tag('br'));
$mform->addElement('html', html_writer::tag('span', get_string('author', 'qtype_easyonamejs'), array(
'class' => 'easyonamejsauthor'
)));
$mform->addElement('html', html_writer::end_tag('small'));
$mform->addElement('html', html_writer::end_tag('div'));
$mform->addElement('html', html_writer::end_tag('div'));
$marvinconfig = get_config('qtype_easyonamejs_options');
$marvinpath = $marvinconfig->path;
$PAGE->requires->js_init_call('M.qtype_easyonamejs.insert_applet', array(
$CFG->wwwroot,
$marvinpath
));
$this->add_per_answer_fields($mform,
get_string('answerno', 'qtype_easyonamejs', '{no}'), question_bank::fraction_options());
$this->add_interactive_settings();
$PAGE->requires->js_init_call('M.qtype_easyonamejs.init_getanswerstring', array(
$CFG->version
));
$PAGE->requires->js_init_call('M.qtype_easyonamejs.init_viewanswerstring', array(
$CFG->version
));
$PAGE->requires->js_init_call('M.qtype_easyonamejs.init_viewanswerstring', array(
$CFG->version
));
}
protected function get_per_answer_fields($mform, $label, $gradeoptions,
&$repeatedoptions, &$answersoption) {
$repeated = array();
$answeroptions = array();
$answeroptions[] = $mform->createElement('textarea', 'answer',
$label, array('row' => 1));
$answeroptions[] = $mform->createElement('select', 'fraction',
get_string('grade'), $gradeoptions);
$repeated[] = $mform->createElement('group', 'answeroptions',
$label, $answeroptions, null, false);
$repeated[] = $mform->createElement('editor', 'feedback',
get_string('feedback', 'question'), array('rows' => 5), $this->editoroptions);
$repeatedoptions['answer']['type'] = PARAM_RAW;
$repeatedoptions['fraction']['default'] = 0;
$answersoption = 'answers';
$scriptattrs = 'class = id_insert';
$viewbutton = $mform->createElement('button', 'view',
get_string('view', 'qtype_easyonamejs'), 'class = id_view');
array_splice($repeated, 1, 0, array($viewbutton));
$insertbutton = $mform->createElement('button', 'insert',
get_string('insertfromeditor', 'qtype_easyonamejs'), $scriptattrs);
array_splice($repeated, 1, 0, array(
$insertbutton
));
return $repeated;
}
protected function data_preprocessing($question) {
$question = parent::data_preprocessing($question);
return $question;
}
public function qtype() {
return 'easyonamejs';
}
}