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)) {
|
if (isset($user->id)) {
|
||||||
$this->authorize('update', $user);
|
$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();
|
} else {
|
||||||
$filename = 'user-' . $user->id . '-' . str_random(8);
|
foreach ($request->file('file') as $file) {
|
||||||
$filename .= '-' . str_slug($file->getClientOriginalName()) . '.' . $extension;
|
|
||||||
$upload_success = $file->move($destinationPath, $filename);
|
|
||||||
|
|
||||||
//Log the uploaded file to the log
|
$extension = $file->getClientOriginalExtension();
|
||||||
$logAction = new Actionlog();
|
$filename = 'user-' . $user->id . '-' . str_random(8);
|
||||||
$logAction->item_id = $user->id;
|
$filename .= '-' . str_slug($file->getClientOriginalName()) . '.' . $extension;
|
||||||
$logAction->item_type = User::class;
|
$upload_success = $file->move($destinationPath, $filename);
|
||||||
$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();
|
|
||||||
|
|
||||||
|
//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>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
@endcan
|
@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>
|
</ul>
|
||||||
|
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
@ -451,39 +457,9 @@
|
||||||
<div class="tab-pane" id="files_tab">
|
<div class="tab-pane" id="files_tab">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 col-sm-12">
|
<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') }}">
|
<!-- start striped rows -->
|
||||||
<link rel="stylesheet" type="text/css" href="{{ asset('css/lib/jquery.fileupload-ui.css') }}">
|
|
||||||
|
|
||||||
<div class="col-md-12 col-sm-12">
|
<div class="col-md-12 col-sm-12">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
|
@ -588,7 +564,13 @@
|
||||||
</div>
|
</div>
|
||||||
</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')
|
@section('moar_scripts')
|
||||||
@include ('partials.bootstrap-table', ['simple_view' => true])
|
@include ('partials.bootstrap-table', ['simple_view' => true])
|
||||||
|
|
Loading…
Reference in a new issue