chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1301015 - /chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
Date Thu, 15 Mar 2012 14:51:53 GMT
Author: jens
Date: Thu Mar 15 14:51:53 2012
New Revision: 1301015

URL: http://svn.apache.org/viewvc?rev=1301015&view=rev
Log:
define a default set of properties to be displayed, some UI improvements

Modified:
    chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html?rev=1301015&r1=1301014&r2=1301015&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html (original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html Thu
Mar 15 14:51:53 2012
@@ -86,20 +86,10 @@
         var tbody;
         var tbl = $('<table>').attr('id', 'childrenTable').attr('border', 1);
         
-        var propsToDisplay = [];
-        var propsToDisplayLabel = [];
-        for (var child in children.objects) {
-            if (baseType === children.objects[child].object.properties["cmis:baseTypeId"].value)
{
-		        for (var prop in children.objects[child].object.properties) {
-		            var propId = children.objects[child].object.properties[prop].id;
-		            if ($.inArray(propId, propsToDisplay) < 0) {
-		                propsToDisplay.push(propId);
-		                propsToDisplayLabel.push(children.objects[child].object.properties[prop].displayName);
-		        	}
-		        }
-            }
-        }
-
+        var propsDisp = getPropIdsToDisplayForObjectListDefault(children, baseType);// getPropIdsToDisplayForObjectListAll(children,
baseType);
+        var propsToDisplay = propsDisp.ids;
+        var propsToDisplayLabel = propsDisp.labels;
+        
         tbl.append($('<thead>').append(row = $('<tr>')));
         row.append($('<td>')); // document or folder icon
         for (var propKey in propsToDisplay) {
@@ -127,12 +117,14 @@
                         var text = convertValue(prop.value, prop.type);
                         if (baseType == "cmis:document" && propsToDisplay[propKey]
== "cmis:name" && props["cmis:contentStreamFileName"] != null &&
                                 props["cmis:contentStreamFileName"].value != null) {
-                            text = "<a href='" + session.getRootUrl() + "?cmisselector=content&objectId="
+ props["cmis:objectId"].value + "' >" + text + "</a>"
+                            text = "<a href='" + session.getRootUrl() + "?cmisselector=content&objectId="
+ props["cmis:objectId"].value + "' target='_new' >" + text + "</a>"
+                        } else if (baseType == "cmis:folder" && propsToDisplay[propKey]
== "cmis:name") {
+                            text = $('<a>').attr("href", "javascript:void()").click(function()
{drillDownChildren(props["cmis:objectId"].value);}).html(text);
                         }
 			            row.append($('<td>').html(text));
 	                    trace ("add col: " + prop.value);
                     } else
-                        row.append($('<td>'));//.text("<n/a>"));
+                        row.append($('<td>'));
 		        }
             }
         }
@@ -140,34 +132,110 @@
         return tbl;
     }
 
-    function createQueryTable(children) {
-        var row;
-        var tbody;
-        var tbl = $('<table>').attr('id', 'childrenTable').attr('border', 1);
-        
+    function getPropIdsToDisplayForObjectListAll(objectList, baseType) {
         var propsToDisplay = [];
         var propsToDisplayLabel = [];
-        for (var child in children.results) {
-	        for (var prop in children.results[child].properties) {
-	            var propQueryName = children.results[child].properties[prop].queryName;
+        for (var child in objectList.objects) {
+            if (baseType === objectList.objects[child].object.properties["cmis:baseTypeId"].value)
{
+		        for (var prop in objectList.objects[child].object.properties) {
+		            var propId = objectList.objects[child].object.properties[prop].id;
+		            if ($.inArray(propId, propsToDisplay) < 0) {
+		                propsToDisplay.push(propId);
+		                propsToDisplayLabel.push(objectList.objects[child].object.properties[prop].displayName);
+		        	}
+		        }
+            }
+        }
+        return { ids: propsToDisplay, labels: propsToDisplayLabel};
+    }
+    
+    // utility function to display most important cmis properties plus all custom properties
+    // from an object list, sequence in array determines display order 
+    function getPropIdsToDisplayForObjectListDefault(objectList, baseType) {
+        var propsToDisplay = ["cmis:name", "cmis:objectId", "cmis:objectTypeId","cmis:baseTypeId","cmis:createdBy",
+        		"cmis:creationDate", "cmis:lastModifiedBy", "cmis:lastModificationDate"];
+        var propsToDisplayLabel = ["Name", "Object-Id", "Type-Id", "Base-Type", "Created
By", "Created At",
+                                   "Modified By", "Modified At"];
+        if ("cmis:folder" === baseType) {
+            propsToDisplay.splice(3, 0, "cmis:parentId");
+            propsToDisplayLabel.splice(3, 0, "Parent Folder Id");
+
+        } else if ("cmis:document" === baseType) {
+            propsToDisplay.push("cmis:contentStreamMimeType");
+            propsToDisplayLabel.push("Content Type");
+        }
+
+        for (var child in objectList.objects) {
+            if (baseType === objectList.objects[child].object.properties["cmis:baseTypeId"].value)
{
+		        for (var prop in objectList.objects[child].object.properties) {
+		            var propId = objectList.objects[child].object.properties[prop].id;
+		            if (propId.indexOf("cmis:") != 0 && $.inArray(propId, propsToDisplay)
< 0) {
+		                propsToDisplay.push(propId);
+		                propsToDisplayLabel.push(objectList.objects[child].object.properties[prop].displayName);
+		        	}
+		        }
+            }
+        }
+
+        return { ids: propsToDisplay, labels: propsToDisplayLabel};
+    }
+    
+    // utility function to display all available properties plus all custom properties
+    // from a query result list, sequence in array determines display order 
+    function getPropIdsToDisplayForQueryAll(queryResp) {
+        var propsToDisplay = [];
+        var propsToDisplayLabel = [];
+        for (var child in queryResp.results) {
+	        for (var prop in queryResp.results[child].properties) {
+	            var propQueryName = queryResp.results[child].properties[prop].queryName;
 	            if ($.inArray(propQueryName, propsToDisplay) < 0) {
 	                propsToDisplay.push(propQueryName);
-	                propsToDisplayLabel.push(children.results[child].properties[prop].queryName);
+	                propsToDisplayLabel.push(queryResp.results[child].properties[prop].queryName);
+	        	}
+	        }
+        }        
+        return { ids: propsToDisplay, labels: propsToDisplayLabel};
+    }
+    
+    // utility function to display most important cmis properties plus all custom properties
+    // from a query result list, sequence in array determines display order 
+    function getPropIdsToDisplayForQueryDefault(queryResp) {
+        var propsToDisplay = ["cmis:name", "cmis:objectId", "cmis:objectTypeId","cmis:baseTypeId","cmis:createdBy",
+        		"cmis:creationDate", "cmis:lastModifiedBy", "cmis:lastModificationDate","cmis:contentStreamMimeType"];
+        var propsToDisplayLabel = ["Name", "Object-Id", "Type-Id", "Base-Type", "Created
By", "Created At",
+                                   "Modified By", "Modified At", "Content Type"];
+        for (var child in queryResp.results) {
+	        for (var prop in queryResp.results[child].properties) {
+	            var propQueryName = queryResp.results[child].properties[prop].queryName;
+	            if (propQueryName.indexOf("cmis:") != 0 && $.inArray(propQueryName,
propsToDisplay) < 0) {
+	                propsToDisplay.push(propQueryName);
+	                propsToDisplayLabel.push(queryResp.results[child].properties[prop].queryName);
 	        	}
 	        }
         }
-
+        return { ids: propsToDisplay, labels: propsToDisplayLabel};
+    }
+    
+    function createQueryTable(queryResp) {
+        var row;
+        var tbody;
+        var tbl = $('<table>').attr('id', 'queryRespTable').attr('border', 1);
+        
+        var propsDisp = getPropIdsToDisplayForQueryDefault(queryResp);// getPropIdsToDisplayForQueryAll(queryResp);
+        var propsToDisplay = propsDisp.ids;
+        var propsToDisplayLabel = propsDisp.labels;
+        
         tbl.append($('<thead>').append(row = $('<tr>')));
         for (var propKey in propsToDisplay) {
 			row.append($('<td>').text(propsToDisplayLabel[propKey]));
         }
         
         tbl.append(tbody = $('<tbody>'));
-        for (var child in children.results) {
+        for (var child in queryResp.results) {
             row = null;
             tbody.append(row = $('<tr>'));
             for (var propKey in propsToDisplay) {
-                var props = children.results[child].properties;
+                var props = queryResp.results[child].properties;
                 var prop = props[propsToDisplay[propKey]];
                 if (null != prop && null != prop.value) {
                     var text = convertValue(prop.value, prop.type);
@@ -333,7 +401,21 @@
        	 	}
        	});
     };
-
+    
+    function drillDownChildren(folderId) {
+        checkSession("#childrensection");
+        var parentId = $('#folderidfield').val();
+        $('#folderidfield').val(folderId);
+        session.getChildren(folderId, function(children) {
+            if (!checkError(children, "#childrensection")) {
+              	var tbl1 = createTable(children, "cmis:folder");
+              	var tbl2 = createTable(children, "cmis:document");
+                $("#childrensection *").remove();
+              	$("#childrensection").append(tbl1).append(tbl2);
+        	}
+        });
+    };
+    
     $(document).ready(function() {
 
         $(document).ajaxError(function(event, request, settings, excep){
@@ -421,19 +503,13 @@
         });
         
         $('#cmischildren').click(function() {
-            checkSession("#childrensection");
-            var rootFolderId = session.rootFolderId == null ? session.rootFolderId : 100;
-            
-            session.getChildren($('#folderidfield').val(), function(children) {
-                if (!checkError(children, "#childrensection")) {
-                  	var tbl1 = createTable(children, "cmis:folder");
-                  	var tbl2 = createTable(children, "cmis:document");
-                    $("#childrensection *").remove();
-                  	$("#childrensection").append(tbl1).append(tbl2);
-            	}
-            });
+            drillDownChildren($('#folderidfield').val());
         });
-        
+                       
+        $('#cmisroot').click(function() {
+            drillDownChildren(session.rootFolderId);
+        });
+
         $('#createdoc').click(function() {
             checkSession("#createdocsection");
            	session.createDocument($('#name').val(), $('#typeId').val(), $('#folderId').val(),
null, function(data) {
@@ -545,7 +621,9 @@
 	      </tr>
 	    </table>
 	</form>
-    <button id="cmischildren">Get Children!</button>  <br/>
+    <button id="cmischildren">Get Children!</button>
+    <button id="cmisroot">Get Root Folder!</button>
+    <br/>
     <div id="childrensection">
     </div>    
     <br/>    



Mime
View raw message