2015-08-02 22:40:24 +00:00
|
|
|
angular.module('SeHub').controller('newTasksController', ['$scope', 'apiService', '$cookies', '$location',
|
2015-08-02 10:44:15 +00:00
|
|
|
function($scope, apiService, $cookies, $location) {
|
2015-06-21 19:27:48 +00:00
|
|
|
|
2015-06-25 19:40:26 +00:00
|
|
|
$scope.newComp = {};
|
|
|
|
$scope.newComp.isMandatory = false;
|
2015-08-02 10:44:15 +00:00
|
|
|
var user = $scope.$parent.user;
|
|
|
|
var token = $cookies['com.sehub.www'];
|
|
|
|
$scope.submitting = false;
|
|
|
|
$scope.course = {}
|
|
|
|
$scope.loading = true;
|
|
|
|
apiService.getCoursesByUserID(token, user.id.toString()).success(function(data) {
|
|
|
|
$scope.courses = [];
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
if (data[i].master_id == user.id)
|
|
|
|
$scope.courses.push(data[i]);
|
|
|
|
}
|
|
|
|
$scope.loading = false;
|
|
|
|
}).error(function(err) {
|
|
|
|
console.error('Error', err);
|
|
|
|
$scope.courses = [];
|
|
|
|
$scope.loading = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var compOrder = 0;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.courseSelected = function() {
|
|
|
|
for (var i = 0; i < $scope.courses.length; i++) {
|
|
|
|
if ($scope.course.title === $scope.courses[i].courseName) {
|
|
|
|
$scope.course.id = $scope.courses[i].id;
|
|
|
|
$scope.task.courseId = $scope.course.id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.submit = function() {
|
|
|
|
if (validForm()) {
|
|
|
|
$scope.submitting = true;
|
|
|
|
var payload = $scope.task;
|
|
|
|
payload.dueDate = new Date(payload.date);
|
|
|
|
payload.dueDate = {
|
|
|
|
year: payload.dueDate.getFullYear(),
|
|
|
|
month: payload.dueDate.getMonth() + 1,
|
|
|
|
day: payload.dueDate.getDate()
|
|
|
|
|
|
|
|
}
|
2015-08-02 22:40:24 +00:00
|
|
|
|
|
|
|
apiService.createTask(token, payload).success(function(data) {
|
2015-08-02 10:44:15 +00:00
|
|
|
$location.path('/tasks');
|
2015-08-02 22:40:24 +00:00
|
|
|
}).error(function(err) {
|
2015-08-02 10:44:15 +00:00
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
} else {
|
2015-08-02 11:55:39 +00:00
|
|
|
alert('Please Fill All Task info & At least one component');
|
2015-08-02 10:44:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function validForm() {
|
|
|
|
if (!$scope.course.title)
|
|
|
|
return false;
|
|
|
|
if (!$scope.task.title || $scope.task.title.trim() == '')
|
|
|
|
return false;
|
|
|
|
if (!$scope.task.description || $scope.task.description.trim() == '')
|
|
|
|
return false;
|
|
|
|
if (!$scope.task.date)
|
|
|
|
return false;
|
2015-08-02 11:55:39 +00:00
|
|
|
if ($scope.task.components.length < 1)
|
|
|
|
return false;
|
2015-08-02 10:44:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-21 19:27:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
$scope.componentTypes = [{
|
|
|
|
"type": "textbox"
|
|
|
|
}, {
|
|
|
|
"type": "textarea"
|
|
|
|
}, {
|
|
|
|
"type": "checkbox"
|
2015-06-25 19:40:26 +00:00
|
|
|
}, {
|
|
|
|
"type": "link"
|
|
|
|
}, {
|
|
|
|
"type": "radiobuttons"
|
2015-06-21 19:27:48 +00:00
|
|
|
}];
|
|
|
|
|
2015-06-22 19:37:47 +00:00
|
|
|
$scope.task = {};
|
|
|
|
$scope.task.task = {};
|
2015-06-25 19:40:26 +00:00
|
|
|
$scope.task.components = [];
|
|
|
|
$scope.task.isPersonal = false;
|
2015-06-21 19:27:48 +00:00
|
|
|
|
2015-06-22 19:37:47 +00:00
|
|
|
// $scope.task = [];
|
2015-06-21 19:27:48 +00:00
|
|
|
|
2015-06-22 19:37:47 +00:00
|
|
|
$scope.addComponent = function() {
|
2015-06-25 19:40:26 +00:00
|
|
|
var comp = {};
|
|
|
|
var type = $scope.newComp.type;
|
|
|
|
comp.type = type;
|
2015-08-02 10:44:15 +00:00
|
|
|
comp.order = compOrder;
|
2015-08-02 22:40:24 +00:00
|
|
|
compOrder++;
|
2015-06-25 19:40:26 +00:00
|
|
|
comp.isMandatory = $scope.newComp.isMandatory;
|
|
|
|
comp.label = "";
|
2015-08-02 22:40:24 +00:00
|
|
|
var i = 0;
|
2015-06-25 19:40:26 +00:00
|
|
|
if (!(type === 'textbox' || type === 'textarea' || type === 'checkbox'))
|
|
|
|
while ($scope.newComp.label[i]) {
|
|
|
|
comp.label += $scope.newComp.label[i] + "|";
|
|
|
|
i++;
|
|
|
|
} else
|
2015-08-02 10:44:15 +00:00
|
|
|
comp.label = $scope.newComp.label[i];
|
2015-06-25 19:40:26 +00:00
|
|
|
|
|
|
|
console.log(comp);
|
|
|
|
$scope.task.components.push(comp);
|
|
|
|
|
|
|
|
// console.log($scope.newComp);
|
2015-06-21 19:27:48 +00:00
|
|
|
$scope.newComp = {};
|
2015-06-25 19:40:26 +00:00
|
|
|
$scope.newComp.isMandatory = false;
|
|
|
|
$scope.compDetails = [];
|
|
|
|
$scope.isRadioButton = false;
|
2015-08-02 10:44:15 +00:00
|
|
|
|
2015-06-25 19:40:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.ComponentType = function(type) {
|
|
|
|
if (type === 'textbox' || type === 'textarea' || type === 'checkbox')
|
|
|
|
$scope.compDetails = [{
|
|
|
|
detail: "Label"
|
|
|
|
}];
|
|
|
|
else if (type === 'radiobuttons') {
|
|
|
|
$scope.compDetails = [{
|
|
|
|
detail: "Label"
|
|
|
|
}];
|
|
|
|
$scope.compDetails.push({
|
|
|
|
detail: "Option" + $scope.compDetails.length + ": "
|
|
|
|
});
|
|
|
|
} else if (type === 'link')
|
|
|
|
$scope.compDetails = [{
|
|
|
|
detail: "Label"
|
|
|
|
}, {
|
2015-08-02 13:57:46 +00:00
|
|
|
detail: "URL Path (You Need To Include 'http://'"
|
2015-06-25 19:40:26 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
if (type === 'radiobuttons')
|
|
|
|
$scope.isRadioButton = true;
|
|
|
|
else
|
|
|
|
$scope.isRadioButton = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.addMoreOptions = function() {
|
|
|
|
$scope.compDetails.push({
|
|
|
|
detail: "Option" + $scope.compDetails.length + ": "
|
|
|
|
});
|
2015-06-21 19:27:48 +00:00
|
|
|
}
|
2015-06-22 19:37:47 +00:00
|
|
|
|
2015-06-25 19:40:26 +00:00
|
|
|
$scope.dueTime = function() {
|
|
|
|
if (!$scope.task.date || $scope.task.date === '')
|
|
|
|
$scope.dueTimeFromNow = "";
|
2015-06-22 19:37:47 +00:00
|
|
|
var d = new Date($scope.task.date);
|
2015-06-25 19:40:26 +00:00
|
|
|
$scope.dueTimeFromNow = moment(d).fromNow();
|
|
|
|
}
|
|
|
|
|
2015-08-02 10:44:15 +00:00
|
|
|
$scope.initLinkComp = function(component) {
|
2015-06-25 19:40:26 +00:00
|
|
|
var arr = component.label.split("|");
|
|
|
|
for (var i = 0; i < arr.length - 1; i++) {
|
2015-08-02 10:44:15 +00:00
|
|
|
if (i == 0)
|
2015-06-25 19:40:26 +00:00
|
|
|
component.title = arr[i];
|
|
|
|
else
|
|
|
|
component.href = arr[i];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-08-02 10:44:15 +00:00
|
|
|
$scope.initRadioButtonsComp = function(component) {
|
2015-06-25 19:40:26 +00:00
|
|
|
var arr = component.label.split("|");
|
|
|
|
component.values = [];
|
|
|
|
for (var i = 0; i < arr.length - 1; i++) {
|
2015-08-02 10:44:15 +00:00
|
|
|
if (i == 0)
|
2015-06-25 19:40:26 +00:00
|
|
|
component.title = arr[i];
|
|
|
|
else
|
2015-08-02 10:44:15 +00:00
|
|
|
component.values.push({
|
|
|
|
text: arr[i],
|
|
|
|
id: i
|
|
|
|
});
|
2015-06-25 19:40:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-08-02 10:44:15 +00:00
|
|
|
$scope.RB = function(comp) {
|
2015-06-25 19:40:26 +00:00
|
|
|
console.info(comp);
|
2015-06-22 19:37:47 +00:00
|
|
|
}
|
2015-06-21 19:27:48 +00:00
|
|
|
}
|
|
|
|
]);
|