|
| 1 | +<div> |
| 2 | + <span class="autocomplete"> |
| 3 | + @include('laravel-crm::partials.form.hidden',[ |
| 4 | + 'name' => 'organisation_id', |
| 5 | + 'attributes' => [ |
| 6 | + 'wire:model' => 'organisation_id' |
| 7 | + ] |
| 8 | + ]) |
| 9 | + <script type="text/javascript"> |
| 10 | + let organisations = {!! \VentureDrake\LaravelCrm\Http\Helpers\AutoComplete\organisationsWithDetails() !!} |
| 11 | + </script> |
| 12 | + |
| 13 | + <span wire:ignore> |
| 14 | + @include('laravel-crm::partials.form.text',[ |
| 15 | + 'name' => 'organisation_name', |
| 16 | + 'label' => ucfirst(__('laravel-crm::lang.organization')), |
| 17 | + 'prepend' => '<span class="fa fa-building" aria-hidden="true"></span>', |
| 18 | + 'attributes' => [ |
| 19 | + 'autocomplete' => \Illuminate\Support\Str::random(), |
| 20 | + 'wire:model' => 'organisation_name' |
| 21 | + ], |
| 22 | + 'required' => 'true' |
| 23 | + ]) |
| 24 | + </span> |
| 25 | + </span> |
| 26 | + |
| 27 | + <span class="autocomplete"> |
| 28 | + @include('laravel-crm::partials.form.hidden',[ |
| 29 | + 'name' => 'person_id', |
| 30 | + 'attributes' => [ |
| 31 | + 'wire:model' => 'person_id' |
| 32 | + ] |
| 33 | + ]) |
| 34 | + <script type="text/javascript"> |
| 35 | + let people = {!! \VentureDrake\LaravelCrm\Http\Helpers\AutoComplete\peopleWithDetails() !!} |
| 36 | + </script> |
| 37 | + |
| 38 | + <span wire:ignore> |
| 39 | + @include('laravel-crm::partials.form.text',[ |
| 40 | + 'name' => 'person_name', |
| 41 | + 'label' => ucfirst(__('laravel-crm::lang.contact_person')), |
| 42 | + 'prepend' => '<span class="fa fa-user" aria-hidden="true"></span>', |
| 43 | + 'attributes' => [ |
| 44 | + 'autocomplete' => \Illuminate\Support\Str::random(), |
| 45 | + 'wire:model' => 'person_name' |
| 46 | + ], |
| 47 | + 'required' => 'true' |
| 48 | + ]) |
| 49 | + </span> |
| 50 | + </span> |
| 51 | + |
| 52 | + @push('livewire-js') |
| 53 | + <script> |
| 54 | + $(document).ready(function () { |
| 55 | +
|
| 56 | + bindOrganisationAutocomplete(); |
| 57 | + bindPersonAutocomplete(); |
| 58 | + |
| 59 | + function bindOrganisationAutocomplete(){ |
| 60 | + $('input[name="organisation_name"]').autocomplete({ |
| 61 | + source: organisations, |
| 62 | + value: 'value', |
| 63 | + label: 'label', |
| 64 | + onSelectItem: function (item, element) { |
| 65 | + @this.set('person_id', $(element).closest('form').find("input[name='person_id']").val()); |
| 66 | + @this.set('person_name', $(element).closest('form').find("input[name='person_name']").val()); |
| 67 | + @this.set('organisation_id', item.value); |
| 68 | +
|
| 69 | + $(element).closest('.autocomplete').find('input[name="organisation_id"]').val(item.value).trigger('change'); |
| 70 | +
|
| 71 | + $.ajax({ |
| 72 | + url: "/crm/organisations/" + item.value + "/autocomplete", |
| 73 | + cache: false |
| 74 | + }).done(function( data ) { |
| 75 | +
|
| 76 | + $('.autocomplete-organisation').find('input[name="line1"]').val(data.address_line1); |
| 77 | + $('.autocomplete-organisation').find('input[name="line2"]').val(data.address_line2); |
| 78 | + $('.autocomplete-organisation').find('input[name="line3"]').val(data.address_line3); |
| 79 | + $('.autocomplete-organisation').find('input[name="city"]').val(data.address_city); |
| 80 | + $('.autocomplete-organisation').find('input[name="state"]').val(data.address_state); |
| 81 | + $('.autocomplete-organisation').find('input[name="code"]').val(data.address_code); |
| 82 | + $('.autocomplete-organisation').find('select[name="country"]').val(data.address_country); |
| 83 | +
|
| 84 | + }); |
| 85 | + }, |
| 86 | + highlightClass: 'text-danger', |
| 87 | + treshold: 2, |
| 88 | + }); |
| 89 | +
|
| 90 | + $('input[name="organisation_name"]').on('input', function() { |
| 91 | + $(this).closest('.autocomplete').find('input[name="organisation_id"]').val(''); |
| 92 | + $('.autocomplete-organisation').find('input,select').val(''); |
| 93 | + $(this).closest('.autocomplete').find('input[name="organisation_id"]').trigger('change'); |
| 94 | + }); |
| 95 | +
|
| 96 | + $('input[name="organisation_id"]').on('change', function() { |
| 97 | + if($(this).val() == '' && $.trim($(this).closest('.autocomplete').find('input[name="organisation_name"]').val()) != ''){ |
| 98 | + $(this).closest('.autocomplete').find(".autocomplete-new").show() |
| 99 | + $('.autocomplete-organisation').find('input,select').removeAttr('disabled'); |
| 100 | + Livewire.emit('invoiceOrganisationDeselected'); |
| 101 | + }else{ |
| 102 | + $(this).closest('.autocomplete').find(".autocomplete-new").hide() |
| 103 | + $('.autocomplete-organisation').find('input,select').attr('disabled','disabled'); |
| 104 | + } |
| 105 | + @this.set('organisation_id',$(this).val()); |
| 106 | + }); |
| 107 | +
|
| 108 | + if($('input[name="organisation_id"]').val() == '' && $.trim($('input[name="organisation_id"]').closest('.autocomplete').find('input[name="organisation_name"]').val()) != ''){ |
| 109 | + $('input[name="organisation_id"]').closest('.autocomplete').find(".autocomplete-new").show(); |
| 110 | + $('.autocomplete-organisation').find('input,select').removeAttr('disabled'); |
| 111 | + } |
| 112 | +
|
| 113 | + if($('input[name="organisation_name"]').closest('.autocomplete').find('input[name="organisation_id"]').val() == ''){ |
| 114 | + $('.autocomplete-organisation').find('input,select').removeAttr('disabled'); |
| 115 | + } |
| 116 | + } |
| 117 | +
|
| 118 | + function bindPersonAutocomplete(){ |
| 119 | +
|
| 120 | + $('input[name="person_name"]').autocomplete({ |
| 121 | + source: people, |
| 122 | + value: 'value', |
| 123 | + label: 'label', |
| 124 | + onSelectItem: function (item, element) { |
| 125 | + @this.set('person_id',item.value); |
| 126 | + @this.set('organisation_id', $(element).closest('form').find("input[name='organisation_id']").val()); |
| 127 | + @this.set('organisation_name', $(element).closest('form').find("input[name='organisation_name']").val()); |
| 128 | + $(element).closest('.autocomplete').find('input[name="person_id"]').val(item.value).trigger('change'); |
| 129 | + }, |
| 130 | + highlightClass: 'text-danger', |
| 131 | + treshold: 2, |
| 132 | + }); |
| 133 | +
|
| 134 | + $('input[name="person_name"]').on('input', function() { |
| 135 | + $(this).closest('.autocomplete').find('input[name="person_id"]').val(''); |
| 136 | + $('.autocomplete-person').find('input,select').val(''); |
| 137 | + $(this).closest('.autocomplete').find('input[name="person_id"]').trigger('change'); |
| 138 | + }); |
| 139 | +
|
| 140 | + $('input[name="person_id"]').on('change', function() { |
| 141 | + if($(this).val() == '' && $.trim($(this).closest('.autocomplete').find('input[name="person_name"]').val()) != ''){ |
| 142 | + $(this).closest('.autocomplete').find(".autocomplete-new").show() |
| 143 | + $('.autocomplete-person').find('input,select').removeAttr('disabled'); |
| 144 | + }else{ |
| 145 | + $(this).closest('.autocomplete').find(".autocomplete-new").hide() |
| 146 | + $('.autocomplete-person').find('input,select').attr('disabled','disabled'); |
| 147 | + } |
| 148 | + @this.set('person_id',$(this).val()); |
| 149 | + }); |
| 150 | +
|
| 151 | + if($('input[name="person_id"]').val() == '' && $.trim($('input[name="person_id"]').closest('.autocomplete').find('input[name="person_name"]').val()) != ''){ |
| 152 | + $('input[name="person_id"]').closest('.autocomplete').find(".autocomplete-new").show() |
| 153 | + $('.autocomplete-person').find('input,select').removeAttr('disabled'); |
| 154 | + } |
| 155 | +
|
| 156 | + if($('input[name="person_name"]').closest('.autocomplete').find('input[name="person_id"]').val() == ''){ |
| 157 | + $('.autocomplete-person').find('input,select').removeAttr('disabled'); |
| 158 | + } |
| 159 | + } |
| 160 | + }); |
| 161 | + </script> |
| 162 | + @endpush |
| 163 | +</div> |
0 commit comments