You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/04/12 13:08:16 UTC

svn commit: r1325204 - /chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js

Author: jens
Date: Thu Apr 12 11:08:16 2012
New Revision: 1325204

URL: http://svn.apache.org/viewvc?rev=1325204&view=rev
Log:
make paging more comfortable

Modified:
    chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js?rev=1325204&r1=1325203&r2=1325204&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js (original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js Thu Apr 12 11:08:16 2012
@@ -52,9 +52,14 @@ function CmisSessionFactory (parameters)
                 this.params[PARAM_USER], this.params[PARAM_PWD]);
     };
         
-    this.getRepositories = function(cbFct) {
+    this.getRepositories = function(cbFct, cbFctError) {
         trace("getRepositories() for URL: " + this.params[PARAM_URL]);
-        doJson(this.params[PARAM_URL], null, "GET", this.params[PARAM_USER], this.params[PARAM_PWD], cbFct);
+        doJson(this.params[PARAM_URL], null, "GET", this.params[PARAM_USER], this.params[PARAM_PWD], cbFct, function(jqXHR, textStatus, errorThrown) {
+            var errorMsg = "Failed to connect " + errorThrown + "(" + textStatus + ")";
+            trace(errorMsg);
+            if (cbFctError != undefined && cbFctError != null)
+                return cbFctError.call(this, errorMsg); 
+        });
     };
 };
 
@@ -127,6 +132,52 @@ function TypeCache() {
     }
 };
 
+function PagingContext(skipCount, totalItems, opCtx) {
+    this.skipCount =  skipCount;
+    this.totalItems = totalItems;
+    this.opCtx = opCtx;
+
+    this.getTotalItems = function() {
+        return  this.totalItems==null || this.totalItems==0 ? 4294967295 : this.totalItems;
+    };
+    
+    this.getCurrentPage = function() {
+        return Math.floor(this.skipCount / this.opCtx.maxItems) + 1;
+    };
+    
+    this.getTotalPages = function() {
+        var totalPages;
+        if (this.totalItems==null || this.opCtx.maxItems==null || this.opCtx.maxItems==0)
+            totalPages = "(unknown)";
+        else
+            totalPages = ((this.totalItems - (this.totalItems % this.opCtx.maxItems)) / this.opCtx.maxItems) + 1;
+        return totalPages;
+    };
+    
+    this.setPreviousPage = function() {
+        this.skipCount = this.skipCount - this.opCtx.maxItems;
+        if (this.skipCount < 0)
+            this.skipCount = 0;
+    }
+    
+    this.setNextPage = function() {
+        this.skipCount = this.skipCount + this.opCtx.maxItems;
+        if (this.skipCount >= this.totalItems)
+            this.skipCount = this.totalItems - this.opCtx.maxItems;
+    }
+    
+    this.setFirstPage = function() {
+        this.skipCount = 0;
+    }
+
+    this.setLastPage = function() {
+        if (this.totalItems==null)
+            return;
+        var totalPages = this.getTotalPages() - 1;
+        this.skipCount = totalPages * this.opCtx.maxItems;
+    }
+}
+
 function CmisSession(urlPrefix, repositoryId, jsonp, user, password) {
     this.repId = repositoryId;;
     this.urlPrefix = urlPrefix; // "/inmemory/browser/" + repId
@@ -158,10 +209,7 @@ function CmisSession(urlPrefix, reposito
     };
 
     this.addPagingContext = function (elementId, skipCount, numItemsTotal) {        
-        this.pagingContext[elementId] = { 
-                "skipCount": skipCount,
-                "totalItems" : numItemsTotal
-                }
+        this.pagingContext[elementId] = new PagingContext(skipCount, numItemsTotal, this.opCtx);
     };
     
     this.getPagingContext = function (elementId) {
@@ -416,7 +464,7 @@ CmisSession.defaultErrorHandler = functi
     return cmisError;
 };
 
-function doJson(url, params, method, username, password, cbFct) {
+function doJson(url, params, method, username, password, cbFct, cbFctError) {
     
     if (username != null && username.length == 0)
         username=null;
@@ -431,6 +479,7 @@ function doJson(url, params, method, use
         type:  method,
         username: username,
         password: password,
-        success: cbFct
+        success: cbFct,
+        error: cbFctError == undefined ? null : cbFctError
     });
 };