Hide 2nd table when invoicing tasks by default

This commit is contained in:
Hillel Coren 2017-08-29 17:59:13 +03:00
parent 507ac7387c
commit 050df75868
4 changed files with 32 additions and 4 deletions

View File

@ -2425,6 +2425,7 @@ $LANG = array(
'include_errors' => 'Include Errors',
'include_errors_help' => 'Include :link from storage/logs/laravel-error.log',
'recent_errors' => 'recent errors',
'add_item' => 'Add Item',
);

View File

@ -536,8 +536,10 @@
@endif
@if ($invoice->id)
{!! DropdownButton::normal(trans('texts.more_actions'))->withContents($invoice->present()->moreActions())->dropup() !!}
@elseif ( ! $invoice->isQuote() && Request::is('*/clone'))
@elseif (! $invoice->isQuote() && Request::is('*/clone'))
{!! Button::normal(trans($invoice->is_recurring ? 'texts.disable_recurring' : 'texts.enable_recurring'))->withAttributes(['id' => 'recurrButton', 'onclick' => 'onRecurrClick()'])->appendIcon(Icon::create('repeat')) !!}
@elseif (! empty($tasks))
{!! Button::normal(trans('texts.add_item'))->withAttributes(['id' => 'addItemButton', 'onclick' => 'onAddItemClick()'])->appendIcon(Icon::create('plus-sign')) !!}
@endif
@endif
@if ($invoice->trashed())
@ -1224,6 +1226,11 @@
$('#saveButton').html(actionLabel + "<span class='glyphicon glyphicon-globe'></span>");
}
function onAddItemClick() {
model.forceShowItems(true);
$('#addItemButton').hide();
}
function onEmailClick() {
if (!NINJA.isRegistered) {
swal("{!! trans('texts.registration_required') !!}");

View File

@ -1,4 +1,4 @@
<thead {!! $isTasks ? 'style="display:none;" data-bind="visible: $root.hasTasks"' : '' !!}>
<thead {!! $isTasks ? 'style="display:none;" data-bind="visible: $root.hasTasks"' : (! empty($tasks) ? 'data-bind="visible: $root.hasItems"' : '') !!}>
@if ($isTasks)
<tr><td style="20px" colspan="20"></td></tr>
@endif
@ -19,7 +19,7 @@
<th style="min-width:32px;" class="hide-border"></th>
</tr>
</thead>
<tbody data-bind="sortable: { data: invoice_items_{{ $isTasks ? 'with_tasks' : 'without_tasks' }}, allowDrop: false, afterMove: onDragged} {{ $isTasks ? ', visible: $root.hasTasks' : '' }}"
<tbody data-bind="sortable: { data: invoice_items_{{ $isTasks ? 'with_tasks' : 'without_tasks' }}, allowDrop: false, afterMove: onDragged} {{ $isTasks ? ', visible: $root.hasTasks' : (! empty($tasks) ? ', visible: $root.hasItems' : '') }}"
{!! $isTasks ? 'style="display:none;border-spacing: 100px"' : '' !!}>
<tr data-bind="event: { mouseover: showActions, mouseout: hideActions }" class="sortable-row">
<td class="hide-border td-icon">

View File

@ -173,7 +173,7 @@ function ViewModel(data) {
}
invoice = self.invoice();
for (var i=0; i<invoice.invoice_items_with_tasks().length; ++i) {
var item = invoice.invoice_items()[i];
var item = invoice.invoice_items_with_tasks()[i];
if (! item.isEmpty()) {
self.hasTasksCached = true;
return true;
@ -181,6 +181,26 @@ function ViewModel(data) {
}
return false;
});
self.hasItemsCached = false;
self.forceShowItems = ko.observable(false);
self.hasItems = ko.computed(function() {
if (self.forceShowItems()) {
return true;
}
if (self.hasItemsCached) {
return true;
}
invoice = self.invoice();
for (var i=0; i<invoice.invoice_items_without_tasks().length; ++i) {
var item = invoice.invoice_items_without_tasks()[i];
if (! item.isEmpty()) {
self.hasItemsCached = true;
return true;
}
}
return false;
});
}
function InvoiceModel(data) {