First pass at this, the ugly way. Just to see wha it looks like.

This commit is contained in:
Brady Wetherington
2015-07-26 18:15:06 -07:00
parent 2b2e6a8829
commit 28304556a9
5 changed files with 130 additions and 13 deletions
@@ -16,6 +16,9 @@ use Validator;
use View;
use Datatable;
//use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
class ModelsController extends AdminController
{
/**
@@ -114,6 +117,32 @@ class ModelsController extends AdminController
return Redirect::to('hardware/models/create')->with('error', Lang::get('admin/models/message.create.error'));
}
public function store()
{
//COPYPASTA!!!! FIXME
$model = new Model;
$settings=Input::all();
$settings['eol']=0;
//
$validator = Validator::make($settings, $model->validationRules());
if ($validator->fails())
{
// The given data did not pass validation
return JsonResponse::create(["error" => "Failed validation: ".print_r($validator->messages()->all('<li>:message</li>'),true)],500);
} else {
$model->name=e(Input::get('name'));
$model->eol=0;
if($model->save()) {
return JsonResponse::create($model);
} else {
return JsonResponse::create(["error" => "Couldn't save Model"],500);
}
}
}
/**
* Model update.
@@ -12,6 +12,8 @@ use Str;
use Validator;
use View;
use Symfony\Component\HttpFoundation\JsonResponse;
class StatuslabelsController extends AdminController
{
/**
@@ -89,6 +91,43 @@ class StatuslabelsController extends AdminController
return Redirect::to('admin/settings/statuslabels/create')->with('error', Lang::get('admin/statuslabels/message.create.error'));
}
public function store()
{
// get the POST data
$new = Input::all();
$new['statuslabel_types']="deployable";
// create a new model instance
$statuslabel = new Statuslabel();
// attempt validation
if ($statuslabel->validate($new)) {
//$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
// Save the Statuslabel data
$statuslabel->name = e(Input::get('name'));
$statuslabel->user_id = Sentry::getId();
//$statuslabel->notes = e(Input::get('notes'));
$statuslabel->deployable = true; //$statustype['deployable'];
$statuslabel->pending = false; //$statustype['pending'];
$statuslabel->archived = false; //$statustype['archived'];
// Was the asset created?
if($statuslabel->save()) {
// Redirect to the new Statuslabel page
return JsonResponse::create($statuslabel);
} else {
return JsonResponse::create(["error" => "Couldn't save Statuslabel"],500);
}
} else {
// failure
$errors = $statuslabel->errors();
return JsonResponse::create(["error" => "Failed validation: ".print_r($errors->all('<li>:message</li>'),true)],500);
}
}
/**
@@ -13,6 +13,9 @@ use Str;
use Validator;
use View;
use Symfony\Component\HttpFoundation\JsonResponse;
class SuppliersController extends AdminController
{
/**
@@ -100,6 +103,26 @@ class SuppliersController extends AdminController
return Redirect::to('admin/settings/suppliers/create')->with('error', Lang::get('admin/suppliers/message.create.error'));
}
public function store()
{
$supplier=new Supplier;
$new=Input::all();
$validator = Validator::make($new, $supplier->validationRules());
if($validator->fails()) {
return JsonResponse::create(["error" => "Failed validation: ".print_r($validator->messages()->all('<li>:message</li>'),true)],500);
} else {
//$supplier->fill($new);
$supplier->name=$new['name'];
$supplier->user_id = Sentry::getId();
if($supplier->save()) {
return JsonResponse::create($supplier);
} else {
return JsonResponse::create(["error" => "Couldn't save Supplier"]);
}
}
}
/**
* Supplier update.
+13 -8
View File
@@ -13,14 +13,15 @@ Route::group(array('prefix' => 'api', 'namespace' => 'Controllers\Admin', 'befor
/*---Status Label API---*/
Route::group(array('prefix'=>'statuslabels'), function() {
Route::get('{statuslabelId}/deployable', function ($statuslabelId) {
$statuslabel = Statuslabel::find($statuslabelId);
if (($statuslabel->deployable=='1') && ($statuslabel->pending!='1') && ($statuslabel->archived!='1')) {
return '1';
} else {
return '0';
}
});
Route::resource('/','StatuslabelsController');
Route::get('{statuslabelId}/deployable', function ($statuslabelId) {
$statuslabel = Statuslabel::find($statuslabelId);
if (($statuslabel->deployable=='1') && ($statuslabel->pending!='1') && ($statuslabel->archived!='1')) {
return '1';
} else {
return '0';
}
});
});
/*---Accessories API---*/
@@ -75,6 +76,10 @@ Route::group(array('prefix' => 'api', 'namespace' => 'Controllers\Admin', 'befor
Route::get('list', ['as'=>'api.categories.list', 'uses'=>'CategoriesController@getDatatable']);
Route::get('{categoryID}/view', ['as'=>'api.categories.view', 'uses'=>'CategoriesController@getDataView']);
});
/*-- Suppliers API (mostly for creating new ones in-line while creating an asset) --*/
Route::group(['prefix'=>'suppliers'], function () {
Route::resource('/', 'SuppliersController');
});
});
/*
+26 -5
View File
@@ -88,7 +88,7 @@
@endif
<span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
<a href='#' onclick="return dependency('model')">Add new Model...</a>
{{ $errors->first('model_id', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') }}
</div>
</div>
@@ -116,7 +116,8 @@
<div class="form-group {{ $errors->has('supplier_id') ? ' has-error' : '' }}">
<label for="supplier_id" class="col-md-2 control-label">@lang('admin/hardware/form.supplier')</label>
<div class="col-md-7 col-sm-12">
{{ Form::select('supplier_id', $supplier_list , Input::old('supplier_id', $asset->supplier_id), array('class'=>'select2', 'style'=>'min-width:350px')) }}
{{ Form::select('supplier_id', $supplier_list , Input::old('supplier_id', $asset->supplier_id), array('class'=>'select2', 'style'=>'min-width:350px','id'=>'supplier_select_id')) }}
<a href='#' onclick="return dependency('supplier','supplier_select_id')">Add new Supplier...</a>
{{ $errors->first('supplier_id', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') }}
</div>
</div>
@@ -165,8 +166,8 @@
<div class="form-group {{ $errors->has('status_id') ? ' has-error' : '' }}">
<label for="status_id" class="col-md-2 control-label">@lang('admin/hardware/form.status') <i class='fa fa-asterisk'></i></label>
<div class="col-md-7 col-sm-12 col-sm-12">
{{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $asset->status_id), array('class'=>'select2 status_id', 'style'=>'width:350px')) }}
{{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $asset->status_id), array('class'=>'select2 status_id', 'style'=>'width:350px','id'=>'status_select_id')) }}
<a href='#' onclick="return dependency('statuslabel','status_select_id')">Add new Status...</a>
<span class="status_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
<p class="help-block">@lang('admin/hardware/form.help_checkout')</p>
@@ -181,6 +182,7 @@
</label>
<div class="col-md-7 col-sm-12">
{{ Form::select('assigned_to', $assigned_to , Input::old('assigned_to', $asset->assigned_to), array('class'=>'select2', 'id'=>'assigned_to', 'style'=>'min-width:350px')) }}
<a href='#' onclick="return dependency('user','assigned_to')">Add new User...</a>
{{ $errors->first('assigned_to', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') }}
</div>
</div>
@@ -199,7 +201,8 @@
<div class="form-group {{ $errors->has('rtd_location_id') ? ' has-error' : '' }}">
<label for="rtd_location_id" class="col-md-2 control-label">@lang('admin/hardware/form.default_location')</label>
<div class="col-md-7 col-sm-12">
{{ Form::select('rtd_location_id', $location_list , Input::old('rtd_location_id', $asset->rtd_location_id), array('class'=>'select2', 'style'=>'width:350px')) }}
{{ Form::select('rtd_location_id', $location_list , Input::old('rtd_location_id', $asset->rtd_location_id), array('class'=>'select2', 'style'=>'width:350px','id'=>'rtd_location_select')) }}
<a href='#' onclick="return dependency('location','rtd_location_select')">Add new Location...</a>
{{ $errors->first('rtd_location_id', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') }}
</div>
</div>
@@ -291,6 +294,24 @@
};
function dependency(what,select_id) {
var name=prompt("Enter the name of your new "+what);
$.post("{{Config::get('app.url')}}/api/"+what+"s",{name: name},function (result) {
var id=result.id;
var name=result.name;
var select=document.getElementById(select_id);
select.options[select.length]=new Option(name,id);
select.selectedIndex=select.length-1;
$(select).trigger("change");
}).fail(function (result) {
//console.dir(result.responseJSON);
msg=result.responseJSON.error.message || result.responseJSON.error;
window.alert("Unable to add new "+what+" - error: "+msg);
});
return false;
}
</script>