2015-07-23 21:57:14 +00:00
|
|
|
angular.module('SeHub')
|
|
|
|
.controller('taskController', ['$scope', '$rootScope', 'dataService', 'apiService',
|
2015-07-25 15:25:45 +00:00
|
|
|
'$cookies', '$location', '$routeParams', '$mdDialog',
|
|
|
|
|
|
|
|
function($scope, $rootScope, dataService, apiService, $cookies, $location, $routeParams, $mdDialog) {
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
var taskId = $routeParams.taskId;
|
|
|
|
var submitterId = $routeParams.submitterId;
|
2015-08-02 11:55:39 +00:00
|
|
|
var token = $cookies['com.sehub.www'];
|
|
|
|
var groupId = $routeParams.gId;
|
2015-08-02 13:57:46 +00:00
|
|
|
$scope.loading = true;
|
2015-07-23 21:57:14 +00:00
|
|
|
|
2015-08-02 13:57:46 +00:00
|
|
|
apiService.getTaskById(token, taskId, groupId).success(function(data) {
|
2015-08-02 11:55:39 +00:00
|
|
|
$scope.task = data;
|
|
|
|
$scope.dateInit($scope.task.dueDate);
|
2015-08-02 13:57:46 +00:00
|
|
|
$scope.loading = false;
|
|
|
|
}).error(function(err) {
|
|
|
|
$location.path('/tasks');
|
2015-08-02 11:55:39 +00:00
|
|
|
})
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
if (submitterId) { //In This Case we Only Want to show The Content of the Submitter
|
|
|
|
$scope.readOnly = true;
|
2015-08-02 11:55:39 +00:00
|
|
|
|
2015-07-23 21:57:14 +00:00
|
|
|
} else { //In This Case We Need An Empty Task To Be Able To Fill It
|
|
|
|
$scope.readOnly = false;
|
2015-08-02 11:55:39 +00:00
|
|
|
apiService.getTaskById(token, taskId, groupId);
|
2015-07-23 21:57:14 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 15:25:45 +00:00
|
|
|
$scope.dateInit = function(date) {
|
2015-07-23 21:57:14 +00:00
|
|
|
d = moment(new Date(date.year, date.month - 1, date.day));
|
|
|
|
$scope.task.date = d.format("d MMMM YYYY");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$scope.dueTime = function() {
|
|
|
|
if (!$scope.task.date || $scope.task.date === '')
|
|
|
|
$scope.dueTimeFromNow = "";
|
|
|
|
var d = new Date($scope.task.date);
|
|
|
|
$scope.dueTimeFromNow = moment(d).fromNow();
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.initLinkComp = function(component) {
|
|
|
|
var arr = component.label.split("|");
|
|
|
|
for (var i = 0; i < arr.length - 1; i++) {
|
|
|
|
if (i == 0)
|
|
|
|
component.title = arr[i];
|
|
|
|
else
|
|
|
|
component.href = arr[i];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.initRadioButtonsComp = function(component) {
|
|
|
|
var arr = component.label.split("|");
|
|
|
|
component.values = [];
|
|
|
|
for (var i = 0; i < arr.length - 1; i++) {
|
|
|
|
if (i == 0)
|
|
|
|
component.title = arr[i];
|
|
|
|
else
|
|
|
|
component.values.push({
|
|
|
|
text: arr[i],
|
|
|
|
id: i
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-07-25 15:25:45 +00:00
|
|
|
function validateComponents() {
|
|
|
|
for (var i = 0; i < $scope.task.components.length; i++) {
|
|
|
|
if ($scope.task.components[i].isMandatory && (!$scope.task.components[i].value || $scope.task.components[i].value == ''))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.submitTask = function(event) { //Dialog will pop-up if not all mandatory fields are filled
|
|
|
|
if (validateComponents()) {
|
2015-08-02 13:57:46 +00:00
|
|
|
apiService.submitTask(token, taskId, groupId, $scope.task.components).success(function(data) {
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('Submitted!')
|
|
|
|
.content('Your Task Was Successfully Submitted!')
|
|
|
|
.ariaLabel('ddd')
|
|
|
|
.ok('GoTo My Submitted Task')
|
2015-08-02 15:15:51 +00:00
|
|
|
.targetEvent(event)
|
|
|
|
|
|
|
|
).then(function(){
|
2015-08-02 13:57:46 +00:00
|
|
|
if($scope.task.isPersonal)
|
|
|
|
$location.path('/tasks/overview/'+taskId+'/'+groupId+'/'+groupId);
|
|
|
|
else
|
|
|
|
$location.path('/tasks/overview/'+taskId+'/'+groupId+'/'+groupId);
|
2015-08-02 15:15:51 +00:00
|
|
|
});
|
|
|
|
return;
|
2015-08-02 13:57:46 +00:00
|
|
|
})
|
|
|
|
|
2015-07-25 15:25:45 +00:00
|
|
|
}
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('Hey There...')
|
|
|
|
.content('You Must Fill All Mandatory Fields In Order To Submit The Task')
|
|
|
|
.ariaLabel('Not All Mandatory Are Filled')
|
|
|
|
.ok('Got it!')
|
|
|
|
.targetEvent(event)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*=================================
|
|
|
|
= Mock Data =
|
|
|
|
=================================*/
|
|
|
|
|
2015-08-02 11:55:39 +00:00
|
|
|
// $scope.task = {
|
|
|
|
// "title": "task1",
|
|
|
|
// "courseId": 1234567890,
|
|
|
|
// "description": "one line\nsecondline\nthirdline",
|
|
|
|
// "dueDate": {
|
|
|
|
// "year": 2010,
|
|
|
|
// "month": 2,
|
|
|
|
// "day": 4
|
|
|
|
// },
|
|
|
|
// "isPersonal": true,
|
|
|
|
// "components": [{
|
|
|
|
// "type": "radiobuttons",
|
|
|
|
// "label": "pick One|this|orthis|MaybeThis",
|
|
|
|
// "isMandatory": true,
|
|
|
|
// "order": 1
|
|
|
|
// }, {
|
|
|
|
// "type": "checkbox",
|
|
|
|
// "label": "tick Me",
|
|
|
|
// "isMandatory": true,
|
|
|
|
// "order": 2
|
|
|
|
// }, {
|
|
|
|
// "type": "textarea",
|
|
|
|
// "label": "fill shit",
|
|
|
|
// "isMandatory": false,
|
|
|
|
// "order": 3
|
|
|
|
// }]
|
|
|
|
// };
|
|
|
|
|
2015-08-02 13:57:46 +00:00
|
|
|
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
$scope.dueTime = function() {
|
2015-07-25 15:25:45 +00:00
|
|
|
if (!$scope.task.date || $scope.task.date === '')
|
|
|
|
$scope.dueTimeFromNow = "";
|
|
|
|
var d = new Date($scope.task.date);
|
|
|
|
$scope.descriptionInit = function(desc) {
|
|
|
|
desc.replace('\n', '<br>');
|
|
|
|
}
|
|
|
|
$scope.descriptionInit($scope.task.description);
|
|
|
|
$scope.dueTimeFromNow = moment(d).fromNow();
|
2015-07-23 21:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
]); //End Controller
|