Skip to content

Instantly share code, notes, and snippets.

@bekzod
Created February 12, 2014 09:21
Show Gist options
  • Save bekzod/8952318 to your computer and use it in GitHub Desktop.
Save bekzod/8952318 to your computer and use it in GitHub Desktop.
Order.prototype.getHotelWidgetData = function(params, cb){
var self = this;
params = params || {};
params.date_start = params.date_start || (new Date().format('yyyy-mm-dd'));
params.date_end = params.date_end || params.date_start;
params.adults = params.adults || 2;
params.currency = params.currency || 'EUR';
params.children = params.children || 0;
params.city = params.city || 'moscow';
var urlParams = $.map( params, function(value, key){
return key + '=' + value;
}).join('&');
var url = encodeURI('/_api/hotel_search/widgetSearch?' + urlParams);
if(this.hotelWidgetXHR && this.hotelWidgetXHR.readystate != 4){
this.hotelWidgetXHR.abort();
this.hotelWidgetXHR = null;
}
clearTimeout(this.hotelWidgetTimer);
this.hotelWidgetXHR = $.ajax({
url: url,
cache: false,
dataType: "json",
success: function(json){
if(json.error) return cb(json.error);
if(json.status == 'loading'){
this.hotelWidgetTimer = setTimeout(function(){
self.getHotelWidgetData(params,cb);
},00);
return;
}
cb(null,json);
},
error: function(xhr,status, error){
cb(error);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment