Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of the customcert module for Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * This file contains the form element for handling the colour picker.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2013 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
26
 
27
require_once($CFG->dirroot . '/lib/form/editor.php');
28
 
29
/**
30
 * Form element for handling the colour picker.
31
 *
32
 * @package    mod_customcert
33
 * @copyright  2013 Mark Nelson <markn@moodle.com>
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class moodlequickform_customcert_colourpicker extends moodlequickform_editor {
37
 
38
    /**
39
     * Sets the value of the form element
40
     *
41
     * @param string $value
42
     */
43
    public function setvalue($value) {
44
        $this->updateAttributes(['value' => $value]);
45
    }
46
 
47
    /**
48
     * Gets the value of the form element
49
     */
50
    public function getvalue() {
51
        return $this->getAttribute('value');
52
    }
53
 
54
    /**
55
     * Returns the html string to display this element.
56
     *
57
     * @return string
58
     */
59
    public function tohtml() {
60
        global $PAGE, $OUTPUT;
61
 
62
        $PAGE->requires->js_init_call('M.util.init_colour_picker', [$this->getAttribute('id'), null]);
63
        $content = '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>';
64
        $content .= html_writer::start_tag('div', ['class' => 'form-colourpicker defaultsnext']);
65
        $content .= html_writer::tag('div', $OUTPUT->pix_icon('i/loading', get_string('loading', 'admin'), 'moodle',
66
            ['class' => 'loadingicon']), ['class' => 'admin_colourpicker clearfix']);
67
        $content .= html_writer::empty_tag('input', ['type' => 'text', 'id' => $this->getAttribute('id'),
68
            'name' => $this->getName(), 'value' => $this->getValue(), 'size' => '12']);
69
        $content .= html_writer::end_tag('div');
70
 
71
        return $content;
72
    }
73
 
74
    /**
75
     * Function to export the renderer data in a format that is suitable for a mustache template.
76
     *
77
     * @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
78
     * @return \stdClass|array
79
     */
80
    public function export_for_template(renderer_base $output) {
81
        $context = $this->export_for_template_base($output);
82
        $context['html'] = $this->toHtml();
83
 
84
        return $context;
85
    }
86
}