Skip to content

A free open source IT asset/license management system

Added more ajax select2 boxes to checkouts, remove helper ->with() methods

snipeea07517ad5c7
diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php
index 10d28b1012..77a5d6fe47 100755
--- a/app/Http/Controllers/AccessoriesController.php
+++ b/app/Http/Controllers/AccessoriesController.php
@@ -271,7 +271,7 @@ class AccessoriesController extends Controller
$this->authorize('checkout', $accessory);
// Get the dropdown of users and then pass it to the checkout view
- return view('accessories/checkout', compact('accessory'))->with('users_list', Helper::usersList());
+ return view('accessories/checkout', compact('accessory'));
}
@@ -296,7 +296,7 @@ class AccessoriesController extends Controller
$this->authorize('checkout', $accessory);
if (!$user = User::find(Input::get('assigned_to'))) {
- return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found'));
+ return redirect()->route('checkout/accessory', $accessory->id)->with('error', trans('admin/accessories/message.checkout.user_does_not_exist'));
}
// Update the accessory data
@@ -323,6 +323,7 @@ class AccessoriesController extends Controller
$data['note'] = $logaction->note;
$data['require_acceptance'] = $accessory->requireAcceptance();
// TODO: Port this to new mail notifications
+
if ((($accessory->requireAcceptance()=='1') || ($accessory->getEula())) && ($user->email!='')) {
Mail::send('emails.accept-accessory', $data, function ($m) use ($user) {
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index 3381df3822..f6ceb10739 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -303,6 +303,9 @@ class AssetsController extends Controller
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
];
}
+
+ array_unshift($assets_array, ['id'=> '', 'text'=> trans('general.select_asset'), 'image' => null]);
+
$results = [
'items' => $assets_array,
'pagination' =>
diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php
index 60bcd1de61..381eedb810 100644
--- a/app/Http/Controllers/Api/LocationsController.php
+++ b/app/Http/Controllers/Api/LocationsController.php
@@ -175,6 +175,9 @@ class LocationsController extends Controller
'image' => ($location->image) ? url('/').'/uploads/locations/'.$location->image : null,
];
}
+
+ array_unshift($locations_array, ['id'=> '', 'text'=> trans('general.select_location'), 'image' => null]);
+
$results = [
'items' => $locations_array,
'pagination' =>
diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php
index 98807c5363..19911bccb6 100644
--- a/app/Http/Controllers/Api/UsersController.php
+++ b/app/Http/Controllers/Api/UsersController.php
@@ -165,6 +165,8 @@ class UsersController extends Controller
'image' => ($user->present()->gravatar) ? $user->present()->gravatar : null,
];
}
+
+ array_unshift($users_array, ['id'=> '', 'text'=> trans('general.select_user'), 'image' => null]);
$results = [
'items' => $users_array,
'pagination' =>
diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php
index 01fc3d55c2..dc875ea3f6 100755
--- a/app/Http/Controllers/AssetsController.php
+++ b/app/Http/Controllers/AssetsController.php
@@ -430,10 +430,7 @@ class AssetsController extends Controller
$this->authorize('checkout', $asset);
// Get the dropdown of users and then pass it to the checkout view
- return view('hardware/checkout', compact('asset'))
- ->with('users_list', Helper::usersList())
- ->with('assets_list', Helper::detailedAssetList())
- ->with('locations_list', Helper::locationsList());
+ return view('hardware/checkout', compact('asset'));
}
/**
diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php
index e06cb32246..41f4c36152 100644
--- a/app/Http/Controllers/ComponentsController.php
+++ b/app/Http/Controllers/ComponentsController.php
@@ -255,7 +255,7 @@ class ComponentsController extends Controller
return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
}
$this->authorize('checkout', $component);
- return view('components/checkout', compact('component'))->with('assets_list', Helper::detailedAssetList());
+ return view('components/checkout', compact('component'));
}
/**
diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php
index dcaa164c05..6201b8af46 100644
--- a/app/Http/Controllers/ConsumablesController.php
+++ b/app/Http/Controllers/ConsumablesController.php
@@ -239,7 +239,7 @@ class ConsumablesController extends Controller
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist'));
}
$this->authorize('checkout', $consumable);
- return view('consumables/checkout', compact('consumable'))->with('users_list', Helper::usersList());
+ return view('consumables/checkout', compact('consumable'));
}
/**
@@ -265,7 +265,7 @@ class ConsumablesController extends Controller
// Check if the user exists
if (is_null($user = User::find($assigned_to))) {
// Redirect to the consumable management page with error
- return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.user_does_not_exist'));
+ return redirect()->route('checkout/consumable', $consumable)->with('error', trans('admin/consumables/message.checkout.user_does_not_exist'));
}
// Update the consumable data
@@ -286,7 +286,7 @@ class ConsumablesController extends Controller
$data['note'] = $logaction->note;
$data['require_acceptance'] = $consumable->requireAcceptance();
- if (($consumable->requireAcceptance()=='1') || ($consumable->getEula())) {
+ if ((($consumable->requireAcceptance()=='1') || ($consumable->getEula())) && $user->email!='') {
Mail::send('emails.accept-asset', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
diff --git a/resources/views/accessories/checkout.blade.php b/resources/views/accessories/checkout.blade.php
index 830e9492a8..e9230c73e8 100755
--- a/resources/views/accessories/checkout.blade.php
+++ b/resources/views/accessories/checkout.blade.php
@@ -51,16 +51,7 @@
<!-- User -->
- <div class="form-group {{ $errors->has('assigned_to') ? ' has-error' : '' }}">
- <label for="assigned_to" class="col-md-3 control-label">
- {{ trans('admin/hardware/form.checkout_to') }}
- <i class='icon-asterisk'></i>
- </label>
- <div class="col-md-9">
- {{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $accessory->assigned_to), array('class'=>'select2', 'style'=>'min-width:350px')) }}
- {!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
- </div>
- </div>
+ @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to'])
@if ($accessory->category->require_acceptance=='1')
<div class="form-group">
diff --git a/resources/views/components/checkout.blade.php b/resources/views/components/checkout.blade.php
index 8796d5846a..5d26e10b59 100644
--- a/resources/views/components/checkout.blade.php
+++ b/resources/views/components/checkout.blade.php
@@ -36,23 +36,17 @@
@endif
<!-- Asset -->
- <div class="form-group {{ $errors->has('asset_id') ? ' has-error' : '' }}">
- <label for="asset_id" class="col-md-3 control-label">{{ trans('admin/hardware/form.checkout_to') }}
- <i class='icon-asterisk'></i></label>
- <div class="col-md-9">
- {{ Form::select('asset_id', $assets_list , Input::old('asset_id', $component->asset_id), array('class'=>'select2', 'style'=>'width:100%')) }}
- {!! $errors->first('asset_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
+ @include ('partials.forms.edit.asset-select', ['translated_name' => trans('general.select_asset'), 'fieldname' => 'asset_id'])
+
+ <div class="form-group {{ $errors->has('assigned_qty') ? ' has-error' : '' }}">
+ <label for="assigned_qty" class="col-md-3 control-label">{{ trans('general.qty') }}
+ <i class='icon-asterisk'></i></label>
+ <div class="col-md-9">
+ <input class="form-control" type="text" name="assigned_qty" id="assigned_qty" style="width: 70px;" value="{{ Input::old('assigned_qty') }}" />
+ {!! $errors->first('assigned_qty', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
+ </div>
</div>
- </div>
- <div class="form-group {{ $errors->has('assigned_qty') ? ' has-error' : '' }}">
- <label for="assigned_qty" class="col-md-3 control-label">{{ trans('general.qty') }}
- <i class='icon-asterisk'></i></label>
- <div class="col-md-9">
- <input class="form-control" type="text" name="assigned_qty" id="assigned_qty" style="width: 70px;" value="{{ Input::old('assigned_qty') }}" />
- {!! $errors->first('assigned_qty', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
- </div>
- </div>
</div> <!-- .BOX-BODY-->
<div class="box-footer">
diff --git a/resources/views/consumables/checkout.blade.php b/resources/views/consumables/checkout.blade.php
index b085c8bb9d..dc6ba5450e 100644
--- a/resources/views/consumables/checkout.blade.php
+++ b/resources/views/consumables/checkout.blade.php
@@ -38,14 +38,7 @@
@endif
<!-- User -->
- <div class="form-group {{ $errors->has('assigned_to') ? ' has-error' : '' }}">
- <label for="assigned_to" class="col-md-3 control-label">{{ trans('admin/hardware/form.checkout_to') }}
- <i class='icon-asterisk'></i></label>
- <div class="col-md-9">
- {{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $consumable->assigned_to), array('class'=>'select2', 'style'=>'min-width:350px')) }}
- {!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
- </div>
- </div>
+ @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to'])
@if ($consumable->category->require_acceptance=='1')
<div class="form-group">
diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php
index f82e12b908..c328f1622d 100755
--- a/resources/views/hardware/checkout.blade.php
+++ b/resources/views/hardware/checkout.blade.php
@@ -45,60 +45,16 @@
</div>
</div>
+ @include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user'])
- <div id="assigned_user" class="form-group{{ $errors->has('assigned_user') ? ' has-error' : '' }}">
-
- {{ Form::label('assigned_user', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
-
- <div class="col-md-7 required">
- <select class="js-data-ajax" data-endpoint="users" name="assigned_user" style="width: 100%" id="assigned_user_select">
- <option value="">{{ trans('general.select_user') }}</option>
- </select>
- </div>
-
- <div class="col-md-1 col-sm-1 text-left">
- @can('create', \App\Models\User::class)
- <a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user_select' class="btn btn-sm btn-default">New</a>
- @endcan
- </div>
+ @if (!$asset->requireAcceptance())
- {!! $errors->first('assigned_user', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
+ @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset'])
- </div>
+ @include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location'])
- @if (!$asset->requireAcceptance())
- <!-- Asset -->
- <div id="assigned_asset" class="form-group{{ $errors->has('assigned_asset') ? ' has-error' : '' }}">
- {{ Form::label('assigned_asset', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
- <div class="col-md-7 required">
- <select class="js-data-ajax" data-endpoint="hardware" name="assigned_asset" style="width: 100%" id="assigned_asset_select">
- <option value="">{{ trans('general.select_asset') }}</option>
- </select>
- </div>
- {!! $errors->first('assigned_asset', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
-
- </div>
-
- <!-- Location -->
- <div id="assigned_location" class="form-group{{ $errors->has('assigned_location') ? ' has-error' : '' }}">
- {{ Form::label('assigned_location', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
- <div class="col-md-7 required">
- <select class="js-data-ajax" data-endpoint="locations" name="assigned_location" style="width: 100%" id="assigned_location_select">
- <option value="">{{ trans('general.select_location') }}</option>
- </select>
- </div>
-
- <div class="col-md-1 col-sm-1 text-left">
- @can('create', \App\Models\Location::class)
- <a href='{{ route('modal.location') }}' data-toggle="modal" data-target="#createModal" data-dependency="location" data-select='assigned_location_select' class="btn btn-sm btn-default">New</a>
- @endcan
- </div>
-
- {!! $errors->first('assigned_location', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
-
- </div>
@endif
<!-- Checkout/Checkin Date -->
<div class="form-group {{ $errors->has('checkout_at') ? 'error' : '' }}">
diff --git a/resources/views/licenses/checkout.blade.php b/resources/views/licenses/checkout.blade.php
index 901cb1b632..50bbff7b90 100755
--- a/resources/views/licenses/checkout.blade.php
+++ b/resources/views/licenses/checkout.blade.php
@@ -27,7 +27,7 @@
<!-- Asset name -->
<div class="form-group">
- <label class="col-sm-2 control-label">{{ trans('admin/hardware/form.name') }}</label>
+ <label class="col-sm-3 control-label">{{ trans('admin/hardware/form.name') }}</label>
<div class="col-md-6">
<p class="form-control-static">{{ $licenseSeat->license->name }}</p>
</div>
@@ -35,41 +35,24 @@
<!-- Serial -->
<div class="form-group">
- <label class="col-sm-2 control-label">{{ trans('admin/hardware/form.serial') }}</label>
- <div class="col-md-10">
+ <label class="col-sm-3 control-label">{{ trans('admin/hardware/form.serial') }}</label>
+ <div class="col-md-9">
<p class="form-control-static" style="word-wrap: break-word;">{{ $licenseSeat->license->serial }}</p>
</div>
</div>
- <!-- Asset -->
- <div class="form-group {{ $errors->has('asset_id') ? ' has-error' : '' }}">
- <label for="asset_id" class="col-md-2 control-label">{{ trans('admin/licenses/form.asset') }}
- </label>
+ @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/licenses/form.asset'), 'fieldname' => 'asset_id'])
- <div class="col-md-10">
- {{ Form::select('asset_id', $asset_list , Input::old('asset_id', $licenseSeat->asset_id), array('class'=>'select2', 'style'=>'min-width:600px')) }}
- {!! $errors->first('asset_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
- </div>
- </div>
+ @include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_to'])
- <!-- User -->
- <div class="form-group {{ $errors->has('assigned_to') ? ' has-error' : '' }}">
- <label for="assigned_to" class="col-md-2 control-label">{{ trans('admin/hardware/form.checkout_to') }}
- </label>
+ <p class="col-md-offset-3 help-block">
+ {{ trans('admin/licenses/form.checkout_help') }}
+ </p>
- <div class="col-md-9">
- {{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $licenseSeat->assigned_to), array('class'=>'select2', 'style'=>'min-width:350px')) }}
- {!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
-
- <p class="help-block">
- {{ trans('admin/licenses/form.checkout_help') }}
- </p>
- </div>
- </div>
<!-- Note -->
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
- <label for="note" class="col-md-2 control-label">{{ trans('admin/hardware/form.notes') }}</label>
+ <label for="note" class="col-md-3 control-label">{{ trans('admin/hardware/form.notes') }}</label>
<div class="col-md-7">
<textarea class="col-md-6 form-control" id="note" name="note">{{ Input::old('note', $licenseSeat->note) }}</textarea>
{!! $errors->first('note', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
diff --git a/resources/views/partials/forms/edit/asset-select.blade.php b/resources/views/partials/forms/edit/asset-select.blade.php
new file mode 100644
index 0000000000..18f5e657f9
--- /dev/null
+++ b/resources/views/partials/forms/edit/asset-select.blade.php
@@ -0,0 +1,10 @@
+<!-- Asset -->
+<div id="assigned_asset" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
+ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
+ <div class="col-md-7 required">
+ <select class="js-data-ajax" data-endpoint="hardware" name="{{ $fieldname }}" style="width: 100%" id="assigned_asset_select">
+ </select>
+ </div>
+ {!! $errors->first($fieldname, '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
+
+</div>
diff --git a/resources/views/partials/forms/edit/location-select.blade.php b/resources/views/partials/forms/edit/location-select.blade.php
new file mode 100644
index 0000000000..cf4b9eb22f
--- /dev/null
+++ b/resources/views/partials/forms/edit/location-select.blade.php
@@ -0,0 +1,17 @@
+<!-- Location -->
+<div id="assigned_location" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
+ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
+ <div class="col-md-7 required">
+ <select class="js-data-ajax" data-endpoint="locations" name="{{ $fieldname }}" style="width: 100%" id="assigned_location_select">
+ </select>
+ </div>
+
+ <div class="col-md-1 col-sm-1 text-left">
+ @can('create', \App\Models\Location::class)
+ <a href='{{ route('modal.location') }}' data-toggle="modal" data-target="#createModal" data-dependency="location" data-select='assigned_location_select' class="btn btn-sm btn-default">New</a>
+ @endcan
+ </div>
+
+ {!! $errors->first($fieldname, '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
+
+</div>
diff --git a/resources/views/partials/forms/edit/user-select.blade.php b/resources/views/partials/forms/edit/user-select.blade.php
new file mode 100644
index 0000000000..c80acd9df1
--- /dev/null
+++ b/resources/views/partials/forms/edit/user-select.blade.php
@@ -0,0 +1,18 @@
+<div id="assigned_user" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
+
+ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
+
+ <div class="col-md-7 required">
+ <select class="js-data-ajax" data-endpoint="users" name="{{ $fieldname }}" style="width: 100%" id="assigned_user_select">
+ </select>
+ </div>
+
+ <div class="col-md-1 col-sm-1 text-left">
+ @can('create', \App\Models\User::class)
+ <a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user_select' class="btn btn-sm btn-default">New</a>
+ @endcan
+ </div>
+
+ {!! $errors->first($fieldname, '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
+
+</div>