Portlet webscript updates:

MySpaces portlet changed to use ajax update to main list div.
Upload file now refreshes list after upload complete.
Manual refresh icon added to MySpaces and MyDocs portlets.
Removed video preview from pop-up panel in portlets (unstable in Firefox).
Manic scrollbar flicking fixed in MyDocs and MySpaces portlets.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5736 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-05-21 17:46:52 +00:00
parent 6419aef81e
commit ed5b547943
10 changed files with 186 additions and 96 deletions

View File

@@ -21,17 +21,8 @@
<tr>
<td valign="middle" align="center">
<#assign isImage=node.isDocument && (node.mimetype = "image/gif" || node.mimetype = "image/jpeg" || node.mimetype = "image/png")>
<#assign isVideo=node.isDocument && node.mimetype?starts_with("video/")>
<#if isImage>
<a href="${url.context}${node.url}" target="new"><img src="${url.context}${node.url}" width=120 border=0></a>
<#elseif isVideo>
<object width="320" height="240" border="0" id="player">
<param name="UIMode" value="none" />
<param name="URL" value="${url.context}${node.url}" />
<param name="autoStart" value="true" />
<#--<embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" src="${url.context}${node.url}" showcontrols="1" showdisplay="0" showstatusbar="0" autosize="1" autoplay="0" autoStart="0" height="240" width="320"></embed>-->
<embed width="320" height="240" src="${url.context}${node.url}" border="0" showcontrols="1" showdisplay="0" showstatusbar="0" autosize="1" autoplay="0" autoStart="0"></embed>
</object>
<#else>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
@@ -72,7 +63,7 @@
</td>
</tr>
<#if node.isDocument && !isImage && !isVideo>
<#if node.isDocument && !isImage>
<#assign c=cropContent(node.properties.content, 512)>
<#if c?length != 0>
<tr>

View File

@@ -36,13 +36,16 @@
<table border=0 cellspacing=0 cellpadding=0 class="docTable">
<tr>
<td align=center height=40>
<table border=0 cellspacing=8 cellpadding=0>
<table border=0 cellspacing=8 cellpadding=0 width=100%>
<tr>
<th><a class="docfilterLink <#if filter=0>docfilterLinkSelected</#if>" href="${scripturl("?f=0&p=${path}")}">All Items</a></th>
<th><a class="docfilterLink <#if filter=1>docfilterLinkSelected</#if>" href="${scripturl("?f=1&p=${path}")}">Word Documents</a></th>
<th><a class="docfilterLink <#if filter=2>docfilterLinkSelected</#if>" href="${scripturl("?f=2&p=${path}")}">HTML Documents</a></th>
<th><a class="docfilterLink <#if filter=3>docfilterLinkSelected</#if>" href="${scripturl("?f=3&p=${path}")}">PDF Documents</a></th>
<th><a class="docfilterLink <#if filter=4>docfilterLinkSelected</#if>" href="${scripturl("?f=4&p=${path}")}">Recently Modified</a></th>
<td align=right>
<a href="${scripturl("?f=${filter}&p=${path}")}" class="refreshViewLink"><img src="${url.context}/images/icons/reset.gif" border="0" width="16" height="16" style="vertical-align:-25%;padding-right:4px">Refresh</a>
</td>
</tr>
</table>
</td>
@@ -139,6 +142,7 @@ a.docfilterLinkSelected:link, a.docfilterLinkSelected:visited
height: 320px;
width: 716px;
overflow: auto;
overflow-y: scroll;
border-top: 1px solid #CCD4DB;
border-bottom: 1px solid #CCD4DB;
visibility: hidden;
@@ -302,4 +306,12 @@ a.docfilterLinkSelected:link, a.docfilterLinkSelected:visited
overflow: hidden;
}
a.refreshViewLink:link, a.refreshViewLink:visited, a.refreshViewLink:hover
{
font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #515D6B;
text-decoration: none;
}
</STYLE>

View File

@@ -48,15 +48,15 @@
</#if>
</#list>
</div>
<span style="float:right;margin:6px 6px 0 0;"><a href="${scripturl("?f=${filter}&p=${path}")}" class="refreshViewLink"><img src="${url.context}/images/icons/reset.gif" border="0" width="16" height="16" style="vertical-align:-25%;padding-right:4px">Refresh</a></span>
<div class="spaceTitle">
<img src="${url.context}${home.icon16}" width="16" height="16" alt="" style="vertical-align:-25%;padding-right:6px">${home.name?html}
<img src="${url.context}${home.icon16}" width="16" height="16" alt="" style="vertical-align:-25%;padding-right:4px">${home.name?html}
</div>
<div class="spaceActions">
<div class="spaceAction spaceActionUpload" title="Upload a new document" onclick="MySpaces.upload(this);">
Upload
</div>
<#-- TODO: haspermission check! -->
<div class="spaceAction spaceActionUpload" title="Upload a new document" onclick="MySpaces.upload(this);">Upload</div>
<div class="spaceUploadPanel">
<#-- TODO: Url encode the path value! -->
<#-- Url encode the path value, and encode any single quotes to generate valid string -->
<input style="margin:4px" type="submit" value="OK" onclick='MySpaces.uploadOK(this, "${path?url?replace("'","_%_")}");'>
<input style="margin:4px" type="button" value="Cancel" onclick="MySpaces.uploadClose(this);">
</div>
@@ -75,52 +75,13 @@
</center>
</div>
<div id="spacePanel">
<#assign user=person.properties.userName>
<#assign count=0>
<#list home.children?sort_by('name') as d>
<#if (filter=0) ||
(filter=1 && d.isContainer) ||
(filter=2 && d.isDocument) ||
(filter=3 && (d.properties.creator == user || d.properties.modifier == user))>
<#assign count=count+1>
<div class="spaceRow">
<div class="spaceIcon">
<#if d.isDocument>
<a href="${url.context}${d.url}" target="new"><img class="spaceIconImage" alt="" width="16" height="16" src="${url.context}${d.icon16?replace(".gif",".png")}" border=0></a>
<#else>
<a href="${scripturl("?f=${filter}&p=${path}/${d.name}")}"><img class="spaceIconImage" alt="" width="16" height="16" src="${url.context}${d.icon16?replace(".gif",".png")}" border=0></a>
</#if>
<div style="display:none"><img class="spaceIconImage64" alt="" width="64" height="64" src="${url.context}${d.icon64}"></div>
</div>
<div class="spaceItem">
${d.name?html}
<span class="spaceInfo" onclick="event.cancelBubble=true; AlfNodeInfoMgr.toggle('${d.nodeRef}',this);">
<img src="${url.context}/images/icons/popup.gif" class="popupImage" width="16" height="16" />
</span>
</div>
<div class="spaceDetail">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>
<span class="spaceMetaprop">Description:</span>&nbsp;<span class="spaceMetadata"><#if d.properties.description?exists>${d.properties.description?html}<#else>&nbsp;</#if></span><br />
<span class="spaceMetaprop">Modified:</span>&nbsp;<span class="spaceMetadata">${d.properties.modified?datetime}</span><br />
<span class="spaceMetaprop">Modified By:</span>&nbsp;<span class="spaceMetadata">${d.properties.modifier}</span>
</td>
<td width="24">&nbsp;</td>
<td>
<span class="spaceMetaprop">Created:</span>&nbsp;<span class="spaceMetadata">${d.properties.created?datetime}</span><br />
<span class="spaceMetaprop">Created By:</span>&nbsp;<span class="spaceMetadata">${d.properties.creator}</span><br />
<span class="spaceMetaprop">Size:</span>&nbsp;<span class="spaceMetadata">${(d.size/1000)?string("0.##")} KB</span>
</td>
</tr>
</table>
</div>
</div>
</#if>
</#list>
<#-- populated via an AJAX call myspacecontent webscript -->
<#-- resolved path, filter and home.noderef required as arguments! -->
<script>MySpaces.Path="${path?replace("\"","\\\"")}";MySpaces.Filter="${filter}";MySpaces.Home="${home.nodeRef}";</script>
</div>
<div class="spaceFooter">
Showing ${count} items(s)
<#-- TODO: get the count value dynamically from the AJAX webscript output above... -->
Showing <span id="spaceCount">0</span> items(s)
</div>
</div>
@@ -172,6 +133,7 @@ a.spacefilterLinkSelected:link, a.spacefilterLinkSelected:visited
height: 320px;
width: 720px;
overflow: auto;
overflow-y: scroll;
border-top: 1px solid #CCD4DB;
border-bottom: 1px solid #CCD4DB;
visibility: hidden;
@@ -309,4 +271,12 @@ a.spaceBreadcrumbLink:link, a.spaceBreadcrumbLink:visited, a.spaceBreadcrumbLink
-moz-border-radius: 5px;
}
a.refreshViewLink:link, a.refreshViewLink:visited, a.refreshViewLink:hover
{
font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #515D6B;
text-decoration: none;
}
</STYLE>

View File

@@ -0,0 +1,7 @@
<webscript>
<shortname>My Spaces Panel</shortname>
<description>Generate the inner panel for the My Spaces portlet page</description>
<url format="html" template="/myspacespanel?f={filter}&amp;p={path}&amp;h={home}"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,45 @@
<#assign user=person.properties.userName>
<#assign count=0>
<#list companyhome.nodeByReference[args.h].childAssocs["cm:contains"]?sort_by('name') as d>
<#if (args.f="0") ||
(args.f="1" && d.isContainer) ||
(args.f="2" && d.isDocument) ||
(args.f="3" && (d.properties.creator == user || d.properties.modifier == user))>
<#assign count=count+1>
<div class="spaceRow">
<div class="spaceIcon">
<#if d.isDocument>
<a href="${url.context}${d.url}" target="new"><img class="spaceIconImage" alt="" width="16" height="16" src="${url.context}${d.icon16?replace(".gif",".png")}" border=0></a>
<#else>
<a href="${scripturl("${url.context}/service/myspaces?f=${args.f}&p=${args.p}/${d.name}", false)}"><img class="spaceIconImage" alt="" width="16" height="16" src="${url.context}${d.icon16?replace(".gif",".png")}" border=0></a>
</#if>
<div style="display:none"><img class="spaceIconImage64" alt="" width="64" height="64" src="${url.context}${d.icon64}"></div>
</div>
<div class="spaceItem">
${d.name?html}
<span class="spaceInfo" onclick="event.cancelBubble=true; AlfNodeInfoMgr.toggle('${d.nodeRef}',this);">
<img src="${url.context}/images/icons/popup.gif" class="popupImage" width="16" height="16" />
</span>
</div>
<div class="spaceDetail">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>
<span class="spaceMetaprop">Description:</span>&nbsp;<span class="spaceMetadata"><#if d.properties.description?exists>${d.properties.description?html}<#else>&nbsp;</#if></span><br />
<span class="spaceMetaprop">Modified:</span>&nbsp;<span class="spaceMetadata">${d.properties.modified?datetime}</span><br />
<span class="spaceMetaprop">Modified By:</span>&nbsp;<span class="spaceMetadata">${d.properties.modifier}</span>
</td>
<td width="24">&nbsp;</td>
<td>
<span class="spaceMetaprop">Created:</span>&nbsp;<span class="spaceMetadata">${d.properties.created?datetime}</span><br />
<span class="spaceMetaprop">Created By:</span>&nbsp;<span class="spaceMetadata">${d.properties.creator}</span><br />
<span class="spaceMetaprop">Size:</span>&nbsp;<span class="spaceMetadata">${(d.size/1000)?string("0.##")} KB</span>
</td>
</tr>
</table>
</div>
</div>
</#if>
</#list>
<#-- hidden div with the count value for the page -->
<div id="spaceCountValue" style="display:none">${count}</div>

View File

@@ -81,6 +81,7 @@
height: 480px;
width: 716px;
overflow: auto;
overflow-y: scroll;
}
a.webPreviewLink:link, a.webPreviewLink:visited, a.webPreviewLink:hover

View File

@@ -55,6 +55,8 @@ import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -64,6 +66,17 @@ import org.w3c.dom.Node;
*/
public class FileUploadBean
{
private static Log logger = LogFactory.getLog(FileUploadBean.class);
/**
* Ajax method to upload a file. A multi-part form is required as the input.
*
* "return-page" =
* "currentPath" =
* and the file item itself
*
* @throws Exception
*/
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void uploadFile() throws Exception
{
@@ -76,7 +89,6 @@ public class FileUploadBean
List<FileItem> fileItems = upload.parseRequest(request);
FileUploadBean bean = new FileUploadBean();
String uploadId = null;
String currentPath = null;
String filename = null;
String returnPage = null;
@@ -84,10 +96,6 @@ public class FileUploadBean
for (FileItem item : fileItems)
{
if (item.isFormField() && item.getFieldName().equals("upload-id"))
{
uploadId = item.getString();
}
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
returnPage = item.getString();
@@ -104,9 +112,12 @@ public class FileUploadBean
}
}
if (logger.isDebugEnabled())
logger.debug("Ajax file upload request: " + filename + " to path: " + currentPath + " return page: " + returnPage);
try
{
if (file != null)
if (file != null && currentPath != null && currentPath.length() != 0)
{
// convert cm:name based path to a NodeRef
StringTokenizer t = new StringTokenizer(currentPath, "/");
@@ -188,6 +199,9 @@ public class FileUploadBean
Node scriptText = result.createTextNode(returnPage);
scriptEl.appendChild(scriptText);
if (logger.isDebugEnabled())
logger.debug("File upload request complete.");
ResponseWriter out = fc.getResponseWriter();
XMLUtil.print(result, out);
out.close();

View File

@@ -26,6 +26,7 @@ package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -60,7 +61,8 @@ public class NodeInfoBean
/**
* Returns information on the node identified by the 'noderef'
* parameter found in the ExternalContext.
* parameter found in the ExternalContext. If no noderef is supplied, then the template
* is executed without context.
* <p>
* The result is the formatted HTML to show on the client.
*/
@@ -69,29 +71,27 @@ public class NodeInfoBean
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String strNodeRef = (String)context.getExternalContext().getRequestParameterMap().get("noderef");
if (strNodeRef == null || strNodeRef.length() == 0)
{
throw new IllegalArgumentException("'noderef' parameter is missing");
}
String strTemplate = (String)context.getExternalContext().getRequestParameterMap().get("template");
Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
String strTemplate = (String)requestMap.get("template");
if (strTemplate == null || strTemplate.length() == 0)
{
strTemplate = "node_summary_panel.ftl";
}
NodeRef nodeRef = new NodeRef(strNodeRef);
if (this.nodeService.exists(nodeRef))
NodeRef nodeRef = null;
if (strNodeRef != null && strNodeRef.length() != 0)
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/" + strTemplate, getModel(nodeRef), out);
}
else
nodeRef = new NodeRef(strNodeRef);
if (this.nodeService.exists(nodeRef) == false)
{
out.write("<span class='errorMessage'>Node could not be found in the repository!</span>");
return;
}
}
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/" + strTemplate, getModel(nodeRef, requestMap), out);
}
// ------------------------------------------------------------------------------
@@ -109,7 +109,7 @@ public class NodeInfoBean
// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(NodeRef nodeRef)
private Map<String, Object> getModel(NodeRef nodeRef, Map<String, String> requestMap)
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
@@ -119,10 +119,21 @@ public class NodeInfoBean
model.put("cropContent", new CropContentMethod());
model.put("url", new BaseTemplateContentServlet.URLHelper(
context.getExternalContext().getRequestContextPath()));
if (nodeRef != null)
{
model.put("node", new TemplateNode(
nodeRef,
Repository.getServiceRegistry(context),
this.imageResolver));
}
// add URL arguments as a map called 'args' to the root of the model
Map<String, String> args = new HashMap<String, String>(4, 1.0f);
for (String name : requestMap.keySet())
{
args.put(name, requestMap.get(name));
}
model.put("args", args);
return model;
}

View File

@@ -26,6 +26,7 @@ package org.alfresco.web.scripts;
import java.util.List;
import freemarker.template.TemplateBooleanModel;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateScalarModel;
@@ -64,17 +65,22 @@ public final class ScriptUrlMethod implements TemplateMethodModelEx
{
String result = "";
if (args.size() == 1)
if (args.size() != 0)
{
Object arg0 = args.get(0);
boolean prefixServiceUrl = true;
if (args.size() == 2 && args.get(1) instanceof TemplateBooleanModel)
{
prefixServiceUrl = ((TemplateBooleanModel)args.get(1)).getAsBoolean();
}
if (arg0 instanceof TemplateScalarModel)
{
String arg = ((TemplateScalarModel)arg0).getAsString();
String url = req.getServicePath();
String url = prefixServiceUrl ? req.getServicePath() : "";
url += arg;
url += (arg.length() > 0) ? "&" : "";
url += (arg.length() != 0) ? "&" : "";
url += "guest=" + (req.isGuest() ? "true" : "");
url += (req.getFormat().length() > 0) ? "&format=" + req.getFormat() : "";
url += (req.getFormat().length() != 0) ? "&format=" + req.getFormat() : "";
result = res.encodeScriptUrl(url);
}
}

View File

@@ -5,16 +5,48 @@ var MySpaces = {
DETAIL_MARGIN: 56,
TITLE_FONT_SIZE: 18,
fileInput: null,
Path: null,
Filter: null,
Home: null,
start: function()
{
if ($('spacePanel'))
{
MySpaces.parseSpacePanels();
$('spacePanel').setStyle('visibility', 'visible');
// fire off the ajax request to populate the spaces list - the 'myspacespanel' webscript
// is responsible for rendering just the contents of the main panel div
YAHOO.util.Connect.asyncRequest(
"GET",
getContextPath() + '/service/myspacespanel?p='+MySpaces.Path+'&f='+MySpaces.Filter+'&h='+MySpaces.Home,
{
success: function(response)
{
// push the response into the space panel div
$('spacePanel').setHTML(response.responseText);
// extract the count value from a hidden div and display it
$('spaceCount').setHTML($('spaceCountValue').innerHTML);
// wire up all the events and animations
MySpaces.init();
},
failure: function(response)
{
$('spacePanel').setHTML("Sorry, preview currently unavailable.");
}
}
);
}
},
init: function()
{
MySpaces.parseSpacePanels();
$('spacePanel').setStyle('visibility', 'visible');
},
/**
* Perform the operations required to add the events and animations required to anim various
* nodes when the user mouseovers and clicks on rows in the space panel
*/
parseSpacePanels: function()
{
var spaces = $$('#spacePanel .spaceRow');
@@ -256,8 +288,9 @@ var MySpaces = {
{
if (error == null)
{
// TODO: refresh!
alert("Uploaded: " + fileName);
// empty the main panel div and restart by reloading the panel contents
$('spacePanel').empty();
MySpaces.start();
}
else
{