Fixes #3888 - broken preview of existing assets

This commit is contained in:
snipe 2017-08-26 15:21:10 -07:00
parent abc3dea8ac
commit fba3949530

View file

@ -292,45 +292,50 @@
});
});
</script>
<script>
$(function() {
$('#assigned_to').on("change",function () {
// console.warn("Model Id has changed!");
var userid=$('#assigned_to').val();
$('#assigned_user').on("change",function () {
var userid = $('#assigned_user option:selected').val();
if(userid=='') {
console.warn('no user selected');
$('#current_assets_box').fadeOut();
$('#current_assets_content').html("");
} else {
$.get("{{url('/') }}/api/users/"+userid+"/assets",{_token: "{{ csrf_token() }}"},function (data) {
// console.warn("Ajax call came back okay for user " + userid + "! " + data.length + " Data is: "+data);
if (data.length > 0) {
$('#current_assets_box').fadeIn();
$.ajax({
type: 'GET',
url: '{{url('/') }}/api/v1/users/' + userid + '/assets',
headers: {
"X-Requested-With": 'XMLHttpRequest',
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
var table_html = '<div class="row"><div class="col-md-12"><table class="table table-striped"><thead><tr><td>{{ trans('admin/hardware/form.name') }}</td><td>{{ trans('admin/hardware/form.tag') }}</td></tr></thead><tbody>';
dataType: 'json',
success: function (data) {
$('#current_assets_box').fadeIn();
$('#current_assets_content').append('');
var table_html = '<div class="row"><div class="col-md-12"><table class="table table-striped"><thead><tr><td>{{ trans('admin/hardware/form.name') }}</td><td>{{ trans('admin/hardware/form.tag') }}</td></tr></thead><tbody>';
for (var i in data) {
var asset = data[i];
table_html += "<tr><td class=\"col-md-8\"><a href=\"{{ url('/') }}/hardware/" + asset.id + "/view\">" + asset.name;
if (asset.model.name!='') {
table_html += " (" + asset.model.name + ")";
$('#current_assets_content').append('');
for (var i in data) {
var asset = data[i];
table_html += '<tr><td class="col-md-8"><a href="{{ url('/') }}/hardware/' + asset.id + '">' + asset.name;
if (asset.model.name!='') {
table_html += " (" + asset.model.name + ")";
}
table_html += "</a></td><td class=\"col-md-4\">" + asset.asset_tag + "</td></tr>";
}
table_html += "</a></td><td class=\"col-md-4\">" + asset.asset_tag + "</td></tr>";
$('#current_assets_content').html(table_html + '</tbody></table></div></div>');
},
error: function (data) {
$('#current_assets_box').fadeOut();
}
$('#current_assets_content').html(table_html + '</tbody></table></div></div>');
} else {
$('#current_assets_box').fadeOut();
}
});
});
}
});
});