(function() { 'use strict'; var app = angular.module('myformsCompleted'); var templatePath = modulesSharedResourcesUrl + 'Modules/MyFormsCompleted/Views/'; var styleSheetPath = modulesSharedResourcesUrl + 'Modules/MyFormsCompleted/styles/styles.css'; app.directive('completedFormViewMenu', ['$location', function($location) { return { restrict: 'E', scope: { onFormClose: '&', //tell the directive host what to do when finished viewing the form }, templateUrl: templatePath + 'completedFormViewMenu.html', link: link }; function link(scope, elem, attrs) { scope.close = function () { $location.path('/completed'); }; } }]); //a directive that renders a completed form (not as a completable form but as markup) app.directive('completedFormRenderer', ['myFormsCompletedDataContext', '$location', function (myFormsDataContext, $location) { return { restrict: 'E', scope: { formId: '=', isPublishView: '=', isTaskView: '=' }, templateUrl: templatePath + 'completedformrenderer.html', link: link }; function link(scope, elem, attrs) { scope.styleSheetPath = styleSheetPath; myFormsDataContext.getForm(scope.formId).then(function (theForm) { scope.selectedForm = theForm; handleChoiceQuestionsOnLoading(scope.selectedForm); scope.formLoaded = true; }); scope.chartOptions = { animate: { duration: 1000, enabled: true }, trackColor: '#444444', barColor: '#FFFFFF', scaleColor: false, lineWidth: 15, lineCap: 'circle', size: 100 }; scope.getIframeSrc = function (formId) { return 'https://myforms.mkmapps.local/app/#!/viewform/' + formId; }; scope.cancel = function () { if (scope.onCancel) scope.onCancel()(scope.selectedForm); } function handleChoiceQuestionsOnLoading(theForm) { for (var i = 0; i < theForm.sections[0].questionAnswers.length; i++) { var questionAnswer = theForm.sections[0].questionAnswers[i]; var question = questionAnswer.question; var answer = questionAnswer.answer; if (question.isCheckListQuestion && answer.choices) { for (var j = 0; j < answer.choices.length; j++) { if (answer.choices[j].isChosen) { for (var k = 0; k < question.choices.length; k++) { if (question.choices[k].choiceId === answer.choices[j].choiceId) question.choices[k].isChosen = true; } } } } if (question.isChoiceQuestion && answer.choices) { for (var j = 0; j < answer.choices.length; j++) { if (answer.choices[j].isChosen) { answer.chosen = { choice: answer.choices[j].choice, choiceId: answer.choices[j].choiceId }; break; } } } } } } }]); //render a completed question app.directive('completedQuestionView', ['myFormsCompletedConfig', '$sce', function (myFormsConfig, $sce) { return { restrict: 'E', scope: { questionAnswer: '=', quizScoringOnCorrectAnswers: '=' }, templateUrl: templatePath + 'completedquestionview.html', link: link }; function link(scope, elem, attrs) { scope.sanitisedQuestionText = $sce.trustAsHtml(scope.questionAnswer.question.questionText); scope.sanitisedSupportingText = $sce.trustAsHtml(scope.questionAnswer.question.supportingText); scope.getImageUrl = function (question) { var publicId = 'placeholder_vlosor'; if (question && question.imageUrl) publicId = question.imageUrl; return myFormsConfig.formIconBlank + 'h_150/' + publicId + '.png'; } } }]); app.directive('styler', function ($compile) { return { restrict: 'E', link: function postLink(scope, element) { if (element.html()) { var template = $compile(''); element.replaceWith(template(scope)); } } }; }); app.directive('formStyles', function () { return { restrict: 'E', templateUrl: '/modules/MyFormsCompleted/views/styles.html' }; }); app.filter('to_trusted', ['$sce', function($sce){ return function(text) { return $sce.trustAsHtml(text); }; }]) })();