@@ -45,7 +45,12 @@ public function index()
4545 'format ' => $ this ->getFormat (),
4646 'access ' => $ access ,
4747 'exports ' => $ exports ->getByExtensions (),
48+ 'bulks ' => $ exports ->where ('bulk ' , 1 )->findAll (),
4849 ];
50+
51+ // AJAX calls skip the wrapping
52+ if ($ this ->request ->isAJAX ())
53+ return view ("Tatter\Files\Views \\formats \\{$ data ['format ' ]}" , $ data );
4954 return view ('Tatter\Files\Views\index ' , $ data );
5055 }
5156
@@ -95,7 +100,12 @@ public function user($userId = null)
95100 'access ' => $ access ,
96101 'username ' => $ username ,
97102 'exports ' => $ exports ->getByExtensions (),
103+ 'bulks ' => $ exports ->where ('bulk ' , 1 )->findAll (),
98104 ];
105+
106+ // AJAX calls skip the wrapping
107+ if ($ this ->request ->isAJAX ())
108+ return view ("Tatter\Files\Views \\formats \\{$ data ['format ' ]}" , $ data );
99109 return view ('Tatter\Files\Views\index ' , $ data );
100110 }
101111
@@ -195,6 +205,59 @@ public function delete($fileId)
195205 return redirect ()->back ();
196206 }
197207
208+ // Handle bulk actions
209+ public function bulk ()
210+ {
211+ // Load post data
212+ $ post = $ this ->request ->getPost ();
213+
214+ // Harvest file IDs and the requested action
215+ $ action = '' ;
216+ $ fileIds = [];
217+ foreach ($ post as $ key => $ value ):
218+ if (is_numeric ($ value )):
219+ $ fileIds [] = $ value ;
220+ else :
221+ $ action = $ key ;
222+ endif ;
223+ endforeach ;
224+
225+ // Make sure some files where checked
226+ if (empty ($ fileIds )):
227+ alert ('warning ' , lang ('File.nofile ' ));
228+ return redirect ()->back ();
229+ endif ;
230+
231+ // Handle actions
232+ switch ($ action ):
233+ case '' :
234+ alert ('warning ' , 'No valid action. ' );
235+ break ;
236+
237+ // Bulk delete request
238+ case 'delete ' :
239+ $ this ->model ->delete ($ fileIds );
240+ alert ('success ' , 'Deleted ' . count ($ fileIds ) . ' files. ' );
241+ break ;
242+
243+ default :
244+ // Match the export handler
245+ $ exports = new ExportModel ();
246+ $ handler = $ exports ->where ('uid ' , $ action )->first ();
247+ if (empty ($ handler )):
248+ alert ('warning ' , 'No handler found for ' . $ uid );
249+ return redirect ()->back ();
250+ endif ;
251+
252+ // Pass to the handler
253+ //$response = $handler->process($file->path, $file->filename);
254+
255+ alert ('success ' , 'Processed ' . count ($ fileIds ) . ' files. ' );
256+ endswitch ;
257+
258+ return redirect ()->back ();
259+ }
260+
198261 // Receives uploads from Dropzone
199262 public function upload ()
200263 {
@@ -357,16 +420,22 @@ public function export($uid, $fileId)
357420 return redirect ()->back ();
358421 endif ;
359422
360- // Load the file and pass to the handler
423+ // Load the file
361424 $ file = $ this ->model ->find ($ fileId );
425+ if (empty ($ file )):
426+ alert ('warning ' , lang ('Files.noFile ' ));
427+ return redirect ()->back ();
428+ endif ;
429+
430+ // Pass to the handler
362431 $ response = $ handler ->process ($ file ->path , $ file ->filename );
363432
364433 // If the handler returned a response then we're done
365434 if ($ response instanceof ResponseInterface)
366435 return $ response ;
367436
368437 if ($ response === true ):
369- alert ('success ' , ucfirst ($ uid ) . ' export was successful. ' );
438+ alert ('success ' , lang ( ' Files.noFile ' , [ ucfirst ($ uid )]) );
370439 elseif ($ response === false ):
371440 $ error = implode ('. ' , $ handler ->getErrors ());
372441 alert ('error ' , $ error );
0 commit comments