From 1eaaed2a2cad66b57f42f3800133cb2b946077cb Mon Sep 17 00:00:00 2001 From: Mike Hatfield Date: Mon, 30 Jun 2008 15:34:36 +0000 Subject: [PATCH] Remaining DocLib filters. Fix to active filter highlight. New "available actions" logic based on document state. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9599 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../documentlibrary/action-sets.lib.js | 26 +++++++++ .../slingshot/documentlibrary/doclist.get.js | 53 +++++++++++++++++-- .../documentlibrary/doclist.get.json.ftl | 18 +++---- .../slingshot/documentlibrary/filters.lib.js | 38 ++++++++++--- 4 files changed, 114 insertions(+), 21 deletions(-) create mode 100644 config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action-sets.lib.js diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action-sets.lib.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action-sets.lib.js new file mode 100644 index 0000000000..7fd72c20f1 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action-sets.lib.js @@ -0,0 +1,26 @@ +function getActionSet(asset, obj) +{ + var actionSet = "empty"; + var itemStatus = obj.itemStatus.toString(); + var isItemOwner = (obj.itemOwner == person.properties.userName); + + // Only 1 action set for folders + if (asset.isContainer) + { + actionSet = "folder"; + } + else if (itemStatus.indexOf("workingCopy") != -1) + { + actionSet = isItemOwner ? "workingCopyOwner" : "locked"; + } + else if (itemStatus.indexOf("locked") != -1) + { + actionSet = isItemOwner ? "lockOwner" : "locked"; + } + else + { + actionSet = "document"; + } + + return actionSet; +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js index 9eaae4cd74..643eff9fcb 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js @@ -1,4 +1,5 @@ + /** * Document List Component: doclist @@ -55,7 +56,7 @@ function getDoclist(siteId, path, type, filter) // Default to all children of pathNode var assets = pathNode.children; - // Try to find a filter query based on the passed-in argument + // Try to find a filter query based on the passed-in arguments var filterParams = { siteNode: siteNode, @@ -75,11 +76,53 @@ function getDoclist(siteId, path, type, filter) showFolders = (type == "folders"); } + // Locked/working copy status + /* + <#if d.isLocked><#assign status = status + ["locked"]><#assign lockedBy = d.properties["cm:lockOwner"]> + <#if d.hasAspect("cm:workingcopy")><#assign status = status + ["workingcopy"]><#assign lockedBy = d.properties["cm:workingCopyOwner"]> + */ + + var itemStatus; + var itemOwner; + var actionSet; + for each(asset in assets) { + itemStatus = []; + itemOwner = ""; + if ((asset.isContainer && showFolders) || (asset.isDocument && showDocs)) { - items.push(asset); + if (asset.isLocked) + { + itemStatus.push("locked"); + itemOwner = asset.properties["cm:lockOwner"]; + } + if (asset.hasAspect("cm:workingcopy")) + { + itemStatus.push("workingCopy"); + itemOwner = asset.properties["cm:workingCopyOwner"]; + } + // Is this user the item owner? + if (itemOwner == person.properties.userName) + { + itemStatus.push("lockedBySelf"); + } + + // Get relevant actions set + actionSet = getActionSet(asset, + { + itemStatus: itemStatus, + itemOwner: itemOwner + }); + + items.push( + { + asset: asset, + status: itemStatus, + owner: itemOwner, + actionSet: actionSet + }); } } @@ -101,9 +144,9 @@ function getDoclist(siteId, path, type, filter) function sortByType(a, b) { - if (a.isContainer == b.isContainer) + if (a.asset.isContainer == b.asset.isContainer) { - return (b.name.toLowerCase() > a.name.toLowerCase() ? -1 : 1); + return (b.asset.name.toLowerCase() > a.asset.name.toLowerCase() ? -1 : 1); } - return (a.isContainer ? -1 : 1); + return (a.asset.isContainer ? -1 : 1); } \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl index 93cca419fa..4e7c74501e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.json.ftl @@ -4,22 +4,19 @@ "totalItems": ${doclist.items?size}, "items": [ - <#list doclist.items as d> - <#assign status = []> - <#assign lockedBy = ""> + <#list doclist.items as item> + <#assign d = item.asset> <#assign version = "1.0"> - <#if d.isLocked><#assign status = status + ["locked"]><#assign lockedBy = d.properties["cm:lockOwner"]> - <#if d.hasAspect("cm:workingcopy")><#assign status = status + ["workingcopy"]> <#if d.hasAspect("cm:versionable")><#assign version = d.versionHistory?sort_by("versionLabel")?reverse[0].versionLabel> { - "index": ${d_index}, + "index": ${item_index}, "nodeRef": "${d.nodeRef}", "type": "<#if d.isContainer>folder<#else>document", "mimetype": "${d.mimetype!""}", "icon32": "${d.icon32}", "name": "${d.name?replace(" (Working Copy)", "")?html}", - "status": "<#list status as s>${s}<#if s_has_next>,", - "lockedBy": "${lockedBy}", + "status": "<#list item.status as s>${s}<#if s_has_next>,", + "lockedBy": "${item.owner}", "title": "${(d.properties.title!"")?html}", "description": "${(d.properties.description!"")?html}", "createdOn": "${d.properties.created?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", @@ -28,8 +25,9 @@ "modifiedBy": "${d.properties.modifier}", "size": "${d.size}", "version": "${version}", - "contentUrl": "api/node/content/${d.storeType}/${d.storeId}/${d.id}/${d.name?url}" - }<#if d_has_next>, + "contentUrl": "api/node/content/${d.storeType}/${d.storeId}/${d.id}/${d.name?url}", + "actionSet": "${item.actionSet}" + }<#if item_has_next>, ] } diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js index e6977aa204..ef022fb56b 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js @@ -4,18 +4,44 @@ function getFilterQuery(filter, obj) switch (String(filter)) { - case "TODO: recentlyModified": + case "recentlyModified": + var usingModified = true; + // fall through... + case "recentlyAdded": + // Which query: created, or modified? + var dateField = "modified"; + if (typeof usingModified === "undefined") + { + dateField = "created"; + } + + // Default to 7 days - can be overridden using "days" argument + var dayCount = 7; + var argDays = args["days"]; + if ((argDays != null) && !isNaN(argDays)) + { + dayCount = argDays; + } + var date = new Date(); + var toQuery = date.getFullYear() + "\\-" + (date.getMonth() + 1) + "\\-" + date.getDate(); + date.setDate(date.getDate() - dayCount); + var fromQuery = date.getFullYear() + "\\-" + (date.getMonth() + 1) + "\\-" + date.getDate(); + + filterQuery = "+PATH:\"" + obj.containerNode.qnamePath + "//*\" "; + filterQuery += "+@cm\\:" + dateField + ":[" + fromQuery + "T00\\:00\\:00 TO " + toQuery + "T23\\:59\\:59] "; + filterQuery += "-ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\""; break; - case "TODO: recentlyAdded": - break; - case "editingMe": filterQuery = "+PATH:\"" + obj.containerNode.qnamePath + "//*\" "; - filterQuery += " +@cm\\:workingCopyOwner:" + person.properties.userName; + filterQuery += "+ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\" "; + filterQuery += "+@cm\\:workingCopyOwner:" + person.properties.userName; break; - case "TODO: editingOthers": + case "editingOthers": + filterQuery = "+PATH:\"" + obj.containerNode.qnamePath + "//*\" "; + filterQuery += "+ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\" "; + filterQuery += "-@cm\\:workingCopyOwner:" + person.properties.userName; break; default: