Author: brushed
Date: Sun Mar 21 15:59:27 2010
New Revision: 925813
URL: http://svn.apache.org/viewvc?rev=925813&view=rev
Log:
v3.0.0-svn-216 : AJAX/JSON fixes.
* EventResolution now returns a static JSON object iso of JavaScriptResolution.
* The Preview functionality is now working through JSON objects.
* Fixed the AttachmentTab so slimbox preview of attachments is working again.
* Fixed the section edit links.
* Fixed the section handling routines.
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js
incubator/jspwiki/trunk/src/WebContent/templates/default/jspwiki.css
incubator/jspwiki/trunk/src/WebContent/templates/default/layout/SearchBox.jsp
incubator/jspwiki/trunk/src/WebContent/templates/default/tabs/AttachmentsTab.jsp
incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Mar 21 15:59:27 2010
@@ -1,3 +1,31 @@
+2010-03-21 Dirk Frederickx <[email protected]>
+
+ * v3.0.0-svn-216 : AJAX/JSON fixes.
+
+ * EventResolution now returns a static JSON object iso of
+ JavaScriptResolution. JSON objects are more safe (no eval)
+ but assume that the converted java beans are acyclical.
+ (which is ok in our case)
+ The overall AJAX/JSON handling is still work in progress.
+
+ * The client javascript is updated accordingly,
+ with a simplified Stripes.submitFormEvent()
+
+ * The Preview functionality is now working through JSON objects.
+
+ * I'm still working on the quick-navigation search functionality.
+ For now, it is broken: the SearchActionBean.quickSearch()
+ needs to some update to use the new json format.
+
+ * Fixed the AttachmentTab so slimbox preview of attachments is
+ working again.
+
+ * Fixed the section edit links.
+
+ * Fixed the section handling routines. Apparently the element with
+ ID="pagecontent" was removed.
+
+
2010-03-19 Andrew Jaquith <ajaquith AT apache DOT org>
* 3.0.0-svn-215
Modified: incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js (original)
+++ incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js Sun Mar 21
15:59:27 2010
@@ -164,7 +164,7 @@ Element.implement({
/*
Function: hide
Hide the element: set 'display' style to 'none'.
- Ref. mootools.1.2.3
+ Ref. mootools.1.2.4
Returns:
(element) - This Element
@@ -177,16 +177,16 @@ Element.implement({
var d;
try {
// IE fails here if the element is not in the dom
- if ((d = this.getStyle('display')) == 'none') d = null;
+ d = this.getStyle('display');
} catch(e){}
- return this.store('originalDisplay', d ||
'block').setStyle('display', 'none');
+ return this.store('originalDisplay', d ||
'').setStyle('display', 'none');
},
/*
Function: show
Show the element: set 'display' style to '' (default display
style)
- Ref. mootools.1.2.3
+ Ref. mootools.1.2.4
Returns:
(element) - This Element
@@ -196,7 +196,8 @@ Element.implement({
*/
show: function(display) {
//return this.setStyle('display','');
- return this.setStyle('display', display ||
this.retrieve('originalDisplay') || 'block');
+ display = display || this.retrieve('originalDisplay') ||
'block';
+ return this.setStyle('display', (display == 'none') ? 'block' :
display);
},
/*
@@ -464,7 +465,7 @@ var Wiki = {
$E('div.tabmenu').id="toptabmenu";
}
- // read all meta elements starting with wiki
+ // read all meta elements prefixed with 'wiki'
$$('meta').each( function(el){
var n = el.get('name') || '';
if( n.indexOf('wiki') == 0 ) this[n.substr(4)] =
el.get('content');
@@ -478,7 +479,9 @@ var Wiki = {
self.prefs = new Hash.Cookie('JSPWikiUserPrefs',
{path:self.BasePath, duration:20});
- self.allowEdit = !!$E('a.edit'); //deduct permission level
+ //FIXME: temporary fixes for v3.0.0 - check for final 'edit'
marker
+ //self.allowEdit = !!$E('a.edit'); //deduct permission level
+ self.allowEdit = !!$('menu-edit'); //deduct permission level
self.url = null;
self.parseHash.periodical(500);
@@ -535,7 +538,10 @@ var Wiki = {
*/
getSections: function(){
- return $$('#pagecontent *[id^=section]').filter(
+
+ //fixme: #pagecontent seems to be removed in v3.0.0 ??
+ // temporary using #view.
+ return $$('#view *[id^=section]').filter(
function(item){ return(item.id != 'section-TOC') }
);
},
@@ -648,7 +654,7 @@ var Wiki = {
/*
Function: setFocus
Set the focus of certain form elements, depending on the
context of the page.
- Protect agains IE6: you can't set the focus on invisible
elements.
+ Protect against IE6: you can't set the focus on invisible
elements.
*/
setFocus: function(){
/* plain.jsp, login.jsp, prefs/profile, prefs/prefs, find */
@@ -1451,28 +1457,73 @@ var SearchBox = {
$('searchOutput').empty();
return;
}
- $('searchTarget').set('html','('+qv+') :');
- $('searchSpin').show();
+ $('searchTarget').set({'class':'spin', html:'('+qv+') :'});
- Wiki.jsonrpc('search.findPages', [qv,20], function(result){
- $('searchSpin').hide();
- if(!result.list) return;
- var frag = new Element('ul');
+ //Wiki.jsonrpc('search.findPages', [qv,20], function(result){
+ Stripes.submitFormEvent('searchForm', 'quickSearch',
'searchOutput', function(response){
- result.list.each(function(el){
+ $('searchTarget').removeClass('spin');
+
+ if(response.results){
+ //fixme: take json as input, not html
+
$('searchOutput').empty().set('html',response.results);
+ //alert(JSON.encode(response.results));
+
+
+ var ul = $('searchOutput'),
+ editurl = Wiki.EditUrl,
+ edit = new Element('a',{
+ 'class':'editsection',
+ html:'quick.edit'.localize()
+ }),
+ clone = new Element('a',{
+ 'class':'editsection',
+ html:'[clone]'
//'quick.clone'.localize()
+ });
+
+ //check first element
+ //if not equal to input: input page does not
exist
+ //Create link with New Page and
+ //add clone links to the suggested pages ??? NOK
+ //alert(editurl);
+ ul.getElements('li').each(function(el){
+ var url = el.getFirst().get('href');
+ //var editurl =
+ //alert(url);
+ el.adopt(
+ edit.set('href', url ).clone(),
+ clone.set('href', url ).clone()
+ )
+ });
+ edit.dispose();
+ clone.dispose();
+
+ /*
+ <li>
+ <a href="view page">page</a>
+ <span class="score">(n)</span>
+ <a class="editsection" href="edit
page">[Edit]</a>
+ <a class="editsection" href="clone
page">[Clone]</a>
+ </li>
+
+
+
+
+ */
+/*
+ var frag = new Element('ul');
+ response.results.list.each(function(el){
new Element('li').adopt(
new
Element('a',{'href':Wiki.toUrl(el.map.page), html:el.map.page }),
new
Element('span',{'class':'small', html:" ("+el.map.score+")" })
).inject(frag);
});
$('searchOutput').empty().adopt(frag);
+*/
+
Wiki.locatemenu( $('query'), $('searchboxMenu')
);
+ }
});
-
- //fixme ??
- //Stripes.submitFormEvent('searchForm', 'quickSearch', 'searchOutput',
null);
- // $('searchSpin').hide();
- // Wiki.locatemenu( $('query'), $('searchboxMenu') );
} ,
/* navigate to url, after smart pagename handling */
@@ -3115,66 +3166,84 @@ var Dialog = new Class({
});
+
/*
Class: Stripes
The main javascript class to support AJAX calls to Stripes ActionBeans.
*/
var Stripes = {
- /*
- Function: submitFormEvent
- Submits a form to its parent ActionBean URL, using a supplied event.
-
- Arguments:
- formName - ID of the form to submit. It will be submitted to the
- action URL supplied by the form element itself. We assume
- this is a Stripes ActionBean URL; for example, this URL
- is likely to be generated by a s:form tag.
- event - the Stripes event handler to invoke. Its name should match
- an event named in a @HandlesEvent method annotation. The
- event method must return an EventResolution, the response
- for which will be eval'ed and be assigned to the variable
- 'eventResponse.' See
org.apache.wiki.ui.stripes.EventResolution.
- divTarget - if the 'callback' function is not supplied, the results
returned
- by the AJAX call will be injected into this target div as a
- single string that includes the HTML representation of any
Stripes
- messages or validation errors prepended, plus the result
object(s).
- The entire string will be wrapped in a <div> whose class is
- "eventResponse".
- callback - a callback function to invoke. The 'eventResponse' variable
- will be passed to this function as a parameter. It contains the
- response object, which can be any primitive type, an array, map
- or anything supported by
net.sourceforge.stripes.ajax.JavaScriptBuilder.
- It also contains two properties that contain HTML
representations of
- any errors or Stripes messages set server-side.
- */
- submitFormEvent: function( formName, event, divTarget, callback ){
- var form = $(formName);
- var url = form.action;
- var params = event + "=&" + form.toQueryString();
- var request = new Request( {
- url: url,
- data: params,
- method: 'post',
- evalResponse: true,
- onComplete: function(response) {
- // If no custom callback function supplied, put results into the div
- if (!callback) {
- var newContent = '<div class="eventResponse">';
- if (eventResponse.errors) { newContent += eventResponse.errors; }
- if (eventResponse.messages) { newContent += eventResponse.messages; }
- if (eventResponse.results) { newContent += eventResponse.results; }
- newContent += "</div>";
- $(divTarget).empty();
- $(divTarget).set('html',newContent);
- }
- // Otherwise, call the callback function
- if (callback) {
- callback(eventResponse);
- }
- }
- });
- request.send();
- }
+
+ /*
+ Function: submitFormEvent
+ Submits a form to its parent ActionBean URL, using a supplied event.
+
+ Arguments:
+ formName - ID of the form to submit. It will be submitted to the
+ action URL supplied by the form element itself. We
assume
+ this is a Stripes ActionBean URL; for example, this URL
+ is likely to be generated by a s:form tag.
+ event - the Stripes event handler to invoke. Its name should
match
+ an event named in a @HandlesEvent method annotation. The
+ event method must return an EventResolution, the
response
+ for which will be eval'ed and be assigned to the
variable
+ 'eventResponse.' See
org.apache.wiki.ui.stripes.EventResolution.
+ divTarget - if the 'callback' function is not supplied, the
results returned
+ by the AJAX call will be injected into this target div
as a
+ single string that includes the HTML representation of
any Stripes
+ messages or validation errors prepended, plus the
result object(s).
+ The entire string will be wrapped in a <div> whose
class is
+ "eventResponse".
+ callback - a callback function to invoke. The 'eventResponse'
variable
+ will be passed to this function as a parameter. It
contains the
+ response object, which can be any primitive type, an
array, map.
+ or anything supported by org.json.JSONObject.
+ It also contains two properties that contain HTML
representations of
+ any errors or Stripes messages set server-side.
+
+ The returned object looks like this:
+
+ (start code)
+ {
+ "class":"class
org.apache.wiki.ui.stripes.EventResolution$Result",
+ "results":"...",
+ "errors":"...",
+ "messages":"..."
+ }
+ (end)
+
+ */
+ submitFormEvent: function( formName, event, divTarget, callback ){
+
+ var form = $(formName);
+
+ new Request.JSON({
+ url: form.action,
+ data: event + "=&" + form.toQueryString(),
+
+ onComplete: function( response ){
+
+ // If no custom callback function supplied, put
results into the div
+ // Otherwise, call the callback function
+ if( $type(callback)=='function' ){
+
+ callback( response, divTarget );
+
+ } else {
+
+ $(divTarget).empty().adopt(
+ new Element('div',{
+ 'class':'eventResponse',
+ html:
['results','errors','messages'].map( function(item){
+ return response[item] || '';
+ })
+ })
+ );
+
+ } /* end if */
+ } /* onComplete */
+ }).send();
+
+ }
}
Modified: incubator/jspwiki/trunk/src/WebContent/templates/default/jspwiki.css
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/jspwiki.css?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/templates/default/jspwiki.css
(original)
+++ incubator/jspwiki/trunk/src/WebContent/templates/default/jspwiki.css Sun
Mar 21 15:59:27 2010
@@ -1643,11 +1643,18 @@ Style: spin
Reusable spin class to show rotating icon to indicate background
processing,
or loading of ajax content.
+ The icon (background image) is positioned at the right-hand side of the
+ enclosing element.
+
+Example:
+> <span class='spin'>(type ahead)</span>
+
*/
.spin {
- background:url(images/spin.gif) no-repeat center;
- height:16px;
- text-indent:20px; /* shift optional text inside spin element */
+ background:url(images/spin.gif) no-repeat 0% 50%;
+ padding-right:16px;
+ xxheight:16px;
+ xxtext-indent:20px; /* shift optional text inside spin element */
}
/*
Modified:
incubator/jspwiki/trunk/src/WebContent/templates/default/layout/SearchBox.jsp
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/layout/SearchBox.jsp?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/WebContent/templates/default/layout/SearchBox.jsp
(original)
+++
incubator/jspwiki/trunk/src/WebContent/templates/default/layout/SearchBox.jsp
Sun Mar 21 15:59:27 2010
@@ -1,4 +1,4 @@
-<%--
+<%--
JSPWiki - a JSP-based WikiWiki clone.
Licensed to the Apache Software Foundation (ASF) under one
@@ -16,7 +16,7 @@
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
- under the License.
+ under the License.
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
@@ -24,7 +24,7 @@
<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" prefix="s" %>
<%@ page errorPage="/Error.jsp" %>
<%-- Provides a simple searchbox that can be easily included anywhere on the
page --%>
-<%-- Powered by jswpwiki-common.js//SearchBox --%>
+<%-- Powered by jspwiki-common.js//SearchBox --%>
<s:form beanclass="org.apache.wiki.action.SearchActionBean" class="wikiform"
id="searchForm" acceptcharset="UTF-8">
@@ -32,7 +32,7 @@
<s:text onblur="if( this.value == '' ) { this.value = this.defaultValue };
return true; "
onfocus="if( this.value == this.defaultValue ) { this.value = ''};
return true; "
name="query" id="query"
- size="20"
+ size="20"
accesskey="f"><fmt:message key='sbox.search.submit'/></s:text>
<s:submit name="search" id="searchSubmit" title="${goTitle}"
value="${goTitle}" />
@@ -44,7 +44,7 @@
<a href="#" id='quickEdit' class='btn'
onclick="SearchBox.navigate( '<s:url
beanclass="org.apache.wiki.action.EditActionBean"><s:param name="page"
value="Main"/></s:url>','<fmt:message key="sbox.edit.title"/>' );"
title="<fmt:message key="sbox.edit.title"/>"><span><span><fmt:message
key="sbox.edit"/></span></span></a>
- <a href="#" id='quickClone' class='btn'
+ <a href="#" id='quickClone' class='btn'
onclick="return SearchBox.navigate( '<s:url
beanclass="org.apache.wiki.action.EditActionBean"><s:param name="page"
value="Main"/></s:url>', '<fmt:message key="sbox.clone.title"/>', true );"
title="<fmt:message key="sbox.clone.title"/>"><span><span><fmt:message
key="sbox.clone"/></span></span></a>
<a href="#" id="advancedSearch" class='btn'
@@ -54,7 +54,6 @@
<div id="searchResult">
<fmt:message key='sbox.search.result' />
<span id="searchTarget"><fmt:message key='sbox.search.target' /></span>
- <span id="searchSpin" class="spin"
style="position:absolute;display:none;"></span>
<div id="searchOutput"></div>
</div>
<div id="recentSearches" style="display:none;">
Modified:
incubator/jspwiki/trunk/src/WebContent/templates/default/tabs/AttachmentsTab.jsp
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/tabs/AttachmentsTab.jsp?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/WebContent/templates/default/tabs/AttachmentsTab.jsp
(original)
+++
incubator/jspwiki/trunk/src/WebContent/templates/default/tabs/AttachmentsTab.jsp
Sun Mar 21 15:59:27 2010
@@ -28,7 +28,7 @@
<wiki:HasAttachments>
<h3><fmt:message key="attach.list" /></h3>
<div class="zebra-table">
- <div class="slimbox-img sortable">
+ <div class="slimbox-image sortable">
<table class="wikitable">
<tr>
<th><fmt:message key="info.attachment.type" /></th>
@@ -48,7 +48,7 @@
<div class="mime ${fn:replace(attachment.contentType,'/','-')}"
/>
</td>
<td title="${attachment.name}">
- <s:link beanclass="org.apache.wiki.action.AttachmentActionBean"
event="download">
+ <s:link beanclass="org.apache.wiki.action.AttachmentActionBean"
class="attachment">
<s:param name="page" value="${attachment.path}" />
${wiki:shorten(attachment.name,30)}
</s:link>
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Sun Mar 21
15:59:27 2010
@@ -77,7 +77,7 @@ public final class Release
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "215";
+ public static final String BUILD = "216";
/**
* This is the generic version string you should use
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
Sun Mar 21 15:59:27 2010
@@ -237,6 +237,13 @@ public class SearchActionBean extends Ab
public Resolution quickSearch()
{
m_results = m_query == null ? NO_RESULTS : doSearch( m_query );
+
+ //FIXME: casting m_results (bean) to 'Object' type seems NOK.
+ // So, for now, still using manual conversion to html
+ // iso straight translation to json object.
+ //
+ //return new EventResolution( getContext(), m_results );
+
String html = null;
StringBuilder b = new StringBuilder();
if( m_results.size() > 0 )
@@ -254,5 +261,6 @@ public class SearchActionBean extends Ab
html = b.toString();
}
return new EventResolution( getContext(), html );
+
}
}
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java?rev=925813&r1=925812&r2=925813&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java
Sun Mar 21 15:59:27 2010
@@ -11,7 +11,9 @@ import javax.servlet.http.HttpServletRes
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.Message;
import net.sourceforge.stripes.action.Resolution;
-import net.sourceforge.stripes.ajax.JavaScriptBuilder;
+
+import org.json.JSONObject;
+
import net.sourceforge.stripes.controller.StripesFilter;
import net.sourceforge.stripes.tag.ErrorsTag;
import net.sourceforge.stripes.tag.MessagesTag;
@@ -219,7 +221,7 @@ public class EventResolution implements
}
}
- private final JavaScriptBuilder m_builder;
+ private final JSONObject m_jsonobject;
/**
* Constructs a new EventResolution for a supplied ActionBeanContext and
@@ -231,7 +233,10 @@ public class EventResolution implements
*/
public EventResolution( ActionBeanContext context, Object... objects )
{
- m_builder = new JavaScriptBuilder( new Result( context, objects ) );
+
+ //FIXME: returning JSON object iso JavascriptResolution
+ m_jsonobject = new JSONObject( new Result(context, objects) );
+
}
/**
@@ -242,9 +247,12 @@ public class EventResolution implements
*/
public void execute( HttpServletRequest request, HttpServletResponse
response ) throws Exception
{
- response.setContentType( "text/javascript" );
- m_builder.setRootVariableName( "eventResponse" );
- m_builder.build( response.getWriter() );
+
+ response.setContentType( "application/json" );
+
+ m_jsonobject.write( response.getWriter() );
+
response.flushBuffer();
+
}
}