diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index c62c7d6894..bd4b137590 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -137,95 +137,6 @@ class Helper return floatval($floatString); } - - /** - * Get the list of models in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function modelList() - { - $models = AssetModel::with('manufacturer')->get(); - $model_array[''] = trans('general.select_model'); - foreach ($models as $model) { - $model_array[$model->id] = $model->present()->modelName(); - } - return $model_array; - } - - /** - * Get the list of companies in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function companyList() - { - $company_list = array('' => trans('general.select_company')) + DB::table('companies') - ->orderBy('name', 'asc') - ->pluck('name', 'id') - ->toArray(); - return $company_list; - } - - - /** - * Get the list of categories in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function categoryList($category_type = null) - { - $categories = Category::orderBy('name', 'asc') - ->whereNull('deleted_at') - ->orderBy('name', 'asc'); - if (!empty($category_type)) { - $categories = $categories->where('category_type', '=', $category_type); - } - $category_list = array('' => trans('general.select_category')) + $categories->pluck('name', 'id')->toArray(); - return $category_list; - } - - - /** - * Get the list of categories in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function departmentList() - { - $departments = Department::orderBy('name', 'asc') - ->whereNull('deleted_at') - ->orderBy('name', 'asc'); - - return array('' => trans('general.select_department')) + $departments->pluck('name', 'id')->toArray(); - - } - - - /** - * Get the list of suppliers in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function suppliersList() - { - $supplier_list = array('' => trans('general.select_supplier')) + Supplier::orderBy('name', 'asc') - ->orderBy('name', 'asc') - ->pluck('name', 'id')->toArray(); - return $supplier_list; - } - - /** * Get the list of status labels in an array to make a dropdown menu * @@ -240,37 +151,6 @@ class Helper return $statuslabel_list; } - - /** - * Get the list of locations in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function locationsList() - { - $location_list = array('' => trans('general.select_location')) + Location::orderBy('name', 'asc') - ->pluck('name', 'id')->toArray(); - return $location_list; - } - - - /** - * Get the list of manufacturers in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function manufacturerList() - { - $manufacturer_list = array('' => trans('general.select_manufacturer')) + - Manufacturer::orderBy('name', 'asc') - ->pluck('name', 'id')->toArray(); - return $manufacturer_list; - } - /** * Get the list of status label types in an array to make a dropdown menu * @@ -289,24 +169,6 @@ class Helper return $statuslabel_types; } - /** - * Get the list of managers in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function managerList() - { - $manager_list = array('' => trans('general.select_user')) + - User::where('deleted_at', '=', null) - ->orderBy('last_name', 'asc') - ->orderBy('first_name', 'asc')->get() - ->pluck('complete_name', 'id')->toArray(); - - return $manager_list; - } - /** * Get the list of depreciations in an array to make a dropdown menu * @@ -341,54 +203,6 @@ class Helper return $category_types; } - /** - * Get the list of users in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function usersList() - { - $users_list = array( '' => trans('general.select_user')) + - Company::scopeCompanyables(User::where('deleted_at', '=', null)) - ->where('show_in_list', '=', 1) - ->orderBy('last_name', 'asc') - ->orderBy('first_name', 'asc')->get() - ->pluck('complete_name', 'id')->toArray(); - - return $users_list; - } - - /** - * Get the list of assets in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return Array - */ - public static function assetsList() - { - $assets_list = array('' => trans('general.select_asset')) + Asset::orderBy('name', 'asc') - ->whereNull('deleted_at') - ->pluck('name', 'id')->toArray(); - return $assets_list; - } - - /** - * Get the detailed list of assets in an array to make a dropdown menu - * - * @author [A. Gianotto] [] - * @since [v2.5] - * @return array - */ - public static function detailedAssetList() - { - $assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::with('assignedTo', 'model'), 'assets.company_id')->get()->pluck('detailed_name', 'id')->toArray(); - return $assets; - } - - /** * Get the list of custom fields in an array to make a dropdown menu * diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 28ea51aa3f..4ea273a8b3 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -372,9 +372,7 @@ class AssetModelsController extends Controller // Show the page $view = View::make('models/edit'); - $view->with('category_list', Helper::categoryList('asset')); $view->with('depreciation_list', Helper::depreciationList()); - $view->with('manufacturer_list', Helper::manufacturerList()); $view->with('item', $model); $view->with('clone_model', $model_to_clone); return $view; @@ -408,7 +406,7 @@ class AssetModelsController extends Controller */ public function postBulkEdit(Request $request) { - + $models_raw_array = Input::get('ids'); // Make sure some IDs have been selected @@ -433,13 +431,8 @@ class AssetModelsController extends Controller $nochange = ['NC' => 'No Change']; $fieldset_list = $nochange + Helper::customFieldsetList(); $depreciation_list = $nochange + Helper::depreciationList(); - $category_list = $nochange + Helper::categoryList('asset'); - $manufacturer_list = $nochange + Helper::manufacturerList(); - return view('models/bulk-edit', compact('models')) - ->with('manufacturer_list', $manufacturer_list) - ->with('category_list', $category_list) ->with('fieldset_list', $fieldset_list) ->with('depreciation_list', $depreciation_list); } diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 9007d8a4bc..4c81dc61fd 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -110,12 +110,8 @@ class AssetsController extends Controller { $this->authorize('create', Asset::class); $view = View::make('hardware/edit') - ->with('supplier_list', Helper::suppliersList()) - ->with('model_list', Helper::modelList()) ->with('statuslabel_list', Helper::statusLabelList()) ->with('item', new Asset) - ->with('manufacturer', Helper::manufacturerList()) //handled in modal now? - ->with('category', Helper::categoryList('asset')) //handled in modal now? ->with('statuslabel_types', Helper::statusTypeList()); if ($request->has('model_id')) { @@ -262,7 +258,6 @@ class AssetsController extends Controller $this->authorize($item); return view('hardware/edit', compact('item')) - ->with('model_list', Helper::modelList()) ->with('statuslabel_list', Helper::statusLabelList()) ->with('statuslabel_types', Helper::statusTypeList()); } @@ -1082,11 +1077,7 @@ class AssetsController extends Controller } elseif ($request->input('bulk_actions')=='edit') { return view('hardware/bulk') ->with('assets', request('ids')) - ->with('statuslabel_list', Helper::statusLabelList()) - ->with( - 'companies_list', - array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList() - ); + ->with('statuslabel_list', Helper::statusLabelList()); } } return redirect()->back()->with('error', 'No action selected'); @@ -1209,10 +1200,7 @@ class AssetsController extends Controller public function getBulkCheckout() { $this->authorize('checkout', Asset::class); - // Filter out assets that are not deployable. - - return view('hardware/bulk-checkout') - ->with('users_list', Helper::usersList()); + return view('hardware/bulk-checkout'); } public function postBulkCheckout(Request $request) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 0738757c64..80671f0165 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -175,8 +175,7 @@ class LocationsController extends Controller $location_options = array('' => 'Top Level') + $location_options; return view('locations/edit', compact('item')) - ->with('location_options', $location_options) - ->with('manager_list', Helper::managerList()); + ->with('location_options', $location_options); } diff --git a/app/Http/Controllers/ModalController.php b/app/Http/Controllers/ModalController.php index c5446aaef3..c55ad04a4d 100644 --- a/app/Http/Controllers/ModalController.php +++ b/app/Http/Controllers/ModalController.php @@ -13,9 +13,7 @@ class ModalController extends Controller } function model() { - return view('modals.model') - ->with('manufacturer', Helper::manufacturerList()) - ->with('category', Helper::categoryList('asset')); + return view('modals.model'); } function statuslabel() { diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index f0eeac0200..662888c624 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -1011,8 +1011,7 @@ class UsersController extends Controller return redirect()->route('users.index')->with('error', $e->getMessage()); } - return view('users/ldap') - ->with('location_list', Helper::locationsList()); + return view('users/ldap'); } diff --git a/resources/assets/js/snipeit_modals.js b/resources/assets/js/snipeit_modals.js index 5efca97faf..4be9f613d1 100644 --- a/resources/assets/js/snipeit_modals.js +++ b/resources/assets/js/snipeit_modals.js @@ -24,7 +24,7 @@ */ - $(function () { +$(function () { //handle modal-add-interstitial calls @@ -39,11 +39,59 @@ model = link.data("dependency"); select = link.data("select"); $('#createModal').load(link.attr('href'),function () { - //do we need to re-select2 this, after load? Probably. - $('#createModal').find('select.select2').select2(); + //do we need to re-select2 this, after load? Probably. + $('#createModal').find('select.select2').select2(); + // Initialize the ajaxy select2 with images. + // This is a copy/paste of the code from snipeit.js, would be great to only have this in one place. + $('.js-data-ajax').each( function (i,item) { + var link = $(item); + var endpoint = link.data("endpoint"); + var select = link.data("select"); + + link.select2({ + ajax: { + + // the baseUrl includes a trailing slash + url: baseUrl + 'api/v1/' + endpoint + '/selectlist', + dataType: 'json', + delay: 250, + headers: { + "X-Requested-With": 'XMLHttpRequest', + "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content') + }, + data: function (params) { + var data = { + search: params.term, + page: params.page || 1, + assetStatusType: link.data("asset-status-type"), + }; + return data; + }, + processResults: function (data, params) { + + params.page = params.page || 1; + + var answer = { + results: data.items, + pagination: { + more: "true" //(params.page < data.page_count) + } + }; + + return answer; + }, + cache: true + }, + escapeMarkup: function (markup) { return markup; }, // let our custom formatter work + templateResult: formatDatalist, + templateSelection: formatDataSelection + }); + }); }); + }); + $('#createModal').on('click','#modal-save', function () { $.ajax({ @@ -102,3 +150,26 @@ }); }); }); + +function formatDatalist (datalist) { + var loading_markup = ' Loading...'; + if (datalist.loading) { + return loading_markup; + } + + var markup = "
" ; + markup +="
"; + if (datalist.image) { + markup += "
"; + } else { + markup += "
"; + } + + markup += "
" + datalist.text + "
"; + markup += "
"; + return markup; +} + +function formatDataSelection (datalist) { + return datalist.text; +} diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 8c0908c0c7..cb2f484678 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -86,18 +86,8 @@ @include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id']) - - - -
- -
- {{ Form::select('company_id', $companies_list , Input::old('company_id'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('company_id', ' :message') !!} -
-
+ + @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
diff --git a/resources/views/modals/model.blade.php b/resources/views/modals/model.blade.php index 1c637c67b9..72659a1213 100644 --- a/resources/views/modals/model.blade.php +++ b/resources/views/modals/model.blade.php @@ -18,13 +18,17 @@
-
{{ Form::select('manufacturer_id', $manufacturer , '', array('class'=>'select2 parent', 'style'=>'width:100%','id' =>'modal-manufacturer_id')) }}
+
+ +
diff --git a/resources/views/models/bulk-edit.blade.php b/resources/views/models/bulk-edit.blade.php index 13d94e64cd..df057f2ca8 100644 --- a/resources/views/models/bulk-edit.blade.php +++ b/resources/views/models/bulk-edit.blade.php @@ -17,38 +17,21 @@
- - -
{{ csrf_field() }}
+
+ @foreach ($models as $model) + {{ $model->display_name }} ({{ $model->model_number }})
+ @endforeach +
- - - -
- -
- {{ Form::select('manufacturer_id', $manufacturer_list , Input::old('manufacturer_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('manufacturer_id', ' :message') !!} -
-
+ @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id']) -
- -
- {{ Form::select('category_id', $category_list , Input::old('category_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('category_id', ' :message') !!} -
-
+ @include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'asset'])
@@ -56,12 +39,13 @@ {{ trans('admin/models/general.fieldset') }}
- {{ Form::select('fieldset_id', $fieldset_list , Input::old('fieldset_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('fieldset_id', ' :message') !!} + {{ Form::select('fieldset_id', $fieldset_list , Input::old('fieldset_id', 'NC'), array('class'=>'select2 js-fieldset-field', 'style'=>'width:350px')) }} + {!! $errors->first('fieldset_id', '
:message
') !!}
+
- - - - @foreach ($models as $model) @endforeach