c4ddf6552b80722e39d76192881b8c238d099c58
[ccsdk/features.git] /
1 (function( $, app ) {
2
3         var services = app.ns("services");
4         var ux = app.ns("ux");
5
6         function parse_version( v ) {
7                 return v.match(/^(\d+)\.(\d+)\.(\d+)/).slice(1,4).map( function(d) { return parseInt(d || 0, 10); } );
8         }
9
10         services.Cluster = ux.Class.extend({
11                 defaults: {
12                         base_uri: null
13                 },
14                 init: function() {
15                         this.base_uri = this.config.base_uri;
16                 },
17                 setVersion: function( v ) {
18                         this.version = v;
19                         this._version_parts = parse_version( v );
20                 },
21                 versionAtLeast: function( v ) {
22                         var testVersion = parse_version( v );
23                         for( var i = 0; i < 3; i++ ) {
24                                 if( testVersion[i] !== this._version_parts[i] ) {
25                                         return testVersion[i] < this._version_parts[i];
26                                 }
27                         }
28                         return true;
29                 },
30                 request: function( params ) {
31                         return $.ajax( $.extend({
32                                 url: this.base_uri + params.path,
33                                 dataType: "json",
34                                 error: function(xhr, type, message) {
35                                         if("console" in window) {
36                                                 console.log({ "XHR Error": type, "message": message });
37                                         }
38                                 }
39                         },  params) );
40                 },
41                 "get": function(path, success) { return this.request( { type: "GET", path: path, success: success } ); },
42                 "post": function(path, data, success) { return this.request( { type: "POST", path: path, data: data, success: success } ); },
43                 "put": function(path, data, success) { return this.request( { type: "PUT", path: path, data: data, success: success } ); },
44                 "delete": function(path, data, success) { return this.request( { type: "DELETE", path: path, data: data, success: success } ); }
45         });
46
47 })( this.jQuery, this.app );