This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/assets/javascripts/ajax_form.js

109 lines
4.3 KiB
JavaScript
Raw Normal View History

$(document).on('click', '#ajax_form_submit', function(){
2012-08-07 09:32:15 +00:00
// $('#ajaxForm').ajaxSubmit({
// beforeSubmit: function(a,f,o) {
// o.dataType = 'script';
// if (o.dataType == 'script') {
// o.url = o.url.split('?'); // split on GET params
// if (o.url[0].substr(-3) != '.js') o.url[0] += '.js'; // force rails to respond to respond to the request with :format = js
// o.url = o.url.join('?'); // join on GET params
// }
// },
// success: function(response,status,xhr){
// alert(response);
// alert(status);
// alert(xhr);
// },
// error:function(){
// alert("error");
// }
// });
var o = {
// dataType: 'script',
dataType: 'html',
url:$("#ajaxForm").attr("action"),
2012-08-13 10:31:50 +00:00
beforeSubmit: function(){
var sub = true;
$("span.error").remove();
2012-08-13 10:45:02 +00:00
$("#dyn_error").empty();
2012-08-13 10:31:50 +00:00
$("#ajaxForm input").each(function(){
if($(this).val() == ""){
2012-08-13 10:45:02 +00:00
$("<span class='error'> *</span>").insertAfter($(this));
2012-08-13 10:31:50 +00:00
sub = false;
}
})
2012-08-13 10:45:02 +00:00
if(!sub){
$("#dyn_error").text("Cannot be empty.");
2012-08-13 10:31:50 +00:00
return false;
2012-08-13 10:45:02 +00:00
}
2012-08-13 10:31:50 +00:00
},
2012-08-07 12:55:18 +00:00
success: function(response,status,xhr){
if(typeof tinyMCEPopup != "undefined"){
2012-08-13 10:31:50 +00:00
var x = response.split("#");
2012-08-07 12:55:18 +00:00
var returnurl = x[0],
2012-08-13 10:31:50 +00:00
returntitle = x[1],
returndescription = x[2];
var win = tinyMCEPopup.getWindowArg("window");
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = returnurl;
win.document.getElementById(tinyMCEPopup.getWindowArg("alt")).value = returndescription;
win.document.getElementById(tinyMCEPopup.getWindowArg("title")).value = returntitle;
if (typeof(win.ImageDialog) != "undefined") {
2012-08-07 12:55:18 +00:00
// we are, so update image dimensions...
if (win.ImageDialog.getImageData)
win.ImageDialog.getImageData();
// ... and preview if necessary
if (win.ImageDialog.showPreviewImage)
win.ImageDialog.showPreviewImage(returnurl);
2012-08-13 10:31:50 +00:00
}
tinyMCEPopup.close();
2012-08-07 12:55:18 +00:00
}else{
//incase if we want to do something for quick edit file upload
2012-08-13 10:31:50 +00:00
// var modalvalues = "";
2012-08-07 12:55:18 +00:00
// var r = "";
// if(rcom.getInternetExplorerVersion() > -1){
// r = "<tr><td>" + response + "</td></tr>";
2012-08-13 10:31:50 +00:00
// r = r.replace("**","</td><td>");
// r = r.replace("**","</td><td>");
2012-08-07 12:55:18 +00:00
// r = $(r);
2012-08-13 10:31:50 +00:00
// modalvalues = r.find("span").attr("data-content").split("#");
2012-08-07 12:55:18 +00:00
// r.attr("id",r.find("span").attr("for"));
2012-08-13 10:31:50 +00:00
// var table=document.getElementById(modalvalues[0]);
// //var tbody = table.getElementsByTagName("tbody");
// var row = table.insertRow(table.rows.length-1);
// var c1 = row.insertCell(0),
// c2 = row.insertCell(1),
// c3 = row.insertCell(2);
// c1.innerHTML = r.find("td").eq(0).html();
// c2.innerHTML = r.find("td").eq(1).html();
// c3.innerHTML = r.find("td").eq(2).html();
// var trow = $("#bulletin_files tfoot").find("tr").eq(0);
// $("#bulletin_files tbody").append(trow);
2012-08-07 12:55:18 +00:00
// }else{
2012-08-13 10:31:50 +00:00
// response = response.replace("**","");
// response = response.replace("**","");
2012-08-07 12:55:18 +00:00
// r = $(response);
2012-08-13 10:31:50 +00:00
// modalvalues = r.find("span").attr("data-content").split("#");
// $('#' + modalvalues[0]+ ' tbody').append(r);
2012-08-07 12:55:18 +00:00
// }
2012-08-13 10:31:50 +00:00
// console.log(modalvalues[1]);
// $("#"+modalvalues[1]).modal('hide');
//$('#bulletin_files tbody').append(r);
2012-08-07 12:55:18 +00:00
//$(response).fadeIn();
}
2012-08-07 09:32:15 +00:00
},
error:function(){
alert("error");
}
}
if (o.dataType == 'script') {
o.url = o.url.split('?'); // split on GET params
if (o.url[0].substr(-3) != '.js') o.url[0] += '.js'; // force rails to respond to respond to the request with :format = js
o.url = o.url.join('?'); // join on GET params
}
$('#ajaxForm').ajaxSubmit(o);
});