-
Notifications
You must be signed in to change notification settings - Fork 3
/
editArea.js
142 lines (119 loc) · 4.62 KB
/
editArea.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// TODO: rename this controller to something better -- should be the controller for the entire page
// TODO: the catNav directive has its own controller - move navigation functions there
angular.module('controllers').controller('EditAreaCtrl', ['$scope', '$location', '$anchorScroll', 'Document', '$modal',
'$log', 'editSession', 'loggerUrl', '$rootScope', 'Wikipedia', 'Document',
function($scope, $location, $anchorScroll, Document, $modal, $log, session, loggerUrl, $rootScope, Wikipedia,
Document) {
// TODO: move this to a proper global controller for the edit area
// global user options (may be accessed or changed from child controllers)
$scope.visible = {
toolbar: false
};
$scope.session = session;
// TODO: remove the Document service and set document data directly on this controller
$scope.document = Document;
$scope.url = loggerUrl;
// based on http:https://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side
// and http:https://stackoverflow.com/a/15031019
$scope.saveDocument = function() {
console.error('prueba!');
var bb = new Blob([new XMLSerializer().serializeToString( Document.DOM )], {type: "application/xml"});
saveAs(bb, "document.xliff");
};
$scope.showReplaceModal = function() {
var modalInstance = $modal.open({
templateUrl: 'scripts/contentArea/replace-modal.html',
controller: 'ReplaceCtrl'
});
modalInstance.result.then(function () {
}, function () {
$log.info('Modal dismissed at: ' + new Date());
}); };
$scope.$on('perform-propagation', function(event, action) {
$scope.$broadcast('propagate-action', action);
});
// Move to the bottom of the page when all the segments are complete
$scope.scrollDone = false;
$scope.scrollToBottom = function() {
$location.hash('footmsg');
$anchorScroll();
$scope.scrollDone = true;
};
// Check if all the segments are marked as completed
$scope.checkTranslationCompleted = function() {
if (!Document.DOM)
return false; // do not show completed before starting the job!
for (var i = 0; i < Document.completedSegments.length; ++i)
if (Document.completedSegments[i] == false)
return false;
if (!$scope.scrollDone)
$scope.scrollToBottom();
return true;
};
$scope.
openHelp = function (size) {
var modalInstance = $modal.open({
templateUrl: 'scripts/contentArea/help-modal.html',
// template: '<div>TEST MODAL</div>',
controller: ModalInstanceCtrl,
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};
// Shows/hides the invisible characters (space is a dot, etc)
// Destination of a ng-click from toolbar.html
$scope.updateShowInvisibleChars = function(value) {
$scope.$broadcast('toggleShowInvisibleChars', value);
};
// used as a callback for the glossary
var updateGlossaryArea = function(glossaryMatches) {
if (glossaryMatches) {
// the toolbar should be listening for this
$rootScope.$broadcast('update-glossary-area', glossaryMatches);
}
};
$scope.queryGlossary = function(query, fromLang, toLang) {
Glossary.getMatches(query, updateGlossaryArea, fromLang, toLang);
Session.updateStat('queryGlossary', $scope.$index, query);
};
// Working - use a callback here just like with the glossary
// Working - remove the event listener here - give it to the toolbar
// Concordance
$scope.queryConcordancer = function(query, lang) {
if (!lang)
lang = $scope.document.sourceLang;
$scope.concordancerError = false;
//Session.updateStat('queryConcordancer', $scope.$index, query);
Wikipedia.getConcordances(query, lang);
};
$scope.$on('concordancer-updated', function() {
// does $scope.$apply happen automagically? - answer: no, so we have to listen for the event
$scope.concordanceMatches = Wikipedia.currentQuery;
});
$scope.$on('concordancer-error', function() {
$scope.concordancerError = true;
});
}]);