1
+ var theApp = angular . module ( 'theApp' , [ ] ) ;
2
+ theApp . controller ( 'filesCtl' , function ( $scope , $http , $element , $timeout , $window ) {
3
+ $scope . downloadFile = function ( event , id ) {
4
+ var trItem = $element . find ( '#tr-' + id ) ;
5
+ var path = trItem . attr ( "data-href" ) ;
6
+ var file = trItem . attr ( "data-file" ) ;
7
+ var url = window . location . href ;
8
+ url += ( url . search ( '/?' ) > 0 ? '&' : '?' ) ;
9
+
10
+ $window . open ( url + "act=download&targetf=" + file , '_blank' ) ;
11
+ $window . focus ( ) ;
12
+ }
13
+ $scope . zipDir = function ( event , id ) {
14
+ var zipBtn = angular . element ( event . target ) ;
15
+ zipBtn . html ( '<span class="spinner-grow spinner-grow-sm" style="margin:0 5px 0 -2px;" role="status" aria-hidden="true"></span> Zipping ...' ) ;
16
+ angular . element ( ".btn-dirtozip" ) . attr ( "disabled" , true ) ;
17
+
18
+ var trItem = $element . find ( '#tr-' + id ) ;
19
+ var path = trItem . attr ( "data-href" ) ;
20
+
21
+ $http ( {
22
+ method : 'POST' ,
23
+ url : "index.php" ,
24
+ headers : {
25
+ 'Content-Type' : 'application/x-www-form-urlencoded'
26
+ } ,
27
+ data : {
28
+ act : 'zip' ,
29
+ path : path
30
+ }
31
+ } ) . then ( function successCallback ( response ) {
32
+ if ( response . data . status === true ) {
33
+ zipBtn . html ( 'Create Zip File' ) ;
34
+ angular . element ( ".btn-dirtozip" ) . attr ( "disabled" , false ) ;
35
+
36
+ $timeout ( function ( ) {
37
+ $window . location . reload ( ) ;
38
+ } , 250 ) ;
39
+ } else {
40
+ trItem . addClass ( "dangerHighlight" ) ;
41
+ $timeout ( function ( ) {
42
+ trItem . addClass ( "highlightOut" ) ;
43
+ } , 1000 ) ;
44
+ }
45
+
46
+ } , function errorCallback ( response ) { } ) ;
47
+ }
48
+
49
+ $scope . deleteFileDir = function ( event , id ) {
50
+ var trItem = $element . find ( '#tr-' + id ) ;
51
+ var path = trItem . attr ( "data-href" ) ;
52
+ trItem . removeClass ( ) ;
53
+ $http ( {
54
+ method : 'DELETE' ,
55
+ url : "index.php" ,
56
+ headers : {
57
+ 'Content-Type' : 'application/x-www-form-urlencoded'
58
+ } ,
59
+ data : {
60
+ act : 'del' ,
61
+ path : path
62
+ }
63
+ } ) . then ( function successCallback ( response ) {
64
+ if ( response . data . status === true ) {
65
+ trItem . hide ( 250 ) ;
66
+ $timeout ( function ( ) {
67
+ trItem . remove ( ) ;
68
+ } , 250 ) ;
69
+ } else {
70
+ trItem . addClass ( "dangerHighlight" ) ;
71
+ $timeout ( function ( ) {
72
+ trItem . addClass ( "highlightOut" ) ;
73
+ } , 1000 ) ;
74
+ }
75
+
76
+ } , function errorCallback ( response ) { } ) ;
77
+ }
78
+
79
+ } ) ;
80
+
81
+
82
+ var addNewFileStatus = true ; // false if addNewFolder is active
83
+
84
+ theApp . controller ( 'addNewCtl' , function ( $scope , $http , $element , $timeout , $window ) {
85
+ $scope . showUploadBox = function ( event , id ) {
86
+ var btn = angular . element ( event . target ) ;
87
+ btn . addClass ( "active" ) ;
88
+ var uploadBox = angular . element ( '#filedrop' ) ;
89
+ if ( uploadBox . is ( ':visible' ) ) {
90
+ btn . removeClass ( "active" ) ;
91
+ uploadBox . hide ( 250 ) ;
92
+ } else {
93
+ btn . addClass ( "active" ) ;
94
+ uploadBox . show ( 250 ) ;
95
+ }
96
+ }
97
+ $scope . addNewFile = function ( event , id ) {
98
+ var btn = angular . element ( event . target ) ;
99
+
100
+ var input = $element . find ( '#newfileName' ) ;
101
+ if ( btn . hasClass ( 'active' ) ) {
102
+ btn . parent ( ) . find ( "li" ) . not ( ':first' ) . removeClass ( ) ;
103
+ input . parent ( ) . find ( 'input' ) . hide ( 250 ) ;
104
+ } else {
105
+ btn . parent ( ) . find ( "li" ) . not ( ':first' ) . removeClass ( ) ;
106
+ btn . addClass ( "active" ) ;
107
+ input . parent ( ) . find ( 'input' ) . show ( 250 ) ;
108
+ }
109
+ input . attr ( 'placeholder' , 'File Name' ) ;
110
+
111
+ addNewFileStatus = true ;
112
+ }
113
+ $scope . addNewFolder = function ( event , id ) {
114
+ var btn = angular . element ( event . target ) ;
115
+
116
+ var input = $element . find ( '#newfileName' ) ;
117
+ if ( btn . hasClass ( 'active' ) ) {
118
+ btn . parent ( ) . find ( "li" ) . not ( ':first' ) . removeClass ( ) ;
119
+ input . parent ( ) . find ( 'input' ) . hide ( 250 ) ;
120
+ } else {
121
+ btn . parent ( ) . find ( "li" ) . not ( ':first' ) . removeClass ( ) ;
122
+ btn . addClass ( "active" ) ;
123
+ input . parent ( ) . find ( 'input' ) . show ( 250 ) ;
124
+ }
125
+ input . attr ( 'placeholder' , 'Folder Name' ) ;
126
+
127
+ addNewFileStatus = false ;
128
+ }
129
+ $scope . addNewFileFolder = function ( event , id ) {
130
+ var input = $element . find ( '#newfileName' ) ;
131
+ $scope . cdata = { } ;
132
+ $scope . cdata . action = 'addFile' ;
133
+ if ( ! addNewFileStatus ) {
134
+ $scope . cdata . action = 'addFolder' ;
135
+ }
136
+
137
+ $scope . cdata . name = input . val ( ) ;
138
+ if ( $scope . cdata . name . length <= 0 ) {
139
+ input . addClass ( "dangerHighlight" ) ;
140
+ $timeout ( function ( ) {
141
+ input . addClass ( "highlightOut" ) ;
142
+ } , 1000 ) ;
143
+ } else {
144
+ $http ( {
145
+ method : 'POST' ,
146
+ url : "index.php" ,
147
+ headers : {
148
+ 'Content-Type' : 'application/x-www-form-urlencoded'
149
+ } ,
150
+ data : {
151
+ act : $scope . cdata . action ,
152
+ dir : directory ,
153
+ name : $scope . cdata . name
154
+ }
155
+ } ) . then ( function successCallback ( response ) {
156
+ console . log ( response . data ) ;
157
+ if ( response . data . status === true ) {
158
+ $window . location . reload ( ) ;
159
+ } else {
160
+ input . addClass ( "dangerHighlight" ) ;
161
+ $timeout ( function ( ) {
162
+ input . addClass ( "highlightOut" ) ;
163
+ } , 1000 ) ;
164
+ }
165
+ } , function errorCallback ( response ) {
166
+ input . addClass ( "dangerHighlight" ) ;
167
+ $timeout ( function ( ) {
168
+ input . addClass ( "highlightOut" ) ;
169
+ } , 1000 ) ;
170
+ } ) ;
171
+ }
172
+ }
173
+ $scope . addNewFileFolderHide = function ( event , id ) {
174
+ var btn = angular . element ( event . target ) ;
175
+ btn . parent ( ) . parent ( ) . find ( "li" ) . not ( ':first' ) . removeClass ( ) ;
176
+ btn . parent ( ) . find ( "input" ) . hide ( 250 ) ;
177
+ }
178
+
179
+ } ) ;
180
+
181
+
182
+ theApp . directive ( 'upload' , [ '$http' , '$window' , function ( $http , $window ) {
183
+ return {
184
+ restrict : 'E' ,
185
+ replace : true ,
186
+ scope : { } ,
187
+ require : '?ngModel' ,
188
+ template : '<div class="asset-upload" id="filedrop">Drag here to upload</div>' ,
189
+ link : function ( scope , element , attrs , ngModel ) {
190
+ var upload = function ( files ) {
191
+ var data = new FormData ( ) ;
192
+ var index = 0 ;
193
+ angular . forEach ( files , function ( value ) {
194
+ data . append ( "files" + ( index ++ ) , value ) ;
195
+ } ) ;
196
+ data . append ( "upload" , 1 ) ;
197
+ data . append ( "path" , directory ) ;
198
+
199
+ $http ( {
200
+ method : 'POST' ,
201
+ url : attrs . to ,
202
+ data : data ,
203
+ withCredentials : true ,
204
+ headers : {
205
+ 'Content-Type' : undefined
206
+ } ,
207
+ transformRequest : angular . identity
208
+ } ) . then ( function successCallback ( response ) {
209
+ if ( response . data . status === true ) {
210
+ $window . location . reload ( ) ;
211
+ } else { }
212
+ } , function errorCallback ( response ) {
213
+
214
+ } ) ;
215
+ } ;
216
+ // Code goes here
217
+ element . on ( 'dragover' , function ( e ) {
218
+ e . preventDefault ( ) ;
219
+ e . stopPropagation ( ) ;
220
+ } ) ;
221
+ element . on ( 'dragenter' , function ( e ) {
222
+ e . preventDefault ( ) ;
223
+ e . stopPropagation ( ) ;
224
+ } ) ;
225
+ element . on ( 'drop' , function ( e ) {
226
+ e . preventDefault ( ) ;
227
+ e . stopPropagation ( ) ;
228
+ if ( e . originalEvent . dataTransfer ) {
229
+ if ( e . originalEvent . dataTransfer . files . length > 0 ) {
230
+ upload ( e . originalEvent . dataTransfer . files ) ;
231
+ }
232
+ }
233
+ return false ;
234
+ } ) ;
235
+ }
236
+ } ;
237
+ } ] ) ;
0 commit comments