diff --git a/app/controllers/admin/LocationsController.php b/app/controllers/admin/LocationsController.php new file mode 100644 index 0000000000..5049a1b88c --- /dev/null +++ b/app/controllers/admin/LocationsController.php @@ -0,0 +1,189 @@ +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')); + } + + + +} diff --git a/app/lang/en/admin/locations/message.php b/app/lang/en/admin/locations/message.php new file mode 100755 index 0000000000..b7a346098a --- /dev/null +++ b/app/lang/en/admin/locations/message.php @@ -0,0 +1,22 @@ + '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.' + ) + +); diff --git a/app/lang/en/admin/locations/table.php b/app/lang/en/admin/locations/table.php new file mode 100755 index 0000000000..09abfd2937 --- /dev/null +++ b/app/lang/en/admin/locations/table.php @@ -0,0 +1,11 @@ + 'ID', + 'name' => 'Name', + 'city' => 'City', + 'state' => 'State', + 'country' => 'Country', + +); diff --git a/app/models/Location.php b/app/models/Location.php new file mode 100644 index 0000000000..6b1695dde3 --- /dev/null +++ b/app/models/Location.php @@ -0,0 +1,19 @@ + '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')); + }); + }); diff --git a/app/views/backend/assets/edit.blade.php b/app/views/backend/assets/edit.blade.php index c64be1461f..22aa7b937a 100755 --- a/app/views/backend/assets/edit.blade.php +++ b/app/views/backend/assets/edit.blade.php @@ -87,7 +87,7 @@
- + {{ $errors->first('purchase_date', ':message') }}
diff --git a/app/views/backend/layouts/default.blade.php b/app/views/backend/layouts/default.blade.php index 3973f650fe..2c43f3fed8 100755 --- a/app/views/backend/layouts/default.blade.php +++ b/app/views/backend/layouts/default.blade.php @@ -113,7 +113,7 @@ Groups Manufacturers Categories - + Locations Depreciation diff --git a/app/views/backend/locations/edit.blade.php b/app/views/backend/locations/edit.blade.php new file mode 100755 index 0000000000..8a31b28cbc --- /dev/null +++ b/app/views/backend/locations/edit.blade.php @@ -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') + + + +
+ + + + +
+ +
+ +
+ +
+ + {{ $errors->first('name', ':message') }} +
+
+
+ +
+ + {{ $errors->first('city', ':message') }} +
+
+ +
+ +
+ + {{ $errors->first('state', ':message') }} +
+
+ +
+ +
+ + {{ $errors->first('country', ':message') }} +
+
+
+ + + +
+
+ Cancel + +
+
+ + + +@stop diff --git a/app/views/backend/locations/index.blade.php b/app/views/backend/locations/index.blade.php new file mode 100755 index 0000000000..150d4807da --- /dev/null +++ b/app/views/backend/locations/index.blade.php @@ -0,0 +1,53 @@ +@extends('backend/layouts/default') + +{{-- Page title --}} +@section('title') +Asset Depreciations :: +@parent +@stop + +{{-- Page content --}} +@section('content') + + +@if (count($locations) > 10) +{{ $locations->links() }} +@endif + + + + + + + + + + + @foreach ($locations as $location) + + + + + + @endforeach + +
@lang('admin/locations/table.name')@lang('admin/locations/table.city'), + @lang('admin/locations/table.state') + @lang('admin/locations/table.country')@lang('table.actions')
{{ $location->name }}{{ $location->city }}, {{ $location->state }} {{ $location->country }} + @lang('button.edit') + @lang('button.delete') +
+ +@if (count($locations) > 10) +{{ $locations->links() }} +@endif + +@stop