Skip to content

Instantly share code, notes, and snippets.

@SergeyNarozhny
Last active August 29, 2015 13:57
Show Gist options
  • Save SergeyNarozhny/9740572 to your computer and use it in GitHub Desktop.
Save SergeyNarozhny/9740572 to your computer and use it in GitHub Desktop.
// var items = <?=CUtil::PhpToJSObject($arResult["ITEMS"])?>;
function Parser(formname) {
this.formname = formname;
this.init = function() {
var instarr = $("#"+this.formname).serializeArray();
var base = {};
for (var i in instarr) {
base[instarr[i].name] = instarr[i].value;
}
this.base = base;
}
this.checkCredit = function(linkClass) {
var promise = $.Deferred();
$.ajax({ type: "POST",
url: "load.php?act=check_limit",
data: { fordCode : this.base["g-fordCode-n"].value,
sum: this.base["g-total-n"].value },
beforeSend: function() {
$("a."+linkClass).hide();
$(".pending").show();
},
success: function(result) { promise.resolve(result); }
});
return promise;
}
this.doApply = function(){
return $.ajax({ type: "POST", url: "load.php?act=make_order",
data: { items: JSON.stringify(items),
sum: this.base["g-total-n"].value,
dat: this.base["g-date-n"].value,
com: this.base["ordering-comment"].value,
adr: this.base["catalog-sort-option"].value
}
});
}
}
var sm = new Parser("ORDER_FORM");
$(".soap-order").on("click", function(){
sm.init();
sm.checkCredit("soap-order").done(function(result){
if (result < 0) {
$(".pending").hide();
$(".checkNo").show();
} else {
sm.doApply().done(function(result2){
$(".pending").hide();
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment