close #767 Fixed: Modals dublicate action issue (Customer, Vendor, Tax, Payment etc)
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
<div class="modal fade" id="modal-create-customer" style="display: none;">
|
||||
<div class="modal fade create-customer-{{ $rand }}" id="modal-create-customer" style="display: none;">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.customers', 1)]) }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
{!! Form::open(['id' => 'form-create-customer', 'role' => 'form', 'class' => 'form-loading-button']) !!}
|
||||
|
||||
<div class="row">
|
||||
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
|
||||
|
||||
@ -19,11 +21,14 @@
|
||||
|
||||
{!! Form::hidden('enabled', '1', []) !!}
|
||||
</div>
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<div class="pull-left">
|
||||
{!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-customer', 'class' => 'btn btn-success button-submit', 'data-loading-text' => trans('general.loading')]) !!}
|
||||
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -33,36 +38,36 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$('#modal-create-customer').modal('show');
|
||||
$('.create-customer-{{ $rand }}#modal-create-customer').modal('show');
|
||||
|
||||
$("#modal-create-customer #currency_code").select2({
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer #currency_code").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#button-create-customer', function (e) {
|
||||
$('#modal-create-customer .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 16em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
|
||||
$(document).on('click', '.create-customer-{{ $rand }} #button-create-customer', function (e) {
|
||||
$('.create-customer-{{ $rand }}#modal-create-customer .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 16em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/customers") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $("#form-create-customer").serialize(),
|
||||
data: $(".create-customer-{{ $rand }} #form-create-customer").serialize(),
|
||||
beforeSend: function () {
|
||||
$('#button-create-customer').button('loading');
|
||||
$('.create-customer-{{ $rand }} #button-create-customer').button('loading');
|
||||
|
||||
$(".form-group").removeClass("has-error");
|
||||
$(".help-block").remove();
|
||||
$(".create-customer-{{ $rand }} .form-group").removeClass("has-error");
|
||||
$(".create-customer-{{ $rand }} .help-block").remove();
|
||||
},
|
||||
complete: function() {
|
||||
$('#button-create-customer').button('reset');
|
||||
$('.create-customer-{{ $rand }} #button-create-customer').button('reset');
|
||||
},
|
||||
success: function(json) {
|
||||
var data = json['data'];
|
||||
|
||||
$('#span-loading').remove();
|
||||
$('.create-customer-{{ $rand }} #span-loading').remove();
|
||||
|
||||
$('#modal-create-customer').modal('hide');
|
||||
$('.create-customer-{{ $rand }}#modal-create-customer').modal('hide');
|
||||
|
||||
$('#customer_id').append('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
|
||||
$('#customer_id').trigger('change');
|
||||
@ -75,23 +80,23 @@
|
||||
@endif
|
||||
},
|
||||
error: function(error, textStatus, errorThrown) {
|
||||
$('#span-loading').remove();
|
||||
$('.create-customer-{{ $rand }} #span-loading').remove();
|
||||
|
||||
if (error.responseJSON.name) {
|
||||
$("#modal-create-customer input[name='name']").parent().parent().addClass('has-error');
|
||||
$("#modal-create-customer input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer input[name='name']").parent().parent().addClass('has-error');
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
|
||||
}
|
||||
|
||||
if (error.responseJSON.email) {
|
||||
$("#modal-create-customer input[name='email']").parent().parent().addClass('has-error');
|
||||
$("#modal-create-customer input[name='email']").parent().after('<p class="help-block">' + error.responseJSON.email + '</p>');
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer input[name='email']").parent().parent().addClass('has-error');
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer input[name='email']").parent().after('<p class="help-block">' + error.responseJSON.email + '</p>');
|
||||
}
|
||||
|
||||
if (error.responseJSON.currency_code) {
|
||||
$("#modal-create-customer select[name='currency_code']").parent().parent().addClass('has-error');
|
||||
$("#modal-create-customer select[name='currency_code']").parent().after('<p class="help-block">' + error.responseJSON.currency_code + '</p>');
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer select[name='currency_code']").parent().parent().addClass('has-error');
|
||||
$(".create-customer-{{ $rand }}#modal-create-customer select[name='currency_code']").parent().after('<p class="help-block">' + error.responseJSON.currency_code + '</p>');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user