Project

General

Profile

1
var module = angular.module('modalRelation', []);
2

    
3
module.directive('modalRelation', function(){
4
	return {
5
		restrict: 'E',
6
		templateUrl: '../resources/html/vocabularies/modalRelation.html',
7
		controller: function($scope) {
8
			$scope.showRelModal = function(term, rel) {
9
				$scope.selectedTermIndex = $scope.entries.indexOf(term);
10
				$scope.selectedRelIndex = $scope.entries[$scope.selectedTermIndex].relations.indexOf(rel);
11
				if (rel != null) {
12
					// edit existing synonym
13
					$scope.modalRel.refTerm = $scope.entries[$scope.selectedTermIndex].englishName;
14
					$scope.modalRel.code = $scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].code;
15
					$scope.modalRel.type = $scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].type;
16
				} else {
17
					// new synonym
18
					$scope.modalRel.refTerm = $scope.entries[$scope.selectedTermIndex].englishName;
19
					$scope.modalRel.code = '';
20
					$scope.modalRel.type = '';
21
				}
22
				$('#relModal').modal();
23
			};
24

    
25
			$scope.editRel = function() {
26
				if ($scope.selectedRelIndex == -1) {
27
					$scope.entries[$scope.selectedTermIndex].relations.push({
28
						"code" : $scope.modalRel.code,
29
						"type" : $scope.modalRel.type
30
					});
31
				} else {
32
					$scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].code = $scope.modalRel.code;
33
					$scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].type = $scope.modalRel.type;
34
				}
35
				// dismiss modal
36
				$('.modal').modal('hide');
37
				if ($scope.autocommit) {
38
					$scope.commit();
39
				} else {
40
					showPermanotice("Uncommitted changes!");
41
				}
42
			}
43
		},
44
		controllerAs: 'modalRelation'
45
	};
46
});
(20-20/34)