How to add a file jquery on view razor? - javascript

I have this view and this works fine
as you see I have added a section (required:false) on _layout
and until now there is not problem,
#model final2.Models.ObjetosUnidos.HelperVenta
#{
ViewBag.Title = "Index";
}
#*
<>
*#
#section JavaScript
{
<script type="text/javascript">
$(document).ready(
function () {
var $loading = $('#cargando').hide();
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
})
$("#btnselectcliente").click(
function () {
$("#diviniciarventa").hide();
$.when(
$.ajax({
type: "post",
dataType: "html",
url: '#Url.Action("mostrarcuerpo", "venta")',
data: { idcliente: $("#selectcliente").val() }
})
).then(
function (data) {
$("#divcuerpo").html(data);
}, function (error) { alert(error.responseText); }
);
}
);
$(this).on("click", "#btnbuscar", function (e) {
/// Do some stuff ...
var idventa1 = $("#idventa").val();
$.ajax({
type: "post",
dataType: "html",
url: '#Url.Action("buscarproducto", "venta")',
data: { texto: $("#txtbuscar").val(), idventa: idventa1 },
success: function (data) {
$("#divtableproductos").html(data);
},
error: function (error) { alert(error.error); }
});
});
var productoid = 0;
var cantidad = 0.0;
var precio = 0.0;
var iva = 0.0;
var nombre = "";
var codigo = "";
var ventaid = "";
var cantidadelegida = 0.0;
$(this).on(
{
click: function () {
productoid = parseInt(this.cells["productoid"].textContent);
cantidad = parseFloat(this.cells["cantidad"].textContent);
precio = parseFloat(this.cells["precio"].textContent);
iva = parseFloat(this.cells["iva"].textContent);
nombre = (this.cells["nombre"].textContent);
codigo = (this.cells["codigo"].textContent);
ventaid = $("#idventa").val();
$("#txtnombre").val(nombre);
$("#txtcodigo").val(codigo);
}
}, "#tableproductos tbody tr");
var colordefault = "";
$(this).on({
mouseenter: function () {
//stuff to do on mouse enter
colordefault = $(this).css("background-color");
$(this).css("background-color", "#ff0");
},
mouseleave: function () {
$(this).css("background-color", colordefault);
}
}, "#tableproductos tbody tr");
$(this).on(
{
click: function () {
cantidadelegida = $("#txtcantidad").val();
if (cantidadelegida < 0 || cantidadelegida > cantidad) {
alert("Cantidad debe estar entre 0 y " + cantidad);
return;
}
texto = $("#txtbuscar").val();
actualizaprodydetalle(productoid, cantidadelegida, ventaid, texto);
}
}, "#btnagregar");
function actualizaprodydetalle(_productoid, _cantidadelegida, _ventaid, _texto) {
$.when(
$.ajax({
async: false,
type: "post",
dataType: "html",
url: '#Url.Action("muestradetalle", "venta")',
data: { productoid: _productoid, cantidad: _cantidadelegida, ventaid: _ventaid }
}),
$.ajax({
async: false,
type: "post",
dataType: "html",
url: '#Url.Action("buscarproducto", "venta")',
data: { texto: _texto, idventa: ventaid }
})
).then(
function (data1, data2) {
$("#divdetalle").html(data1);
$("#divtableproductos").html(data2);
}
);
}
iddetalle = 0;
$(this).on(
{
mouseover: function () {
iddetalle = parseInt(this.cells["iddetalle"].textContent);
}
}, "#tbldetalle tbody tr");
$(this).on(
{
click: function () {
texto = $("#txtbuscar").val();
try {
$.ajax({
type: "post",
dataType: "html",
url: '#Url.Action("actualizadetalle", "venta")',
data: {
iddetalle: iddetalle,
texto: texto
},
success: function (data) {
$("#divmodal").html(data);
},
error: function (dat) {
alert(dat.responseText);
alert(dat.statusText);
}
});
}
catch (ex) {
alert(ex.message);
}
}
}, "#btnmodificar");
$(this).on(
{
click: function () {
var productoid5 = $("#adproductoid").val();
var ventaid5 = $("#idventa").val();
var texto5 = $("#adtexto").val();
if (parseFloat($("#txtnuevacantidad").val()) < 0 || parseFloat($("#txtnuevacantidad").val()) > (parseFloat($("#addisponible").val()) + parseFloat($("#adcantidadactual").val()))) {
alert("Cantidad debe estar entre 0 y " + (parseFloat($("#addisponible").val()) + parseFloat($("#adcantidadactual").val())));
return;
}
var cantidad5 = parseFloat($("#txtnuevacantidad").val()) - parseFloat($("#adcantidadactual").val());
actualizaprodydetalle(productoid5, cantidad5, ventaid5, texto5);
$('#divmodal').html("");
}
}, "#btnnuevacantidad");
$(this).on(
{
click: function () {
var ventaid5 = $("#idventa").val();
try {
$.ajax({
type: "post",
dataType: "html",
url: '#Url.Action("finalizarventa", "venta")',
data: {
ventaid: ventaid5
},
success: function (data) {
$("#divmodal").html(data);
},
error: function (dat) {
alert(dat.responseText);
alert(dat.statusText);
}
});
}
catch (ex) {
alert(ex.message);
}
}
}, "#btnfinalizarvta");
cambiofinal = 0;
$(this).on(
{
keypress: function (e) {
try {
if (e.which == 13) {//Enter key pressed
total = parseFloat($(this).val());
total = total.toFixed(2);
cobrar = parseFloat($("#fvprecio").val());
cobrar = cobrar.toFixed(2);
cambio = (total - cobrar);
cambio = cambio.toFixed(2);
cambiofinal = cambio;
$("#txtcambio").val(cambio);
}
}
catch (ex) {
alert("Solo números flotantos por favór " + ex.message);
return false;
}
}
}, "#txtentrega");
$(this).on(
{
click: function (e) {
$('#divmodal').html("");
}
}, "#fvcerrar");
$(this).on(
{
click: function (e) {
if (cambiofinal < 0) {
alert("Dinero Insuficiente");
return;
}
$('#divmodal').html("");
var ventaid5 = $("#idventa").val();
//ventafinalizada
$.ajax(
{
type: "post",
dataType: "text",
url: '#Url.Action("ventafinalizada", "venta")',
data: { ventaid: ventaid5 },
async: false,
success: function (response) {
alert(response);
window.close();
},
error: function (data) { alert("Ocurrio un errorxx"); }
}
);
}
}, "#fvfinalizarventa");
//$("#buscar").keypress(function (e) {
// if (e.which == 13) {//Enter key pressed
// //$("#btnaceptar").click();//Trigger search button click event
// alert("buscar enter")
// buscar();
// }
//});
});
</script>
}
<div id="cargando">
<img src="~/Images/cargandoajax.gif" />
</div> ...
I know to add the Javascript code in a file is a good practic,
then I copy
$(document).ready(
function () {...}
in a file but it does not work
#section JavaScript
{
<script type="text/javascript" src="~/Scripts/scriptventa.js"></script>
}
what am i doing wrong?
I tried doing it too
<script type="text/javascript" src="~/Scripts/scriptventa.js"></script> (not using #section) but it does not work
this is happening when the javascript code is on a file, I believe its caused by this line
url: '#Url.Action("mostrarcuerpo", "venta")',

Related

Redirect whit SweetAlert2

i have a problem with redirect page after the user click on ok button in sweet alert. i don't understand where i have to insert the code and which code. i would like that when the user press ok, after the success on form, is redirected to... example "google.com".
I tried to use the solutions on the site, but they did not work or I was wrong to insert them
Thanks to all for help
<script src="https://cdn.jsdelivr.net/npm/sweetalert2#9"></script>
<script>
$(function() {
$(document).ajaxStop($.unblockUI);
$('form').on('submit', function(e) {
e.preventDefault();
var response = grecaptcha.getResponse();
if(response.length == 0) {
//reCaptcha not verified
alert("Verifica di non essere un robot!");
return false;
} else {
//reCaptch verified
$.blockUI({
message: '<p><img src="img/Eclipse-1s-134px.svg" alt="">Ci siamo...non uscire</p>'
});
var formData = new FormData(this);
$.ajax({
type: 'post',
url: 'mailer.php',
data: formData,
cache: false,
dataType: 'json',
contentType: false,
processData: false,
mimeType: "multipart/form-data",
xhr: function () {
//upload Progress
var xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener('progress', function (event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total;
if (event.lengthComputable) {
percent = Math.ceil(position / total * 100);
}
//update progressbar
$('.progress-bar').animate({
width: percent + '%'
}, {
duration: 100
});
}, true);
}
return xhr;
},
success: function (response) {
if (response.success) {
Swal.fire(
'Perfetto!',
'Il tuo locale è registrato!',
'success'
);
$('form').trigger("reset");
$('.progress-bar').animate({
width: '10%'
}, {
duration: 1000
});
} else {
alert(response.message);
}
},
error: function (response) {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Qualcosa è andato storto!',
footer: '<a href>Riprovaci!</a>'
});
}
});
}
});
});
</script>
I think it must be placed before the success code, something like this:
<script src="https://cdn.jsdelivr.net/npm/sweetalert2#9"></script>
<script>
$(function() {
$(document).ajaxStop($.unblockUI);
$('form').on('submit', function(e) {
e.preventDefault();
var response = grecaptcha.getResponse();
if(response.length == 0) {
//reCaptcha not verified
alert("Verifica di non essere un robot!");
return false;
} else {
//reCaptch verified
$.blockUI({
message: '<p><img src="img/Eclipse-1s-134px.svg" alt="">Ci siamo...non uscire</p>'
});
var formData = new FormData(this);
$.ajax({
type: 'post',
url: 'mailer.php',
data: formData,
cache: false,
dataType: 'json',
contentType: false,
processData: false,
mimeType: "multipart/form-data",
xhr: function () {
//upload Progress
var xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener('progress', function (event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total;
if (event.lengthComputable) {
percent = Math.ceil(position / total * 100);
}
//update progressbar
$('.progress-bar').animate({
width: percent + '%'
}, {
duration: 100
});
}, true);
}
return xhr;
},
success: function (response) {
if (response.success) {
Swal.fire(
'Perfetto!',
'Il tuo locale è registrato!',
'success'
);
$('form').trigger("reset");
$('.progress-bar').animate({
width: '10%'
}, {
duration: 1000
});
window.location.href = 'www.yourpage.com';
} else {
alert(response.message);
}
},
error: function (response) {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Qualcosa è andato storto!',
footer: '<a href>Riprovaci!</a>'
});
}
});
}
});
});
</script>

popup close event detect javascript

I want to know hot to detect popup close event, When i open popup close event automatically call, its i am using .close event.
function start() {
$.ajax({
type: "post",
dataType: "html",
url: 'client_get',
crossDomain: true,
data: {
'id': '123'
},
success: function(response) {
try {
var json = JSON.parse(response);
} catch (err) {
start();
}
jQuery(document).ready(function($) {
var close_interval = setInterval(function() {
var newwindow = window.open('https://www.example.com/key?v=' + json[0]['url'], 'key', 'width=800,height=600,status=0,toolbar=0');
if (newwindow.close) {
console.log("Closed");
clearInterval(close_interval);
}
}, 1000);
});
}
});
}
Capturing the close event of a window requires the onbeforeunload event handler:
var new_window = window.open('some url')
new_window.onbeforeunload = function(){ my code}
so in your case:
function start() {
$.ajax({
type: "post",
dataType: "html",
url: 'client_get',
crossDomain: true,
data: {
'id': '123'
},
success: function (response) {
try {
var json = JSON.parse(response);
} catch (err) {
start();
}
jQuery(document).ready(function ($) {
var close_interval = setInterval(function () {
var newwindow = window.open('https://www.example.com/key?v=' + json[0]['url'], 'key', 'width=800,height=600,status=0,toolbar=0');
newwindow.onload = function() {
newwindow.onbeforeunload = function() {
console.log("Closed");
clearInterval(close_interval);
}
}
}, 1000);
});
}
});
}

Infinite reload on Ajax Stop function

I have a long javascript file which I included a auto reload page every ajax success, however I got infinite ajax reload on this
<script>
var latest;
var par;
var widgets;
var test;
var $randomId;
var gridster;
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
gridster = $(".gridster ul").gridster({
widget_margins: [10, 10],
widget_base_dimensions: [140, 140],
helper: 'clone',
resize: {
enabled: true
},
serialize_params: function($w, wgd) {
return {
id:$($w).attr('id'),
col: wgd.col,
row: wgd.row,
size_x:wgd.size_x,
size_y:wgd.size_y,
};
},
draggable: {
stop: function(event, ui) {
var positions = JSON.stringify(this.serialize());
var data_id = $(ui.$helper[0]).attr('id');
var size_x = $(ui.$helper[0]).attr('data-sizex');
var size_y = $(ui.$helper[0]).attr('data-sizey');
var data_row = $(ui.$helper[0]).attr('data-row');
var data_col = $(ui.$helper[0]).attr('data-col');
$.ajax({
url: "/partA-save-widgets-positions",
type: "POST",
data: {
'size_y': size_y,
'size_x': size_x,
'data_row': data_row,
'data_col': data_col,
'id' : data_id
},
dataType: "json",
error: function(log) {
console.log(log);
},
success: function(log) {
//console.log(log);
}
})
}
}
}).data('gridster');
$.getJSON('/partA-widgets-current-positions', function(data) {
if (data !=null) {
var id_name;
id_name = 'widgets';
id_name = id_name + data.id;
$.each(JSON.parse(data.positions), function(i, value) {
console.log(value);
$(id_name).attr({
'data-col': value.col,
'data-row': value.row,
'data-sizex': value.size_x,
'data-sizey': value.size_y
});
});
} else {
console.log("no data returned");
}
})
function Generator(){};
Generator.prototype.rand = Math.floor(Math.random() * 26) + Date.now();
Generator.prototype.getId = function() {
return this.rand++;
};
widgetTemplate = function($widgetTitle,$widgetContent){
idGen = new Generator();
$randomId = idGen.getId();
var html = $widgetContent;
return html;
},
addWidget = function($widgetType){
var mapAPI='<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d253304.652017724!2d125.31098975138514!3d7.25390594287568!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x32f96d9f519e327f%3A0xb53a24589f79c573!2sDavao+City%2C+Davao+del+Sur!5e0!3m2!1sen!2sph!4v1467344380693" width="200" height="150" frameborder="0" style="border:0" allowfullscreen></iframe>';
var costApi = 'https://api.del.icio.us/v1/';
widgets = {
'map': widgetTemplate('MAP',mapAPI),
'cost': widgetTemplate('COST','COST CONTENT'),
'revenue': widgetTemplate('REVENUE','REVENUE CONTENT'),
'traffic': widgetTemplate('TRAFFIC','TRAFFIC CONTENT'),
'admin': widgetTemplate('ADMIN','ADMIN CONTENT'),
'feedback': widgetTemplate('FEEDBACK','FEEDBACK CONTENT'),
'default': 'Error/Invalid Input'
};
}
$("ul.dropdown-menu li").click(function() {
par = $.trim($(this).find("span.widgets").text());
//var data_id = $(".random").closest('div.portlet').attr('data-id');
var style = $('.ui-resizable').attr('style');
idGen = new Generator();
var $randomId2 = idGen.getId();
console.log($randomId2);
switch(par) {
case "MAP": {
test = widgets.map;
break;
}
case "COST": {
test = widgets.cost;
break;
}
case "REVENUE": {
test = widgets.revenue;
break;
}
case "TRAFFIC": {
test = widgets.traffic;
break;
}
case "ADMIN": {
test = widget.admin;
break;
}
case "FEEDBACK": {
test = widget.feedback;
break;
}
default: {
console.log(par);
}
}
$.ajax({
url: '/partA-save',
type: "POST",
data: {
'test': test,
'widget': par,
'random_id': $randomId2,
'style': style
},
dataType: 'JSON',
}).success(function(data) {
console.log(data);
});
console.log(par);
console.log(test);
console.log($randomId2);
//return true;
});
//delete
$(".remove").click(function() {
var id = $(this).closest('div.portlet').attr('data-id');
$.ajax({
url: '/partA-delete',
type: "post",
data: {
'id': id
},
dataType: "JSON",
//async: false,
success: function(data) {
if (data.status == 200) {
setTimeout(function(){
location.reload();
},5000);
}
},
error: function(data) {
console.log(data);
}
});
});
//auto reload page if success
$(document).ajaxStop(function() {
window.location.reload();
});
});
</script>
This may be your infinite loop.
$.getJSON:call // async
$(document).ajaxStop(fn) // bind event
$.getJSON:success // ajaxStop:event
You could try putting the $(document).ajaxStop(fn) binding inside of the $.getJSON callback

How to solve Uncaught TypeError: Cannot read property 'length' of null

I have installed a wp plugin , When I use default wp theme , it works fine but when I use another theme it does not loads one of the tabs , by inspect element I get this
Uncaught TypeError: Cannot read property 'length' of null
The code on the page it is mentioning is this
function show_submissions(page,search)
{
if (typeof page=='string')
{
var data = 'action=formcraft_page&page='+page;
}
else
{
var data = 'action=formcraft_page&search='+search;
var page = 0;
}
jQuery('#subs tbody').html('<tr><td colspan="6"><center><div style="margin: 30px auto; width: 30px;font-size: 14px; color: #888">loading...</div></center></td></tr>')
jQuery.ajax({
url: ajaxurl,
type: "POST",
dataType: "json",
data: data,
success: function (response) {
jQuery('.fc_pagination .active').removeClass('active');
jQuery('.fc_pagination .page:nth-child('+page+')').addClass('active');
if (response.length==0)
{
jQuery('#subs tbody').html('<center style="margin: 20px; font-size: 14px">No Results</center>');
return false;
}
for (var sub in response)
{
var read = response[sub]['seen'] == '' || response[sub]['seen'] == null ? 'Unread' : 'Read';
var shade = response[sub]['seen'] == '' || response[sub]['seen'] == null ? 'row_shade' : '';
var id = response[sub]['id'];
var name = response[sub]['name'] ? response[sub]['name'] : 'deleted';
var row = '<tr id="sub_'+id+'" class="'+shade+'">';
var row = row + '<td>'+id+'</td>';
var row = row + '<td id="rd_'+id+'">'+read+'</td>';
var row = row + '<td id="rd_'+id+'">'+response[sub]['added']+'</td>';
var row = row + '<td>'+name+'</td>';
var row = row + '<td><a class="fc-btn show-message" id="upd_'+id+'" data-target="#view_modal" data-toggle="fcmodal">View</a><div class="sub-content" id="sub-content-'+id+'">'+response[sub]['content']+'</div></td>';
var row = row + '<td><i class="formcraft-trash sub_upd" id="del_'+id+'" title="Delete message"></i> <i class="formcraft-bookmark-empty sub_upd" id="read_'+id+'" title="Mark as unread"></i></td>';
var row = row + '</tr>';
var html = html + row;
}
jQuery('#subs tbody').html('');
jQuery('#subs tbody').append(html);
},
error: function (response) {
jQuery('#save_form_btn').html(jQuery('#save_form_btn').attr('data-error'));
window.saving = false;
}
});
}
function drawChart(id, from, to)
{
jQuery('#chart-cover').addClass('loading')
if (id)
{
var jsonData = jQuery.ajax({
url: ajaxurl,
dataType: "json",
type: "POST",
data: 'id='+id+'&action=formcraft_chart&from='+from+'&to='+to,
async: false
}).responseText;
}
else
{
var jsonData = jQuery.ajax({
url: ajaxurl,
dataType: "json",
data: 'action=formcraft_chart&from='+from+'&to='+to,
async: false
}).responseText;
}
var jsonData = jQuery.parseJSON( jsonData );
var totalViews = 0;
for (values in jsonData.views)
{
totalViews = totalViews + parseInt(jsonData.views[values][1]);
}
var totalSubmissions = 0;
for (values in jsonData.submissions)
{
totalSubmissions = totalSubmissions + parseInt(jsonData.submissions[values][1]);
}
jQuery({someValue: parseInt(jQuery('#tvs').text())}).animate({someValue: totalViews}, {
duration: 900,
easing:'swing',
step: function() {
jQuery('#tvs').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: parseInt(jQuery('#tss').text())}).animate({someValue: totalSubmissions}, {
duration: 900,
easing:'swing',
step: function() {
jQuery('#tss').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: parseInt(jQuery('#tcs').text())}).animate({someValue: (Math.round((totalSubmissions/totalViews)*10000)/100)}, {
duration: 900,
easing:'swing',
step: function() {
jQuery('#tcs').text(Math.ceil(this.someValue)+'%');
}
});
setTimeout(function(){
jQuery('#tvs').text(totalViews);
jQuery('#tss').text(totalSubmissions);
jQuery('#tcs').text((Math.round((totalSubmissions/totalViews)*10000)/100)+'%');
}, 1000);
var plot = jQuery.plot("#chart-inner", [{
data: jsonData.views,
label: 'views',
color: 'rgb(255, 175, 80)',
bars: {show:true, align: 'center'}
},{
data: jsonData.submissions,
label: 'submissions',
color: 'rgb(28, 160, 28)',
lines: {show:true}
}], {
series: {
points: { show:true }
},
grid: {
hoverable: true,
clickable: true
},
xaxis: {
mode: "categories"
}
});
jQuery('#chart-cover').removeClass('loading')
jQuery("#chart-inner").bind("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
jQuery("#tooltip").remove();
var x = Object.keys(item.series.xaxis.categories)[item.datapoint[0]],
y = item.datapoint[1];
showTooltip(item.pageX, item.pageY,
y + ' ' + item.series.label + " on " + x);
}
} else {
jQuery("#tooltip").remove();
previousPoint = null;
}
});
jQuery("#chart-inner").bind("plotclick", function (event, pos, item) {
if (item) {
jQuery("#clickdata").text(" - click point " + item.dataIndex + " in " + item.series.label);
plot.highlight(item.series, item.datapoint);
}
});
}
function setupLabel()
{
if (jQuery('.label_check input').length) {
jQuery('.label_check').each(function(){
jQuery(this).removeClass('c_on');
});
jQuery('.label_check input:checked').each(function(){
jQuery(this).parent('label').addClass('c_on');
});
};
if (jQuery('.label_radio input').length) {
jQuery('.label_radio').each(function(){
jQuery(this).removeClass('r_on');
});
jQuery('.label_radio input:checked').each(function(){
jQuery(this).parent('label').addClass('r_on');
});
};
};
jQuery(function () {
jQuery('#import').fileupload({
dataType: 'json',
add: function (e, data)
{
var type = data.files[0].name;
var type = type.split('.');
var type = type[1];
if (type!='txt')
{
alert('Only .txt files');
return false;
}
data.submit();
jQuery('#fu-label').text('wait');
jQuery('#import').prop("disabled",true);
},
done: function (e, resp) {
if(resp.result.failed)
{
jQuery('#import').prop("disabled",false);
jQuery('#fu-label').text(resp.failed);
}
else
{
jQuery('#import_form').val(resp.result.files.new_name);
jQuery('#import').prop("disabled",true);
jQuery('#fu-label').html('<i class="formcraft-ok" style="font-size: 10px"></i> Done');
jQuery('#rand_b').trigger('click');
setupLabel();
jQuery('#import').parent().addClass('green');
}
},
fail: function (e, data){
jQuery('.import').prop("disabled",false);
jQuery('#import_field_label').text('Failed');
jQuery('#fu-label').text('Rety');
}
});
});
jQuery(document).ready(function () {
setTimeout(function(){
jQuery('#fc-page-1').trigger('click');
}, 1000);
/* Update Submissions */
jQuery('body').on('click','.sub_upd, .show-message',function(){
var id = jQuery(this).attr('id').split('_');
var id2 = jQuery(this).attr('id');
jQuery('#view_modal .modal-body').html(jQuery('#sub-content-'+id[1]).html());
if (id[0]=='upd')
{
jQuery('#view_modal .modal-body').html(jQuery('#upd_text_'+id[1]).html());
jQuery('#view_modal .myModalLabel').html(jQuery('#upd_name_'+id[1]).html());
jQuery('#rd_'+id[1]).html('Read');
jQuery(this).parent().parent().addClass('row_shade');
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=formcraft_sub_upd&type=upd&id='+id[1],
success: function (response) {
jQuery('#'+id2).parent().parent().removeClass('row_shade');
},
error: function (response) {
}
});
}
else if (id[0]=='del')
{
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=formcraft_sub_upd&type=del&id='+id[1],
success: function (response) {
if (response=='D')
{
jQuery('#'+id2).removeClass('formcraft-trash');
jQuery('#'+id2).addClass('formcraft-ok').css('color','green');
}
},
error: function (response) {
}
});
}
else if (id[0]=='read')
{
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=formcraft_sub_upd&type=read&id='+id[1],
success: function (response) {
if (response=='D')
{
jQuery('#rd_'+id[1]).html('Unread');
jQuery('#'+id2).parent().parent().addClass('row_shade');
}
},
error: function (response) {
}
});
}
});
// Set up DataTable
if (jQuery('#subs').length)
{
jQuery('#ext').dataTable({
"sPaginationType": "full_numbers"
});
jQuery('#files_manager_table').dataTable({
"sPaginationType": "full_numbers"
});
}
jQuery('#new_form').submit(function(event){
event.preventDefault();
var data = 'action=formcraft_add&import_form='+jQuery('#import_form').val()+'&name='+jQuery('#new_name').val()+'&desc='+jQuery('#new_desc').val()+'&type_form='+jQuery('[name="type_form"]:checked').val()+'&duplicate='+jQuery('[name="duplicate"]').val();
jQuery('.response_ajax').html('processing ...');
jQuery.ajax({
url: ajaxurl,
type: "POST",
dataType: 'json',
data: data,
success: function (response) {
if (response.Added)
{
jQuery('.response_ajax').html('Added');
window.location.href = 'admin.php?page=formcraft_admin&id='+response.Added;
}
else if (response.Error)
{
jQuery('.response_ajax').html(response.Error);
}
},
error: function (response) {
jQuery('.response_ajax').html(response);
}
});
});
jQuery('#subs_search').submit(function(event){
event.preventDefault();
show_submissions(false,jQuery('#search_query').val());
});
drawChart();
jQuery('.datepicker-field').datepicker().on('changeDate', function(ev){
jQuery(this).datepicker('hide');
jQuery(this).trigger('change');
});
jQuery('.datepicker-field').wrap("<div class='datepicker-cover'></div>");
jQuery('body').on('click', '.datepicker-cover', function(){
jQuery(this).find('input').focus();
});
jQuery('body').on('click','.nav-main li', function(event)
{
event.preventDefault();
var index = jQuery(this).parent().index();
jQuery('.tab-content .tab-pane').removeClass('active');
jQuery('.tab-content .tab-pane:eq('+index+')').addClass('active');
jQuery('.nav-main table td li').removeClass('active');
jQuery('.nav-main table td:eq('+index+') li').addClass('active');
});
jQuery("input.rand2").focus(function(){
event.stopPropagation();
});
jQuery('#rand_a').change(function(){
jQuery('#rand_aa').trigger('click');
setupLabel();
});
jQuery('body').on('submit','#fc-pk',function(event){
event.preventDefault();
jQuery('#fc-pk .response').text('...');
jQuery.ajax({
type: "GET",
url: ajaxurl,
data: 'key='+jQuery('#fc-pk-input').val()+'&action=formcraft_verifyLicense',
dataType: "json",
success: function(response)
{
if (response.message)
{
jQuery('#fc-pk .response').text(response.message);
}
else
{
jQuery('#fc-pk .response').text('Unknown error');
}
},
});
});
jQuery('body').on('click','.delete_from_manager',function(){
jQuery(this).html(jQuery(this).attr('data-loading'));
if (jQuery(this).attr('data-name')){var data = 'name='+encodeURIComponent(jQuery(this).attr('data-name'));}
else if (jQuery(this).attr('data-key')){var data = 'key='+encodeURIComponent(jQuery(this).attr('data-key'));}
var id_this = this.id;
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=formcraft_delete_file&'+data,
success: function (response) {
if (response=='Deleted')
{
jQuery('#'+id_this).removeClass('btn-danger');
jQuery('#'+id_this).addClass('btn-success');
jQuery('#'+id_this).html(jQuery('#'+id_this).attr('data-complete'));
}
},
error: function (response) {
}
});
});
jQuery('#export').click(function(){
window.open(Url.exporturl,'_blank');
});
jQuery('body').on('click', '.delete-row', function() {
if (confirm('Are you sure you want to delete the form? You can\'t undo this action.')) {
if(jQuery(this).hasClass('btn-danger'))
{
var this_id = jQuery(this).attr('id');
jQuery(this).html(jQuery(this).attr('data-loading'));
var id = jQuery(this).parent('td').parent('tr').attr('id');
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=formcraft_del&id='+id,
success: function (response) {
if (response=='Deleted')
{
jQuery('#'+this_id).html(jQuery('#'+this_id).attr('data-complete'));
jQuery('#'+this_id).removeClass('btn-danger');
jQuery('#'+this_id).addClass('btn-success');
}
else
{
jQuery('#'+this_id).html(jQuery('#'+this_id).attr('data-reset'));
}
},
error: function (response) {
alert("There was an error.");
}
});
}
}
});
jQuery('body').on('click', '.row_click', function() {
var id = jQuery(this).parent('tr').attr('id');
window.location.href = 'admin.php?page=formcraft_admin&id='+id;
});
// Edit Form Name and Description
jQuery("body").on('click', '.edit_btn', function(event){
event.stopPropagation();
jQuery(this).hide();
jQuery(this).parent().children('.rand').hide();
var name = jQuery(this).prev('a').html();
jQuery(this).prev('input.rand2').show();
jQuery(this).prev('input.rand2').focus();
jQuery(this).next('a.save_btn').show();
});
jQuery('body').on('click','.rand2',function(event){
event.stopPropagation();
});
jQuery("body").on('click', '.save_btn', function(event){
event.stopPropagation();
jQuery(this).hide();
var this_id = jQuery(this).attr('id');
var id = jQuery(this).attr('id').split('_');
var val = jQuery(this).parents().children('.rand2').val();
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=formcraft_name_update&name='+val+'&id='+id[1],
success: function (response)
{
if (response=='D')
{
jQuery('#'+this_id).parent().children('.rand').text(val);
jQuery('#'+this_id).parent().children('input.rand2').hide();
jQuery('#'+this_id).parent().children('.rand').show();
jQuery('#'+this_id).parent().children('.edit_btn').show();
}
else
{
jQuery('#'+this_id).show();
jQuery('#'+this_id).parent().children('input.rand2').hide();
jQuery('#'+this_id).parent().children('.rand').show();
jQuery('#'+this_id).parent().children('.edit_btn').show();
}
},
error: function (response)
{
jQuery('#'+this_id).show();
}
});
});
jQuery('#stats_select, #chart-from, #chart-to').change(function(){
var id = jQuery('#stats_select').val();
var from = jQuery('#chart-from').val();
var to = jQuery('#chart-to').val();
drawChart(id, from, to);
});
jQuery('#chart-to').datepicker('remove');
jQuery('#chart-to').datepicker({'endDate': new Date()});
jQuery('#chart-from').change(function(){
var sd = jQuery(this).val().split('/');
sd = new Date( parseInt(sd[0]), parseInt(sd[1])-1, parseInt(sd[2]) );
jQuery('#chart-to').datepicker('remove');
jQuery('#chart-to').datepicker({'startDate': sd}).on('changeDate', function(ev){
jQuery(this).datepicker('hide');
jQuery(this).trigger('change');
});
});
jQuery('#export_select').change(function(){
var val = jQuery(this).val();
if (val=='0')
{
var href = jQuery('#export_url').attr('href');
var href = href.replace('?id='+href.substring(href.indexOf('?id=')+4, href.length),'?id=0');
}
else
{
var href = jQuery('#export_url').attr('href');
var href = href.replace('?id='+href.substring(href.indexOf('?id=')+4, href.length),'?id='+val);
}
jQuery('#export_url').attr('href',href);
});
setupLabel();
jQuery('body').addClass('has-js');
jQuery('body').on("click",'.label_check, .label_radio' , function(){
setupLabel();
});
jQuery('body').on('click', '.show-message', function(){
var html = jQuery(this).parent().find('.sub-content').html();
jQuery('#print_area').html(html);
});
jQuery('body').on('click','.fc_pagination > .page',function(){
show_submissions(jQuery(this).text(),false);
});
});
Here is a screenshot on both theme from inspect element and working/non working page
http://i.stack.imgur.com/6TkWs.png

jquery triggerhandler not being called

the trigger below never call. The alert on call never pop up.
It was triggered by these statements. See second block.
$('#sCart').trigger('add', {
stock_id: stock_id
$('#sCart').on('add', function(event, data) {
alert('on add');
$.ajax({
url: '$subCartUpdate'.replace('$tokenHolder', Math.random()),
type: 'GET',
dataType: 'json',
beforeSend: function(jqXHR) {
jqXHR.setRequestHeader('if-Modified-Since', '0');
},
success: function(success, statusText, jqXHR) {
alert(statusText);
$('#sCart').trigger('clear');
$('#sCart').html(success.subCart);
if(timerId === null) {
$('#sCart').queue('add', function() {
$(this).fadeIn(function() {
$(this).dequeue('add');
});
});
} else {
clearTimeout(timerId);
}
timerId = setTimeout(function() {
$('#sCart').fadeOut();
timerId = null;
}, 7000);
$('#sCart').queue('add', function() {
var updatedItemSelector = '#stock_'+data.stock_id;
var updatedItem = $(updatedItemSelector).fadeOut(500);
updatedItem.fadeIn(2000, function() {
$(this).dequeue('add');
});
});
if(success.reservedTimeStamp) {
$('#sCartTimer').trigger('start', {timer: success.reservedTimeStamp});
}
$('#sCart').dequeue('add');
},
error: function(jqXHR, statusText, errors) {
var i = 0;
}
});
});
It was triggered from code below.
$.ajax({
url: '$addUrl',
type: 'POST',
data: {
id: stock_id,
amount: amount
},
success: function(success, statusText, jqXHR) {
alert(statusText);
if(success.reload) {
location.reload(true);
} else if(success.redirect) {
location.href = success.redirect;
} else {
$('#sCart').trigger('add', {
stock_id: stock_id
});
$('.product-amount').val(1);
//$('.type .selected').first().trigger('click');
$('.stock_left').trigger('update');
$('.purchase').trigger('unblock');
}
},
error: function(jqXHR, statusText, error) {
var i = 0;
}
});

Categories