Sha256: 94f7c9b5c0f7ae24fc1193ee5bd0b53354d2182c4fed219eb9d6a5fcb91fef22

Contents?: true

Size: 1.75 KB

Versions: 22

Compression:

Stored size: 1.75 KB

Contents

var ajaxForm = {
    "obj": null,
    "onError": function (type, error, data) {
	ajaxForm.obj.find("[errorType=\"" + type + "\"]").html(error).show().parents(".control-group").addClass("error");
    },
    "onSubmit": function () {
	var args = {};
	ajaxForm.obj.find("input, select, textarea").attr("disabled", "disabled").each(
	    function () {
		if ($(this).attr("name") && ($(this).attr("type") != "checkbox" || $(this).attr("checked")))
		    args[$(this).attr("name")] = $(this).val();
	    });
	ajaxForm.clear();
	ajaxForm.obj.find(".loader").show();
	$.post(ajaxForm.obj.attr("action"),
	       args,
	       ajaxForm.response,
	       "text");
    },
    "clear": function() {
	ajaxForm.obj.find(".errorContainer").hide().parents(".control-group").removeClass("error");
    },
    "enable": function () {
	ajaxForm.obj.find("input, select, textarea").removeAttr("disabled");
	ajaxForm.obj.find(".loader").hide();
    },
    "response": function (data, status) {
	//alert(data);
	data=data.replace(/<!\[CDATA\[/,'').replace(/]]>/,'');//Rus 07-02-2013 Screening <![CDATA[  ]]>
	var response = $(data);
	if (response.find("error").length != 0) {
	    ajaxForm.onError(response.find("type").text(), response.find("error").text(), response);
	    ajaxForm.enable();
	}
	else if (response.find("redirect").length != 0)
	    document.location.href = response.find("redirect").text();
	else
	    ajaxForm.onSuccess(response);
    },
    "onSuccess": function() { }
};

$.fn.ajaxForm = function(onSuccess, onError) {
    $(this).submit(function() {
		       ajaxForm.obj = $(this);
		       ajaxForm.onSuccess = onSuccess;
		       if (onError)
			   ajaxForm.onError = onError;
		       ajaxForm.onSubmit();
		       return false;
		   });
};

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
kirgudu_base-0.0.25 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.23 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.22 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.21 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.19 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.18 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.17 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.16 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.15 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.14 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.13 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.12 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.11 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.10 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.9 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.8 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.7 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.6 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.5 app/assets/javascripts/kirgudu_base/ajax_form.js
kirgudu_base-0.0.4 app/assets/javascripts/kirgudu_base/ajax_form.js