fixed some warnings in the js-client

Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1d0fa4cf
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1d0fa4cf
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1d0fa4cf

Branch: refs/heads/develop
Commit: 1d0fa4cf31c9985c7e6ae5181648fe5d7db5bb29
Parents: 3bd8124
Author: Jakob Frank <[email protected]>
Authored: Wed Sep 24 18:01:11 2014 +0200
Committer: Jakob Frank <[email protected]>
Committed: Thu Sep 25 16:36:18 2014 +0200

----------------------------------------------------------------------
 .../marmotta-client-js/src/main/js/marmotta.js  | 300 ++++++++++---------
 1 file changed, 153 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/1d0fa4cf/client/marmotta-client-js/src/main/js/marmotta.js
----------------------------------------------------------------------
diff --git a/client/marmotta-client-js/src/main/js/marmotta.js 
b/client/marmotta-client-js/src/main/js/marmotta.js
index b5bd437..984b4f3 100644
--- a/client/marmotta-client-js/src/main/js/marmotta.js
+++ b/client/marmotta-client-js/src/main/js/marmotta.js
@@ -25,37 +25,43 @@
  */
 function MarmottaClient(url,opts) {
 
-    if( url==undefined) throw "url must be defined"; //test if url is defined
-    if( url.lastIndexOf("/")==url.length-1) url=url.substring(0,url.length-1); 
//clean url
+    if(url === undefined) {
+        //test if url is defined
+        throw "url must be defined";
+    }
+    if(url.lastIndexOf("/") === url.length -1) {
+        //clean url
+        url = url.substring(0, url.length -1);
+    }
 
     //default options
-    var options = {
-        configuration : {
-            path : "/config" //path to config webservices
-        },
-        resource : {
-            path : "/resource"
-        },
-        import : {
-            path : "/import"
-        },
-        sparql : {
-            path : "/sparql"
-        },
-        ldpath : {
-            path : "/ldpath"
-        }
-    }
+    var HTTP,
+        options = {
+            configuration : {
+                path : "/config" //path to config webservices
+            },
+            resource : {
+                path : "/resource"
+            },
+            'import' : {
+                path : "/import"
+            },
+            sparql : {
+                path : "/sparql"
+            },
+            ldpath : {
+                path : "/ldpath"
+            }
+        };
     if ( opts ) {
         $.extend( options, opts );
     }
 
     //create http stub
-    var HTTP = new HTTP_Client(url);
+    HTTP = new HTTP_Client(url);
 
     //init client and return
-    var client = new Client(options);
-    return client;
+    return new Client(options);
 
     /*
      **************************************
@@ -71,7 +77,7 @@ function MarmottaClient(url,opts) {
          */
         this.configurationClient = {
             /**
-             *         Requests for a list of all configuration keys in the 
system.
+             * Requests for a list of all configuration keys in the system.
              * @param onsuccess Function is executed on success. It takes a 
parameter array with key strings (e.g. ['key1','key2']).
              * @param onfailure Function is executed on failure. It takes a 
ServerError object.(OPTIONAL)
              */
@@ -97,7 +103,7 @@ function MarmottaClient(url,opts) {
                 configurationClient.getConfiguration(key,onsuccess,onfailure);
             },
             /**
-             *         Sets a configuration property.
+             * Sets a configuration property.
              * @param key The name of the property to set. If the property 
already exists it is overwritten.
              * @param value The value (a javascript Object, Array or 
Primitive).
              * @param onsuccess Function is executed on success. (OPTIONAL)
@@ -107,7 +113,7 @@ function MarmottaClient(url,opts) {
                 
configurationClient.setConfiguration(key,value,onsuccess,onfailure);
             },
             /**
-             *         Delete a configuration property. If property does not 
exists a ServerError 500 is passed to the onfailure function.
+             * Delete a configuration property. If property does not exists a 
ServerError 500 is passed to the onfailure function.
              * @param key The name of the property to delete.
              * @param onsuccess Function is executed on success.(OPTIONAL)
              * @param onfailure Function is executed on failure. It takes a 
ServerError object.(OPTIONAL)
@@ -115,7 +121,7 @@ function MarmottaClient(url,opts) {
             deleteConfiguration : function(key,onsuccess,onfailure) {
                 
configurationClient.deleteConfiguration(key,onsuccess,onfailure);
             }
-        }
+        };
 
         var resourceClient = new ResourceClient(options.resource);
         /**
@@ -191,11 +197,11 @@ function MarmottaClient(url,opts) {
             deleteResource : function(uri,onsuccess,onfailure) {
                 resourceClient.deleteResource(uri,onsuccess,onfailure);
             }
-        }
+        };
 
-        var importClient = new ImportClient(options.import);
+        var importClient = new ImportClient(options['import']);
         /**
-         * TODO TEST
+         * TODO: TEST
          * This client offers import functionalities
          */
         this.importClient = {
@@ -229,7 +235,7 @@ function MarmottaClient(url,opts) {
             upload : function(data,mimetype,context,onsuccess,onfailure) {
                 importClient.upload(data,mimetype,context,onsuccess,onfailure);
             }
-        }
+        };
 
         var sparqlClient = new SparqlClient(options.sparql);
         /**
@@ -263,7 +269,7 @@ function MarmottaClient(url,opts) {
             update : function(query,onsuccess,onfailure) {
                 sparqlClient.update(query,onsuccess,onfailure);
             }
-        }
+        };
 
         var ldPathClient = new LDPathClient(options.ldpath);
         /**
@@ -283,16 +289,16 @@ function MarmottaClient(url,opts) {
             /**
              * Evaluate a LDPath program
              * @param uri the starting point
-             * @param path the path
+             * @param program the ldpath program
              * @param onsuccess Function is executed on success with ldpath 
result object (Map) as parameter.
              * @param onfailure Function is executed on failure. It takes a 
ServerError object.(OPTIONAL)
              */
             evaluateProgram : function(uri, program, onsuccess, onfailure) {
                 ldPathClient.evaluateProgram(uri, program, onsuccess, 
onfailure);
             }
-        }
+        };
     }
-    
+
 
     function LDPathClient(options) {
         this.evaluatePath = function(uri,path,onsuccess,onfailure) {
@@ -302,7 +308,7 @@ function MarmottaClient(url,opts) {
                 404:function(){if(onfailure)onfailure(new ServerError("the 
resource with URI does not exist on the server",404));else throw new Error("the 
resource with URI does not exist on the server")},
                 "default":function(err,request){if(onfailure)onfailure(new 
ServerError("unexpected error",request.status));else throw new 
Error("unexpected error")}
             })
-        }
+        };
         this.evaluateProgram = function(uri,program,onsuccess,onfailure) {
             
HTTP.get(options.path+"/program",{uri:encodeURIComponent(uri),program:encodeURIComponent(program)},null,null,{
                 
200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("path 
evaluated successfully");},
@@ -310,7 +316,7 @@ function MarmottaClient(url,opts) {
                 404:function(){if(onfailure)onfailure(new ServerError("the 
resource with URI does not exist on the server",404));else throw new Error("the 
resource with URI does not exist on the server")},
                 "default":function(err,request){if(onfailure)onfailure(new 
ServerError("unexpected error",request.status));else throw new 
Error("unexpected error")}
             })
-        }
+        };
     }
 
 
@@ -324,19 +330,19 @@ function MarmottaClient(url,opts) {
                 
200:function(data){if(onsuccess)onsuccess(JSON.parse(data).results.bindings);console.debug("query
 returned successful");},
                 "default":function(err,response){if(onfailure)onfailure(new 
ServerError(err,response.status));else throw new Error(err)}
             });
-        }
+        };
         this.ask = function(query,onsuccess,onfailure) {
             
HTTP.get(options.path+"/select",{query:encodeURIComponent(query)},null,"application/sparql-results+json",{
                 
200:function(data){if(onsuccess)onsuccess(JSON.parse(data).boolean);console.debug("ask-query
 returned successful");},
                 "default":function(err,response){if(onfailure)onfailure(new 
ServerError(err,response.status));else throw new Error(err)}
             });
-        }
+        };
         this.update = function(query,onsuccess,onfailure) {
             
HTTP.get(options.path+"/update",{query:encodeURIComponent(query)},null,null,{
                 200:function(){if(onsuccess)onsuccess();console.debug("sparql 
update was successful");},
                 "default":function(err,response){if(onfailure)onfailure(new 
ServerError(err,response.status));else throw new Error(err)}
             });
-        }
+        };
     }
 
     /**
@@ -349,23 +355,23 @@ function MarmottaClient(url,opts) {
                 
200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("loaded
 types successfully");},
                 "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
             });
-        }
+        };
         this.uploadFromUrl = 
function(url,mimetype,context,onsuccess,onfailure) {
             var params = context ? {url:url,context:context} : {url:url};
-             HTTP.post(options.path+"/external",params,null,mimetype,{
-                 200:function(){if(onsuccess)onsuccess();console.debug("import 
successful");},
-                 412:function(){if(onfailure)onfailure(new ServerError("mime 
type "+mimetype+" not acceptable by import service",412));else throw new 
Error("mime type "+mimetype+" not acceptable by import service")},
-                 "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-             });
-        }
+            HTTP.post(options.path+"/external",params,null,mimetype,{
+                200:function(){if(onsuccess)onsuccess();console.debug("import 
successful");},
+                412:function(){if(onfailure)onfailure(new ServerError("mime 
type "+mimetype+" not acceptable by import service",412));else throw new 
Error("mime type "+mimetype+" not acceptable by import service")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
         this.upload = function(data,mimetype,context,onsuccess,onfailure) {
             var params = context ? {context:context} : null;
             HTTP.post(options.path+"/upload",params,data,mimetype,{
-                 200:function(){if(onsuccess)onsuccess();console.debug("import 
successful");},
-                 412:function(){if(onfailure)onfailure(new ServerError("mime 
type "+mimetype+" not acceptable by import service",412));else throw new 
Error("mime type "+mimetype+" not acceptable by import service")},
-                 "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-             });
-        }
+                200:function(){if(onsuccess)onsuccess();console.debug("import 
successful");},
+                412:function(){if(onfailure)onfailure(new ServerError("mime 
type "+mimetype+" not acceptable by import service",412));else throw new 
Error("mime type "+mimetype+" not acceptable by import service")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
     }
 
     /**
@@ -373,58 +379,58 @@ function MarmottaClient(url,opts) {
      * @param options
      */
     function ResourceClient(options) {
-            this.createResource = function(uri,onsuccess,onfailure) {
-                var queryParam = uri ? {uri:encodeURIComponent(uri)} : null;
-                HTTP.post(options.path,queryParam,null,null,{
-                    
200:function(location){if(onsuccess)onsuccess(location);console.debug("resource 
"+location+" already existed, not creating new")},
-                    
201:function(location){if(onsuccess)onsuccess(location);console.debug("resource 
"+location+" created")},
-                    "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                });
-            }
-            this.existsResource = function(uri,onsuccess,onfailure) {
-                //TODO implement
-                alert('Resource existence test is not implemented yet!');
-            }
-            this.getResourceMetadata = function(uri,onsuccess,onfailure) {
-                
HTTP.get(options.path,{uri:encodeURIComponent(uri)},null,"application/json; 
rel=meta",{
-                    
200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("metadata
 for resource "+uri+" retrieved");},
-                    406:function(){if(onfailure)onfailure(new 
ServerError("server does not support metadata type application/json",406));else 
throw new Error("server does not support metadata type application/json")},
-                    404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist",404));else throw new 
Error("resource "+uri+" does not exist")},
-                    "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                })
-            }
-            this.updateResourceMetadata = 
function(uri,data,onsuccess,onfailure) {
-                 
HTTP.put(options.path,{uri:encodeURIComponent(uri)},JSON.stringify(data),"application/json;
 rel=meta",{
-                     
200:function(){if(onsuccess)onsuccess();console.debug("metadata for resource 
"+uri+" updated")},
-                     415:function(){if(onfailure)onfailure(new 
ServerError("server does not support metadata type application/json",415));else 
throw new Error("server does not support metadata type application/json")},
-                     404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist, cannot update",404));else throw 
new Error("resource "+uri+" does not exist, cannot update")},
-                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                 });
-            }
-            this.getResourceContent = 
function(uri,mimetype,onsuccess,onfailure) {
-                
HTTP.get(options.path,{uri:encodeURIComponent(uri)},null,mimetype+"; 
rel=content",{
-                    
200:function(data){if(onsuccess)onsuccess(data);console.debug("content for 
resource "+uri+" retrieved");},
-                    406:function(){if(onfailure)onfailure(new 
ServerError("server does not support content type "+mimetype,406));else throw 
new Error("server does not support content type "+mimetype)},
-                    404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist",404));else throw new 
Error("resource "+uri+" does not exist")},
-                    "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                });
-            }
-            this.updateResourceContent = 
function(uri,data,mimetype,onsuccess,onfailure) {
-                 
HTTP.put(options.path,{uri:encodeURIComponent(uri)},data,mimetype+"; 
rel=content",{
-                     
200:function(){if(onsuccess)onsuccess();console.debug("content for resource 
"+uri+" updated")},
-                     415:function(){if(onfailure)onfailure(new 
ServerError("server does not support content type "+mimetype,415));else throw 
new Error("server does not support content type "+mimetype)},
-                     404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist, cannot update",404));else throw 
new Error("resource "+uri+" does not exist, cannot update")},
-                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                 });
-            }
-            this.deleteResource = function(uri,onsuccess,onfailure) {
-                 
HTTP.delete(options.path,{uri:encodeURIComponent(uri)},null,null,{
-                     
200:function(){if(onsuccess)onsuccess();console.debug("resource "+uri+" 
deleted")},
-                     400:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" invalid, cannot delete",400));else throw new 
Error("resource "+uri+" invalid, cannot delete")},
-                     404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist, cannot delete",404));else throw 
new Error("resource "+uri+" does not exist, cannot delete")},
-                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                 });
-            }
+        this.createResource = function(uri,onsuccess,onfailure) {
+            var queryParam = uri ? {uri:encodeURIComponent(uri)} : null;
+            HTTP.post(options.path,queryParam,null,null,{
+                
200:function(location){if(onsuccess)onsuccess(location);console.debug("resource 
"+location+" already existed, not creating new")},
+                
201:function(location){if(onsuccess)onsuccess(location);console.debug("resource 
"+location+" created")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
+        this.existsResource = function(uri,onsuccess,onfailure) {
+            //TODO implement
+            alert('Resource existence test is not implemented yet!');
+        };
+        this.getResourceMetadata = function(uri,onsuccess,onfailure) {
+            
HTTP.get(options.path,{uri:encodeURIComponent(uri)},null,"application/json; 
rel=meta",{
+                
200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("metadata
 for resource "+uri+" retrieved");},
+                406:function(){if(onfailure)onfailure(new ServerError("server 
does not support metadata type application/json",406));else throw new 
Error("server does not support metadata type application/json")},
+                404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist",404));else throw new 
Error("resource "+uri+" does not exist")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            })
+        };
+        this.updateResourceMetadata = function(uri,data,onsuccess,onfailure) {
+            
HTTP.put(options.path,{uri:encodeURIComponent(uri)},JSON.stringify(data),"application/json;
 rel=meta",{
+                
200:function(){if(onsuccess)onsuccess();console.debug("metadata for resource 
"+uri+" updated")},
+                415:function(){if(onfailure)onfailure(new ServerError("server 
does not support metadata type application/json",415));else throw new 
Error("server does not support metadata type application/json")},
+                404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist, cannot update",404));else throw 
new Error("resource "+uri+" does not exist, cannot update")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
+        this.getResourceContent = function(uri,mimetype,onsuccess,onfailure) {
+            
HTTP.get(options.path,{uri:encodeURIComponent(uri)},null,mimetype+"; 
rel=content",{
+                
200:function(data){if(onsuccess)onsuccess(data);console.debug("content for 
resource "+uri+" retrieved");},
+                406:function(){if(onfailure)onfailure(new ServerError("server 
does not support content type "+mimetype,406));else throw new Error("server 
does not support content type "+mimetype)},
+                404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist",404));else throw new 
Error("resource "+uri+" does not exist")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
+        this.updateResourceContent = 
function(uri,data,mimetype,onsuccess,onfailure) {
+            
HTTP.put(options.path,{uri:encodeURIComponent(uri)},data,mimetype+"; 
rel=content",{
+                200:function(){if(onsuccess)onsuccess();console.debug("content 
for resource "+uri+" updated")},
+                415:function(){if(onfailure)onfailure(new ServerError("server 
does not support content type "+mimetype,415));else throw new Error("server 
does not support content type "+mimetype)},
+                404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist, cannot update",404));else throw 
new Error("resource "+uri+" does not exist, cannot update")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
+        this.deleteResource = function(uri,onsuccess,onfailure) {
+            HTTP.delete(options.path,{uri:encodeURIComponent(uri)},null,null,{
+                
200:function(){if(onsuccess)onsuccess();console.debug("resource "+uri+" 
deleted")},
+                400:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" invalid, cannot delete",400));else throw new 
Error("resource "+uri+" invalid, cannot delete")},
+                404:function(){if(onfailure)onfailure(new 
ServerError("resource "+uri+" does not exist, cannot delete",404));else throw 
new Error("resource "+uri+" does not exist, cannot delete")},
+                "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+            });
+        };
     }
 
     /**
@@ -435,51 +441,51 @@ function MarmottaClient(url,opts) {
 
         this.listConfigurationKeys = function(onsuccess,onfailure) {
             HTTP.get(options.path+"/list",null,null,null,
-                    {200:function(data){
-                            data = JSON.parse(data);
-                            var keys = [];
-                            for(prop in data) { //filter keys
-                                keys.push(prop)
-                            }
-                            if(onsuccess)onsuccess(keys);console.debug("listed 
configuration keys successfully")
-                        },
-                    "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+                {200:function(data){
+                    data = JSON.parse(data);
+                    var keys = [];
+                    for(var prop in data) { //filter keys
+                        keys.push(prop)
                     }
+                    if(onsuccess)onsuccess(keys);console.debug("listed 
configuration keys successfully")
+                },
+                    "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
+                }
             );
-        }
+        };
         this.listConfigurations = function(prefix,onsuccess,onfailure) {
             var queryParams = prefix==null ? null : {prefix:prefix};
             HTTP.get(options.path+"/list",queryParams,null,null,
-                    
{200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("listed
 configurations"+(prefix==null?"":" width prefix "+prefix)+" successfully")},
+                
{200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("listed
 configurations"+(prefix==null?"":" width prefix "+prefix)+" successfully")},
                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                    }
+                }
             );
-        }
+        };
         this.getConfiguration = function(key,onsuccess,onfailure) {
             
HTTP.get(options.path+"/data/"+encodeURIComponent(key),null,null,null,
-                    
{200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("get 
configuration '"+key+"' successfully")},
-                     404:function(){if(onfailure)onfailure(new 
ServerError("configuration "+key+" is not set",404));else throw new 
Error("configuration "+key+" is not set")},
+                
{200:function(data){if(onsuccess)onsuccess(JSON.parse(data));console.debug("get 
configuration '"+key+"' successfully")},
+                    404:function(){if(onfailure)onfailure(new 
ServerError("configuration "+key+" is not set",404));else throw new 
Error("configuration "+key+" is not set")},
                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                    }
+                }
             );
-        }
+        };
         this.setConfiguration = function(key,value,onsuccess,onfailure) {
             
HTTP.post(options.path+"/data/"+encodeURIComponent(key),null,JSON.stringify(value),null,
-                    
{200:function(){if(onsuccess)onsuccess();console.debug("set '"+key+"' to 
'"+value+"' successfully")},
-                     400:function(){if(onfailure)onfailure(new 
ServerError("cannot parse input into json",400));else throw new Error("cannot 
parse input into json")},
+                {200:function(){if(onsuccess)onsuccess();console.debug("set 
'"+key+"' to '"+value+"' successfully")},
+                    400:function(){if(onfailure)onfailure(new 
ServerError("cannot parse input into json",400));else throw new Error("cannot 
parse input into json")},
                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                    }
+                }
             );
-        }
+        };
         this.deleteConfiguration = function(key,onsuccess,onfailure) {
             
HTTP.delete(options.path+"/data/"+encodeURIComponent(key),null,null,null,
-                    
{200:function(){if(onsuccess)onsuccess();console.debug("deleted configuration 
'"+key+"' successfully")},
-                     404:function(){if(onfailure)onfailure(new 
ServerError("configuration "+key+" does not exist",404));else throw new 
Error("configuration "+key+" is not set")},
-                     500:function(){if(onfailure)onfailure(new 
ServerError("cannot delete configuration",500));else throw new Error("cannot 
delete configuration")},
+                
{200:function(){if(onsuccess)onsuccess();console.debug("deleted configuration 
'"+key+"' successfully")},
+                    404:function(){if(onfailure)onfailure(new 
ServerError("configuration "+key+" does not exist",404));else throw new 
Error("configuration "+key+" is not set")},
+                    500:function(){if(onfailure)onfailure(new 
ServerError("cannot delete configuration",500));else throw new Error("cannot 
delete configuration")},
                     "default":function(){if(onfailure)onfailure(new 
ServerError("unknown error"));else throw new Error("unknown error")}
-                    }
+                }
             );
-        }
+        };
     }
 
     /**
@@ -488,7 +494,7 @@ function MarmottaClient(url,opts) {
      * @param status
      */
     function ServerError(message,status) {
-       function getStatus(){
+        function getStatus(){
             switch(status) {
                 case 203: return "Non-Authoritative Information";
                 case 204: return "No Content";
@@ -529,8 +535,8 @@ function MarmottaClient(url,opts) {
         //build a query param string
         function buildQueryParms(params) {
             if(params==null||params.length==0) return "";
-            var s="?"
-            for(prop in params) {
+            var s="?";
+            for(var prop in params) {
                 s+=prop+"="+params[prop]+"&";
             } return s.substring(0,s.length-1);
         }
@@ -539,8 +545,8 @@ function MarmottaClient(url,opts) {
         function doRequest(method,path,queryParams,data,mimetype,callbacks) {
             mimetype = mimetype ||  "application/json";
             var _url = url+path+buildQueryParms(queryParams);
-             var request = createRequest();
-             request.onreadystatechange = function() {
+            var request = createRequest();
+            request.onreadystatechange = function() {
                 if (request.readyState==4) {
                     if(callbacks.hasOwnProperty(request.status)) {
                         
callbacks[request.status](request.responseText,request);
@@ -550,28 +556,28 @@ function MarmottaClient(url,opts) {
                         throw 
"Status:"+request.status+",Text:"+request.responseText;
                     }
                 }
-             };
-             request.open(method, _url, true);
-             
if(method=="PUT"||method=="POST")request.setRequestHeader("Content-Type",mimetype);
-             if(method=="GET")request.setRequestHeader("Accept",mimetype);
-             request.send( data );
+            };
+            request.open(method, _url, true);
+            
if(method=="PUT"||method=="POST")request.setRequestHeader("Content-Type",mimetype);
+            if(method=="GET")request.setRequestHeader("Accept",mimetype);
+            request.send( data );
         }
 
         this.get = function(path,queryParams,data,mimetype,callbacks) {
-             doRequest("GET",path,queryParams,data,mimetype,callbacks);
-        }
+            doRequest("GET",path,queryParams,data,mimetype,callbacks);
+        };
 
         this.put = function(path,queryParams,data,mimetype,callbacks) {
-             doRequest("PUT",path,queryParams,data,mimetype,callbacks);
-        }
+            doRequest("PUT",path,queryParams,data,mimetype,callbacks);
+        };
 
         this.post = function(path,queryParams,data,mimetype,callbacks) {
-             doRequest("POST",path,queryParams,data,mimetype,callbacks);
-        }
+            doRequest("POST",path,queryParams,data,mimetype,callbacks);
+        };
 
         this.delete = function(path,queryParams,data,mimetype,callbacks) {
-             doRequest("DELETE",path,queryParams,data,mimetype,callbacks);
-        }
+            doRequest("DELETE",path,queryParams,data,mimetype,callbacks);
+        };
     }
 }
 

Reply via email to