(function () { 'use strict'; var serviceId = 'myFormsDataContext'; angular.module('myforms').factory(serviceId, ['appDataContext', 'myFormsConfig', datacontext]); function datacontext(appDataContext, config) { var currentForm; var service = {}; /** * Get all my forms */ service.getForms = function () { return appDataContext.get(config.formRemoteServiceUrl); } /** * Get a specific form */ service.getForm = function (formId) { return appDataContext.get(config.formRemoteServiceUrl + formId); } /** * Create a new form */ service.createForm = function (form) { appDataContext.clearCaches([config.myTemplatesCacheItem, config.templatesCacheItem]); return appDataContext.post(config.formRemoteServiceUrl, form); } /** * Edit an existing form */ service.editForm = function (formId, form) { appDataContext.clearCaches([config.myTemplatesCacheItem, config.templatesCacheItem]); return appDataContext.put(config.formRemoteServiceUrl + formId, form); } /** * Lock a form */ service.lockForm = function (formId) { return appDataContext.get(config.formRemoteServiceUrl + formId + "/lock"); } /** * Unlock a form */ service.unlockForm = function (formId) { return appDataContext.get(config.formRemoteServiceUrl + formId + "/unlock"); } /** * Delete a form */ service.deleteForm = function (formId) { return appDataContext.delete(config.formRemoteServiceUrl + formId); } /** * Get the available form templates for a user / organisation */ service.getAvailableTemplates = function (id) { return appDataContext.get(config.formTemplateRemoteServiceUrl + id + "/allavailable", config.cache, config.myTemplatesCacheItem); } /** * Get the available activity templates */ service.getAvailableActivityTemplates = function() { return appDataContext.get(config.formTemplateRemoteServiceUrl + "/activities/allavailable"); } /** * Get the available templates to create forms */ service.getAvailableTemplatesToCreateForms = function() { return appDataContext.get(config.formTemplateManagementRemoteServiceUrl + "/activities/allavailabletocreate"); } /** * Get the available templates to view entries */ service.getAvailableTemplatesToViewEntries = function() { return appDataContext.get(config.formTemplateManagementRemoteServiceUrl + "/activities/allavailabletoviewentries"); } /** * Get the activity entries for a form */ service.getActivityEntries = function(activityFormId) { return appDataContext.get(config.formRemoteServiceUrl + "activities/" + activityFormId + "/entries"); } /** * Get all available form templates */ service.getAllAvailableTemplates = function() { return appDataContext.get(config.formTemplateRemoteServiceUrl + "/allavailable", config.cache, config.templatesCacheItem); } /** * Get all publicly available form templates */ service.getPublicFormTemplates = function() { return appDataContext.get(config.formTemplateRemoteServiceUrl + "public"); } /** * Get a specific form template using the Id */ service.getFormTemplate = function(formTemplateId) { return appDataContext.get(config.formTemplateRemoteServiceUrl + formTemplateId); } /** * Set form */ service.setCurrentForm = function (form) { currentForm = form; } /** * Get form */ service.getCurrentForm = function () { return currentForm; } /** * Get a new scoring band based on the max range and existing scoring bands */ service.getNewScoringBand = function (scoring, max) { var data = { bands: scoring, maxRange: max, }; return appDataContext.post(config.formTemplateManagementRemoteServiceUrl + "scoringbands", data); } return service; } })();