-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsurvey-preview.js
47 lines (41 loc) · 1.33 KB
/
survey-preview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var studyPreviewModule = angular.module("SurveyPreview", ['SurveyCommon'])
.controller("SurveyPreviewController",
["$scope", "surveyCache", "$routeParams", "$location",
function($scope, surveyCache, $routeParams, $location) {
var surveyData = $routeParams.id ? surveyCache.get($routeParams.id) : {};
if (!surveyData) {
$location.path('/');
return;
}
$scope.data = {};
this.survey = surveyData;
this.submit = function(valid, data) {
if (valid) {
console.log('submitted', data);
}
}
}])
.controller("InputComponentController", ['$scope', '$attrs', function($scope, $attrs) {
var directiveScope = $scope.$parent;
this.options = directiveScope.$eval($attrs.field);
}]);
angular.forEach({
'input-text': 'appInputTextComponent',
'input-url': 'appInputUrlComponent',
'input-email': 'appInputEmailComponent',
'input-date': 'appInputDateComponent',
'select': 'appSelectComponent',
'textarea': 'appTextareaComponent'
}, function(directiveSelector, tpl) {
studyPreviewModule
.directive(directiveSelector, [function() {
return {
controller: 'InputComponentController',
controllerAs: 'componentCtrl',
templateUrl : './field-templates/' + tpl + '.html',
scope: {
model: '='
}
}
}])
});