mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Add channel module wrapping our various JSON requests to the server.
(imported from commit 6489938678551ad8594822363ae6d1c9ae295496)
This commit is contained in:
		
							
								
								
									
										44
									
								
								static/js/channel.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								static/js/channel.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
var channel = (function () {
 | 
			
		||||
 | 
			
		||||
var exports = {};
 | 
			
		||||
 | 
			
		||||
function call(args) {
 | 
			
		||||
    return $.ajax(args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get = function (options) {
 | 
			
		||||
    var args = _.extend({type: "GET", dataType: "json"}, options);
 | 
			
		||||
    return call(args);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.post = function (options) {
 | 
			
		||||
    var args = _.extend({type: "POST", dataType: "json"}, options);
 | 
			
		||||
    return call(args);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.put = function (options) {
 | 
			
		||||
    var args = _.extend({type: "PUT", dataType: "json"}, options);
 | 
			
		||||
    return call(args);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Not called exports.delete because delete is a reserved word in JS
 | 
			
		||||
exports.del = function (options) {
 | 
			
		||||
    var args = _.extend({type: "DELETE", dataType: "json"}, options);
 | 
			
		||||
    return call(args);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.patch = function (options) {
 | 
			
		||||
    // Send a PATCH as a POST in order to work around QtWebkit
 | 
			
		||||
    // (Linux/Windows desktop app) not supporting PATCH body.
 | 
			
		||||
    options.method = "PATCH";
 | 
			
		||||
    if (options.processData === false) {
 | 
			
		||||
        // If we're submitting a FormData object, we need to add the
 | 
			
		||||
        // method this way
 | 
			
		||||
        options.data.append("method", "PATCH");
 | 
			
		||||
    }
 | 
			
		||||
    return exports.post(options);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
return exports;
 | 
			
		||||
 | 
			
		||||
}());
 | 
			
		||||
		Reference in New Issue
	
	Block a user