function refreshrqstquotepop() {
$.ajax({
url: 'index.php?route=extension/rqstquote/refreshrqstquotepop',
dataType: 'html',
cache: false,
beforeSend: function() {
$('#rqstquotepop').modal('show');
$('#rqstquotepop .modal-body').html('');
},
success: function(html) {
$('#rqstquotepop .modal-body').html($(html).find('.modal-body').html());
$('#rqstquotepop .modal-footer').html($(html).find('.modal-footer').html());
setdatepickr();
}
});
}
function addtorqstquoteprod() {
$.ajax({
url: 'index.php?route=extension/rqstquotecart/add',
type: 'post',
data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
dataType: 'json',
cache: false,
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
var element = $('#input-option' + i.replace('_', '-'));
if (element.parent().hasClass('input-group')) {
element.parent().after('
' + json['error']['option'][i] + '
');
} else {
element.after('' + json['error']['option'][i] + '
');
}
}
}
if (json['error']['recurring']) {
$('select[name=\'recurring_id\']').after('' + json['error']['recurring'] + '
');
}
// Highlight any found errors
$('.text-danger').parent().addClass('has-error');
}
if (json['success']) {
if(json['popquote'] == 1) {
refreshrqstquotepop();
} else {
if (json['redirectquotecart']) {
location = 'index.php?route=extension/rqstquotecart';
} else {
$('#content').parent().before(' ' + json['success'] + '
');
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
}
}
});
}
// rqstquote add remove update functions
var rqstquote = {
'add': function(product_id, quantity) {
$.ajax({
url: 'index.php?route=extension/rqstquotecart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
cache: false,
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
if(json['popquote'] == 1) {
refreshrqstquotepop();
} else {
if (json['redirectquotecart']) {
location = 'index.php?route=extension/rqstquotecart';
} else {
$('#content').parent().before(' ' + json['success'] + '
');
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
}
}
});
},
'update': function(key, quantity) {
$.ajax({
url: 'index.php?route=extension/rqstquotecart/updatequote',
type: 'post',
data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
cache: false,
success: function(json) {
if($('input[name=rqstquotecartroute]').val() == 1) {
location = 'index.php?route=extension/rqstquotecart';
} else {
refreshrqstquotepop();
}
}
});
},
'remove': function(key) {
$.ajax({
url: 'index.php?route=extension/rqstquotecart/remove',
type: 'post',
data: 'key=' + key,
dataType: 'json',
cache: false,
success: function(json) {
if($('input[name=rqstquotecartroute]').val() == 1) {
location = 'index.php?route=extension/rqstquotecart';
} else {
refreshrqstquotepop();
}
}
});
}
}
function submitrqstquoteform(popflag) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
var targetele = 'rqstquoteformpop';
if(popflag == 0) {
targetele = 'rqstquoteformcart';
}
$.ajax({
url: 'index.php?route=extension/rqstquotecart/save',
type: 'post',
data: $('#' + targetele + ' input[type=\'text\'], #' + targetele + ' input[type=\'date\'], #' + targetele + ' input[type=\'datetime-local\'], #' + targetele + ' input[type=\'time\'], #' + targetele + ' input[type=\'password\'], #' + targetele + ' input[type=\'hidden\'], #' + targetele + ' input[type=\'checkbox\']:checked, #' + targetele + ' input[type=\'radio\']:checked, #' + targetele + ' textarea, #' + targetele + ' select'),
dataType: 'json',
beforeSend: function() {
$('#button-rqstquotesubmit').button('loading');
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
},
complete: function() {
$('#button-rqstquotesubmit').button('reset');
},
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
} else if (json['error']) {
for (i in json['error']) {
var element = $('#' + targetele).find('#input-' + i.replace('_', '-'));
if ($(element).parent().hasClass('input-group')) {
$(element).parent().after('' + json['error'][i] + '
');
} else {
$(element).after('' + json['error'][i] + '
');
}
}
// Highlight any found errors
$('.text-danger').parent().parent().addClass('has-error');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
$(document).delegate('button[id^=\'button-rqstquotefield\']', 'click', function() {
var node = this;
$('#form-upload').remove();
$('body').prepend('');
$('#form-upload input[name=\'file\']').trigger('click');
if (typeof timer != 'undefined') {
clearInterval(timer);
}
timer = setInterval(function() {
if ($('#form-upload input[name=\'file\']').val() != '') {
clearInterval(timer);
$.ajax({
url: 'index.php?route=tool/upload',
type: 'post',
dataType: 'json',
data: new FormData($('#form-upload')[0]),
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$(node).button('loading');
},
complete: function() {
$(node).button('reset');
},
success: function(json) {
$(node).parent().find('.text-danger').remove();
if (json['error']) {
$(node).parent().find('input').after('' + json['error'] + '
');
}
if (json['success']) {
alert(json['success']);
$(node).parent().find('input').val(json['code']);
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
}, 500);
});
function setdatepickr() {
$('.date').datetimepicker({
language: '{{ datepicker }}',
pickTime: false
});
$('.datetime').datetimepicker({
language: '{{ datepicker }}',
pickDate: true,
pickTime: true
});
$('.time').datetimepicker({
language: '{{ datepicker }}',
pickDate: false
});
}
//setdatepickr();