(function () { 'use strict'; //helper functionality for myforms var serviceId = 'myFormsService'; angular.module('myforms').factory(serviceId, [ myFormsService]); function myFormsService() { var service = { createFormFromTemplate: createFormFromTemplate }; return service; function getQuestionAnswers(template) { var questionAnswers = []; //go through all the questions and create a question / answer pair for (var i = 0; i < template.sections[0].questions.length; i++) { questionAnswers.push({ question: template.sections[0].questions[i], answer: {} }); } return questionAnswers; } //create a new form from its template function createFormFromTemplate(template, formId) { var form = { formType: template.formType, formTemplateId: template.id, name: template.name, title: template.title, description: template.description, iconUri: template.iconUri, backgroundColour: template.backgroundColour, fontColour: template.fontColour, highlightColour:template.highlightColour, sections: [ { name: template.sections[0].name } ], externalId: template.externalId, isFeedbackGivenAfterQuiz: template.isFeedbackGivenAfterQuiz, isFeedbackGivenDuringQuiz: template.isFeedbackGivenDuringQuiz, id: formId, //might be null //activity fields targetEntriesNumber: template.targetEntriesNumber, individualCanCreate: template.individualCanCreate, individualCanDelete: template.individualCanDelete, individualCanEdit: template.individualCanEdit, individualCanView: template.individualCanView }; form.sections[0].questionAnswers = getQuestionAnswers(template); return form; } } })();