(function () { 'use strict'; var app = angular.module('tasks'); var templatePath = modulesSharedResourcesUrl + 'Modules/Tasks/Views/'; //a directive that renders the task classes list app.directive('taskList', ['tasksDataContext', 'tasksService', 'common', '$location', '$modal', function (tasksDataContext, tasksService, common, $location, $modal) { return { restrict: 'E', templateUrl: templatePath + 'tasklist.html?version=160718', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("taskClass", "success"); var logError = getLogFn("taskClass", "error"); $scope.orderByPredicate = '-dateAssigned'; // Define the status filters $scope.filters = [ { name: 'Assigned', value: null }, { name: 'In progress', value: 9 }, { name: 'Submitted', value: 4 }, { name: 'Under review', value: 5 }, { name: 'Reviewed', value: 6 }, { name: 'Returned', value: 7 }, { name: 'Completed', value: 8 }, { name: 'Recalled', value: 1 } ]; $scope.filterValues = [null, 0, 4, 5, 6, 7, 8, 9]; // Apply the status filters $scope.applyStatusFilter = function (value, index) { return $scope.filterValues.indexOf(value.status) !== -1; } function getMyTasks() { tasksDataContext.getAssignedTasks().then(function (tasks) { $scope.tasks = tasks; angular.forEach($scope.tasks, function(task){ task.name = task.taskRecord.name; task.description = task.taskRecord.description; var responseTypes = task.taskRecord.taskResponseTypes; var responses = task.taskAssignmentResponses; //There are no database 'inprogress' or 'completed' statuses so figure these out now // if there's should be a response but not one submitted yet, then it should be inprogress if(task.status == 0 && responses != null && responses.length > 0){ task.status = 8; } // otherwise assigned if(task.status != 1 && responses != null && responses.length == 0){ task.status = 0; } // if there should be response and one has been submitted if(task.status == 4 && responseTypes != null && responseTypes.length > 0){ task.status = 4; } // otherwise completed if(task.status == 4 && (responseTypes == null || responseTypes.length == 0)){ task.status = 9; } if (task.taskAssignmentResponses.length == 0 && task.status !== 1) { task.status = null; } }) $scope.tasksLoaded = true; }); } $scope.startAssignedTask = function (assignedTask) { tasksService.setCurrentAssignedTask(assignedTask); $location.path('/task'); } getMyTasks(); } }]); //a directive that renders the task classes list app.directive('viewTask', ['tasksDataContext', 'tasksService', 'commentsDataContext', 'datacontext', 'user', 'myFormsService', 'myUsersDataContext', 'myFormsDataContext', 'common', '$location', '$rootScope', '$modal', '$filter', 'config', '$window', function (tasksDataContext, tasksService, commentsDataContext, datacontext, user, myFormsService, myUsersDataContext, myFormsDataContext, common, $location, $rootScope, $modal, $filter, config, $window) { return { restrict: 'E', templateUrl: templatePath + 'viewtask.html?version=160718', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("taskClass", "success"); var logError = getLogFn("taskClass", "error"); $scope.currentAssignedTask = tasksService.getCurrentAssignedTask(); $scope.comment = { content: '', isPrivate: false, }; $scope.showcases = []; $scope.siteUrl = config.siteUrl; $scope.formTypes = tasksService.getFormTypes(); $scope.selectedItemId = null; $scope.getBadgeCollectionUrl = function (collectionId) { return $scope.siteUrl + 'view/#!/collection?collectionid=' + collectionId + '&preview=true'; } //get showcases for this user function getShowcases() { datacontext.getShowcases().then(function (result) { for (var i = 0; i < result.length; i++) { if (result[i].showcaseState == "Published") { $scope.showcases.push(result[i]); } } if ($scope.showcases.length == 0) { $scope.noShowcases = true; } }); } // Get all the available forms for a user function getAllForms(type) { myFormsDataContext.getAvailableTemplates($scope.currentAssignedTask.ownerId).then(function (data) { //Don't include activity forms var filteredTemplates = $filter('filter')(data, function(template){ return template.formType != 5; }); if (type) { $scope.availableForms = []; for (i in data) { if (data[i].formType == type) { $scope.availableForms.push(data[i]); } } } else { $scope.availableForms = filteredTemplates; } $scope.availableFormsLoaded = true; }); } //get showcases for this user function getItems() { datacontext.getMyItems().then(function (items) { if (items.length == 0) { $scope.noItems = true; return; } if (items.items) $scope.items = items.items; else $scope.items = items; }); } function getComment() { if ($scope.currentAssignedTask.latestResponse) { if ($scope.currentAssignedTask.latestResponse.commentId !== "00000000-0000-0000-0000-000000000000") { commentsDataContext.getCommentById($scope.currentAssignedTask.latestResponse.commentId).then(function (comment) { $scope.comment = comment; }); } } } /* * Get showcase data from web service then set in selectedShowcase variable */ function getShowcaseDetail(showcaseId) { tasksDataContext.getShowcase(showcaseId).then(function (showcase) { $scope.selectedShowcase = showcase; }); } /* * Pick the matching showcase from she showcases array using an id */ function getSelectedShowcaseDetail(showcaseId){ angular.forEach($scope.showcases, function(s){ if(s.showcaseId == showcaseId){ $scope.selectedShowcase = s; $scope.deliverableValue = showcaseId return; } }); } /* * Get item data from web service then set in selectedItem variable */ $scope.getItemDetail = function (itemId) { $scope.item = null; if (itemId) { datacontext.getItem(itemId).then(function (item) { $scope.item = item; $scope.deliverableValue = config.myShowcaseItemApiUrl + item.type.replace(/\s/g, '') + 'items/' + item.itemId; }); } } $scope.getItemDetailBySource = function (source) { if (source) { datacontext.getItemDetailBySource(source).then(function (item) { $scope.item = item; $scope.deliverableValue = config.myShowcaseItemApiUrl + item.type.replace(/\s/g, '') + 'items/' + item.id; }); } } $scope.getFormDetail = function(formId) { tasksDataContext.getFormTemplate(formId).then(function (form) { $scope.selectedForm = myFormsService.createFormFromTemplate(form) }); } function getCompletedFormDetail(formId) { tasksDataContext.getCompletedForm(formId).then(function (form) { $scope.availableFormsLoaded = true; $scope.selectedForm = form; }); } if (!$scope.currentAssignedTask) { $location.path('/tasks'); } else { getItems(); datacontext.getShowcases().then(function (result) { for (var i = 0; i < result.length; i++) { if (result[i].showcaseState == "Published") { $scope.showcases.push(result[i]); } } if ($scope.showcases.length == 0) { $scope.noShowcases = true; } if ($scope.currentAssignedTask.latestResponse) { getComment(); if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Showcase') { $scope.responseType = 'Showcase'; getSelectedShowcaseDetail($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value) } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Stuff item') { $scope.responseType = 'Stuff item'; $scope.getItemDetailBySource($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value) } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { $scope.responseType = 'Form'; $scope.deliverableValue = $scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value if($scope.deliverableValue != null){ getCompletedFormDetail($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value); } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].name == 'formType') { getAllForms($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].value); } else { getAllForms(); } }else { getAllForms(); } } } } else { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { $scope.responseType = 'Form'; if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].name == 'formTemplateId') { var formId = $scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].value; if(formId != null){ $scope.getFormDetail(formId); } } else { getAllForms($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].value); } } else { getAllForms(); } } } } }); } // if status == 0 we save, else 1 is submit $scope.saveResponse = function (status, noRedirect, formResponse) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { $scope.submitStatus = status; if($scope.selectedForm != null){ $scope.selectedForm.externalId = $scope.currentAssignedTask.ownerId; $rootScope.$broadcast('saveFormResponse', { isComplete: status, isHosted: true }); } else { $scope.doSubmit(status, noRedirect, formResponse); } } else { $scope.doSubmit(status, noRedirect, formResponse); } } else { $scope.doSubmit(status, noRedirect, formResponse); } } $scope.doSubmit = function (status, noRedirect, formResponse) { commentsDataContext.createComment($scope.comment).then(function (data) { var response = { taskIndividualAssignmentId: $scope.currentAssignedTask.id, commentId: data.id, taskAssignmentResponseDeliverables: [], status: status } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0]) { response.taskAssignmentResponseDeliverables = [{ taskResponseTypeId: $scope.currentAssignedTask.taskRecord.taskResponseTypes[0].id, value: $scope.deliverableValue }]; if ($scope.currentAssignedTask.latestResponse) { if ($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables.length > 0) { $scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value = $scope.deliverableValue; delete $scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].id; } } } // It's a brand new response if (!$scope.currentAssignedTask.latestResponse) { if ($scope.currentAssignedTask.taskRecord.autoComplete) { response.status = status == 1 ? 6 : 0; tasksDataContext.submitAutoCompleteTaskResponse(response).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } else { tasksDataContext.submitTaskResponse(response).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } } else { $scope.currentAssignedTask.latestResponse.status = status; $scope.currentAssignedTask.latestResponse.commentId = data.id; if ($scope.currentAssignedTask.taskRecord.autoComplete) { $scope.currentAssignedTask.latestResponse.status = status == 1 ? 6 : 0; tasksDataContext.updateAutoCompleteTaskResponse($scope.currentAssignedTask.latestResponse).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } else { tasksDataContext.updateTaskResponse($scope.currentAssignedTask.latestResponse).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } } }); } //Set the selected showcase $scope.setSelectedShowcase = function (selectedShowcase) { $scope.selectedShowcase = selectedShowcase; if (selectedShowcase) { $scope.deliverableValue = selectedShowcase.showcaseId; } } $scope.getMarkingSchemeDetailsForValue = function (markingScheme) { for (var i = 0; i < $scope.currentAssignedTask.taskRecord.taskMarkingSchemes.length; i++) { if (markingScheme.taskMarkingSchemeId == $scope.currentAssignedTask.taskRecord.taskMarkingSchemes[i].id) { $scope.getMarkingScheme(markingScheme, $scope.currentAssignedTask.taskRecord.taskMarkingSchemes[i].markingSchemeId); } } } $scope.getMarkingScheme = function (markingScheme, markingSchemeId) { tasksDataContext.getMarkingScheme(markingSchemeId).then(function (data) { markingScheme.markingScheme = data; return markingScheme; }); } $scope.getBadgeDetails = function (badge) { tasksDataContext.getTemplate(badge.badgeId).then(function (data) { badge.badge = data; return badge; }); } $scope.setBadgeDetails = function (badge) { for (var j = 0; j < $scope.currentAssignedTask.taskRecord.taskBadges.length; j++) { if (badge.taskBadgeId == $scope.currentAssignedTask.taskRecord.taskBadges[j].id) { badge.taskBadge = $scope.currentAssignedTask.taskRecord.taskBadges[j]; tasksDataContext.getTemplate(badge.taskBadge.badgeId).then(function (data) { badge.badge = data; return badge; }); } } } $scope.getAssignerDetails = function (assigner) { if (assigner) { user.getUserProfile(assigner.createdBy).then(function (data) { assigner.user = data; }); } } $scope.getUserDetails = function (assignedTask) { if (assignedTask) { user.getUserProfile(assignedTask.ownerId).then(function (data) { assignedTask.user = data; }); } } $scope.checkResponseValidility = function () { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length>0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Showcase') { if (!$scope.selectedShowcase) { return true; } } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { if (!$scope.selectedForm) { return true; } } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Stuff item') { if (!$scope.item) { return true; } } } } $scope.onFormItemCreated = function (form) { $scope.deliverableValue = form.formId; $scope.doSubmit($scope.submitStatus, false); } $scope.downloadFile = function (fileUrl, fileName) { var url; user.getUploadBucketSas().then(function (sas) { $scope.sasToken = sas.sas; $scope.requiresAuth = true; //set the sas token start and end dates $scope.tokenStart = new Date().getTime(); $scope.tokenEnd = $scope.tokenStart + 1800000; url = fileUrl + $scope.sasToken; $window.open(url); }); } } }]); // embed app.directive('itemEmbedded', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/embed.html' }; }); //prezi app.directive('itemPrezi', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/embedprezi.html' }; }); //Evernote app.directive('itemEvernote', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/evernote.html' }; }); // Rich text / HTML block app.directive('itemStatus', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/status.html' }; }); // Uploaded file app.directive('itemFile', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/file.html' }; }); // Uploaded image app.directive('itemImage', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/image.html' }; }); // Uploaded video app.directive('itemVideo', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/video.html', link: function (scope, elm, attr) { scope.cloudinaryVideoBaseUrl = cloudinaryVideoBaseUrl; } }; }); // Uploaded badge app.directive('itemBadge', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/badge.html' }; }); // Added form app.directive('itemForm', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/form.html' }; }); // Added badge collection app.directive('itemBadgeCollection', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/badge-collection.html' }; }); // Form styles app.directive('formStyles', function () { return { restrict: 'E', templateUrl: '/modules/MyFormsCompleted/views/styles.html' }; }); // Uploaded weblink app.directive('itemWeblink', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/weblink.html', link: link }; function link(scope, element, attrs) { scope.baseWebLinkImageUrl = baseWebLinkImageUrl; } }); // MyProgress Assessment items app.directive('itemAssessment', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/assessment2.html', scope: { myShowcaseItem: '=', accessToken: '=', hideDate: '=' }, link: function ($scope, element, attrs) { function lowerFirstLetterObjectKeys(input) { if (typeof input !== 'object' || input == null) return input; if (Array.isArray(input)) return input.map(lowerFirstLetterObjectKeys); return Object.keys(input).reduce(function (newObj, key) { let val = input[key]; let newVal = (typeof val === 'object') ? lowerFirstLetterObjectKeys(val) : val; newObj[key.replace(key[0], key[0].toLowerCase())] = newVal; return newObj; }, {}); } function parseResponse(jsonResponse) { //Parse json, restoring properties to PascalCase where needed var parsedResponse = JSON.parse(jsonResponse, function (key, value) { if (key.length < 2 || key[0] === key[0].toUpperCase() || key === "allocatedAssessmentGuid" || key === "publishedResourceId" || key === "responseIdentifier" || key === "usingEmail" || key === "data" || key === "type" || key === "width" || key === "height" || key === "src") { return value; } else { var newKey = key.replace(key[0], key[0].toUpperCase()); this[newKey] = value; return undefined; //removes old key } }); //recursively return result properties to camel case. We can't do this in the reviver function when parsing //because only properties in the result object hierarchy should be changed, and some share names with properties //in other objects parsedResponse.Result = lowerFirstLetterObjectKeys(parsedResponse.Result); //StreamedResource.Type is an exception to the rule that all 'type' properties are lowercase parsedResponse.StreamedResources.forEach(function (resource) { if (resource.Type == undefined && resource.type != undefined) { resource.Type = resource.type; } }); return parsedResponse; } $scope.$watch('myShowcaseItem', function() { if (typeof $scope.myShowcaseItem.jsonResponse === 'string') $scope.myShowcaseItem.jsonResponse = parseResponse($scope.myShowcaseItem.jsonResponse); }); if (!$scope.myShowcaseItem.itemId) $scope.myShowcaseItem.itemId = $scope.myShowcaseItem.id; $scope.getLetter = function (index) { if (0 <= index && index <= 25) { return String.fromCharCode(65 + index); } else if (26 <= index <= 51) { return String.fromCharCode(71 + index); } else { return ''; } } $scope.getAssessmentItemResultFromCustomText = function (customText) { var assessmentItemIdentifier = $scope.getAssessmentItemIdentifier(customText); if (assessmentItemIdentifier.length > 0) { var result = $scope.getAssessmentItemResult(assessmentItemIdentifier); return result; } return null; } $scope.getAssessmentItemResult = function (assessmentItemIdentifier) { var resultArray = $scope.myShowcaseItem.jsonResponse.Result.itemResults.filter(function (assessmentItemResult) { return assessmentItemResult.identifier === assessmentItemIdentifier; }) if (resultArray.length > 0) { return resultArray[0]; } else { return null; } } $scope.getAssessmentItemIdentifier = function (customText) { var identifierString = 'identifier:'; if (customText && customText.length > 0 && customText.indexOf(identifierString) > -1) { var startIndex = customText.indexOf(identifierString) + identifierString.length; return customText.substring(startIndex); } return ''; } $scope.isAssessmentItemHidden = function (customText) { if (customText && customText.length > 0) { for (var i = 0; i < $scope.myShowcaseItem.jsonResponse.HiddenAssessmentItemIdentifiers.length; i++) { if (customText.includes($scope.myShowcaseItem.jsonResponse.HiddenAssessmentItemIdentifiers[i])) { return true; } } } return false; } } }; }); })();