issue #953 fixed

parent df7dd36c
......@@ -86,10 +86,14 @@ module.exports = {
if (!params.id_sup)
return res.badRequest("No supervisor defined");
if (!params.lang)
return res.badRequest("No lang defined");
MetaMethod.create({
"name": params.name,
"description": "",
"supervisor": params.id_sup
"supervisor": params.id_sup,
"lang": params.lang
})
.then(function(createdMethod){
return res.ok(createdMethod);
......
......@@ -132,16 +132,29 @@ module.exports = {
},
// FERNANDO: avoid method name duplicates
//
// Saves a method as a template
//
/*
* Saves a method as a template
* @param {request} req
* {
* id_stu: studentId,
* id_sup: supervisorID
* lang: student lang code
* }
* @param {response} res
* {
* id: methodId,
* supervisor: supervisorId
* lang: {string} language code
* description: {string}
* }
*/
save: function(req, res){
var params = req.allParams();
if (!params.id_met) return res.json(500, {error: "No method defined"});
if (!params.id_sup) return res.json(500, {error: "No supervisor defined"});
if (!params.lang) return res.json(500, {error: "No lang defined"});
Method.findOne(params.id_met).populate('instructions').exec(function(err, method) {
if (err){
......@@ -152,7 +165,8 @@ module.exports = {
MetaMethod.create({
"name": method.name,
"description": method.description,
"supervisor": params.id_sup
"supervisor": params.id_sup,
"lang": params.lang
}).exec(function(err, createdMethod){
if (err){
sails.log.debug("Create Method error: " + err);
......
......@@ -164,7 +164,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
$scope.save_as_template = function(method){
$http
.post(config.backend+'/method/save', { 'id_met': method.id, 'id_sup': $scope.user.id })
.post(config.backend+'/method/save', { 'id_met': method.id, 'id_sup': $scope.user.id, 'lang': $scope.user.lang })
.then( //success
function(data, status, headers, config) {
console.log('Saved method as template:' + JSON.stringify(data));
......@@ -180,7 +180,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
}
,function(data, status, headers, config) { //error
console.log("Error from API: " + data.error+"("+data.status+")");
ngToast.success({
ngToast.warning({
content: $translate.instant('method_name_duplicated', {method_name: method.name}),
timeout: 6000 // By default 4000
});
......
......@@ -33,12 +33,13 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Functions
//
// Add new method template (metamethod) selected to the student
// Add new method template (metamethod)
$scope.add_method = function(){
var new_data = {
name: $translate.instant("new_method"),
id_sup: $scope.user.id
id_sup: $scope.user.id,
lang: $scope.user.lang,
};
$http
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment