-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathnew-unit.js
76 lines (72 loc) · 2.12 KB
/
new-unit.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
'use strict';
/**
* @ngdoc function
* @name fleetuiApp.controller:NewUnitCtrl
* @description
* # NewUnitCtrl
* Controller of the fleetuiApp
*/
angular.module('fleetuiApp')
.controller('NewUnitCtrl', function ($scope, $state, $timeout, unitService) {
$scope.newUnit = {
isLoading: false,
name: 'new-service.service',
service: "[Unit]\n" +
"Description=New Service\n" +
"Requires=docker.service\n" +
"After=docker.service\n" +
"\n[Service]\n" +
"ExecStart=\n" +
"ExecStop=\n" +
"\n[X-Fleet]\n",
submit: function() {
var _this = this;
if(!_this.isLoading && confirm('Start unit?')) {
_this.isLoading = true;
unitService.save({ name: _this.name, service: _this.service }, function(data) {
_this.isLoading = false;
$state.go('root.main.unit', { name: _this.name });
}, function() {
_this.isLoading = false;
});
}
}
}
$scope.unitUpload = {
loading: false,
url: 'api/v1/units/upload',
options: {
container: 'unitUploadBtn',
multi_selection: false,
max_file_size: '6mb',
filters: {
mime_types : [
{ title: "service file", extensions : "service" }
]
}
},
callbacks: {
filesAdded: function(uploader, files) {
$scope.unitUpload.loading = true;
$timeout(function() { uploader.start() }, 1);
},
fileUploaded: function(uploader, file, response) {
$scope.unitUpload.loading = false;
if(response.response) {
var data = $.parseJSON(response.response);
if(data.result == 'success') {
$state.go('root.main.unit', { name: file.name });
}
}
},
error: function(uploader, error) {
$scope.unitUpload.loading = false;
if(error.code == plupload.FILE_SIZE_ERROR) {
alert("최대 6mb까지 첨부가능합니다.");
} else {
alert(error.message);
}
}
}
};
});