You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ne...@apache.org on 2007/07/27 16:43:14 UTC

svn commit: r560251 - in /lenya/trunk/src/modules/editors: config/ resources/i18n/ resources/javascript/ usecases/ usecases/forms/ xslt/

Author: nettings
Date: Fri Jul 27 07:43:13 2007
New Revision: 560251

URL: http://svn.apache.org/viewvc?view=rev&rev=560251
Log:
new generic usecase API for editors. see
modules/editors/resources/javascript/org.apache.lenya.editors.js for
documentation.
adds generic insertLink and insertAsset/Image usecases with
infrastructure.
enhanced oneform editor, it uses external usecases now.

this will break external usecase support in all editors.


Added:
    lenya/trunk/src/modules/editors/resources/javascript/oneform_lenya_glue.js
      - copied, changed from r559652, lenya/trunk/src/modules/editors/resources/javascript/oneform.js
Removed:
    lenya/trunk/src/modules/editors/resources/javascript/oneform.js
    lenya/trunk/src/modules/editors/usecases/insertLink.jx
Modified:
    lenya/trunk/src/modules/editors/config/module.xml
    lenya/trunk/src/modules/editors/resources/i18n/cmsui.xml
    lenya/trunk/src/modules/editors/resources/i18n/cmsui_de.xml
    lenya/trunk/src/modules/editors/resources/javascript/disablebackspace.js
    lenya/trunk/src/modules/editors/resources/javascript/org.apache.lenya.editors.js
    lenya/trunk/src/modules/editors/usecases/forms/oneform.jx
    lenya/trunk/src/modules/editors/usecases/insertAsset.jx
    lenya/trunk/src/modules/editors/xslt/insertLink.xsl

Modified: lenya/trunk/src/modules/editors/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/config/module.xml?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/config/module.xml (original)
+++ lenya/trunk/src/modules/editors/config/module.xml Fri Jul 27 07:43:13 2007
@@ -25,9 +25,12 @@
   <depends module="org.apache.lenya.modules.sitemanagement"/>
   <depends module="org.apache.lenya.modules.linking"/>
   <package>org.apache.lenya.modules</package>
-  <version>0.2-dev</version>
+  <version>0.3-dev</version>
   <name>Editors</name>
   <lenya-version>@lenya.version@</lenya-version>
-  <description>Editor base and support classes, Forms and Oneform editor
-  implementations, generic insertLink usecase implementation</description>
+  <description>
+    Editor base and support classes,  
+    generic insertLink, insertAsset and insertImage usecase implementations,
+    Forms and Oneform editor implementations
+  </description>
 </module>

Modified: lenya/trunk/src/modules/editors/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/resources/i18n/cmsui.xml?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/resources/i18n/cmsui.xml (original)
+++ lenya/trunk/src/modules/editors/resources/i18n/cmsui.xml Fri Jul 27 07:43:13 2007
@@ -29,5 +29,23 @@
   <message key="insertLink.URL">URL</message>
   <message key="insertLink.text">Link text</message>
   <message key="insertLink.title">Link title</message>
-  <message key="insertLink.submit">Insert Link!</message>
+  <message key="insertLink.submit">Insert Link</message>
+  
+  <message key="insertAsset.headingAsset">Insert Asset</message>
+  <message key="insertAsset.headingImage">Insert Image</message>
+  <message key="insertAsset.availableAsset">Available assets</message>
+  <message key="insertAsset.availableImage">Available images</message>
+  <message key="insertAsset.file">File</message>
+  <message key="insertAsset.preview">Preview</message>
+  <message key="insertAsset.title">Title</message>
+  <message key="insertAsset.fileSize">Size</message>
+  <message key="insertAsset.imageSize">W x H</message>
+  <message key="insertAsset.creationDate">created</message>
+  <message key="insertAsset.captionImage">Image description</message>
+  <message key="insertAsset.captionAsset">Asset text</message>
+  <message key="insertAsset.width">Width</message>
+  <message key="insertAsset.height">height</message>
+  <message key="insertAsset.insertAsset">Insert asset</message>
+  <message key="insertAsset.insertImage">Insert image</message>
+  <message key="insertAsset.createResource">Upload new resource</message>
 </catalogue>

Modified: lenya/trunk/src/modules/editors/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/resources/i18n/cmsui_de.xml?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/resources/i18n/cmsui_de.xml (original)
+++ lenya/trunk/src/modules/editors/resources/i18n/cmsui_de.xml Fri Jul 27 07:43:13 2007
@@ -29,6 +29,23 @@
   <message key="insertLink.URL">URL</message>
   <message key="insertLink.text">Link-Text</message>
   <message key="insertLink.title">Link-Titel</message>
-  <message key="insertLink.submit">Link einfügen!</message>
-            
+  <message key="insertLink.submit">Link einfügen</message> 
+   
+  <message key="insertAsset.headingAsset">Anlage einfügen</message>
+  <message key="insertAsset.headingImage">Bild einfügen</message>
+  <message key="insertAsset.availableAsset">Verfügbare Anlagen</message>
+  <message key="insertAsset.availableImage">Verfügbare Bilder</message>
+  <message key="insertAsset.file">Datei</message>
+  <message key="insertAsset.preview">Vorschau</message>
+  <message key="insertAsset.title">Titel</message>
+  <message key="insertAsset.fileSize">Größe</message>
+  <message key="insertAsset.imageSize">B x H</message>
+  <message key="insertAsset.creationDate">erstellt am</message>
+  <message key="insertAsset.captionAsset">Anlagentext</message>
+  <message key="insertAsset.captionImage">Bildbeschreibung</message>
+  <message key="insertAsset.width">Breite</message>
+  <message key="insertAsset.height">Höhe</message>
+  <message key="insertAsset.insertAsset">Anlage einfügen</message>
+  <message key="insertAsset.insertImage">Bild einfügen</message>
+  <message key="insertAsset.createResource">Neue Datei hochladen...</message>
 </catalogue>

Modified: lenya/trunk/src/modules/editors/resources/javascript/disablebackspace.js
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/resources/javascript/disablebackspace.js?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/resources/javascript/disablebackspace.js (original)
+++ lenya/trunk/src/modules/editors/resources/javascript/disablebackspace.js Fri Jul 27 07:43:13 2007
@@ -22,8 +22,9 @@
      key = window.event.keyCode;
    else
      key = e.which;
-   if (key == 8)
+   if (key == 8) {
+     alert("disablebackspace.js just ate a backspace event. Burp!");
      return false;
-   else
+   } else
      return true;
 }

Copied: lenya/trunk/src/modules/editors/resources/javascript/oneform_lenya_glue.js (from r559652, lenya/trunk/src/modules/editors/resources/javascript/oneform.js)
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/resources/javascript/oneform_lenya_glue.js?view=diff&rev=560251&p1=lenya/trunk/src/modules/editors/resources/javascript/oneform.js&r1=559652&p2=lenya/trunk/src/modules/editors/resources/javascript/oneform_lenya_glue.js&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/resources/javascript/oneform.js (original)
+++ lenya/trunk/src/modules/editors/resources/javascript/oneform_lenya_glue.js Fri Jul 27 07:43:13 2007
@@ -1,48 +1,12 @@
 org.apache.lenya.editors.setObjectData = function(objectData, windowName) {
   var currentUsecase = usecaseMap[windowName];
-  // alert("windowName: "+ windowName);
-  var beforeSelection, afterSelection, replaceSelection;
-  
-  switch (currentUsecase) {
-    case "insertLink":
-      beforeSelection = '<a'
-        + (objectData.url ? ' href="' + objectData.url + '"' : '')
-        + (objectData.title ? ' title="' + objectData.title + '"' : '')
-        + '>';
-      afterSelection = '</a>';
-      replaceSelection =
-        objectData.text ? objectData.text : undefined;
-      break;
-    case "insertImage":
-      beforeSelection = '<img'
-        + (objectData.url ? ' src="' + objectData.url + '"' : '')
-        + (objectData.title ? ' title="' + objectData.title + '"' : '')
-        + (objectData.text ? ' alt="' + objectData.title + '"' : '')
-        + '/>';
-      afterSelection = undefined;
-      replaceSelection = undefined;
-      break;
-    case "insertAsset":
-      beforeSelection = '<a'
-        + (objectData.url ? ' href="' + objectData.url + '"' : '')
-        + (objectData.title ? ' title="' + objectData.title + '"' : '')
-        + ' class="asset">';
-      afterSelection = '</a>';
-      replaceSelection =
-        objectData.text ? objectData.text : undefined;
-      break;
-    default:
-      alert("setObjectData: Unknown usecase " + currentUsecase + ". This is likely a programming error.");
-      return;
-  }
+  var snippet = org.apache.lenya.editors.generateContentSnippet(currentUsecase, objectData);
   org.apache.lenya.editors.insertContent(
     document.forms['oneform'].elements['content'], 
-    beforeSelection, 
-    afterSelection, 
-    replaceSelection
+    snippet
   );
-  usecaseMap[windowName] = undefined;
-  objectData[windowName] = undefined;
+  usecaseMap[windowName] = undefined; // we're done!
+  objectData[windowName] = undefined; // we're done!
 }
 
 org.apache.lenya.editors.getObjectData = function(windowName) {
@@ -51,19 +15,41 @@
 
 function triggerUsecase(usecase) {
   var windowName = org.apache.lenya.editors.generateUniqueWindowName();
+  var selectedText = org.apache.lenya.editors.getSelectedText(document.forms[0].elements['content']);
+  switch (usecase) {
+
+    case "insertLink":
+      objectData[windowName] = new org.apache.lenya.editors.ObjectData({
+        url   : "",
+        text  : selectedText,
+        title : ""
+      });
+      break;
+
+    case "insertImage":
+      objectData[windowName] = new org.apache.lenya.editors.ObjectData({
+        url   : "",
+        text  : selectedText,
+        title : "",
+        width : "",
+        height: ""
+      });
+      break;
+
+    case "insertAsset":
+      objectData[windowName] = new org.apache.lenya.editors.ObjectData({
+        url   : "",
+        text  : selectedText,
+        title : ""
+      })
+      break;
+  }
   org.apache.lenya.editors.openUsecaseWindow(usecase, windowName);
-  objectData[windowName] = {
-    url   : "",
-    text  : "",
-    title : ""
-  } 
   usecaseMap[windowName] = usecase;
-  /* alert("Stored values:" 
-      + "\n windowName = '" + windowName 
-      + "'\n objectData[windowName] = '" + objectData[windowName] 
-      + "'\n usecaseMap[windowName] = '" + usecaseMap[windowName] 
-      + "'"); 
-  */
+    alert("Stored values for new window " + windowName + ":\n"
+      + "objectData[windowName] = '" + objectData[windowName] + "'\n"
+      + "usecaseMap[windowName] = '" + usecaseMap[windowName] + "'"
+  ); 
 }
 
 var objectData = new Array();

Modified: lenya/trunk/src/modules/editors/resources/javascript/org.apache.lenya.editors.js
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/resources/javascript/org.apache.lenya.editors.js?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/resources/javascript/org.apache.lenya.editors.js (original)
+++ lenya/trunk/src/modules/editors/resources/javascript/org.apache.lenya.editors.js Fri Jul 27 07:43:13 2007
@@ -5,6 +5,7 @@
 if (!org.apache.lenya) org.apache.lenya = new Object();
 if (!org.apache.lenya.editors) org.apache.lenya.editors = new Object();
 
+//alert("Module 'org.apache.lenya.editors' loaded.");
 
 /**
   * ObjectData constructor, the interface between generic editor usecases
@@ -87,10 +88,16 @@
   * org.apache.lenya.editors.generateContentSnippet  and 
   * org.apache.lenya.editors.insertContent as helpers), or
   * to fill the values into some editor-specific dialog.
+  *
+  * If you want to allow for multiple active usecase windows in parallel,
+  * you can use the windowName parameter to uniquely identify each window
+  * and do your own bookkeeping. 
+  * Consider using org.apache.lenya.editors.openUsecaseWindow to 
+  * manage your windows.
   * 
   * @param objectData a data object as defined by objectDataTemplate
   * @param windowName the ID of the usecase window (window.name).
-  * @see org.apache.lenya.editors.objectDataTemplate
+  * @see org.apache.lenya.editors.ObjectData
   */
 org.apache.lenya.editors.setObjectData = function(objectData, windowName) {
   alert("Programming error:\n  You must override org.apache.lenya.editors.setObjectData(objectData, windowName)!");
@@ -107,10 +114,10 @@
   * deactivated, so that your editor can handle them.
   *
   * Usually, default values are based on selected text or user settings.
-  * 
   * @param windowName the ID of the usecase window (window.name).
   * @returns an objectData object.
-  * @see org.apache.lenya.editors.objectDataTemplate
+  * @see org.apache.lenya.editors.ObjectData
+  * @see org.apache.lenya.editors.setObjectData
    */
 org.apache.lenya.editors.getObjectData = function(windowName) {
   alert("Programming error:\n  You must override org.apache.lenya.editors.getObjectData(windowName)!");
@@ -130,7 +137,7 @@
   * @param objectData 
   * @see org.apache.lenya.editors.objectDataTemplate
   */
-org.apache.lenya.editors.setFormValues = function(formName,objectData) {
+org.apache.lenya.editors.setFormValues = function(formName, objectData) {
   var form = document.forms[formName];
   for (var i in org.apache.lenya.editors.ObjectData.prototype) {
     if (form[i] !== undefined) {
@@ -164,6 +171,32 @@
   return objectData;
 }
 
+/*
+org.apache.lenya.editors.findAncestor = function() {
+  // check our parent window:
+  return org.apache.lenya.editors.__findAncestor(window.opener.top);
+}
+
+org.apache.lenya.editors.__findAncestor = function(ancestor) {
+  // if ancestor is undefined, we don't have an ancestor that
+  // provides the org.apache.lenya.editors package.
+  if (!ancestor) {
+    alert("no ancestor found. baling out...");
+    return undefined;
+  }
+  try {
+  // probe for the package in the ancestor:
+     var probe = ancestor.org.apache.lenya.editors;
+  } catch (exception) { 
+     alert("probe: " + probe + "\n" + exception);
+   // woops. no package. check the ancestor's parent.
+    return org.apache.lenya.editors.__findAncestor(ancestor.opener.top);
+  }
+  // gotcha: ancestor has the package.
+  alert("found ancestor '" + ancestor.name + "' with package!");
+  return ancestor;
+}
+*/
 
 /**
   * handle the submit event of the form
@@ -200,19 +233,27 @@
     + "width=600,"
     + "height=700";
 
+
+org.apache.lenya.editors.USECASE_INSERTLINK = 'insertLink';
+org.apache.lenya.editors.USECASE_INSERTIMAGE = 'insertImage';
+org.apache.lenya.editors.USECASE_INSERTASSET = 'insertAsset';
+
+
 org.apache.lenya.editors.generateUniqueWindowName = function() {
-  return new String("windowName-" + Math.random().toString().substr(2));
+  return new String("Lenya-" + Math.random().toString().substr(2));
 }
 
 
 /**
   * a helper function to open new usecase windows.
   *
-  * If everyone used this, we'd save some maintenance work 
-  * in the long run and can ensure consistent
-  * behaviour across different editors.
+  * If everyone used this, we'd save some maintenance work in the long run 
+  * and can ensure consistent behaviour across different editors.
+  *
   * @param usecase the name of the usecase to invoke, one of
-  *   ("insertLink" | "insertImage" | "insertAsset")
+  *   org.apache.lenya.editors.USECASE_INSERTLINK 
+  *   | org.apache.lenya.editors.USECASE_INSERTIMAGE 
+  *   | org.apache.lenya.editors.USECASE_INSERTASSET
   * @param windowName the name of the new window, in case the editor needs 
   *   that info later on.
   * @returns the new window object
@@ -222,9 +263,9 @@
   var usecaseWindow;
 
   switch (usecase) {
-    case "insertLink":
-    case "insertAsset": 
-    case "insertImage":
+    case org.apache.lenya.editors.USECASE_INSERTLINK:
+    case org.apache.lenya.editors.USECASE_INSERTASSET:
+    case org.apache.lenya.editors.USECASE_INSERTIMAGE:
       currentBaseURL = window.location.href.replace(/\?.*$/,"");
       usecaseWindow = window.open(
         currentBaseURL + "?lenya.usecase=editors." + usecase,
@@ -289,7 +330,7 @@
 
   switch (usecase) {
 
-    case "insertLink":
+    case org.apache.lenya.editors.USECASE_INSERTLINK:
       snippet.beforeSelection = '<a'
         + (namespace ? ' xmlns="' + namespace + '"' : '')
         + (objectData.url ? ' href="' + objectData.url + '"' : '')
@@ -300,7 +341,7 @@
         objectData.text ? objectData.text : undefined;
       break;
 
-    case "insertAsset":
+    case org.apache.lenya.editors.USECASE_INSERTASSET:
       snippet.beforeSelection = '<a'
         + (namespace ? ' xmlns="' + namespace + '"' : '')
         + (objectData.url ? ' href="' + objectData.url + '"' : '')
@@ -311,7 +352,7 @@
         objectData.text ? objectData.text : undefined;
       break;
 
-    case "insertImage":
+    case org.apache.lenya.editors.USECASE_INSERTIMAGE:
       snippet.beforeSelection = '<img'
         + (namespace ? ' xmlns="' + namespace + '"' : '')
         + (objectData.url ? ' src="' + objectData.url + '"' : '')
@@ -333,23 +374,46 @@
 
 
 /**
-  * a cross-browser helper to obtain selected text in form elements
+  * a cross-browser helper to obtain selected text
+  *
+  * @param sourceElement an XHTML input or window object (optional), such as
+  *   document.forms['youreditor'].elements['content'] or window.top.
+  * You must specify it if you want to retrieve selections from 
+  * form fields, or from frames other than "window" (the default).
   *
-  * @param formElement a XHTML form element (document.forms[foo].bar)
-  * In IE, this parameter is disregarded, since IE uses a document-wide 
-  * selection mechanism.
   * @returns the selected text or the empty string.
+  *
+  * NOTE: This function is really versatile and powerful. It is also totally
+  * untested on anything except Firefox.
   */
-org.apache.lenya.editors.getSelectedText = function(formElement) {
-  if (formElement.selectionStart !== undefined) {
-    return formElement.value.substr(
-         formElement.selectionStart, 
-         formElement.selectionEnd - formElement.selectionStart);
+org.apache.lenya.editors.getSelectedText = function(sourceElement) {
+  var debug = true;
+
+  if (!sourceElement) sourceElement = window;
+
+  // FF and friends if a form input element was specified
+  if (sourceElement.selectionStart) {
+    debug && alert("FF or similar, using 'selectionStart' on an XHTML <input> element named '" + sourceElement.name + "'.");
+    return sourceElement.value.substr(
+         sourceElement.selectionStart, 
+         sourceElement.selectionEnd - sourceElement.selectionStart);
   } else 
-  if (document.selection !== undefined) {
-    return document.selection.createRange().text;
+  // FF and friends in other parts of the document
+  if (sourceElement.getSelection) {
+    debug && alert("FF or similar, using a 'getSelection()' on a window element named '" + sourceElement.name + "'.");
+    return sourceElement.getSelection().toString();
+  } else
+  // IE if a window element was specified
+  if (sourceElement.document.selection) {
+    debug && alert("IE, using using 'selection' on the document element of a window named '" + sourceElement.name + "'.");
+    return sourceElement.document.selection.createRange().text;
   } else {
-    alert("Sorry, your browser apparently doesn't support text selection via javascript.");
+  // IE if a form object was specified (ignore it and use document instead)
+  if (window.document.selection) {
+    debug && alert("IE, ignoring form element and using 'selection' on the document element of the current window '" + window.name + "'.");
+    return window.document.selection.createRange().text;
+  } else
+    debug && alert("Sorry, your browser apparently doesn't support text selection via javascript.");
     return "";
   }
 }
@@ -365,7 +429,7 @@
   */
 org.apache.lenya.editors.insertContent = function(formElement, snippet) {
 
-  alert("snippet: '" + snippet.toString() + "'\n");
+  //alert("snippet: '" + snippet.toString() + "'\n");
  
   // Danger, Will Robinson: you are leaving the w3c sector!
   // Selections are not properly standardized yet...
@@ -387,7 +451,7 @@
     formElement.selectionEnd = begin;
   } else 
   // IE does it thusly:
-  if (document.selection !== undefined) {
+  if (document.selection) {
     alert("Hey, you are using IE, right? Please get in touch with dev@lenya.apache.org to test this feature!");
     var range = document.selection.createRange();
     var selection = range.text;
@@ -404,3 +468,4 @@
       + snippet.afterSelection;
   }
 }
+

Modified: lenya/trunk/src/modules/editors/usecases/forms/oneform.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/usecases/forms/oneform.jx?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/usecases/forms/oneform.jx (original)
+++ lenya/trunk/src/modules/editors/usecases/forms/oneform.jx Fri Jul 27 07:43:13 2007
@@ -25,11 +25,16 @@
   >
   
   <page:title><i18n:text>Edit</i18n:text></page:title>
+  <page:head>
+    <script type="text/javascript" src="/modules/editors/javascript/org.apache.lenya.editors.js"/>
+    <script type="text/javascript" src="/modules/editors/javascript/oneform_lenya_glue.js"/>
+  </page:head>
   <page:body>
     
+
     <jx:import uri="fallback://lenya/modules/usecase/templates/messages.jx"/>
     
-    <form method="post" id="form-onformeditor">
+    <form method="post" name="oneform">
       <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
       <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
       <jx:choose>
@@ -59,7 +64,7 @@
             </div>
           </div>
           
-          <div class="lenya-box-toggled" style="float: left; margin-right: 10px;">
+          <div class="lenya-box-toggled" style="margin-right: 10px;">
             <div class="lenya-box-title">
               <a href="http://www.w3.org/TR/REC-xml#syntax">Predefined Entities</a>
             </div>
@@ -74,18 +79,24 @@
             </div>
           </div>
           
-          <div style="float: left;">
+          <div style="clear: both;">
             <input type="submit" value="Save" name="submit" i18n:attr="value"/>
             <input type="submit" value="Cancel" name="cancel" i18n:attr="value"/>
-
             <input type="submit" value="Reformat" name="reformat" i18n:attr="value"/>
-
+            <input type="button" value="insertLink.submit" i18n:attr="value"
+              onclick="triggerUsecase('insertLink')"/>
+            <input type="button" value="insertAsset.insertImage" i18n:attr="value"
+              onclick="triggerUsecase('insertImage')"/>
+            <input type="button" value="insertAsset.insertAsset" i18n:attr="value"
+              onclick="triggerUsecase('insertAsset')"/>
           </div>
 
           <div style="clear: both;">
             <jx:choose>
               <jx:when test="${usecase.getParameter('content')}">
-                <textarea name="content" cols="120" rows="80"><jx:out value="${usecase.getParameter('content')}"/></textarea>
+                <textarea name="content" cols="120" rows="80">
+                  <jx:out value="${usecase.getParameter('content')}"/>
+                </textarea>
               </jx:when>
               <jx:otherwise>
                 <cinclude:includexml>

Modified: lenya/trunk/src/modules/editors/usecases/insertAsset.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/usecases/insertAsset.jx?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/usecases/insertAsset.jx (original)
+++ lenya/trunk/src/modules/editors/usecases/insertAsset.jx Fri Jul 27 07:43:13 2007
@@ -24,124 +24,165 @@
   xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
   
   <page:head>
-    <script src="/modules/${usecase.getParameter('editor')}/javascript/insertAsset.js"/>
+    <script type="text/javascript" src="/modules/editors/javascript/org.apache.lenya.editors.js">&#160;</script>
+    <script type="text/javascript" src="/modules/editors/javascript/insertAsset.js">&#160;</script>
   </page:head>
   
+  <!-- This view can handle both insertAsset and insertImage, depending on the setting of the mode parameter ("Asset"|"Image") -->
+  <jx:set var="mode" value="${usecase.getParameterAsString('mode')}"/>
+  
   <page:title>
-    <i18n:text>Insert Asset</i18n:text>
+    <i18n:text>insertAsset.heading<jx:out value="${mode}"/></i18n:text>
   </page:title>
   
   <page:body>
-    
+
+    <form method="POST" name="insertAsset">
+
     <jx:import uri="fallback://lenya/modules/usecase/templates/messages.jx"/>
     
-    <form method="POST" name="image" id="image">
       <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
       <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
       <div class="lenya-box">
-        <div class="lenya-box-title"><i18n:text>Available Assets</i18n:text></div>
+        <div class="lenya-box-title">
+          <i18n:text>insertAsset.available<jx:out value="${mode}"/></i18n:text>
+        </div>
         <div class="lenya-box-body">
+
           <table class="lenya-table-list" style="border: none">
+
             <tr>
               <th style="background: none;"/>
-              <th style="background: none;"><i18n:text>Assets</i18n:text></th>
-              <th style="background: none;"><i18n:text>Preview</i18n:text></th>
-              <th style="background: none;"><i18n:text>Title</i18n:text></th>
-              <th style="background: none;"><i18n:text>File Size</i18n:text></th>
-              <th style="background: none;"><i18n:text>Dimension (w x h)</i18n:text></th>
-              <th style="background: none;"><i18n:text>Creation Date</i18n:text></th>
+              <th style="background: none;"><i18n:text>insertAsset.file</i18n:text></th>
+              <th style="background: none;"><i18n:text>insertAsset.preview</i18n:text></th>
+              <th style="background: none;"><i18n:text>insertAsset.title</i18n:text></th>
+              <th style="background: none;"><i18n:text>insertAsset.fileSize</i18n:text></th>
+              <th style="background: none;"><i18n:text>insertAsset.imageSize</i18n:text></th>
+              <th style="background: none;"><i18n:text>insertAsset.creationDate</i18n:text></th>
             </tr>
+
             <jx:set var="asset2proxyUrl" value="${usecase.getParameter('asset2proxyUrl')}"/>
             <jx:forEach var="asset" items="${usecase.getParameter('assets')}">
-              <jx:set var="url" value="${asset2proxyUrl.get(asset)}"/>
-              <tr>
-                <td>
-                  <input type="radio" name="asset" value="${asset.getPath()}" 
-                    onClick="insertData('${url}', '${asset.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}', '${asset.getMimeType()}', '${asset.getContentLength() / 1000}', '${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('height')}', '${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('width')}')"/> 
-                </td>
-                <td><jx:out value="${asset.getPath()}"/></td>
-                <td>
-                  <jx:set var="mimeType" value="${asset.getMimeType()}"/>
-                  <jx:if test="${mimeType.startsWith('image/')}">
-                    <jx:set var="doc" value="${usecase.getParameter('document')}"/>
-                    <img src="${url}" style="height: 32px; vertical-align: middle; margin: 3px 0px;"/>&#160;
-                  </jx:if>
-                </td>
-                <td><jx:out value="${asset.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}"/></td>
-                <td align="right"><jx:out value="${asset.getContentLength() / 1000}"/> kB</td>
-                <td align="right"><jx:if test="${mimeType.startsWith('image/')}"><jx:out value="${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('width')}"/> x <jx:out value="${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('height')}"/></jx:if></td>
-                <td align="right"><jx:out value="${java.text.DateFormat.getDateInstance().format(asset.getLastModified())}"/></td>
-              </tr>
+              <jx:set var="mimeType" value="${asset.getMimeType()}"/>
+              <jx:if test="${mode.equals('Asset') || mimeType.startsWith('image/')}">
+                <jx:set var="url" value="${asset2proxyUrl.get(asset)}"/>
+                <tr>
+                  <td>
+                    <!-- the +'' is to avoid nulls, which would cause the form field to be disabled -->
+                    <input type="radio" name="asset" value="${asset.getPath()}" 
+                      onClick="updateData(
+                          '${url}',
+                          '${asset.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title') + ''}',
+                          '${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('height') + ''}',
+                          '${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('width') + ''}',
+                          '${asset.getMimeType() + ''}'
+                      )"
+                    /> 
+                  </td>
+                  <td>
+                    <jx:out value="${asset.getPath()}"/>
+                  </td>
+                  <td>
+                    <jx:choose>
+                      <jx:when test="${mimeType.startsWith('image/')}">
+                        <!-- ??? --><jx:set var="doc" value="${usecase.getParameter('document')}"/>
+                        <img src="${url}" style="height: 32px; vertical-align: middle; margin: 3px 0px;"/>&#160;
+                      </jx:when>
+                      <jx:otherwise>
+                        <jx:out value="${mimeType}"/>
+                      </jx:otherwise>
+                    </jx:choose>
+                  </td>
+                  <td>
+                    <jx:out value="${asset.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}"/>
+                  </td>
+                  <td align="right">
+                    <jx:out value="${asset.getContentLength() / 1000}"/> kB
+                  </td>
+                  <td align="right">
+                    <jx:if test="${mimeType.startsWith('image/')}">
+                      <jx:out value="${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('width')}"/> x <jx:out value="${asset.getMetaData('http://apache.org/lenya/metadata/media/1.0').getFirstValue('height')}"/></jx:if>
+                  </td>
+                  <td align="right">
+                    <jx:out value="${java.text.DateFormat.getDateInstance().format(asset.getLastModified())}"/>
+                  </td>
+                </tr>
+              </jx:if>
             </jx:forEach>
+
           </table>
+
           <br/>
+          <input type="hidden" name="url" value=""/>
           <input type="hidden" name="type" value=""/>
-          <input type="hidden" name="assetName" value=""/>
-          <input type="hidden" name="assetSize" value=""/>
           <input type="hidden" name="ratio" value=""/>
           <table class="lenya-table-noborder">
             <tr>
-              <td class="lenya-entry-caption"><label for="caption"><i18n:text>Caption</i18n:text></label>:</td>
-              <td><input class="lenya-form-element" type="text" name="caption"/></td>
+              <td class="lenya-entry-caption">
+                <label for="text"><i18n:text>insertAsset.caption<jx:out value="${mode}"/></i18n:text></label>:
+              </td>
+              <td>
+                <input class="lenya-form-element" type="text" name="text" title=""/>
+              </td>
+            </tr>
+            <tr>
+              <td class="lenya-entry-caption">
+                <label for="title"><i18n:text>insertAsset.title</i18n:text></label>:
+              </td>
+              <td>
+                <input class="lenya-form-element" type="text" name="title" title=""/>
+              </td>
             </tr>
-            <jx:if test="${usecase.getName().equals(usecase.getParameter('editor') + '.insertImage')}">
+
+            <jx:if test="${mode.equals('Image')}">
               <tr>
-                <td class="lenya-entry-caption"><label for="width"><i18n:text>width</i18n:text></label>:</td>
-                <td><input class="lenya-form-element" type="text" name="width" onchange="javascript:scaleHeight(this.value)"/></td>
+                <td class="lenya-entry-caption">
+                  <label for="width"><i18n:text>insertAsset.width</i18n:text></label>:
+                </td>
+                <td>
+                  <input class="lenya-form-element" type="text" name="width" title="" onchange="scaleHeight(this.value)"/>
+                </td>
               </tr>
               <tr>
-                <td class="lenya-entry-caption"><label for="height"><i18n:text>height</i18n:text></label>:</td>
-                <td><input class="lenya-form-element" type="text" name="height" onchange="javascript:scaleWidth(this.value)"/></td>
+                <td class="lenya-entry-caption">
+                  <label for="height"><i18n:text>insertAsset.height</i18n:text></label>:
+                </td>
+                <td>
+                  <input class="lenya-form-element" type="text" name="height" title="" onchange="scaleWidth(this.value)"/>
+                </td>
               </tr>
             </jx:if>
+
             <tr>
               <td colspan="2">
-                <input i18n:attr="value" type="submit" value="Insert"
-                  onClick="javascript:${usecase.getView().getParameter('callbackFunction')}('${usecase.getParameter('document').getName()}');" />
+                <input 
+                  i18n:attr="value" 
+                  type="submit" 
+                  value="insertAsset.insert${mode}"
+                  onclick="org.apache.lenya.editors.handleFormSubmit('insertAsset');" 
+                />
                 &#160;
-                <input i18n:attr="value" type="submit" name="cancel" value="Cancel"
-                  onClick="location.href='javascript:window.close();';" />
+                <input 
+                  i18n:attr="value" 
+                  type="submit" 
+                  name="cancel" 
+                  value="Cancel"
+                  onClick="window.close();" 
+                />
+                &#160;
+                <input 
+                  i18n:attr="value"
+                   type="button"
+                   value="insertAsset.createResource"
+                   onclick="location.href='?doctype=resource&amp;lenya.usecase=editors.createResource&amp;lenya.exitUsecase=${usecase.getName()}'"
+                />
               </td>
             </tr>
           </table>
         </div>
       </div>
+
     </form>
-    
-    <div class="lenya-box">
-      <div class="lenya-box-title"><i18n:text>Upload Asset</i18n:text></div>
-      <div class="lenya-box-body">
-        <jx:if test="${usecase.getParameter('document').getArea().equals('authoring')}">
-          <form method="POST" enctype="multipart/form-data" id="form-add_asset">
-            <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
-            <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
-            
-            <input type="hidden" name="doctype" value="resource"/>
-            <input type="hidden" name="relation" value="child"/>
-            
-            <table class="lenya-table-noborder">
-              <tr>
-                <td colspan="2">
-                  <jx:import uri="fallback://lenya/modules/usecase/templates/messages.jx"/>
-                </td>
-              </tr>
-              <tr>
-                <td class="lenya-entry-caption"><label for="file">
-                  <i18n:text>File</i18n:text> *</label></td>
-                <td><input type="file" name="file" class="lenya-form-element"/></td>
-              </tr>
-              <jx:import uri="fallback://lenya/modules/sitemanagement/usecases/site/createFields.jx"/>
-              <tr>
-                <td/>
-                <td>
-                  <input i18n:attr="value" name="submit" type="submit"
-                    value="New Asset"/>
-                </td>
-              </tr>
-            </table>
-          </form>
-        </jx:if>
-      </div>
-    </div>
+
   </page:body>
 </page:page>

Modified: lenya/trunk/src/modules/editors/xslt/insertLink.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/editors/xslt/insertLink.xsl?view=diff&rev=560251&r1=560250&r2=560251
==============================================================================
--- lenya/trunk/src/modules/editors/xslt/insertLink.xsl (original)
+++ lenya/trunk/src/modules/editors/xslt/insertLink.xsl Fri Jul 27 07:43:13 2007
@@ -120,11 +120,27 @@
               <td colspan="2">&#160;</td>
             </tr>
             <tr>
-              <td/>
-              <td>
-                <input i18n:attr="value" type="submit" value="insertLink.submit" name="input-insert"/>
+              <td colspan="2">
+                <input 
+                  i18n:attr="value" 
+                  type="submit" 
+                  value="insertLink.submit" 
+                  name="input-insert"
+                />
                 &#160;
-                <input i18n:attr="value" type="button" value="insertLink.createResource" onclick="location.href='?doctype=resource&amp;lenya.usecase=resource.create&amp;lenya.exitUsecase=editors.insertLink'"/>
+                <input 
+                  i18n:attr="value"
+                  type="submit"
+                  value="Cancel" 
+                  onclick="window.close()"
+                />
+                &#160;
+                <input 
+                  i18n:attr="value" 
+                  type="button" 
+                  value="insertAsset.createResource" 
+                  onclick="location.href='?lenya.usecase=editors.createResource&amp;doctype=resource&amp;lenya.exitUsecase=editors.insertLink'"
+                />
               </td>
             </tr>
           </table>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org