Added locations CRUD
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
<?php namespace Controllers\Admin;
|
||||
|
||||
use AdminController;
|
||||
use Input;
|
||||
use Lang;
|
||||
use Location;
|
||||
use Redirect;
|
||||
use DB;
|
||||
use Sentry;
|
||||
use Str;
|
||||
use Validator;
|
||||
use View;
|
||||
|
||||
class LocationsController extends AdminController {
|
||||
|
||||
/**
|
||||
* Show a list of all the locations.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
// Grab all the locations
|
||||
$locations = Location::orderBy('created_at', 'DESC')->paginate(10);
|
||||
|
||||
// Show the page
|
||||
return View::make('backend/locations/index', compact('locations'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Location create.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function getCreate()
|
||||
{
|
||||
// Show the page
|
||||
$location_options = array('0' => 'Top Level') + Location::lists('name', 'id');
|
||||
return View::make('backend/locations/edit')->with('location_options',$location_options)->with('location',new Location);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Location create form processing.
|
||||
*
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postCreate()
|
||||
{
|
||||
// Declare the rules for the form validation
|
||||
$rules = array(
|
||||
'name' => 'required|min:3',
|
||||
'city' => 'required|min:3',
|
||||
'state' => 'required|min:2|max:2',
|
||||
'country' => 'required|min:2|max:2',
|
||||
);
|
||||
|
||||
// Create a new validator instance from our validation rules
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
// If validation fails, we'll exit the operation now.
|
||||
if ($validator->fails())
|
||||
{
|
||||
// Ooops.. something went wrong
|
||||
return Redirect::back()->withInput()->withErrors($validator);
|
||||
}
|
||||
|
||||
// Create a new location
|
||||
$location = new Location;
|
||||
|
||||
// Update the location data
|
||||
$location->name = e(Input::get('name'));
|
||||
$location->city = e(Input::get('city'));
|
||||
$location->state = e(Input::get('state'));
|
||||
$location->country = e(Input::get('country'));
|
||||
$location->user_id = Sentry::getId();
|
||||
|
||||
// Was the location created?
|
||||
if($location->save())
|
||||
{
|
||||
// Redirect to the new location page
|
||||
return Redirect::to("admin/settings/locations")->with('success', Lang::get('admin/locations/message.create.success'));
|
||||
}
|
||||
|
||||
// Redirect to the location create page
|
||||
return Redirect::to('admin/settings/locations/create')->with('error', Lang::get('admin/locations/message.create.error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Location update.
|
||||
*
|
||||
* @param int $locationId
|
||||
* @return View
|
||||
*/
|
||||
public function getEdit($locationId = null)
|
||||
{
|
||||
// Check if the location exists
|
||||
if (is_null($location = Location::find($locationId)))
|
||||
{
|
||||
// Redirect to the blogs management page
|
||||
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Show the page
|
||||
//$location_options = array('' => 'Top Level') + Location::lists('name', 'id');
|
||||
|
||||
$location_options = array('' => 'Top Level') + DB::table('locations')->where('id', '!=', $locationId)->lists('name', 'id');
|
||||
return View::make('backend/locations/edit', compact('location'))->with('location_options',$location_options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Location update form processing page.
|
||||
*
|
||||
* @param int $locationId
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postEdit($locationId = null)
|
||||
{
|
||||
// Check if the blog post exists
|
||||
if (is_null($location = Location::find($locationId)))
|
||||
{
|
||||
// Redirect to the blogs management page
|
||||
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Declare the rules for the form validation
|
||||
$rules = array(
|
||||
'name' => 'required|min:3',
|
||||
'city' => 'required|min:3',
|
||||
'state' => 'required|min:2|max:2',
|
||||
'country' => 'required|min:2|max:2',
|
||||
);
|
||||
|
||||
// Create a new validator instance from our validation rules
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
// If validation fails, we'll exit the operation now.
|
||||
if ($validator->fails())
|
||||
{
|
||||
// Ooops.. something went wrong
|
||||
return Redirect::back()->withInput()->withErrors($validator);
|
||||
}
|
||||
|
||||
// Update the location data
|
||||
$location->name = e(Input::get('name'));
|
||||
$location->city = e(Input::get('city'));
|
||||
$location->state = e(Input::get('state'));
|
||||
$location->country = e(Input::get('country'));
|
||||
|
||||
|
||||
// Was the location updated?
|
||||
if($location->save())
|
||||
{
|
||||
// Redirect to the new location page
|
||||
return Redirect::to("admin/settings/locations/$locationId/edit")->with('success', Lang::get('admin/locations/message.update.success'));
|
||||
}
|
||||
|
||||
// Redirect to the location management page
|
||||
return Redirect::to("admin/settings/locations/$locationId/edit")->with('error', Lang::get('admin/locations/message.update.error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given location.
|
||||
*
|
||||
* @param int $locationId
|
||||
* @return Redirect
|
||||
*/
|
||||
public function getDelete($locationId)
|
||||
{
|
||||
// Check if the blog post exists
|
||||
if (is_null($location = Location::find($locationId)))
|
||||
{
|
||||
// Redirect to the blogs management page
|
||||
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.not_found'));
|
||||
}
|
||||
|
||||
// Delete the blog post
|
||||
$location->delete();
|
||||
|
||||
// Redirect to the blog posts management page
|
||||
return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
'does_not_exist' => 'Location does not exist.',
|
||||
|
||||
'create' => array(
|
||||
'error' => 'Location was not created, please try again.',
|
||||
'success' => 'Location created successfully.'
|
||||
),
|
||||
|
||||
'update' => array(
|
||||
'error' => 'Location was not updated, please try again',
|
||||
'success' => 'Location updated successfully.'
|
||||
),
|
||||
|
||||
'delete' => array(
|
||||
'error' => 'There was an issue deleting the location. Please try again.',
|
||||
'success' => 'The location was deleted successfully.'
|
||||
)
|
||||
|
||||
);
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
'id' => 'ID',
|
||||
'name' => 'Name',
|
||||
'city' => 'City',
|
||||
'state' => 'State',
|
||||
'country' => 'Country',
|
||||
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class Location extends Eloquent {
|
||||
|
||||
/**
|
||||
* Deletes a location
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
protected $table = 'locations';
|
||||
|
||||
public function delete()
|
||||
{
|
||||
// Delete the depreciation
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,6 +123,17 @@ Route::group(array('prefix' => 'admin'), function()
|
||||
Route::get('{depreciationId}/delete', array('as' => 'delete/depreciations', 'uses' => 'Controllers\Admin\DepreciationsController@getDelete'));
|
||||
});
|
||||
|
||||
# Locations
|
||||
Route::group(array('prefix' => 'locations'), function()
|
||||
{
|
||||
Route::get('/', array('as' => 'locations', 'uses' => 'Controllers\Admin\LocationsController@getIndex'));
|
||||
Route::get('create', array('as' => 'create/location', 'uses' => 'Controllers\Admin\LocationsController@getCreate'));
|
||||
Route::post('create', 'Controllers\Admin\LocationsController@postCreate');
|
||||
Route::get('{locationId}/edit', array('as' => 'update/location', 'uses' => 'Controllers\Admin\LocationsController@getEdit'));
|
||||
Route::post('{locationId}/edit', 'Controllers\Admin\LocationsController@postEdit');
|
||||
Route::get('{locationId}/delete', array('as' => 'delete/location', 'uses' => 'Controllers\Admin\LocationsController@getDelete'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
<div class="control-group {{ $errors->has('purchase_date') ? 'error' : '' }}">
|
||||
<label class="control-label" for="purchase_date">Purchase Date</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="datepicker span2" data-date-format="yyyy-mm-dd" placeholder="Select Date" name="purchase_date" id="purchase_date" value="{{ Input::old('purchase_date', $asset->purchase_date) }}"> <span class="add-on"><i class="icon-th"></i></span>
|
||||
<input type="text" class="datepicker span2" data-date-format="yyyy-mm-dd" placeholder="Select Date" name="purchase_date" id="purchase_date" value="{{ Input::old('purchase_date', $asset->purchase_date) }}"> <span class="add-on"><i class="icon-calendar"></i></span>
|
||||
{{ $errors->first('purchase_date', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
<li{{ (Request::is('admin/groups*') ? ' class="active"' : '') }}><a href="{{ URL::to('admin/groups') }}"><i class="icon-user"></i> Groups</a></li>
|
||||
<li{{ (Request::is('admin/settings/manufacturers*') ? ' class="active"' : '') }}><a href="{{ URL::to('admin/settings/manufacturers') }}"><i class="icon-briefcase"></i> Manufacturers</a></li>
|
||||
<li{{ (Request::is('admin/settings/categories*') ? ' class="active"' : '') }}><a href="{{ URL::to('admin/settings/categories') }}"><i class="icon-th"></i> Categories</a></li>
|
||||
|
||||
<li{{ (Request::is('admin/settings/locations*') ? ' class="active"' : '') }}><a href="{{ URL::to('admin/settings/locations') }}"><i class="icon-globe"></i> Locations</a></li>
|
||||
<li{{ (Request::is('admin/settings/depreciations*') ? ' class="active"' : '') }}><a href="{{ URL::to('admin/settings/depreciations') }}"><i class="icon-arrow-down"></i> Depreciation</a></li>
|
||||
|
||||
|
||||
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
@extends('backend/layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
|
||||
@if ($location->id)
|
||||
Update Location
|
||||
@else
|
||||
Create Location
|
||||
@endif
|
||||
|
||||
@parent
|
||||
@stop
|
||||
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
<div class="page-header">
|
||||
<h3>
|
||||
@if ($location->id)
|
||||
Update Location
|
||||
@else
|
||||
Create Location
|
||||
@endif
|
||||
|
||||
<div class="pull-right">
|
||||
<a href="{{ route('locations') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
|
||||
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
||||
<!-- CSRF Token -->
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
|
||||
|
||||
<!-- Tabs Content -->
|
||||
<div class="tab-content">
|
||||
|
||||
<div class="tab-pane active" id="tab-general">
|
||||
<!-- Class Title -->
|
||||
<div class="control-group {{ $errors->has('name') ? 'error' : '' }}">
|
||||
<label class="control-label" for="name">Location Name</label>
|
||||
<div class="controls">
|
||||
<input class="span4" type="text" name="name" id="name" value="{{ Input::old('name', $location->name) }}" />
|
||||
{{ $errors->first('name', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group {{ $errors->has('city') ? 'error' : '' }}">
|
||||
<label class="control-label" for="name">City</label>
|
||||
<div class="controls">
|
||||
<input class="span4" type="text" name="city" id="city" value="{{ Input::old('city', $location->city) }}" />
|
||||
{{ $errors->first('city', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group {{ $errors->has('state') ? 'error' : '' }}">
|
||||
<label class="control-label" for="state">State Abbrev</label>
|
||||
<div class="controls">
|
||||
<input class="span2" type="text" name="state" id="state" value="{{ Input::old('state', $location->state) }}" />
|
||||
{{ $errors->first('state', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group {{ $errors->has('country') ? 'error' : '' }}">
|
||||
<label class="control-label" for="state">Country Abbrev</label>
|
||||
<div class="controls">
|
||||
<input class="span2" type="text" name="country" id="country" value="{{ Input::old('country', $location->country) }}" />
|
||||
{{ $errors->first('country', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Form actions -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<a class="btn btn-link" href="{{ route('locations') }}">Cancel</a>
|
||||
<button type="submit" class="btn btn-success">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
@stop
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
@extends('backend/layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
Asset Depreciations ::
|
||||
@parent
|
||||
@stop
|
||||
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
<div class="page-header">
|
||||
<h3>
|
||||
Asset Depreciations
|
||||
|
||||
<div class="pull-right">
|
||||
<a href="{{ route('create/location') }}" class="btn btn-small btn-info"><i class="icon-plus-sign icon-white"></i> Create</a>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
@if (count($locations) > 10)
|
||||
{{ $locations->links() }}
|
||||
@endif
|
||||
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="span6">@lang('admin/locations/table.name')</th>
|
||||
<th class="span6">@lang('admin/locations/table.city'),
|
||||
@lang('admin/locations/table.state')
|
||||
@lang('admin/locations/table.country')</th>
|
||||
<th class="span2">@lang('table.actions')</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($locations as $location)
|
||||
<tr>
|
||||
<td>{{ $location->name }}</td>
|
||||
<td>{{ $location->city }}, {{ $location->state }} {{ $location->country }} </td>
|
||||
<td>
|
||||
<a href="{{ route('update/location', $location->id) }}" class="btn btn-mini">@lang('button.edit')</a>
|
||||
<a href="{{ route('delete/location', $location->id) }}" class="btn btn-mini btn-danger">@lang('button.delete')</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if (count($locations) > 10)
|
||||
{{ $locations->links() }}
|
||||
@endif
|
||||
|
||||
@stop
|
||||
Reference in New Issue
Block a user