From: <die...@us...> - 2009-10-19 15:57:25
|
Revision: 1495 http://openutils.svn.sourceforge.net/openutils/?rev=1495&view=rev Author: diego_schivo Date: 2009-10-19 15:57:11 +0000 (Mon, 19 Oct 2009) Log Message: ----------- added trigger editors: media-picker, fckeditor, file-upload Modified Paths: -------------- trunk/openutils-mgnlcontrols/src/main/resources/dialogs/grid.ftl trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/grid.css trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/LinkField.js Added Paths: ----------- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGridSaveHandler.java trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/fckedit-trigger.gif trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/fileupload-trigger.gif trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/media-trigger.gif trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fckeditor.html trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fileupload.html trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FckEditorField.js trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FileField.js trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/MediaField.js Added: trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGridSaveHandler.java =================================================================== --- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGridSaveHandler.java (rev 0) +++ trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGridSaveHandler.java 2009-10-19 15:57:11 UTC (rev 1495) @@ -0,0 +1,110 @@ +package net.sourceforge.openutils.mgnlcontrols.dialog; + +import info.magnolia.cms.beans.runtime.Document; +import info.magnolia.cms.beans.runtime.MultipartForm; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.core.Path; +import info.magnolia.cms.gui.fckeditor.FCKEditorTmpFiles; +import info.magnolia.cms.security.AccessDeniedException; +import info.magnolia.cms.util.ContentUtil; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.context.MgnlContext; +import info.magnolia.module.admininterface.FieldSaveHandler; +import info.magnolia.module.admininterface.SaveHandlerImpl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.jcr.RepositoryException; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Needed by file upload. Setup: assign this class name as a "saveHandler" + * property of the grid field's configuration node. + * + * @author dschivo + * + */ +public class DialogGridSaveHandler implements FieldSaveHandler +{ + + public static Logger log = LoggerFactory.getLogger(DialogGridSaveHandler.class); + + @SuppressWarnings("unchecked") + public void save(Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType, + int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException + { + HierarchyManager hm = parentNode.getHierarchyManager(); + Content filesNode = ContentUtil.getOrCreateContent(parentNode, name + "_files", ItemType.CONTENTNODE); + String value = form.getParameter(name); + String ctx = MgnlContext.getContextPath(); + String tmpPath = "/tmp/fckeditor/"; + List usedFiles = new ArrayList(); + StringBuffer sbValue = new StringBuffer(value.length()); + StringBuffer sbLine = new StringBuffer(); + for (String line : StringUtils.splitPreserveAllTokens(value, '\n')) + { + for (String token : StringUtils.splitPreserveAllTokens(line, '\t')) + { + if (token.startsWith(ctx)) + { + String link = StringUtils.substringAfter(token, ctx); + if (StringUtils.startsWith(link, tmpPath)) + { + String uuid = StringUtils.substringBetween(link, tmpPath, "/"); + Document doc = FCKEditorTmpFiles.getDocument(uuid); + String fileNodeName = Path.getUniqueLabel(hm, filesNode.getHandle(), "file"); + SaveHandlerImpl.saveDocument(filesNode, doc, fileNodeName, "", ""); + link = filesNode.getHandle() + "/" + fileNodeName + "/" + doc.getFileNameWithExtension(); + token = link; + doc.delete(); + try + { + FileUtils.deleteDirectory(new java.io.File(Path.getTempDirectory() + "/fckeditor/" + uuid)); + } + catch (IOException e) + { + log.error("can't delete tmp file [" + Path.getTempDirectory() + "/fckeditor/" + uuid + "]"); + } + } + } + if (token.startsWith(filesNode.getHandle())) + { + String fileNodeName = StringUtils.removeStart(token, filesNode.getHandle() + "/"); + fileNodeName = StringUtils.substringBefore(fileNodeName, "/"); + usedFiles.add(fileNodeName); + } + if (sbLine.length() > 0) + { + sbLine.append('\t'); + } + sbLine.append(token); + } + if (sbValue.length() > 0) + { + sbValue.append('\n'); + } + sbValue.append(sbLine); + sbLine.setLength(0); + } + for (Iterator iter = filesNode.getNodeDataCollection().iterator(); iter.hasNext();) + { + NodeData fileNodeData = (NodeData) iter.next(); + if (!usedFiles.contains(fileNodeData.getName())) + { + fileNodeData.delete(); + } + } + NodeDataUtil.getOrCreateAndSet(parentNode, name, new String(sbValue)); + } + +} Property changes on: trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGridSaveHandler.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcontrols/src/main/resources/dialogs/grid.ftl =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/dialogs/grid.ftl 2009-10-19 15:29:31 UTC (rev 1494) +++ trunk/openutils-mgnlcontrols/src/main/resources/dialogs/grid.ftl 2009-10-19 15:57:11 UTC (rev 1495) @@ -9,6 +9,9 @@ <script type="text/javascript" src="${request.contextPath}/.resources/controls/js/LinkField.js"></script> <script type="text/javascript" src="${request.contextPath}/.resources/controls/js/CheckColumn.js"></script> <script type="text/javascript" src="${request.contextPath}/.resources/controls/js/PipeComboBox.js"></script> + <script type="text/javascript" src="${request.contextPath}/.resources/controls/js/MediaField.js"></script> + <script type="text/javascript" src="${request.contextPath}/.resources/controls/js/FckEditorField.js"></script> + <script type="text/javascript" src="${request.contextPath}/.resources/controls/js/FileField.js"></script> <script type="text/javascript"> // <![CDATA[ function gridMoveRow(grid, delta) { @@ -127,6 +130,9 @@ sortable: false, [#if (colmap.type?? && colmap.type = 'link')] editor: new Ed(new LinkField({ + [#if (colmap.repository??)]repository: '${colmap.repository}',[/#if] + [#if (colmap.extension??)]extension: '${colmap.extension}',[/#if] + dummy: undefined })) [#elseif (colmap.type?? && colmap.type = 'date')] renderer: function(value) { @@ -143,6 +149,22 @@ lazyRender: true, listClass: 'x-combo-list-small' })) + [#elseif (colmap.type?? && colmap.type = 'media')] + editor: new Ed(new MediaField({ + [#if (colmap.valueType??)]valueType: '${colmap.valueType}'[/#if] + })), + renderer : function(v, p, record){ + return v ? '<img border="0" alt="" src="${request.contextPath}/mediaObject' + v + '/resolutions/thumbnail/data.jpg"/>' : v; + } + [#elseif (colmap.type?? && colmap.type = 'fckedit')] + editor: new Ed(new FckEditorField({ + })) + [#elseif (colmap.type?? && colmap.type = 'file')] + editor: new Ed(new FileField({ + })), + renderer : function(v, p, record){ + return v ? v.replace(/^.*\//, '') : v; + } [#else] editor: new Ed(new fm.TextField({ allowBlank: true Modified: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/grid.css =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/grid.css 2009-10-19 15:29:31 UTC (rev 1494) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/grid.css 2009-10-19 15:57:11 UTC (rev 1495) @@ -1,4 +1,19 @@ .x-form-field-wrap .x-form-link-trigger { background-image: url(img/link-trigger.gif); cursor: pointer; -} \ No newline at end of file +} + +.x-form-field-wrap .x-form-media-trigger { + background-image: url(img/media-trigger.gif); + cursor: pointer; +} + +.x-form-field-wrap .x-form-fckedit-trigger { + background-image: url(img/fckedit-trigger.gif); + cursor: pointer; +} + +.x-form-field-wrap .x-form-fileupload-trigger { + background-image: url(img/fileupload-trigger.gif); + cursor: pointer; +} Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/fckedit-trigger.gif =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/fckedit-trigger.gif ___________________________________________________________________ Added: svn:mime-type + image/gif Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/fileupload-trigger.gif =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/fileupload-trigger.gif ___________________________________________________________________ Added: svn:mime-type + image/gif Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/media-trigger.gif =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/css/img/media-trigger.gif ___________________________________________________________________ Added: svn:mime-type + image/gif Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fckeditor.html =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fckeditor.html (rev 0) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fckeditor.html 2009-10-19 15:57:11 UTC (rev 1495) @@ -0,0 +1,31 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> + <head> + <title>FCK Editor</title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <script type="text/javascript" src="../../.magnolia/pages/javascript.js"></script> + <script type="text/javascript" src="../../.resources/admin-js/dialogs/dialogs.js"></script> + <link rel="stylesheet" type="text/css" href="../../.resources/admin-css/admin-all.css" /> + + <script type="text/javascript" src="../../.resources/fckeditor/fckeditor.js"></script> + </head> + <body style="padding:0;margin:0"> + <h1 style="background-color:#F0F2E6; color:#396101; font-size:11pt; border-bottom:1px solid #999;margin:0;padding:3px 10px">FCK Editor</h1> + <p style="margin: 10px"> + <script type="text/javascript"> +var sBasePath = '../../.resources/fckeditor/'; +var oFCKeditor = new FCKeditor('FCKeditor1'); +oFCKeditor.BasePath = sBasePath; +oFCKeditor.Height = 300; +oFCKeditor.Value = window.opener.getFckEditorValue(); +oFCKeditor.Create() ; + </script> + </p> + <div class="mgnlDialogTabsetSaveBar"> + <span class="mgnlControlButton" onclick="window.opener.setFckEditorValue(FCKeditorAPI.GetInstance('FCKeditor1').GetXHTML(true)); mgnlShiftPushButtonClick(this); window.opener.focus(); window.close();" onmouseout="mgnlShiftPushButtonOut(this);" + onmousedown="mgnlShiftPushButtonDown(this);"> + OK + </span> + </div> + </body> +</html> \ No newline at end of file Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fckeditor.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fileupload.html =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fileupload.html (rev 0) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fileupload.html 2009-10-19 15:57:11 UTC (rev 1495) @@ -0,0 +1,49 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> + <head> + <title>File upload</title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <script type="text/javascript" src="../../.magnolia/pages/javascript.js"></script> + <script type="text/javascript" src="../../.resources/admin-js/dialogs/dialogs.js"></script> + <script type="text/javascript"> +function OnUploadCompleted(errorNumber, fileUrl, fileName, customMsg) { + switch (errorNumber) { + case 0: + alert("Your file has been successfully uploaded"); + break; + default: + alert("Error on file upload. Error number: " + errorNumber); + return; + } + window.opener.setFileValue(fileUrl); + window.opener.focus(); + window.close(); +} + </script> + <link rel="stylesheet" type="text/css" href="../../.resources/admin-css/admin-all.css" /> + </head> + <body style="padding:0;margin:0"> + <h1 + style="background-color:#F0F2E6; color:#396101; font-size:11pt; border-bottom:1px solid #999;margin:0;padding:3px 10px"> + File upload + </h1> + + <div id="divUpload"> + <form + action="../../.magnolia/fckeditor/upload?repository=website&path=/temp/it/home/quick-answers&nodeCollection=main&node=0&name=text&type=file" + enctype="multipart/form-data" target="UploadWindow" method="post" id="frmUpload"> + <span fcklang="DlgLnkUpload">Carica</span> + <br /> + <input type="file" name="NewFile" size="40" style="width: 100%;" id="txtUploadFile" /> + <br /> + <br /> + <input type="submit" fcklang="DlgLnkBtnUpload" value="Invia al Server" id="btnUpload" /> + <script type="text/javascript"> + // <!-- + document.write('<iframe name="UploadWindow" style="display: none" src="javascript: void(0);"><\/iframe>'); + // --> + </script> + </form> + </div> + </body> +</html> \ No newline at end of file Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/grid-fileupload.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FckEditorField.js =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FckEditorField.js (rev 0) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FckEditorField.js 2009-10-19 15:57:11 UTC (rev 1495) @@ -0,0 +1,14 @@ +var FckEditorField = Ext.extend(Ext.form.TriggerField, { + + triggerClass: 'x-form-fckedit-trigger', + + onTriggerClick : function() { + if (this.disabled) return; + window.getFckEditorValue = this.getValue.createDelegate(this); + window.setFckEditorValue = function(value) { + this.setValue(value); + }.createDelegate(this); + mgnlOpenWindow('/.resources/controls/grid-fckeditor.html', 880, 380); + } + +}); Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FckEditorField.js ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FileField.js =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FileField.js (rev 0) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FileField.js 2009-10-19 15:57:11 UTC (rev 1495) @@ -0,0 +1,13 @@ +var FileField = Ext.extend(Ext.form.TriggerField, { + + triggerClass: 'x-form-fileupload-trigger', + + onTriggerClick : function() { + if (this.disabled) return; + window.setFileValue = function(value) { + this.setValue(value); + }.createDelegate(this); + mgnlOpenWindow('/.resources/controls/grid-fileupload.html', 400, 150); + } + +}); Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/FileField.js ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/LinkField.js =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/LinkField.js 2009-10-19 15:29:31 UTC (rev 1494) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/LinkField.js 2009-10-19 15:57:11 UTC (rev 1495) @@ -2,9 +2,13 @@ triggerClass : 'x-form-link-trigger', + repository: 'website', + + // extension: undefined, + onTriggerClick : function() { if (this.disabled) return; - mgnlDialogLinkOpenBrowser(this.el.id, 'website', 'html'); + mgnlDialogLinkOpenBrowser(this.el.id, this.repository, this.extension); } }); Added: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/MediaField.js =================================================================== --- trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/MediaField.js (rev 0) +++ trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/MediaField.js 2009-10-19 15:57:11 UTC (rev 1495) @@ -0,0 +1,16 @@ +var MediaField = Ext.extend(Ext.form.TriggerField, { + + triggerClass: 'x-form-media-trigger', + + // valueType: undefined, + + onTriggerClick: function(){ + if (this.disabled) return; + + window.setNewMedia = function(nodeid, uuid, file, thumb){ + this.setValue(this.valueType == 'path' ? thumb.replace(/^.*\/mediaObject\/(.*)\/resolutions\/.*$/, '/$1') : uuid); + }.createDelegate(this); + mgnlOpenWindow('/.magnolia/pages/mediaBrowser.html?nodeid=' + name + '&selectMedia=true&mgnlCK=' + mgnlGetCacheKiller(), 800, 500); + } + +}); Property changes on: trunk/openutils-mgnlcontrols/src/main/resources/mgnl-resources/controls/js/MediaField.js ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |