Skip to content

Commit 444c1c9

Browse files
author
dularion
committed
refactor: hoist methods in modal-file-ctrl.js
1 parent b6e0882 commit 444c1c9

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

grails-app/assets/javascripts/streama/controllers/modal-file-ctrl.js

+35-30
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@ angular.module('streama').controller('modalFileCtrl', [
1313
var localFileLastPath = localStorageService.get('localFileLastPath')|| '';
1414
$scope.localDir = localFileLastPath.split('/') || [];
1515
$scope.video = video;
16+
$scope.uploadStatus = {};
17+
$scope.upload = uploadService.doUpload.bind(uploadService, $scope.uploadStatus, 'video/uploadFile.json?id=' + video.id, onUploadSuccess, function () {});
1618

1719
$scope.loadLocalFiles = loadLocalFiles;
1820
$scope.backLocalDirectory = backLocalDirectory;
1921
$scope.openLocalDirectory = openLocalDirectory;
2022
$scope.toggleCloseOnSelect = toggleCloseOnSelect;
21-
23+
$scope.addLocalFile = addLocalFile;
24+
$scope.cancel = cancel;
25+
$scope.removeFile = removeFile;
26+
$scope.saveChanges = saveChanges;
27+
$scope.getFilesForExtensions = getFilesForExtensions;
28+
$scope.addExternalUrl = addExternalUrl;
2229

2330
$scope.loadLocalFiles(localFileLastPath);
2431

32+
$scope.$watch('activeTab', onTabChange);
2533

26-
$scope.$watch('activeTab', function (newVal, oldVal) {
34+
function onTabChange(newVal, oldVal) {
2735
localStorageService.set('activeFileModalTab', newVal);
28-
});
36+
}
2937

3038
function loadLocalFiles(path) {
3139
apiService.file.localFiles(path).then(function(response) {
@@ -53,7 +61,8 @@ angular.module('streama').controller('modalFileCtrl', [
5361
$scope.loadLocalFiles($scope.localDir.join('/'));
5462
}
5563

56-
$scope.addExternalUrl = function (externalUrl) {
64+
65+
function addExternalUrl(externalUrl) {
5766
apiService.video.addExternalUrl({id: $scope.video.id, externalUrl: externalUrl}).then(function (response) {
5867
alertify.success("External URL Added.");
5968
$scope.video.externalLink = null;
@@ -66,9 +75,9 @@ angular.module('streama').controller('modalFileCtrl', [
6675
$scope.video.hasFiles = true;
6776
}
6877
});
69-
};
78+
}
7079

71-
$scope.addLocalFile = function (localFile) {
80+
function addLocalFile(localFile) {
7281
apiService.video.addLocalFile({id: $scope.video.id, localFile: localFile}).then(function (response) {
7382
var data = response.data;
7483
alertify.success("Local File Added.");
@@ -79,21 +88,17 @@ angular.module('streama').controller('modalFileCtrl', [
7988
}else{
8089
$scope.video.files = $scope.video.files || [];
8190
$scope.video.files.push(data);
82-
$scope.video.hasFiles = true;
91+
$scope.video.hasFiles = true;
8392
}
8493
if($scope.closeOnSelect){
8594
$uibModalInstance.dismiss('cancel');
8695
}
8796
}, function(data) {
8897
alertify.error(data.message);
8998
});
90-
};
91-
92-
$scope.cancel = function () {
93-
$uibModalInstance.dismiss('cancel');
94-
};
99+
}
95100

96-
$scope.removeFile = function (file) {
101+
function removeFile(file) {
97102
alertify.set({ buttonReverse: true, labels: {ok: "Yes", cancel : "Cancel"}});
98103
alertify.confirm('Are you sure you want to remove the file "'+file.originalFilename+'"?', function (confirmed) {
99104
if(confirmed){
@@ -108,44 +113,44 @@ angular.module('streama').controller('modalFileCtrl', [
108113
});
109114
}
110115
});
111-
};
116+
}
112117

113-
$scope.saveChanges = function (file) {
118+
function cancel() {
119+
$uibModalInstance.dismiss('cancel');
120+
}
121+
function saveChanges(file) {
114122
apiService.file.save(file).then(function (data) {
115123
alertify.success('File successfully saved.');
116124
});
117-
};
118-
125+
}
119126

120-
$scope.uploadStatus = {};
121-
$scope.upload = uploadService.doUpload.bind(uploadService, $scope.uploadStatus, 'video/uploadFile.json?id=' + video.id, function (data) {
122-
127+
function onUploadSuccess(data) {
123128
$scope.uploadStatus.percentage = null;
124-
125-
if(data.error) return
129+
if(data.error) return;
126130

127131
if(data.extension == '.srt' || data.extension == '.vtt'){
128132
$scope.video.subtitles = $scope.video.subtitles || [];
129133
$scope.video.subtitles.push(data);
130-
$scope.video.hasFiles = true;
134+
$scope.video.hasFiles = true;
131135
alertify.success('Subtitles uploaded successfully.');
132136
}else{
133137
$scope.video.files = $scope.video.files || [];
134138
$scope.video.files.push(data);
135-
$scope.video.hasFiles = true;
139+
$scope.video.hasFiles = true;
136140
alertify.success('Video uploaded successfully.');
137141
}
138142

139-
}, function () {});
143+
}
140144

141-
$scope.getFilesForExtensions = function(extensions){
142-
return _.filter($scope.video.files, function (file) {
143-
return (extensions.indexOf(file.extension.toLowerCase()) > -1);
144-
})
145-
};
146145

147146
function toggleCloseOnSelect() {
148147
localStorageService.set('fileModal.closeOnSelect', $scope.closeOnSelect);
149148
}
150149

150+
function getFilesForExtensions(extensions){
151+
return _.filter($scope.video.files, function (file) {
152+
return (extensions.indexOf(file.extension.toLowerCase()) > -1);
153+
})
154+
}
155+
151156
}]);

0 commit comments

Comments
 (0)