mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Use upload modal
This commit is contained in:
parent
e0eb10ca1e
commit
a467a6999e
|
@ -731,30 +731,37 @@ class UsersController extends Controller
|
|||
if (isset($user->id)) {
|
||||
$this->authorize('update', $user);
|
||||
|
||||
foreach (Input::file('file') as $file) {
|
||||
if (!$request->has('file')) {
|
||||
\Log::debug('No file selected: ');
|
||||
\Log::debug(print_r($request, true));
|
||||
return redirect()->back()->with('error', 'No file submitted.');
|
||||
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$filename = 'user-' . $user->id . '-' . str_random(8);
|
||||
$filename .= '-' . str_slug($file->getClientOriginalName()) . '.' . $extension;
|
||||
$upload_success = $file->move($destinationPath, $filename);
|
||||
} else {
|
||||
foreach ($request->file('file') as $file) {
|
||||
|
||||
//Log the uploaded file to the log
|
||||
$logAction = new Actionlog();
|
||||
$logAction->item_id = $user->id;
|
||||
$logAction->item_type = User::class;
|
||||
$logAction->user_id = Auth::user()->id;
|
||||
$logAction->note = e(Input::get('notes'));
|
||||
$logAction->target_id = null;
|
||||
$logAction->created_at = date("Y-m-d H:i:s");
|
||||
$logAction->filename = $filename;
|
||||
$logAction->action_type = 'uploaded';
|
||||
$logAction->save();
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$filename = 'user-' . $user->id . '-' . str_random(8);
|
||||
$filename .= '-' . str_slug($file->getClientOriginalName()) . '.' . $extension;
|
||||
$upload_success = $file->move($destinationPath, $filename);
|
||||
|
||||
//Log the uploaded file to the log
|
||||
$logAction = new Actionlog();
|
||||
$logAction->item_id = $user->id;
|
||||
$logAction->item_type = User::class;
|
||||
$logAction->user_id = Auth::user()->id;
|
||||
$logAction->note = $request->input('notes');
|
||||
$logAction->target_id = null;
|
||||
$logAction->created_at = date("Y-m-d H:i:s");
|
||||
$logAction->filename = $filename;
|
||||
$logAction->action_type = 'uploaded';
|
||||
$logAction->save();
|
||||
|
||||
}
|
||||
return redirect()->back()->with('success', 'File uploaded');
|
||||
}
|
||||
return JsonResponse::create($logAction);
|
||||
|
||||
}
|
||||
return JsonResponse::create(["error" => "Failed validation: ".print_r($logAction->getErrors(), true)], 500);
|
||||
return redirect()->route('users.index')->with('error', 'Error uploading files');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -98,6 +98,12 @@
|
|||
</ul>
|
||||
</li>
|
||||
@endcan
|
||||
|
||||
@can('update', \App\Models\User::class)
|
||||
<li class="pull-right"><a href="#" data-toggle="modal" data-target="#uploadFileModal">
|
||||
<i class="fa fa-paperclip" aria-hidden="true"></i> {{ trans('button.upload') }}</a>
|
||||
</li>
|
||||
@endcan
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
|
@ -451,39 +457,9 @@
|
|||
<div class="tab-pane" id="files_tab">
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-sm-12">
|
||||
<p>{{ trans('admin/hardware/general.filetype_info') }}</p>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<!-- The fileinput-button span is used to style the file input field as button -->
|
||||
@can('update', $user)
|
||||
<span class="btn btn-info fileinput-button hidden-print">
|
||||
<i class="fa fa-plus icon-white"></i>
|
||||
<span>{{ trans('button.select_file') }}</span>
|
||||
<!-- The file input field used as target for the file upload widget -->
|
||||
<input id="fileupload" type="file" name="file[]" data-url="{{ route('upload/user', $user->id) }}">
|
||||
</span>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<input id="notes" type="text" name="notes">
|
||||
</div>
|
||||
<div class="col-md-6" id="progress-container" style="visibility: hidden; padding-bottom: 20px;">
|
||||
<!-- The global progress bar -->
|
||||
<div class="col-md-11">
|
||||
<div id="progress" class="progress progress-striped active" style="margin-top: 8px;">
|
||||
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 45%">
|
||||
<span id="progress-bar-text">0% {{ trans('general.complete') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<div class="pull-right progress-checkmark" style="display: none;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="{{ asset('css/lib/jquery.fileupload.css') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ asset('css/lib/jquery.fileupload-ui.css') }}">
|
||||
<!-- start striped rows -->
|
||||
|
||||
|
||||
<div class="col-md-12 col-sm-12">
|
||||
<div class="table-responsive">
|
||||
|
@ -588,7 +564,13 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
@stop
|
||||
@can('update', \App\Models\User::class)
|
||||
@include ('modals.upload-file', ['item_type' => 'user', 'item_id' => $user->id])
|
||||
@endcan
|
||||
|
||||
|
||||
|
||||
@stop
|
||||
|
||||
@section('moar_scripts')
|
||||
@include ('partials.bootstrap-table', ['simple_view' => true])
|
||||
|
|
Loading…
Reference in a new issue