rollback to retrieve buttons
This commit is contained in:
@@ -1,80 +1,38 @@
|
|||||||
@if(!defined('LOAD_MODAL'))
|
@if(!defined('LOAD_MODAL'))
|
||||||
|
|
||||||
@push('js')
|
@push('js')
|
||||||
@component('boilerplate::minify')
|
|
||||||
<script>
|
<script>
|
||||||
|
function openModal(title, form_id, url_open, url_save, callback, size, no_confirm, buttons, callback_after_loaded) {
|
||||||
// bootbox.setLocale('{{ App::getLocale() }}');
|
|
||||||
|
|
||||||
function openModal(title, form_id, url_open, url_save, callback, size, no_confirm, options) {
|
|
||||||
var status = 0;
|
var status = 0;
|
||||||
|
|
||||||
if (typeof(options) != 'undefined') {
|
|
||||||
var className = (typeof(options['className']) == 'undefined') ? '' : options['className'];
|
|
||||||
var onHide = (typeof(options['onHide']) == 'undefined') ? false : options['onHide'];
|
|
||||||
var onHidden = (typeof(options['onHidden']) == 'undefined') ? false : options['onHidden'];
|
|
||||||
var onShow = (typeof(options['onShow']) == 'undefined') ? false : options['onShow'];
|
|
||||||
var onShown = (typeof(options['onShown']) == 'undefined') ? false : options['onShown'];
|
|
||||||
var onPostModal = (typeof(options['onPostModal']) == 'undefined') ? false : options['onPostModal'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var dialog = bootbox.dialog({
|
var dialog = bootbox.dialog({
|
||||||
title: title,
|
title: title,
|
||||||
message: '<p><i class="fa fa-spin fa-spinner"></i> {{ __('loading') }} ...</p>',
|
message: '<p><i class="fa fa-spin fa-spinner"></i> {{ __('loading') }} ...</p>',
|
||||||
size: size ? size : 'large',
|
size: size ? size : 'large',
|
||||||
scrollable: true,
|
scrollable: true,
|
||||||
className: className,
|
buttons: buildModalButtons(form_id, no_confirm, buttons)
|
||||||
onHide: function(e) {
|
|
||||||
// console.log(status);
|
|
||||||
if (onHide) {
|
|
||||||
eval(onHide);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onHidden: function(e) {
|
|
||||||
// console.log(status);
|
|
||||||
if (onHidden) {
|
|
||||||
eval(onHidden);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onShow: function(e) {
|
|
||||||
var modal = e.target.firstChild;
|
|
||||||
// console.log(modal);
|
|
||||||
// console.log($('.close'));
|
|
||||||
if (onShow) {
|
|
||||||
eval(onShow);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onShown: function(e) {
|
|
||||||
var modal = e.target.firstChild;
|
|
||||||
// console.log(modal);
|
|
||||||
// console.log($('.close'));
|
|
||||||
if (onShown) {
|
|
||||||
eval(onShown);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
buttons: buildModalButtons(form_id, no_confirm, callback)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.init(function() {
|
dialog.init(function() {
|
||||||
$.get(url_open, function(data) {
|
$.get(url_open, function(data) {
|
||||||
dialog.find('.bootbox-body').html(data);
|
dialog.find('.bootbox-body').html(data);
|
||||||
handlePostModal(form_id, url_save, callback, onPostModal);
|
if (callback_after_loaded) {
|
||||||
});
|
eval(callback_after_loaded);
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
changeModalContent(dialog, url_open);
|
|
||||||
if (! no_confirm) {
|
|
||||||
handlePostModal(form_id, url_save, callback, onPostModal);
|
|
||||||
}
|
}
|
||||||
*/
|
if (typeof(url_save) !== 'undefined') {
|
||||||
return dialog;
|
handlePostModal(form_id,url_save, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeModalContent(dialog, url, callback) {
|
function changeModalContent(dialog, url, callback) {
|
||||||
dialog.init(function() {
|
dialog.init(function() {
|
||||||
$.get(url, function(data) {
|
$.get(url, function(data) {
|
||||||
dialog.find('.bootbox-body').html(data);
|
dialog.find('.bootbox-body').html(data);
|
||||||
|
if (callback) {
|
||||||
|
eval(callback);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -94,119 +52,53 @@
|
|||||||
window.open(url,title,"menubar=no, status=no, scrollbars=no, menubar=no, width=" + width + ", height=400");
|
window.open(url,title,"menubar=no, status=no, scrollbars=no, menubar=no, width=" + width + ", height=400");
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildModalButtons(form_id, no_confirm, callback) {
|
function buildModalButtons(form_id, no_confirm, buttons) {
|
||||||
return no_confirm ? '' : {
|
if (!no_confirm) {
|
||||||
|
var buttons = {
|
||||||
cancel: {
|
cancel: {
|
||||||
label: '<i class="fa fa-ban"></i> {{ __("Core.cancel") }}',
|
label: '{{ __('Annuler') }}',
|
||||||
className: 'btn-secondary'
|
className: 'btn-secondary'
|
||||||
},
|
},
|
||||||
confirm: {
|
confirm: {
|
||||||
label: '<i class="fa fa-save"></i> {{ __("Core.save") }}',
|
label: '{{ __('Sauver') }}',
|
||||||
className: 'btn-success',
|
className: 'btn-success',
|
||||||
callback: function() {
|
callback: function() {
|
||||||
return submitModal(form_id, callback);
|
submitModal(form_id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
function submitModal(form_id, callback) {
|
function submitModal(form_id) {
|
||||||
if (typeof(tinyMCE) != 'undefined') {
|
if (typeof(tinyMCE) != 'undefined') {
|
||||||
tinyMCE.triggerSave();
|
tinyMCE.triggerSave();
|
||||||
}
|
}
|
||||||
var $form = $(form_id);
|
$('form ' + form_id).submit();
|
||||||
console.log('submitModal ' + form_id);
|
status = 1;
|
||||||
if ($form.valid()) {
|
|
||||||
deactivateButton($form);
|
|
||||||
console.log('check valid');
|
|
||||||
$form.submit();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePostModal(form_id, url_save, callback, onPostModal) {
|
function handlePostModal(form_id, url_save, callback) {
|
||||||
// console.log('handlePostModal');
|
$('form ' + form_id).submit(function(e) {
|
||||||
// initValidator();
|
|
||||||
var response = false;
|
|
||||||
$(form_id).submit(function(e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log('handlepostmodal submit');
|
var formData = new FormData(this);
|
||||||
|
|
||||||
if (onPostModal) {
|
|
||||||
response = eval(onPostModal);
|
|
||||||
} else {
|
|
||||||
response = postModal(form_id, url_save, callback);
|
|
||||||
}
|
|
||||||
// console.log(response);
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function postModal(form_id, url_save, callback) {
|
|
||||||
console.log('postModal');
|
|
||||||
console.log(form_id);
|
|
||||||
console.log(callback);
|
|
||||||
var ret = false;
|
|
||||||
var $form = $(form_id);
|
|
||||||
var myForm = document.getElementById(form_id.substring(1));
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url_save,
|
url: url_save,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: new FormData(myForm),
|
data: formData,
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
eval(callback);
|
eval(callback);
|
||||||
}
|
}
|
||||||
if (!data.error) {
|
|
||||||
bootbox.hideAll();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
crossDomain: true,
|
|
||||||
headers: {
|
|
||||||
"accept": "application/json",
|
|
||||||
"Access-Control-Allow-Origin":"*"
|
|
||||||
},
|
},
|
||||||
cache: false,
|
cache: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
processData: false
|
processData: false
|
||||||
});
|
});
|
||||||
|
});
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openWindow(url, target) {
|
|
||||||
target = (typeof(target) == 'undefined') ? '_blank' : target;
|
|
||||||
if (target == '_blank') {
|
|
||||||
var anchor = document.createElement('a');
|
|
||||||
anchor.href = url;
|
|
||||||
anchor.target = "_blank";
|
|
||||||
anchor.click();
|
|
||||||
} else {
|
|
||||||
window.location = url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function reactivateButton($form) {
|
|
||||||
console.log('activateButton');
|
|
||||||
var $button = $form.closest('.modal-content').find('.bootbox-accept').first();
|
|
||||||
if ($button.attr("disabled")) {
|
|
||||||
$button.prop("disabled", false);
|
|
||||||
$button.html("<i class='fa fa-save'></i> {{ __('Core.save') }}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function deactivateButton($form) {
|
|
||||||
console.log('deactivateButton');
|
|
||||||
console.log($form);
|
|
||||||
var $button = $form.closest('.modal-content').find('.bootbox-accept').first();
|
|
||||||
console.log($button);
|
|
||||||
$button.prop("disabled", true);
|
|
||||||
$button.html("<i class='fa fa-spinner fa-spin'></i> {{ __('Core.processing') }}");
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@endcomponent
|
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
@php(define('LOAD_MODAL', true))
|
@php(define('LOAD_MODAL', true))
|
||||||
|
|||||||
Reference in New Issue
Block a user