MDL-51967 tool_lp: Create a dialogue to view the competency information

This commit is contained in:
Issam Taboubi 2015-11-06 17:22:41 -05:00 committed by Frederic Massart
parent 9fb8385183
commit 2e90c62f79
10 changed files with 384 additions and 7 deletions

View file

@ -0,0 +1 @@
define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/dialogue"],function(a,b,c,d,e,f){var g=function(b){this.options={includerelated:!1,includecourses:!1},a.extend(this.options,b)};return g.prototype.enhanceDialogue=function(a){var b=new g({includerelated:!1});b.watch(a.getContent())},g.prototype.showDialogue=function(a){var c=this.getCompetencyDataPromise(a),e=this;c.done(function(a){d.render("tool_lp/competency_summary",a).done(function(b){new f(a.shortname,b,e.enhanceDialogue)}).fail(b.exception)}).fail(b.exception)},g.prototype.showDialogueFromData=function(a){var c=this;d.render("tool_lp/competency_summary",a).done(function(b){new f(a.shortname,b,c.enhanceDialogue)}).fail(b.exception)},g.prototype.clickEventHandler=function(b){var c=b.data.compdialogue,d=a(b.target).data("id");c.showDialogue(d),b.preventDefault()},g.prototype.getCompetencyDataPromise=function(a){var d=c.call([{methodname:"tool_lp_data_for_competency_summary",args:{competencyid:a,includerelated:this.options.includerelated,includecourses:this.options.includecourses}}]);return d[0].then(function(a){return a}).fail(b.exception)},g.prototype.watch=function(b){a(b).off("click",'[data-action="competency-dialogue"]',this.clickEventHandler),a(b).on("click",'[data-action="competency-dialogue"]',{compdialogue:this},this.clickEventHandler)},g});

View file

@ -1 +1 @@
define(["core/yui"],function(a){var b=function(b,c,d){this.yuiDialogue=null;var e=this;a.use("moodle-core-notification","timers",function(){e.yuiDialogue=new M.core.dialogue({headerContent:b,bodyContent:c,draggable:!0,visible:!1,center:!0,modal:!0}),e.yuiDialogue.after("visibleChange",function(b){b.newVal&&a.soon(function(){d(e)})}),e.yuiDialogue.show()})};return b.prototype.close=function(){this.yuiDialogue.hide(),this.yuiDialogue.destroy()},b.prototype.getContent=function(){return this.yuiDialogue.bodyNode.getDOMNode()},b}); define(["core/yui"],function(a){var b=function(b,c,d){this.yuiDialogue=null;var e=this;a.use("moodle-core-notification","timers",function(){e.yuiDialogue=new M.core.dialogue({headerContent:b,bodyContent:c,draggable:!0,visible:!1,center:!0,modal:!0}),e.yuiDialogue.after("visibleChange",function(b){b.newVal&&"undefined"!=typeof d&&a.soon(function(){d(e)})}),e.yuiDialogue.show()})};return b.prototype.close=function(){this.yuiDialogue.hide(),this.yuiDialogue.destroy()},b.prototype.getContent=function(){return this.yuiDialogue.bodyNode.getDOMNode()},b});

View file

@ -0,0 +1,154 @@
// 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/>.
/**
* Display Competency in dialogue box.
*
* @module tool_lp/Competencydialogue
* @package tool_lp
* @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery',
'core/notification',
'core/ajax',
'core/templates',
'core/str',
'tool_lp/dialogue'],
function($, notification, ajax, templates, str, Dialogue) {
/**
* Constructor for CompetencyDialogue.
*
* @param {Object} options
*
*/
var Competencydialogue = function(options) {
this.options = {
includerelated: false,
includecourses: false
};
$.extend(this.options, options);
};
/**
* Callback on dialogue display, it apply enhance on competencies dialogue.
*
* @param {Dialogue} dialogue
* @method enhanceDialogue
*/
Competencydialogue.prototype.enhanceDialogue = function(dialogue) {
//Apply watch on the related competencies and competencies in the dialogue.
var comprelated = new Competencydialogue({includerelated : false});
comprelated.watch(dialogue.getContent());
};
/**
* Display a dialogue box by competencyid.
*
* @param {Number} the competency id
* @param {Object} Options for tool_lp_data_for_competency_summary service
* @param {Object} dataSource data to be used to display dialogue box
* @method showDialogue
*/
Competencydialogue.prototype.showDialogue = function(competencyid) {
var datapromise = this.getCompetencyDataPromise(competencyid);
var localthis = this;
datapromise.done(function(data) {
// Inner Html in the dialogue content.
templates.render('tool_lp/competency_summary', data)
.done(function(html) {
new Dialogue(
data.shortname,
html,
localthis.enhanceDialogue
);
}).fail(notification.exception);
}).fail(notification.exception);
};
/**
* Display a dialogue box from data.
*
* @param {Object} dataSource data to be used to display dialogue box
* @method showDialogueFromData
*/
Competencydialogue.prototype.showDialogueFromData = function(dataSource) {
var localthis = this;
// Inner Html in the dialogue content.
templates.render('tool_lp/competency_summary', dataSource)
.done(function(html) {
new Dialogue(
dataSource.shortname,
html,
localthis.enhanceDialogue
);
}).fail(notification.exception);
};
/**
* The action on the click event.
*
* @param {Event} event click
* @method clickEventHandler
*/
Competencydialogue.prototype.clickEventHandler = function(e) {
var compdialogue = e.data.compdialogue;
var competencyid = $(e.target).data('id');
// Show the dialogue box.
compdialogue.showDialogue(competencyid);
e.preventDefault();
};
/**
* Get a promise on data competency.
*
* @param {Number} competencyid
* @return {Promise} return promise on data request
* @method getCompetencyDataPromise
*/
Competencydialogue.prototype.getCompetencyDataPromise = function(competencyid) {
var requests = ajax.call([
{ methodname: 'tool_lp_data_for_competency_summary',
args: { competencyid: competencyid,
includerelated: this.options.includerelated,
includecourses: this.options.includecourses
}
}
]);
return requests[0].then(function(context) {
return context;
}).fail(notification.exception);
};
/**
* Watch the competencies links in container.
*
* @param {String} container selector of node containing competencies links
* @method watch
*/
Competencydialogue.prototype.watch = function(containerSelector) {
$(containerSelector).off('click', '[data-action="competency-dialogue"]', this.clickEventHandler);
$(containerSelector).on('click', '[data-action="competency-dialogue"]', { compdialogue: this }, this.clickEventHandler);
};
return Competencydialogue;
});

View file

@ -51,9 +51,11 @@ define(['core/yui'], function(Y) {
if (e.newVal) { if (e.newVal) {
// Delay the callback call to the next tick, otherwise it can happen that it is // Delay the callback call to the next tick, otherwise it can happen that it is
// executed before the dialogue constructor returns. // executed before the dialogue constructor returns.
Y.soon(function() { if ((typeof afterShow !== 'undefined')) {
afterShow(parent); Y.soon(function() {
}); afterShow(parent);
});
}
} }
}); });

View file

@ -1054,6 +1054,88 @@ class external extends external_api {
} }
/**
* Returns description of data_for_competency_summary() parameters.
*
* @return \external_function_parameters
*/
public static function data_for_competency_summary_parameters() {
$competencyid = new external_value(
PARAM_INT,
'The competency id',
VALUE_REQUIRED
);
$includerelated = new external_value(
PARAM_BOOL,
'Include or not related competencies',
VALUE_DEFAULT,
false
);
$includecourses = new external_value(
PARAM_BOOL,
'Include or not competency courses',
VALUE_DEFAULT,
false
);
$params = array(
'competencyid' => $competencyid,
'includerelated' => $includerelated,
'includecourses' => $includecourses
);
return new external_function_parameters($params);
}
/**
* Loads the data required to render the competency_page template.
*
* @param int $competencyid Competency id.
* @param boolean $includerelated Include or not related competencies.
* @param boolean $includecourses Include or not competency courses.
*
* @return \stdClass
*/
public static function data_for_competency_summary($competencyid, $includerelated = false, $includecourses = false) {
global $PAGE;
$params = self::validate_parameters(self::data_for_competency_summary_parameters(),
array(
'competencyid' => $competencyid,
'includerelated' => $includerelated,
'includecourses' => $includecourses
));
$competency = api::read_competency($params['competencyid']);
$framework = api::read_framework($competency->get_competencyframeworkid());
$renderable = new output\competency_summary($competency, $framework, $params['includerelated'], $params['includecourses']);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
/**
* Returns description of data_for_competency_summary_() result value.
*
* @return \external_description
*/
public static function data_for_competency_summary_returns() {
return new external_single_structure(array (
'framework' => competency_Framework_exporter::get_read_structure(),
'id' => new external_value(PARAM_INT, 'The competency id'),
'shortname' => new external_value(PARAM_TEXT, 'The competency shortname'),
'idnumber' => new external_value(PARAM_TEXT, 'The competency idnumber'),
'visible' => new external_value(PARAM_BOOL, 'True if competency visible'),
'descriptionformatted' => new external_value(PARAM_RAW, 'The competency description'),
'relatedcompetencies' => new external_multiple_structure(
competency_exporter::get_read_structure()
),
'courses' => self::list_courses_using_competency_returns(),
'showrelatedcompetencies' => new external_value(PARAM_BOOL, 'Show or not the related competencies'),
'showcourses' => new external_value(PARAM_BOOL, 'Show or not the linked courses'),
));
}
/** /**
* Returns description of set_parent_competency() parameters. * Returns description of set_parent_competency() parameters.
* *

View file

@ -0,0 +1,111 @@
<?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/>.
/**
* Class containing data for competency_page page
*
* @package tool_lp
* @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
use renderable;
use templatable;
use renderer_base;
use stdClass;
use tool_lp\api;
use tool_lp\external\competency_exporter;
use tool_lp\external\competency_framework_exporter;
/**
* Class containing data for competency summary
*
* @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_summary implements renderable, templatable {
/** @var \tool_lp\competency_framework $framework This competency framework. */
protected $framework = null;
/** @var \tool_lp\competency $competency. */
protected $competency = null;
/** @var \tool_lp\competency[] $relatedcompetencies List of competencies. */
protected $relatedcompetencies = array();
/** @var course[] $courses List of courses. */
protected $courses = array();
/** @var stdClass $data result exported to template. */
protected $data = null;
/**
* Construct this renderable.
*
* @param \tool_lp\competency $competency Competency persistent.
* @param \tool_lp\competency_framework $framework framework persistent.
* @param boolean $includerelated Include or not related competencies.
* @param boolean $includecourses Include or not competency courses.
*/
public function __construct($competency, $framework, $includerelated, $includecourses) {
$this->data = new stdClass();
$this->data->showrelatedcompetencies = $includerelated;
$this->data->showrcourses = $includecourses;
$this->competency = $competency;
$this->framework = $framework;
if ($includerelated) {
$this->relatedcompetencies = $this->competency->get_related_competencies();
}
if ($includecourses) {
$this->courses = api::list_courses_using_competency($competency->get_id());
}
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$frameworkexp = new competency_framework_exporter($this->framework, array('context' => $this->framework->get_context()));
$this->data->framework = $frameworkexp->export($output);
$compexp = new competency_exporter($this->competency, array('context' => $this->framework->get_context()));
$competency = $compexp->export($output);
$this->data->id = $competency->id;
$this->data->shortname = $competency->shortname;
$this->data->visible = $competency->visible;
$this->data->idnumber = $competency->idnumber;
$this->data->relatedcompetencies = array();
if ($this->relatedcompetencies) {
foreach ($this->relatedcompetencies as $competency) {
$compexporter = new competency_exporter($competency, array('context' => $this->framework->get_context()));
$this->data->relatedcompetencies[] = $compexporter->export($output);
}
}
$this->data->courses = $this->courses;
return $this->data;
}
}

View file

@ -136,6 +136,15 @@ $functions = array(
'capabilities' => 'tool/lp:competencymanage', 'capabilities' => 'tool/lp:competencymanage',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_data_for_competency_summary' => array(
'classname' => 'tool_lp\external',
'methodname' => 'data_for_competency_summary',
'classpath' => '',
'description' => 'Load competency data for summary template.',
'type' => 'read',
'capabilities' => 'tool/lp:competencyview',
'ajax' => true,
),
'tool_lp_list_competencies' => array( 'tool_lp_list_competencies' => array(
'classname' => 'tool_lp\external', 'classname' => 'tool_lp\external',
'methodname' => 'list_competencies', 'methodname' => 'list_competencies',

View file

@ -1,11 +1,19 @@
<p><strong>{{shortname}} <em>{{idnumber}}</em></strong></p> <p><strong>{{shortname}} <em>{{idnumber}}</em></strong></p>
<p>{{description}}</p> <p>{{description}}</p>
{{#framework}}
<p><strong>{{framework.shortname}}</strong></p>
<p>{{framework.description}}</p>
{{/framework}}
{{^visible}} {{^visible}}
( {{#str}} hidden, tool_lp{{/str}}) ( {{#str}} hidden, tool_lp{{/str}})
{{/visible}} {{/visible}}
{{#showrelatedcompetencies}} {{#showrelatedcompetencies}}
{{> tool_lp/related_competencies }} {{> tool_lp/related_competencies }}
{{/showrelatedcompetencies}} {{/showrelatedcompetencies}}
{{#showrule}} {{#showrule}}
<h5>{{#str}}competencyrule, tool_lp{{/str}}</h5> <h5>{{#str}}competencyrule, tool_lp{{/str}}</h5>
<dl> <dl>

View file

@ -41,7 +41,7 @@
<span class="drag-handlecontainer pull-left"></span> <span class="drag-handlecontainer pull-left"></span>
{{/canbeedited}} {{/canbeedited}}
{{/canmanage}} {{/canmanage}}
{{shortname}} <a href="#" data-action="competency-dialogue" data-id="{{id}}">{{shortname}}</a>
</td> </td>
{{#iscompleted}} {{#iscompleted}}
<td>{{usercompetencyplan.gradename}}</td> <td>{{usercompetencyplan.gradename}}</td>
@ -85,3 +85,9 @@ require(['tool_lp/competencies'], function(mod) {
}); });
{{/js}} {{/js}}
{{/canmanage}} {{/canmanage}}
{{#js}}
require(['tool_lp/competencydialogue'], function(Compdialogue) {
var competencydialogue = new Compdialogue({includerelated : true});
competencydialogue.watch('[data-region="plancompetenciespage"]');
});
{{/js}}

View file

@ -1,4 +1,4 @@
<div data-region='relatedcompetencies'> <div data-region="relatedcompetencies">
<p> <p>
<strong>{{#str}}relatedcompetencies, tool_lp{{/str}}:</strong> <strong>{{#str}}relatedcompetencies, tool_lp{{/str}}:</strong>
</p> </p>
@ -11,7 +11,11 @@
<a href="#" data-action="deleterelation" id="id-related-{{id}}">{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a> <a href="#" data-action="deleterelation" id="id-related-{{id}}">{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
</div> </div>
{{/showdeleterelatedaction}} {{/showdeleterelatedaction}}
<p>{{shortname}}{{#idnumber}} {{idnumber}}{{/idnumber}}</p> <p>
<a href="#" data-action="competency-dialogue" data-id="{{id}}">
{{shortname}}{{#idnumber}} {{idnumber}}{{/idnumber}}
</a>
</p>
</li> </li>
{{/visible}} {{/visible}}
</ul> </ul>