mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on datatables on client page
This commit is contained in:
parent
eb710348bf
commit
1323f21867
@ -1,6 +1,7 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use Utils;
|
||||
use Request;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
@ -29,12 +30,18 @@ class BaseController extends Controller
|
||||
}
|
||||
|
||||
$isDatatable = filter_var(request()->datatable, FILTER_VALIDATE_BOOLEAN);
|
||||
$referer = Request::server('HTTP_REFERER');
|
||||
$entityTypes = Utils::pluralizeEntityType($entityType);
|
||||
|
||||
if ($action == 'restore' && count($ids) == 1) {
|
||||
if (strpos($referer, '/clients/')) {
|
||||
// when restoring redirect to entity
|
||||
return redirect($referer);
|
||||
} elseif ($action == 'restore' && count($ids) == 1) {
|
||||
return redirect("{$entityTypes}/" . $ids[0]);
|
||||
// when viewing from a datatable list
|
||||
} elseif ($isDatatable || ($action == 'archive' || $action == 'delete')) {
|
||||
return redirect("{$entityTypes}");
|
||||
// when viewing individual entity
|
||||
} elseif (count($ids)) {
|
||||
return redirect("{$entityTypes}/" . $ids[0]);
|
||||
} else {
|
||||
|
@ -114,7 +114,7 @@ class ExpenseDatatable extends EntityDatatable
|
||||
[
|
||||
trans('texts.invoice_expense'),
|
||||
function ($model) {
|
||||
return "javascript:invoiceEntity({$model->public_id})";
|
||||
return "javascript:submitForm_expense('invoice', {$model->public_id})";
|
||||
},
|
||||
function ($model) {
|
||||
return ! $model->invoice_id && (!$model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE);
|
||||
|
@ -110,8 +110,8 @@ class InvoiceDatatable extends EntityDatatable
|
||||
],
|
||||
[
|
||||
trans('texts.mark_sent'),
|
||||
function ($model) {
|
||||
return "javascript:markEntity({$model->public_id})";
|
||||
function ($model) use ($entityType) {
|
||||
return "javascript:submitForm_{$entityType}('markSent', {$model->public_id})";
|
||||
},
|
||||
function ($model) {
|
||||
return $model->invoice_status_id < INVOICE_STATUS_SENT && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
|
||||
@ -147,7 +147,7 @@ class InvoiceDatatable extends EntityDatatable
|
||||
[
|
||||
trans('texts.convert_to_invoice'),
|
||||
function ($model) {
|
||||
return "javascript:convertEntity({$model->public_id})";
|
||||
return "javascript:submitForm_quote('convert', {$model->public_id})";
|
||||
},
|
||||
function ($model) use ($entityType) {
|
||||
return $entityType == ENTITY_QUOTE && ! $model->quote_invoice_id && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
|
||||
|
@ -78,7 +78,7 @@ class TaskDatatable extends EntityDatatable
|
||||
[
|
||||
trans('texts.stop_task'),
|
||||
function ($model) {
|
||||
return "javascript:stopTask({$model->public_id})";
|
||||
return "javascript:submitForm_task('stop', {$model->public_id})";
|
||||
},
|
||||
function ($model) {
|
||||
return $model->is_running && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]);
|
||||
@ -87,7 +87,7 @@ class TaskDatatable extends EntityDatatable
|
||||
[
|
||||
trans('texts.invoice_task'),
|
||||
function ($model) {
|
||||
return "javascript:invoiceEntity({$model->public_id})";
|
||||
return "javascript:submitForm_task('invoice', {$model->public_id})";
|
||||
},
|
||||
function ($model) {
|
||||
return ! $model->invoice_number && (!$model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE);
|
||||
|
@ -116,16 +116,16 @@ class DatatableService
|
||||
}
|
||||
|
||||
if (($datatable->entityType != ENTITY_USER || $model->public_id) && $can_edit) {
|
||||
$dropdown_contents .= "<li><a href=\"javascript:archiveEntity({$model->public_id})\">"
|
||||
$dropdown_contents .= "<li><a href=\"javascript:submitForm_{$datatable->entityType}('archive', {$model->public_id})\">"
|
||||
. trans("texts.archive_{$datatable->entityType}") . '</a></li>';
|
||||
}
|
||||
} else if($can_edit) {
|
||||
$dropdown_contents .= "<li><a href=\"javascript:restoreEntity({$model->public_id})\">"
|
||||
$dropdown_contents .= "<li><a href=\"javascript:submitForm_{$datatable->entityType}('restore', {$model->public_id})\">"
|
||||
. trans("texts.restore_{$datatable->entityType}") . '</a></li>';
|
||||
}
|
||||
|
||||
if (property_exists($model, 'is_deleted') && !$model->is_deleted && $can_edit) {
|
||||
$dropdown_contents .= "<li><a href=\"javascript:deleteEntity({$model->public_id})\">"
|
||||
$dropdown_contents .= "<li><a href=\"javascript:submitForm_{$datatable->entityType}('delete', {$model->public_id})\">"
|
||||
. trans("texts.delete_{$datatable->entityType}") . '</a></li>';
|
||||
}
|
||||
|
||||
|
@ -218,6 +218,7 @@
|
||||
trans('texts.adjustment'))
|
||||
->setUrl(url('api/activities/'. $client->public_id))
|
||||
->setCustomValues('entityType', 'activity')
|
||||
->setCustomValues('clientId', $client->public_id)
|
||||
->setOptions('sPaginationType', 'bootstrap')
|
||||
->setOptions('bFilter', false)
|
||||
->setOptions('aaSorting', [['0', 'desc']])
|
||||
|
@ -79,7 +79,9 @@
|
||||
{!! json_encode($k) !!}: {!! $o !!},
|
||||
@endforeach
|
||||
"fnDrawCallback": function(oSettings) {
|
||||
if (window.onDatatableReady) {
|
||||
if (window.onDatatableReady_{{ $values['entityType'] }}) {
|
||||
window.onDatatableReady_{{ $values['entityType'] }}();
|
||||
} else if (window.onDatatableReady) {
|
||||
window.onDatatableReady();
|
||||
}
|
||||
},
|
||||
|
@ -1,27 +1,28 @@
|
||||
{!! Former::open(Utils::pluralizeEntityType($entityType) . '/bulk')->addClass('listForm') !!}
|
||||
{!! Former::open(Utils::pluralizeEntityType($entityType) . '/bulk')
|
||||
->addClass('listForm_' . $entityType) !!}
|
||||
|
||||
<div style="display:none">
|
||||
{!! Former::text('action') !!}
|
||||
{!! Former::text('public_id') !!}
|
||||
{!! Former::text('action')->id('action_' . $entityType) !!}
|
||||
{!! Former::text('public_id')->id('public_id_' . $entityType) !!}
|
||||
{!! Former::text('datatable')->value('true') !!}
|
||||
</div>
|
||||
|
||||
<div class="pull-left">
|
||||
@can('create', 'invoice')
|
||||
@if ($entityType == ENTITY_TASK)
|
||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm_'.$entityType.'("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||
@endif
|
||||
@if ($entityType == ENTITY_EXPENSE)
|
||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm_'.$entityType.'("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||
@endif
|
||||
@endcan
|
||||
|
||||
@if (in_array($entityType, [ENTITY_EXPENSE_CATEGORY, ENTITY_PRODUCT]))
|
||||
{!! Button::normal(trans('texts.archive'))->asLinkTo('javascript:submitForm("archive")')->appendIcon(Icon::create('trash')) !!}
|
||||
{!! Button::normal(trans('texts.archive'))->asLinkTo('javascript:submitForm_'.$entityType.'("archive")')->appendIcon(Icon::create('trash')) !!}
|
||||
@else
|
||||
{!! DropdownButton::normal(trans('texts.archive'))->withContents([
|
||||
['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm("archive")'],
|
||||
['label' => trans('texts.delete_'.$entityType), 'url' => 'javascript:submitForm("delete")'],
|
||||
['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm_'.$entityType.'("archive")'],
|
||||
['label' => trans('texts.delete_'.$entityType), 'url' => 'javascript:submitForm_'.$entityType.'("delete")'],
|
||||
])->withAttributes(['class'=>'archive'])->split() !!}
|
||||
@endif
|
||||
|
||||
@ -49,7 +50,7 @@
|
||||
</div>
|
||||
|
||||
<div id="top_right_buttons" class="pull-right">
|
||||
<input id="tableFilter" type="text" style="width:140px;margin-right:17px;background-color: white !important"
|
||||
<input id="tableFilter_{{ $entityType }}" type="text" style="width:140px;margin-right:17px;background-color: white !important"
|
||||
class="form-control pull-left" placeholder="{{ trans('texts.filter') }}" value="{{ Input::get('filter') }}"/>
|
||||
|
||||
@if (empty($clientId))
|
||||
@ -64,6 +65,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{!! Datatable::table()
|
||||
->addColumn(Utils::trans($datatable->columnFields()))
|
||||
->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : '')))
|
||||
@ -112,53 +114,23 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function submitForm(action) {
|
||||
function submitForm_{{ $entityType }}(action, id) {
|
||||
if (id) {
|
||||
$('#public_id_{{ $entityType }}').val(id);
|
||||
}
|
||||
|
||||
if (action == 'delete') {
|
||||
sweetConfirm(function() {
|
||||
$('#action').val(action);
|
||||
$('form.listForm').submit();
|
||||
$('#action_{{ $entityType }}').val(action);
|
||||
$('form.listForm_{{ $entityType }}').submit();
|
||||
});
|
||||
} else {
|
||||
$('#action').val(action);
|
||||
$('form.listForm').submit();
|
||||
$('#action_{{ $entityType }}').val(action);
|
||||
$('form.listForm_{{ $entityType }}').submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deleteEntity(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('delete');
|
||||
}
|
||||
|
||||
function archiveEntity(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('archive');
|
||||
}
|
||||
|
||||
function restoreEntity(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('restore');
|
||||
}
|
||||
function convertEntity(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('convert');
|
||||
}
|
||||
|
||||
function markEntity(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('markSent');
|
||||
}
|
||||
|
||||
function stopTask(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('stop');
|
||||
}
|
||||
|
||||
function invoiceEntity(id) {
|
||||
$('#public_id').val(id);
|
||||
submitForm('invoice');
|
||||
}
|
||||
|
||||
@if ($entityType == ENTITY_PAYMENT)
|
||||
@if ($entityType == ENTITY_PAYMENT)
|
||||
var paymentId = null;
|
||||
function showRefundModal(id, amount, formatted, symbol){
|
||||
paymentId = id;
|
||||
@ -170,60 +142,50 @@ function invoiceEntity(id) {
|
||||
|
||||
function handleRefundClicked(){
|
||||
$('#public_id').val(paymentId);
|
||||
submitForm('refund');
|
||||
submitForm_{{ $entityType }}('refund');
|
||||
}
|
||||
@endif
|
||||
@endif
|
||||
|
||||
/*
|
||||
function setTrashVisible() {
|
||||
var checked = $('#trashed').is(':checked');
|
||||
var url = '{{ URL::to('set_entity_filter/' . $entityType) }}' + (checked ? '/true' : '/false');
|
||||
$(function() {
|
||||
|
||||
$.get(url, function(data) {
|
||||
refreshDatatable();
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
$(function() {
|
||||
// Handle datatable filtering
|
||||
var tableFilter = '';
|
||||
var searchTimeout = false;
|
||||
|
||||
var oTable0 = $('#DataTables_Table_0').dataTable();
|
||||
var oTable1 = $('#DataTables_Table_1').dataTable();
|
||||
function filterTable(val) {
|
||||
function filterTable_{{ $entityType }}(val) {
|
||||
if (val == tableFilter) {
|
||||
return;
|
||||
}
|
||||
tableFilter = val;
|
||||
var oTable0 = $('.listForm_{{ $entityType }} .data-table').dataTable();
|
||||
oTable0.fnFilter(val);
|
||||
}
|
||||
|
||||
$('#tableFilter').on('keyup', function(){
|
||||
$('#tableFilter_{{ $entityType }}').on('keyup', function(){
|
||||
if (searchTimeout) {
|
||||
window.clearTimeout(searchTimeout);
|
||||
}
|
||||
|
||||
searchTimeout = setTimeout(function() {
|
||||
filterTable($('#tableFilter').val());
|
||||
filterTable_{{ $entityType }}($('#tableFilter_{{ $entityType }}').val());
|
||||
}, 500);
|
||||
})
|
||||
|
||||
if ($('#tableFilter').val()) {
|
||||
filterTable($('#tableFilter').val());
|
||||
if ($('#tableFilter_{{ $entityType }}').val()) {
|
||||
filterTable_{{ $entityType }}($('#tableFilter_{{ $entityType }}').val());
|
||||
}
|
||||
|
||||
window.onDatatableReady = function() {
|
||||
// Enable/disable bulk action buttons
|
||||
window.onDatatableReady_{{ Utils::pluralizeEntityType($entityType) }} = function() {
|
||||
$(':checkbox').click(function() {
|
||||
setBulkActionsEnabled();
|
||||
setBulkActionsEnabled_{{ $entityType }}();
|
||||
});
|
||||
|
||||
$('tbody tr').unbind('click').click(function(event) {
|
||||
$('.listForm_{{ $entityType }} tbody tr').unbind('click').click(function(event) {
|
||||
if (event.target.type !== 'checkbox' && event.target.type !== 'button' && event.target.tagName.toLowerCase() !== 'a') {
|
||||
$checkbox = $(this).closest('tr').find(':checkbox:not(:disabled)');
|
||||
var checked = $checkbox.prop('checked');
|
||||
$checkbox.prop('checked', !checked);
|
||||
setBulkActionsEnabled();
|
||||
setBulkActionsEnabled_{{ $entityType }}();
|
||||
}
|
||||
});
|
||||
|
||||
@ -234,25 +196,27 @@ $(function() {
|
||||
$('#completeRefundButton').click(handleRefundClicked)
|
||||
@endif
|
||||
|
||||
$('.archive, .invoice').prop('disabled', true);
|
||||
$('.archive:not(.dropdown-toggle)').click(function() {
|
||||
submitForm('archive');
|
||||
$('.listForm_{{ $entityType }} .archive, .invoice').prop('disabled', true);
|
||||
$('.listForm_{{ $entityType }} .archive:not(.dropdown-toggle)').click(function() {
|
||||
submitForm_{{ $entityType }}('archive');
|
||||
});
|
||||
|
||||
$('.selectAll').click(function() {
|
||||
$('.listForm_{{ $entityType }} .selectAll').click(function() {
|
||||
$(this).closest('table').find(':checkbox:not(:disabled)').prop('checked', this.checked);
|
||||
});
|
||||
|
||||
function setBulkActionsEnabled() {
|
||||
function setBulkActionsEnabled_{{ $entityType }}() {
|
||||
var buttonLabel = "{{ trans('texts.archive') }}";
|
||||
var count = $('tbody :checkbox:checked').length;
|
||||
$('button.archive, button.invoice').prop('disabled', !count);
|
||||
var count = $('.listForm_{{ $entityType }} tbody :checkbox:checked').length;
|
||||
$('.listForm_{{ $entityType }} button.archive, .listForm_{{ $entityType }} button.invoice').prop('disabled', !count);
|
||||
if (count) {
|
||||
buttonLabel += ' (' + count + ')';
|
||||
}
|
||||
$('button.archive').not('.dropdown-toggle').text(buttonLabel);
|
||||
$('.listForm_{{ $entityType }} button.archive').not('.dropdown-toggle').text(buttonLabel);
|
||||
}
|
||||
|
||||
|
||||
// Setup state/status filter
|
||||
$('#statuses_{{ $entityType }}').select2({
|
||||
placeholder: "{{ trans('texts.status') }}",
|
||||
}).val('{{ session('entity_state_filter:' . $entityType, STATUS_ACTIVE) . ',' . session('entity_status_filter:' . $entityType) }}'.split(','))
|
||||
@ -272,6 +236,6 @@ $(function() {
|
||||
|
||||
$('#statusWrapper_{{ $entityType }}').show();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user