orbit-basic/app/assets/javascripts/ajax_form.js

75 lines
2.7 KiB
JavaScript

$(document).on('click', '#ajax_form_submit', function(){
// $('#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"),
success: function(response,status,xhr){
if(typeof tinyMCEPopup != "undefined"){
var x = response.split("#");
var returnurl = x[0],
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") {
// 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);
}
tinyMCEPopup.close();
}else{
//incase if we want to do something for quick edit file upload
// $("#modal-file").modal('hide');
// var r = "";
// if(rcom.getInternetExplorerVersion() > -1){
// r = "<tr><td>" + response + "</td></tr>";
// r = r.replace("</a><a","</a></td><td><a");
// r = $(r);
// r.attr("id",r.find("span").attr("for"));
// alert(r.html())
// }else{
// r = $(response);
// }
// $('#bulletin_files tbody').append(r);
//$(response).fadeIn();
}
},
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);
});