/
formDirective.js
76 lines (66 loc) · 2.54 KB
/
formDirective.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/// <reference path="../../../../typings/angularjs/angular.d.ts"/>
angular.module('changeApp')
.directive('renderForm', function (FormServ) {
return {
scope: {},
templateUrl: "/app/components/form/renderFullFormView.html",
restrict: 'E',
link: function (scope, elem, attrs) {
scope.formData = FormServ.currentFormData.getAllItems();
}
};
})
.directive('renderFormComponent', function (FormServ) {
return {
restrict: 'E',
scope: {
componentData: '=component',
type: '=type'
},
templateUrl: "/app/components/form/renderComponentView.html",
controller: function ($scope, FormServ) {
var deletion = false;
$scope.confirmDeletion = function () {
return deletion;
};
$scope.clickUpButton = function ( index ) {
// log only for reference. Need to be removed
console.log('Up button pressed for ' + index);
FormServ.currentFormData.moveUp(index);
};
$scope.clickDownButton = function ( index ) {
// log only for reference. Need to be removed
console.log('Down button pressed');
FormServ.currentFormData.moveDown(index);
};
$scope.clickEditButton = function ( index ) {
// log only for reference. Need to be removed
console.log('Edit button pressed');
};
$scope.clickDeleteButton = function ( index ) {
// log only for reference. Need to be removed
console.log('Delete button pressed');
deletion = true;
//code to show the confirmation dialog
};
$scope.deletionConfirmed = function ( index ) {
//call deletion method in currentForm
console.log('Delete item with index: ', index);
FormServ.currentFormData.deleteItem(index);
};
$scope.deletionCancelled = function () {
//close the confirmation dialog
deletion = false;
};
}
};
})
.directive('createFormComponent', function (FormServ) {
return {
restrict: 'E',
link: function (scope, elem, attrs) {
scope.itemData = FormServ.newItemData;
},
templateUrl: "/app/components/form/createComponentView.html"
};
});