Skip to content

Commit

Permalink
Fixes #759 - populate form with parent location info
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed May 7, 2015
1 parent 75644eb commit 95279f8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/config/version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
return array (
'app_version' => 'v1.2.7-12',
'hash_version' => 'v1.2.7-12-g2f52369',
'app_version' => 'v1.2.7-14',
'hash_version' => 'v1.2.7-14-g2d7a348',
);
6 changes: 1 addition & 5 deletions app/controllers/admin/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,15 @@ 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');

$locations = Location::orderBy('name','ASC')->get();

$location_options_array = Location::getLocationHierarchy($locations);
$location_options = Location::flattenLocationsArray($location_options_array);
$location_options = array('' => 'Top Level') + $location_options;

return View::make('backend/locations/edit', compact('location'))->with('location_options',$location_options);
}

Expand Down
19 changes: 12 additions & 7 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@
Route::resource('/', 'LicensesController');
Route::get('list', array('as'=>'api.licenses.list', 'uses'=>'LicensesController@getDatatable'));
});

/*---Locations API---*/
Route::group(array('prefix'=>'locations'), function() {
Route::get('{locationID}/check', function ($locationID) {
$location = Location::find($locationID);
return $location;
});
});
/*---Models API---*/
Route::group(array('prefix'=>'models'), function() {
Route::resource('/', 'ModelsController');
Route::get('list/{status?}', array('as'=>'api.models.list', 'uses'=>'ModelsController@getDatatable'));
Route::get('list/{status?}', array('as'=>'api.models.list', 'uses'=>'ModelsController@getDatatable'));
Route::get('{modelId}/check', function ($modelId) {
$model = Model::find($modelId);
return $model->show_mac_address;
Expand Down Expand Up @@ -255,7 +263,7 @@

# User Management
Route::group(array('prefix' => 'users'), function () {

Route::get('create', array('as' => 'create/user', 'uses' => 'UsersController@getCreate'));
Route::post('create', 'UsersController@postCreate');
Route::get('import', array('as' => 'import/user', 'uses' => 'UsersController@getImport'));
Expand All @@ -269,7 +277,7 @@
Route::get('{userId}/view', array('as' => 'view/user', 'uses' => 'UsersController@getView'));
Route::get('{userId}/unsuspend', array('as' => 'unsuspend/user', 'uses' => 'UsersController@getUnsuspend'));
Route::get('/', array('as' => 'users', 'uses' => 'UsersController@getIndex'));

});

# Group Management
Expand Down Expand Up @@ -387,13 +395,10 @@

Route::get('reports/custom', array('as' => 'reports/custom', 'uses' => 'ReportsController@getCustomReport'));
Route::post('reports/custom', 'ReportsController@postCustom');

Route::get('reports/activity', array('as' => 'reports/activity', 'uses' => 'ReportsController@getActivityReport'));
});



Route::get('/', array('as' => 'home', 'before' => 'admin-auth', 'uses' => 'Controllers\Admin\DashboardController@getIndex'));



40 changes: 38 additions & 2 deletions app/views/backend/locations/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</label>
<div class="col-md-12">
<div class="col-xs-8">
{{ Form::select('parent_id', $location_options , Input::old('parent_id', $location->parent_id), array('class'=>'select2', 'style'=>'width:350px')) }} </div>
{{ Form::select('parent_id', $location_options , Input::old('parent_id', $location->parent_id), array('class'=>'select2 parent', 'style'=>'width:350px')) }} </div>
{{ $errors->first('parent_id', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') }}
</div>
</div>
Expand Down Expand Up @@ -126,7 +126,7 @@
</label>
<div class="col-md-5">

{{ Form::countries('country', Input::old('country', $location->country), 'select2') }}
{{ Form::countries('country', Input::old('country', $location->country), 'select2 country') }}
</div>
{{ $errors->first('country', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') }}
</div>
Expand All @@ -144,5 +144,41 @@

</form>

@if (!$location->id)
<script>
var $eventSelect = $(".parent");
$eventSelect.on("change", function () { parent_details($eventSelect.val()); });
$(function() {
var parent_loc = $(".parent option:selected").val();
if(parent_loc!=''){
parent_details(parent_loc);
}
});
function parent_details(id) {
//start ajax request
$.ajax({
type: 'GET',
url: "{{Config::get('app.url')}}/api/locations/"+id+"/check",
//force to handle it as text
dataType: "text",
success: function(data) {
var json = $.parseJSON(data);
$("#city").val(json.city);
$("#address").val(json.address);
$("#address2").val(json.address2);
$("#state").val(json.state);
$("#zip").val(json.zip);
$(".country").select2("val",json.country);
//$(".country option[value="+json.country+"]").attr("selected", "selected");
//$("select option[value="+json.country+"]")).prop('selected','true');
}
});
};
</script>
@endif

@stop

0 comments on commit 95279f8

Please sign in to comment.