-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated Courses Final Inscription New (#118)
* Integrated Courses Final Inscription New Add Delete Final Modal to Courses Show
- Loading branch information
1 parent
d6af4e5
commit 3d4af22
Showing
9 changed files
with
154 additions
and
23 deletions.
There are no files selected for viewing
43 changes: 30 additions & 13 deletions
43
app/scripts/controllers/courses/CoursesFinalInscriptionNewCtrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
'use strict'; | ||
|
||
define(['paw'], function(paw) { | ||
paw.controller('CoursesFinalInscriptionNewCtrl', ['$routeParams', '$window', '$filter', function($routeParams, $window, $filter) { | ||
define(['paw', 'services/Courses', 'services/flashMessages'], function(paw) { | ||
paw.controller('CoursesFinalInscriptionNewCtrl', | ||
['$routeParams', 'Courses', '$window', '$filter', 'flashMessages', '$log', '$route', 'Paths', | ||
function($routeParams, Courses, $window, $filter, flashMessages, $log, $route, Paths) { | ||
|
||
var _this = this; | ||
var courseId = $routeParams.courseId; | ||
this.courseId = $routeParams.courseId; | ||
|
||
this.currentDate = new Date(); | ||
|
||
Courses.get(this.courseId).then(function(course) { | ||
_this.course = course; | ||
}, function(response) { | ||
$log.info('Response status: ' + response.status); | ||
if (response.status === 404) { | ||
Paths.get().notFound().go(); | ||
} | ||
}); | ||
|
||
this.new = function(finalInscription) { | ||
// Make Api request | ||
var parsedDate = $filter('date')(finalInscription.finalExamDate, 'yyyy-MM-ddTHH:mm:ss'); | ||
_this.errors = []; | ||
var newFinalInscription = angular.copy(finalInscription); | ||
newFinalInscription.finalExamDate = $filter('date')(finalInscription.finalExamDate, 'yyyy-MM-ddTHH:mm:ss'); | ||
Courses.newFinalInscription(this.courseId, newFinalInscription).then(function(response) { | ||
flashMessages.setSuccess('i18nFinalSuccessfullyCreated'); | ||
Paths.get().courses(_this.course).go(); | ||
}, function(response) { | ||
|
||
$log.warn(JSON.stringify(response)); | ||
flashMessages.setError('i18nFormErrors'); | ||
$route.reload(); | ||
}); | ||
}; | ||
|
||
this.cancel = function() { | ||
$window.history.back(); | ||
}; | ||
|
||
this.currentDate = new Date(); | ||
|
||
this.course = { | ||
courseId: '72.03', | ||
credits: 3, | ||
name: 'Introducción a Informática', | ||
semester: 1 | ||
}; | ||
}]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
define(['paw', 'services/modalFactory', 'services/Courses', 'services/flashMessages'], function(paw) { | ||
paw.controller('DeleteFinalController', | ||
['modalFactory', '$log', 'Courses', '$route', 'flashMessages', | ||
function (modalFactory, $log, Courses, $route, flashMessages) { | ||
var modalTemplateUrl = 'views/modals/delete_final.html'; | ||
var onSuccess = function(result) { | ||
Courses.deleteFinalInscription(result.courseId, result.id) | ||
.then(function(response) { | ||
flashMessages.setSuccess('i18nDeleteFinalSuccess'); | ||
$route.reload(); | ||
}, function(response) { | ||
flashMessages.setError('i18nFormErrors'); | ||
$log.warn('[ERROR] - Response: ' + JSON.stringify(response)); | ||
$route.reload(); | ||
}); | ||
}; | ||
|
||
var onFailure = function(msg) { | ||
$log.info(msg); | ||
}; | ||
this.open = function (size, title, courseId, courseName, finalExamDate, id) { | ||
var resolve = getResolve(title, courseId, courseName, finalExamDate, id); | ||
modalFactory.create(size, 'DeleteFinalModalInstanceController', modalTemplateUrl, resolve, onSuccess, onFailure); | ||
}; | ||
}]); | ||
|
||
paw.controller('DeleteFinalModalInstanceController', | ||
function($uibModalInstance, title, courseId, courseName, finalExamDate, id) { | ||
this.title = title; | ||
this.courseId = courseId; | ||
this.courseName = courseName; | ||
this.finalExamDate = finalExamDate; | ||
this.id = id; | ||
|
||
var _this = this; | ||
|
||
this.ok = function () { | ||
$uibModalInstance.close({ | ||
courseId: courseId, | ||
courseName: courseName, | ||
finalExamDate: finalExamDate, | ||
id: id | ||
}); | ||
}; | ||
|
||
this.cancel = function () { | ||
$uibModalInstance.dismiss('Delete Final modal dismissed at: ' + new Date()); | ||
}; | ||
}); | ||
|
||
function getResolve(title, courseId, courseName, finalExamDate, id) { | ||
return { | ||
title: function() { | ||
return title; | ||
}, | ||
courseId: function () { | ||
return courseId; | ||
}, | ||
courseName: function () { | ||
return courseName; | ||
}, | ||
finalExamDate: function () { | ||
return finalExamDate; | ||
}, | ||
id: function() { | ||
return id; | ||
} | ||
}; | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class='modal-header'> | ||
<h4 class='modal-title' id='modal-title' translate='i18nModalDeleteFinal'></h4> | ||
</div> | ||
<div class='modal-body'> | ||
<p class='break-words'> | ||
<span class='bold' translate='i18nModalCourseId'></span>: {{ controller.courseId }} | ||
</p> | ||
<p class='break-words'> | ||
<span class='bold' translate='i18nModalCourseName'></span>: {{ controller.courseName }} | ||
</p> | ||
<p class='break-words'> | ||
<span class='bold' translate='i18nFinalExamDate'></span>: {{ controller.finalExamDate | date: 'dd/MM/yyyy HH:mm'}} | ||
</p> | ||
</div> | ||
<div class='modal-footer'> | ||
<button class='btn btn-default' type='button' ng-click="controller.cancel()" translate='i18nCancel'></button> | ||
<button class='btn btn-danger' type='button' ng-click='controller.ok()' translate='i18nConfirm'></button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters