Allow bulk model update for #1462, fixes #1442

This commit is contained in:
snipe
2015-12-09 20:35:24 -08:00
parent eb83d9c486
commit e1837069da
8 changed files with 190 additions and 32 deletions
+95 -28
View File
@@ -33,6 +33,7 @@ use Artisan;
use Symfony\Component\Console\Output\BufferedOutput;
use CustomField;
use Symfony\Component\HttpFoundation\JsonResponse;
use Models;
class AssetsController extends AdminController
@@ -1086,43 +1087,56 @@ class AssetsController extends AdminController
public function postBulkEdit($assets = null)
{
if (!Company::isCurrentUserAuthorized()) {
return Redirect::to('hardware')->with('error', Lang::get('general.insufficient_permissions'));
}
else if (!Input::has('edit_asset')) {
return Redirect::back()->with('error', 'No assets selected');
} else {
$asset_raw_array = Input::get('edit_asset');
foreach ($asset_raw_array as $asset_id => $value) {
$asset_ids[] = $asset_id;
if (!Company::isCurrentUserAuthorized()) {
return Redirect::to('hardware')->with('error', Lang::get('general.insufficient_permissions'));
}
} elseif (!Input::has('edit_asset')) {
return Redirect::back()->with('error', 'No assets selected');
}
} else {
$asset_raw_array = Input::get('edit_asset');
foreach ($asset_raw_array as $asset_id => $value) {
$asset_ids[] = $asset_id;
}
}
if (Input::has('bulk_actions')) {
// Create labels
if (Input::get('bulk_actions')=='labels') {
$assets = Asset::find($asset_ids);
$assetcount = count($assets);
$count = 0;
$settings = Setting::getSettings();
if ($settings->qr_code=='1') {
$settings = Setting::getSettings();
return View::make('backend/hardware/labels')->with('assets',$assets)->with('settings',$settings)->with('count',$count);
$assets = Asset::find($asset_ids);
$assetcount = count($assets);
$count = 0;
return View::make('backend/hardware/labels')->with('assets',$assets)->with('settings',$settings)->with('count',$count);
} else {
// QR codes are not enabled
return Redirect::to("hardware")->with('error','Barcodes are not enabled in Admin > Settings');
}
} elseif (Input::get('bulk_actions')=='delete') {
$assets = Asset::with('assigneduser','assetloc')->find($asset_ids);
return View::make('backend/hardware/bulk-delete')->with('assets',$assets);
// Bulk edit
} elseif (Input::get('bulk_actions')=='edit') {
$assets = Input::get('edit_asset');
$supplier_list = array('' => '') + Supplier::orderBy('name', 'asc')->lists('name', 'id');
$statuslabel_list = array('' => '') + Statuslabel::lists('name', 'id');
$location_list = array('' => '') + Location::lists('name', 'id');
$statuslabel_list = array('' => '') + Statuslabel::lists('name', 'id');
$location_list = array('' => '') + Location::lists('name', 'id');
$models_list = array('' => '') + Model::lists('name', 'id');
return View::make('backend/hardware/bulk')->with('assets',$assets)->with('supplier_list',$supplier_list)->with('statuslabel_list',$statuslabel_list)->with('location_list',$location_list);
return View::make('backend/hardware/bulk')->with('assets',$assets)->with('supplier_list',$supplier_list)->with('statuslabel_list',$statuslabel_list)->with('location_list',$location_list)->with('models_list',$models_list);
}
@@ -1145,14 +1159,14 @@ class AssetsController extends AdminController
public function postBulkSave($assets = null)
{
if (!Company::isCurrentUserAuthorized()) {
return Redirect::to('hardware')->with('error', Lang::get('general.insufficient_permissions'));
}
else if (Input::has('bulk_edit')) {
if (!Company::isCurrentUserAuthorized()) {
return Redirect::to('hardware')->with('error', Lang::get('general.insufficient_permissions'));
} elseif (Input::has('bulk_edit')) {
$assets = Input::get('bulk_edit');
if ( (Input::has('purchase_date')) || (Input::has('purchase_cost')) || (Input::has('supplier_id')) || (Input::has('order_number')) || (Input::has('warranty_months')) || (Input::has('rtd_location_id')) || (Input::has('requestable')) || (Input::has('status_id')) ) {
if ( (Input::has('purchase_date')) || (Input::has('purchase_cost')) || (Input::has('supplier_id')) || (Input::has('order_number')) || (Input::has('warranty_months')) || (Input::has('rtd_location_id')) || (Input::has('requestable')) || (Input::has('status_id')) || (Input::has('model_id')) ) {
foreach ($assets as $key => $value) {
@@ -1170,6 +1184,10 @@ class AssetsController extends AdminController
$update_array['supplier_id'] = e(Input::get('supplier_id'));
}
if (Input::has('model_id')) {
$update_array['model_id'] = e(Input::get('model_id'));
}
if (Input::has('order_number')) {
$update_array['order_number'] = e(Input::get('order_number'));
}
@@ -1186,11 +1204,11 @@ class AssetsController extends AdminController
$update_array['status_id'] = e(Input::get('status_id'));
}
if (Input::get('requestable')=='1') {
if (Input::get('requestable')=='1') {
$update_array['requestable'] = 1;
} else {
$update_array['requestable'] = 0;
}
$update_array['requestable'] = 0;
}
if (DB::table('assets')
@@ -1227,6 +1245,55 @@ class AssetsController extends AdminController
}
/**
* Save bulk edits
*
* @return View
**/
public function postBulkDelete($assets = null)
{
if (!Company::isCurrentUserAuthorized()) {
return Redirect::to('hardware')->with('error', Lang::get('general.insufficient_permissions'));
} elseif (Input::has('bulk_edit')) {
//$assets = Input::get('bulk_edit');
$assets = Asset::find(Input::get('bulk_edit'));
//print_r($assets);
foreach ($assets as $asset) {
//echo '<li>'.$asset;
$update_array['deleted_at'] = date('Y-m-d h:i:s');
$update_array['assigned_to'] = NULL;
if (DB::table('assets')
->where('id', $asset->id)
->update($update_array)) {
$logaction = new Actionlog();
$logaction->asset_id = $asset->id;
$logaction->asset_type = 'hardware';
$logaction->created_at = date("Y-m-d H:i:s");
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('deleted');
}
} // endforeach
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.delete.success'));
// no values given, nothing to update
} else {
return Redirect::to("hardware")->with('info',Lang::get('admin/hardware/message.delete.nothing_updated'));
}
// Something weird happened here - default to hardware
return Redirect::to("hardware");
}
public function getDatatable($status = null)
{