(function () { var endpointSelector = new DevExpress.EndpointSelector(Partials.config.endpoints); function handleServiceError(error) { if (window.WinJS) { try { new Windows.UI.Popups.MessageDialog(error.message).showAsync(); } catch (e) { } } else { alert(error.message); } } $.support.cors = true; Partials.api = Partials.api = { url: endpointSelector.urlFor("api"), errorHandler: handleServiceError, post: function (apiName, postData, parameters) { var url = this.makeApiUriWithParameters(apiName, parameters); var promise = $.ajax({ url: url, dataType: 'json', contentType: 'application/json', method: "POST", data: JSON.stringify(postData) }); promise.fail(handleServiceError); return promise; }, get: function (apiName, parameters) { var url = this.makeApiUriWithParameters(apiName, parameters); var promise = $.ajax({ url: url, method: "GET", }); promise.fail(handleServiceError); return promise; }, makeApiUriWithParameters: function (apiName, parameters) { var uri = [this.url, '/']; uri.push(apiName); if (typeof parameters === 'object') { uri.push('?'); $.each(parameters, function (name, value) { if (value == null) return true; uri.push('&'); uri.push(name); uri.push('='); uri.push(value); }); } return uri.join(''); }, } }());