(function () { 'use strict'; var serviceId = 'tasksDataContext'; angular.module('tasks').factory(serviceId, ['$q', '$http', 'tasksConfig', datacontext]); function datacontext($q, $http, config, $modal) { var service = { submitTaskResponse: submitTaskResponse, submitAutoCompleteTaskResponse: submitAutoCompleteTaskResponse, getAssignedTasks: getAssignedTasks, hasAssignedTasks: hasAssignedTasks, updateTaskResponse: updateTaskResponse, updateAutoCompleteTaskResponse: updateAutoCompleteTaskResponse, getShowcase: getShowcase, getMarkingScheme: getMarkingScheme, getTemplate: getTemplate, getFormTemplate: getFormTemplate, getCompletedForm: getCompletedForm }; return service; function handleError(response) { // The API response from the server should be returned in a // nomralized format. However, if the request was not handled by the // server (or what not handles properly - ex. server error), then we // may have to normalize it on our end, as best we can. if ( !angular.isObject(response.data) || !response.data.message ) { return ($q.reject("An unknown error occurred.")); } // Otherwise, use expected error message. return ($q.reject(response.data.message)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } function getAssignedTasks() { var request = $http({ method: "get", url: config.taskUrl + 'taskindividualassignments', }); return (request.then(handleSuccess, handleError)); } function hasAssignedTasks() { var request = $http({ method: "get", url: config.taskUrl + 'taskindividualassignments/assigned', }); return (request.then(handleSuccess, handleError)); } function submitTaskResponse(response) { var request = $http({ method: "post", url: config.taskUrl + 'taskassignmentresponses', data: response }); return (request.then(handleSuccess, handleError)); } function submitAutoCompleteTaskResponse(response) { var request = $http({ method: "post", url: config.taskUrl + 'taskassignmentresponses/autocomplete', data: response }); return (request.then(handleSuccess, handleError)); } function updateTaskResponse(response) { var request = $http({ method: "put", url: config.taskUrl + 'taskassignmentresponses', data: response }); return (request.then(handleSuccess, handleError)); } function updateAutoCompleteTaskResponse(response) { var request = $http({ method: "put", url: config.taskUrl + 'taskassignmentresponses/autocomplete', data: response }); return (request.then(handleSuccess, handleError)); } //get a specific showcase using its unique ID function getShowcase(showcaseId) { var request = $http({ method: "get", url: 'api/showcase/' + showcaseId }); return (request.then(handleSuccess, handleError)); } function getMarkingScheme(markingSchemeId) { var request = $http({ method: "get", url: markingSchemeUrl + 'schemes/' + markingSchemeId, }); return (request.then(handleSuccess, handleError)); } // Get existing badge template function getTemplate(templateId) { var request = $http({ method: "get", url: config.mybadgesUrl + 'badgetemplates/' + templateId }); return (request.then(handleSuccess, handleError)); } //get a specific form template function getFormTemplate(formTemplateId) { var request = $http({ method: "get", url: myformsUrl + 'formtemplate/' + formTemplateId }); return (request.then(handleSuccess, handleError)); } //get a specific form template function getCompletedForm(formTemplateId) { var request = $http({ method: "get", url: myformsUrl + 'form/' + formTemplateId }); return (request.then(handleSuccess, handleError)); } } })();