File indexing completed on 2025-05-04 05:29:39
0001 /* 0002 0003 ASP.NET WEB FORMS PAGE METHODS EXTENSION FOR JTABLE 0004 http://www.jtable.org 0005 0006 --------------------------------------------------------------------------- 0007 0008 Copyright (C) 2011 by Halil İbrahim Kalkan (http://www.halilibrahimkalkan.com) 0009 0010 Permission is hereby granted, free of charge, to any person obtaining a copy 0011 of this software and associated documentation files (the "Software"), to deal 0012 in the Software without restriction, including without limitation the rights 0013 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0014 copies of the Software, and to permit persons to whom the Software is 0015 furnished to do so, subject to the following conditions: 0016 0017 The above copyright notice and this permission notice shall be included in 0018 all copies or substantial portions of the Software. 0019 0020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0021 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0022 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0023 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0024 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0025 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0026 THE SOFTWARE. 0027 0028 */ 0029 (function ($) { 0030 0031 //extension members 0032 $.extend(true, $.hik.jtable.prototype, { 0033 0034 /* OVERRIDES BASE METHOD. 0035 * THIS METHOD IS DEPRECATED AND WILL BE REMOVED FROM FEATURE RELEASES. 0036 * USE _ajax METHOD. 0037 *************************************************************************/ 0038 _performAjaxCall: function (url, postData, async, success, error) { 0039 this._ajax({ 0040 url: url, 0041 data: postData, 0042 async: async, 0043 success: success, 0044 error: error 0045 }); 0046 }, 0047 0048 /* OVERRIDES BASE METHOD */ 0049 _ajax: function (options) { 0050 var self = this; 0051 0052 var opts = $.extend({}, this.options.ajaxSettings, options); 0053 0054 if (opts.data == null || opts.data == undefined) { 0055 opts.data = {}; 0056 } else if (typeof opts.data == 'string') { 0057 opts.data = self._convertQueryStringToObject(opts.data); 0058 } 0059 0060 var qmIndex = opts.url.indexOf('?'); 0061 if (qmIndex > -1) { 0062 $.extend(opts.data, self._convertQueryStringToObject(opts.url.substring(qmIndex + 1))); 0063 } 0064 0065 opts.data = JSON.stringify(opts.data); 0066 opts.contentType = 'application/json; charset=utf-8'; 0067 0068 //Override success 0069 opts.success = function (data) { 0070 data = self._normalizeJSONReturnData(data); 0071 if (options.success) { 0072 options.success(data); 0073 } 0074 }; 0075 0076 //Override error 0077 opts.error = function () { 0078 if (options.error) { 0079 options.error(); 0080 } 0081 }; 0082 0083 //Override complete 0084 opts.complete = function () { 0085 if (options.complete) { 0086 options.complete(); 0087 } 0088 }; 0089 0090 $.ajax(opts); 0091 }, 0092 0093 /* OVERRIDES BASE METHOD */ 0094 _submitFormUsingAjax: function (url, formData, success, error) { 0095 var self = this; 0096 0097 formData = { 0098 record: self._convertQueryStringToObject(formData) 0099 }; 0100 0101 var qmIndex = url.indexOf('?'); 0102 if (qmIndex > -1) { 0103 $.extend(formData, self._convertQueryStringToObject(url.substring(qmIndex + 1))); 0104 } 0105 0106 var postData = JSON.stringify(formData); 0107 0108 $.ajax({ 0109 url: url, 0110 type: 'POST', 0111 dataType: 'json', 0112 contentType: "application/json; charset=utf-8", 0113 data: postData, 0114 success: function (data) { 0115 data = self._normalizeJSONReturnData(data); 0116 success(data); 0117 }, 0118 error: function () { 0119 error(); 0120 } 0121 }); 0122 }, 0123 0124 _convertQueryStringToObject: function (queryString) { 0125 var jsonObj = {}; 0126 var e, 0127 a = /\+/g, 0128 r = /([^&=]+)=?([^&]*)/g, 0129 d = function (s) { return decodeURIComponent(s.replace(a, " ")); }; 0130 0131 while (e = r.exec(queryString)) { 0132 jsonObj[d(e[1])] = d(e[2]); 0133 } 0134 0135 return jsonObj; 0136 }, 0137 0138 /* Normalizes JSON data that is returned from server. 0139 *************************************************************************/ 0140 _normalizeJSONReturnData: function (data) { 0141 //JSON Normalization for ASP.NET 0142 if (data.hasOwnProperty('d')) { 0143 return data.d; 0144 } 0145 0146 return data; 0147 } 0148 }); 0149 0150 })(jQuery);