Skip to content

Commit

Permalink
MDL-52754 tool_lp: Dropdown list of scales with single quotes in values
Browse files Browse the repository at this point in the history
  • Loading branch information
gauts authored and Frederic Massart committed Apr 18, 2016
1 parent d54c4f8 commit c7484fc
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 52 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions admin/tool/lp/amd/build/scalevalues.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 51 additions & 45 deletions admin/tool/lp/amd/src/grade_user_competency_inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ define(['jquery',
'core/log',
'tool_lp/grade_dialogue',
'tool_lp/event_base',
], function($, notification, ajax, log, GradeDialogue, EventBase) {
'tool_lp/scalevalues',
], function($, notification, ajax, log, GradeDialogue, EventBase, ScaleValues) {

/**
* InlineEditor
*
* @param {String} selector The selector to trigger the grading.
* @param {Object} The scale config for this competency.
* @param {Number} The id of the scale for this competency.
* @param {Number} The id of the competency.
* @param {Number} The id of the user.
* @param {Number} The id of the plan.
Expand All @@ -42,15 +43,15 @@ define(['jquery',
* @param {Boolean} canGrade Whether the user can grade.
* @param {Boolean} canSuggest Whether the user can suggest.
*/
var InlineEditor = function(selector, scaleConfig, competencyId, userId, planId, courseId, chooseStr, canGrade, canSuggest) {
var InlineEditor = function(selector, scaleId, competencyId, userId, planId, courseId, chooseStr, canGrade, canSuggest) {
EventBase.prototype.constructor.apply(this, []);

var trigger = $(selector);
if (!trigger.length) {
throw new Error('Could not find the trigger');
}

this._scaleConfig = scaleConfig;
this._scaleId = scaleId;
this._competencyId = competencyId;
this._userId = userId;
this._planId = planId;
Expand Down Expand Up @@ -97,52 +98,55 @@ define(['jquery',
var options = [],
self = this;

options.push({
value: '',
name: this._chooseStr
});

for (var i = 1; i < this._scaleConfig.length; i++) {
var optionConfig = this._scaleConfig[i];
var promise = ScaleValues.get_values(self._scaleId);
promise.done(function(scalevalues) {
options.push({
value: optionConfig.id,
name: optionConfig.name
value: '',
name: self._chooseStr
});
}

this._dialogue = new GradeDialogue(options, this._canGrade, this._canSuggest);
this._dialogue.on('rated', function(e, data) {
var args = this._args;
args.grade = data.rating;
args.note = data.note;
args.override = true;
ajax.call([{
methodname: this._methodName,
args: args,
done: function(evidence) {
this._trigger('competencyupdated', { args: args, evidence: evidence });
}.bind(self),
fail: notification.exception
}]);
}.bind(this));
this._dialogue.on('suggested', function(e, data) {
var args = this._args;
args.grade = data.rating;
args.note = data.note;
args.override = false;
ajax.call([{
methodname: this._methodName,
args: args,
done: function(evidence) {
this._trigger('competencyupdated', { args: args, evidence: evidence });
}.bind(self),
fail: notification.exception
}]);
}.bind(this));
for (var i = 0; i < scalevalues.length; i++) {
var optionConfig = scalevalues[i];
options.push({
value: optionConfig.id,
name: optionConfig.name
});
}

self._dialogue = new GradeDialogue(options, self._canGrade, self._canSuggest);
self._dialogue.on('rated', function(e, data) {
var args = self._args;
args.grade = data.rating;
args.note = data.note;
args.override = true;
ajax.call([{
methodname: self._methodName,
args: args,
done: function(evidence) {
self._trigger('competencyupdated', { args: args, evidence: evidence });
}.bind(self),
fail: notification.exception
}]);
}.bind(self));
self._dialogue.on('suggested', function(e, data) {
var args = self._args;
args.grade = data.rating;
args.note = data.note;
args.override = false;
ajax.call([{
methodname: self._methodName,
args: args,
done: function(evidence) {
self._trigger('competencyupdated', { args: args, evidence: evidence });
}.bind(self),
fail: notification.exception
}]);
}.bind(self));
}).fail(notification.exception);
};

/** @type {Object} The scale config for this competency. */
InlineEditor.prototype._scaleConfig = null;
/** @type {Number} The scale id for this competency. */
InlineEditor.prototype._scaleId = null;
/** @type {Number} The id of the competency. */
InlineEditor.prototype._competencyId = null;
/** @type {Number} The id of the user. */
Expand All @@ -151,6 +155,8 @@ define(['jquery',
InlineEditor.prototype._planId = null;
/** @type {Number} The id of the course. */
InlineEditor.prototype._courseId = null;
/** @type {String} The text for Choose rating. */
InlineEditor.prototype._chooseStr = null;
/** @type {GradeDialogue} The grading dialogue. */
InlineEditor.prototype._dialogue = null;
/** @type {Boolean} Can grade. */
Expand Down
57 changes: 57 additions & 0 deletions admin/tool/lp/amd/src/scalevalues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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/>.

/**
* Module to get the scale values.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax'], function($, ajax) {
var localCache = [];

return /** @alias module:tool_lp/scalevalues */ {

/**
* Return a promise object that will be resolved into a string eventually (maybe immediately).
*
* @method get_values
* @param {Number} scaleid The scale id
* @return [] {Promise}
*/

get_values: function(scaleid) {

var deferred = $.Deferred();

if (!localCache[scaleid]) {
ajax.call([{
methodname: 'tool_lp_get_scale_values',
args: {scaleid : scaleid},
done: function(scaleinfo) {
localCache[scaleid] = scaleinfo;
deferred.resolve(scaleinfo);
},
fail: (deferred.reject)
}]);
} else {
deferred.resolve(localCache[scaleid]);
}

return deferred.promise();
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ protected static function define_other_properties() {
'hasrelatedcompetencies' => array(
'type' => PARAM_BOOL
),
'scaleid' => array(
'type' => PARAM_INT
),
'scaleconfiguration' => array(
'type' => PARAM_RAW
),
Expand Down Expand Up @@ -108,10 +111,13 @@ protected function get_other_values(renderer_base $output) {
$exporter = new competency_framework_exporter($this->related['framework']);
$result->framework = $exporter->export($output);
$scaleconfiguration = $this->related['framework']->get_scaleconfiguration();
$scaleid = $this->related['framework']->get_scaleid();
if ($competency->get_scaleid()) {
$scaleconfiguration = $competency->get_scaleconfiguration();
$scaleid = $competency->get_scaleid();
}
$result->scaleconfiguration = $scaleconfiguration;
$result->scaleid = $scaleid;

$level = $competency->get_level();
$taxonomy = $this->related['framework']->get_taxonomy($level);
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/lp/templates/user_competency_summary.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
</dd>
{{#js}}
require(['jquery', 'tool_lp/grade_user_competency_inline', 'tool_lp/user_competency_info', 'tool_lp/user_competency_workflow'], function($, mod, info, UserCompWorkflow) {
var scaleConfig = JSON.parse('{{{competency.scaleconfiguration}}}');
var competencyElement = $('[data-region-id="{{uniqid}}"]');
var infoReloader = new info(competencyElement, '{{competency.competency.id}}', '{{user.id}}');
Expand All @@ -81,7 +80,7 @@
ucw.on('status-changed', infoReloader.reload.bind(infoReloader));
ucw.on('error-occured', infoReloader.reload.bind(infoReloader));
var inlineGrader = new mod('#rate_{{uniqid}}', scaleConfig, '{{competency.competency.id}}', '{{user.id}}', '{{plan.id}}', '', '{{#str}}chooserating, tool_lp{{/str}}', {{cangrade}}, {{cansuggest}});
var inlineGrader = new mod('#rate_{{uniqid}}', '{{competency.scaleid}}', '{{competency.competency.id}}', '{{user.id}}', '{{plan.id}}', '', '{{#str}}chooserating, tool_lp{{/str}}', {{cangrade}}, {{cansuggest}});
inlineGrader.on('competencyupdated', infoReloader.reload.bind(infoReloader));
});
{{/js}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@
</dd>
{{#js}}
require(['jquery', 'tool_lp/grade_user_competency_inline', 'tool_lp/user_competency_info'], function($, mod, info) {
var scaleConfig = JSON.parse('{{{competency.scaleconfiguration}}}');
var inlineGrader = new mod('#rate_{{uniqid}}', scaleConfig, '{{competency.competency.id}}', '{{user.id}}', '', '{{course.id}}', '{{#str}}chooserating, tool_lp{{/str}}', {{cangrade}}, {{cansuggest}});
var inlineGrader = new mod('#rate_{{uniqid}}', '{{competency.scaleid}}', '{{competency.competency.id}}', '{{user.id}}', '', '{{course.id}}', '{{#str}}chooserating, tool_lp{{/str}}', {{cangrade}}, {{cansuggest}});
var competencyElement = $('[data-region-id="{{uniqid}}"]');

var displayuser = ('{{displayuser}}' == 'true') ? true : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
</dd>
{{#js}}
require(['jquery', 'tool_lp/grade_user_competency_inline', 'tool_lp/user_competency_info', 'tool_lp/user_competency_workflow'], function($, mod, info, UserCompWorkflow) {
var scaleConfig = JSON.parse('{{{competency.scaleconfiguration}}}');
var competencyElement = $('[data-region-id="{{uniqid}}"]');
var infoReloader = new info(competencyElement, '{{competency.competency.id}}', '{{user.id}}', '{{plan.id}}');
Expand All @@ -84,7 +83,7 @@
ucw.on('error-occured', infoReloader.reload.bind(infoReloader));
{{#cangradeorsuggest}}
var inlineGrader = new mod('#rate_{{uniqid}}', scaleConfig, '{{competency.competency.id}}', '{{user.id}}', '{{plan.id}}', '', '{{#str}}chooserating, tool_lp{{/str}}', {{cangrade}}, {{cansuggest}});
var inlineGrader = new mod('#rate_{{uniqid}}', '{{competency.scaleid}}', '{{competency.competency.id}}', '{{user.id}}', '{{plan.id}}', '', '{{#str}}chooserating, tool_lp{{/str}}', {{cangrade}}, {{cansuggest}});
inlineGrader.on('competencyupdated', infoReloader.reload.bind(infoReloader));
{{/cangradeorsuggest}}
});
Expand Down

0 comments on commit c7484fc

Please sign in to comment.