mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-51036 tool_lp: Making comments work inside templates
This commit is contained in:
parent
0d1a2e71f0
commit
23381ab803
133
admin/tool/lp/classes/external/comment_area_exporter.php
vendored
Normal file
133
admin/tool/lp/classes/external/comment_area_exporter.php
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Exporting a comment area.
|
||||
*
|
||||
* A comment area is the set of information about a defined comments area.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2015 Frédéric Massart - FMCorz.net
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_lp\external;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use comment;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class for exporting a comment area.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2015 Frédéric Massart - FMCorz.net
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_area_exporter extends exporter {
|
||||
|
||||
/** @var comment The comment instance. */
|
||||
protected $comment = null;
|
||||
|
||||
public function __construct(comment $comment, $related = array()) {
|
||||
$this->comment = $comment;
|
||||
$data = new stdClass();
|
||||
$data->component = $comment->get_component();
|
||||
$data->commentarea = $comment->get_commentarea();
|
||||
$data->itemid = $comment->get_itemid();
|
||||
$data->courseid = $comment->get_courseid();
|
||||
$data->contextid = $comment->get_context()->id;
|
||||
$data->cid = $comment->get_cid();
|
||||
parent::__construct($data, $related);
|
||||
}
|
||||
|
||||
protected static function define_properties() {
|
||||
return array(
|
||||
'component' => array(
|
||||
'type' => PARAM_COMPONENT,
|
||||
),
|
||||
'commentarea' => array(
|
||||
'type' => PARAM_AREA,
|
||||
),
|
||||
'itemid' => array(
|
||||
'type' => PARAM_INT,
|
||||
),
|
||||
'courseid' => array(
|
||||
'type' => PARAM_INT,
|
||||
),
|
||||
'contextid' => array(
|
||||
'type' => PARAM_INT,
|
||||
),
|
||||
'cid' => array(
|
||||
'type' => PARAM_ALPHANUMEXT,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected static function define_other_properties() {
|
||||
return array(
|
||||
'autostart' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'canpost' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'canview' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'count' => array(
|
||||
'type' => PARAM_INT,
|
||||
),
|
||||
'collapsediconurl' => array(
|
||||
'type' => PARAM_URL,
|
||||
),
|
||||
'displaytotalcount' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'displaycancel' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'fullwidth' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'linktext' => array(
|
||||
'type' => PARAM_RAW,
|
||||
),
|
||||
'notoggle' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'template' => array(
|
||||
'type' => PARAM_RAW,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_other_values(renderer_base $output) {
|
||||
$values = array();
|
||||
$values['autostart'] = $this->comment->get_autostart();
|
||||
$values['canpost'] = $this->comment->can_post();
|
||||
$values['canview'] = $this->comment->can_view();
|
||||
$values['collapsediconurl'] = $output->pix_url(right_to_left() ? 't/collapsed_rtl' : 't/collapsed')->out(false);
|
||||
$values['count'] = $this->comment->count();
|
||||
$values['displaycancel'] = $this->comment->get_displaycancel();
|
||||
$values['displaytotalcount'] = $this->comment->get_displaytotalcount();
|
||||
$values['fullwidth'] = $this->comment->get_fullwidth();
|
||||
$values['linktext'] = $this->comment->get_linktext();
|
||||
$values['notoggle'] = $this->comment->get_notoggle();
|
||||
$values['template'] = $this->comment->get_template();
|
||||
return $values;
|
||||
}
|
||||
}
|
113
admin/tool/lp/templates/comment_area.mustache
Normal file
113
admin/tool/lp/templates/comment_area.mustache
Normal file
@ -0,0 +1,113 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template tool_lp/comment_area
|
||||
|
||||
IDs required for JS:
|
||||
* all
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Context variables required for this template:
|
||||
* autostart
|
||||
* canpost
|
||||
* cid
|
||||
* collapsediconurl
|
||||
* commentarea
|
||||
* component
|
||||
* contextid
|
||||
* count
|
||||
* courseid
|
||||
* displaycancel
|
||||
* fullwidth
|
||||
* itemid
|
||||
* linktext
|
||||
* notoggle
|
||||
* displaytotalcount
|
||||
* template
|
||||
* uniqid
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
}
|
||||
|
||||
}}
|
||||
<div style="display: none;" id="cmt-tmpl">{{{template}}}</div>
|
||||
<div class="mdl-left">
|
||||
{{^notoggle}}
|
||||
<a href="#" class="comment-link" id="comment-link-{{cid}}">
|
||||
<img src="{{{collapsediconurl}}}" id="comment-img-{{cid}}" alt="{{linktext}}" title="{{linktext}}"><span id="comment-link-text-{{cid}}">{{linktext}}
|
||||
{{#displaytotalcount}}
|
||||
({{count}})
|
||||
{{/displaytotalcount}}</span>
|
||||
</a>
|
||||
{{/notoggle}}
|
||||
|
||||
<div id="comment-ctrl-{{cid}}" class="comment-ctrl">
|
||||
<ul id="comment-list-{{cid}}" class="comment-list">
|
||||
<li class="first"></li>
|
||||
</ul>
|
||||
<div id="comment-pagination-{{cid}}" class="comment-pagination"></div>
|
||||
|
||||
{{#canpost}}
|
||||
<div class="comment-area">
|
||||
<div class="db">
|
||||
<textarea name="context" id="dlg-content-{{cid}}" rows="2" {{^fullwidth}}cols="20"{{/fullwidth}}{{#fullwidth}}class="fullwidth"{{/fullwidth}}></textarea>
|
||||
</div>
|
||||
<div class="fd" id="comment-action-{{cid}}">
|
||||
<a href="#" id="comment-action-post-{{cid}}">{{#str}}savecomment{{/str}}</a>
|
||||
{{#displaycancel}}
|
||||
| <a href="#" id="comment-action-cancel-{{cid}}">{{#str}}cancel{{/str}}</a>
|
||||
{{/displaycancel}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
{{/canpost}}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{{#js}}
|
||||
require(['core/str'], function(Str) {
|
||||
// Preloading strings.
|
||||
Str.get_strings([
|
||||
{ key: 'addcomment', component: 'moodle' },
|
||||
{ key: 'comments', component: 'moodle' },
|
||||
{ key: 'commentscount', component: 'moodle' },
|
||||
{ key: 'commentsrequirelogin', component: 'moodle' },
|
||||
{ key: 'deletecomment', component: 'moodle' },
|
||||
]).then(function() {
|
||||
// Kick off when strings are loaded.
|
||||
Y.use('core_comment', function(Y) {
|
||||
M.core_comment.init(Y, {
|
||||
client_id: '{{cid}}',
|
||||
commentarea: '{{commentarea}}',
|
||||
itemid: {{itemid}},
|
||||
page: 0,
|
||||
courseid: {{courseid}},
|
||||
contextid: {{contextid}},
|
||||
component: '{{component}}',
|
||||
notoggle: false, // {{notoggle}} True not supported just yet.
|
||||
autostart: false // {{autostart}} True not supported just yet.
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
{{/js}}
|
@ -1039,6 +1039,87 @@ class comment {
|
||||
public function set_fullwidth($fullwidth = true) {
|
||||
$this->fullwidth = (bool)$fullwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return string
|
||||
*/
|
||||
public function get_template() {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cid.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return string
|
||||
*/
|
||||
public function get_cid() {
|
||||
return $this->cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the link text.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return string
|
||||
*/
|
||||
public function get_linktext() {
|
||||
return $this->linktext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return no toggle.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return bool
|
||||
*/
|
||||
public function get_notoggle() {
|
||||
return $this->notoggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return display total count.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return bool
|
||||
*/
|
||||
public function get_displaytotalcount() {
|
||||
return $this->displaytotalcount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return display cancel.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return bool
|
||||
*/
|
||||
public function get_displaycancel() {
|
||||
return $this->displaycancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return fullwidth.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return bool
|
||||
*/
|
||||
public function get_fullwidth() {
|
||||
return $this->fullwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return autostart.
|
||||
*
|
||||
* @since 3.1
|
||||
* @return bool
|
||||
*/
|
||||
public function get_autostart() {
|
||||
return $this->autostart;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,6 +296,7 @@ class page_requirements_manager {
|
||||
|
||||
// Every page should include definition of following modules.
|
||||
$this->js_module($this->find_module('core_filepicker'));
|
||||
$this->js_module($this->find_module('core_comment'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user