2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 var services = app.ns("services");
19 var ux = app.ns("ux");
21 function parse_version( v ) {
22 return v.match(/^(\d+)\.(\d+)\.(\d+)/).slice(1,4).map( function(d) { return parseInt(d || 0, 10); } );
25 services.Cluster = ux.Class.extend({
30 this.base_uri = this.config.base_uri;
32 setVersion: function( v ) {
34 this._version_parts = parse_version( v );
36 versionAtLeast: function( v ) {
37 var testVersion = parse_version( v );
38 for( var i = 0; i < 3; i++ ) {
39 if( testVersion[i] !== this._version_parts[i] ) {
40 return testVersion[i] < this._version_parts[i];
45 request: function( params ) {
46 return $.ajax( $.extend({
47 url: this.base_uri + params.path,
49 error: function(xhr, type, message) {
50 if("console" in window) {
51 console.log({ "XHR Error": type, "message": message });
56 "get": function(path, success) { return this.request( { type: "GET", path: path, success: success } ); },
57 "post": function(path, data, success) { return this.request( { type: "POST", path: path, data: data, success: success } ); },
58 "put": function(path, data, success) { return this.request( { type: "PUT", path: path, data: data, success: success } ); },
59 "delete": function(path, data, success) { return this.request( { type: "DELETE", path: path, data: data, success: success } ); }
62 })( this.jQuery, this.app );