You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2010/02/20 18:57:09 UTC

svn commit: r912162 - in /incubator/jspwiki/trunk/src/WebContent/scripts: jspwiki-common.js jspwiki-edit.js jspwiki-prefs.js posteditor.js stripes-support.js

Author: ajaquith
Date: Sat Feb 20 17:57:09 2010
New Revision: 912162

URL: http://svn.apache.org/viewvc?rev=912162&view=rev
Log:
Removed posteditor. Moved Stripes AJAX function to jspwiki-common.js. Light cleanup of unneeded functions in prefs/edit JS.

Removed:
    incubator/jspwiki/trunk/src/WebContent/scripts/posteditor.js
    incubator/jspwiki/trunk/src/WebContent/scripts/stripes-support.js
Modified:
    incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js
    incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-edit.js
    incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-prefs.js

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=912162&r1=912161&r2=912162&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js (original)
+++ incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js Sat Feb 20 17:57:09 2010
@@ -764,33 +764,12 @@
 	},
 
 	/*
-	Function: SubmitOnce
-		Disable all form buttons to avoid double submits.
-		At the start, overwrite any {{onbeforeunload}} handler installed by
-		eg. the WikiEdit class.
-
-	Fixme:
-		Replaced by stripes in v3.0 ??
-	*/
-	submitOnce: function(form){
-
-		window.onbeforeunload = null; /* regular exit of this page -- see jspwiki-edit.js */
-		(function(){
-			$A(form.elements).each(function(e){
-				if( (/submit|button/i).test(e.type)) e.disabled = true;
-			});
-		}).delay(10);
-
-		return true;
-	},
-
-	/*
 	Function: submitUpload
 		Support for the upload progressbar.
 		Attached to the attachment upload submit form.
 
 	Returns:
-		Returns via the submitOnce() function.
+		Returns via the form.submit().
 	*/
 	submitUpload: function(form, progress){
 
@@ -805,7 +784,7 @@
 				if(!result.code) bar.getFirst().setStyle('width',result+'%').set('html',result+'%');
 			}]
 		);
-		return self.submitOnce(form);
+		return form.submit();
 	},
 
 	/*
@@ -1447,20 +1426,9 @@
 		$('searchTarget').set('html','('+qv+') :');
 		$('searchSpin').show();
 
-		Wiki.jsonrpc('search.findPages', [qv,20], function(result){
-				$('searchSpin').hide();
-				if(!result.list) return;
-				var frag = new Element('ul');
-
-				result.list.each(function(el){
-					new Element('li').adopt(
-						new Element('a',{'href':Wiki.toUrl(el.map.page) }).set('html',el.map.page),
-						new Element('span',{'class':'small'}).set('html'," ("+el.map.score+")")
-					).inject(frag);
-				});
-				$('searchOutput').empty().adopt(frag);
-				Wiki.locatemenu( $('query'), $('searchboxMenu') );
-		});
+    Stripes.submitFormEvent('searchForm', 'quickSearch', 'searchOutput', null);
+		$('searchSpin').hide();
+		Wiki.locatemenu( $('query'), $('searchboxMenu') );
 	} ,
 
 	/* navigate to url, after smart pagename handling */
@@ -2942,6 +2910,60 @@
 
 });
 
+/*
+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 'eventResponse' variable returned by the AJAX call
+                has an 'html' property whose boolean value is true,
+                the results will be injected into this target div.
+    callback -  a callback function to invoke. The 'eventResponse' variable
+                will be passed to this function. 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 a list of validation errors messages and
+                the 'html' boolean property.
+  */
+  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 HTML response, put results into the div
+        if (eventResponse.html) {
+          $(divTarget).empty();
+          $(divTarget).set('html',eventResponse.results);
+        }
+        // Call the callback function
+        if (callback) {
+          callback(eventResponse);
+        }
+      }
+    });
+    request.send();
+  }
+}
+
 
 /*
 Global: domready

Modified: incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-edit.js
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-edit.js?rev=912162&r1=912161&r2=912162&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-edit.js (original)
+++ incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-edit.js Sat Feb 20 17:57:09 2010
@@ -57,7 +57,8 @@
 		//should always run first, but seems not guaranteed on ie so let's do this for sure
 		Wiki.initialize();
 
-		var txta = $('wikiText'),
+    // Snip-editing is deliberately disabled, for now, because it causes duplication in post contents.
+		var txta = $('wikiTexts'),
 			self = this,
 			snipe,
 			config,
@@ -159,28 +160,6 @@
 		});
 		configFn();
 
-		/*
-			Initialize the preview layout buttons: tile-vert or tile-horz
-		*/
-		tileBtns = $$('.tHORZ','.tVERT');
-		tileFn = function(tile){
-
-			prefs.set('previewLayout',tile);
-			tileBtns.each(function(el){
-				el[( el.get('text')==tile ) ? 'hide': 'show']();
-			});
-
-			tile = (tile=='tile-vert') ? 'size1of1':'size1of2';
-			$('editor-content').getChildren().each(function(el){
-				el.removeClass('size1of1').removeClass('size1of2').addClass(tile);
-			});
-		};
-		tileBtns.each( function(el){
-			el.addEvent( 'click',function(){ tileFn(this.get('text')); });
-		});
-		tileFn( prefs.get('previewLayout')||'tile-vert' );
-
-
 		//add a localized hover title to the resize drag-bar
 		//CHECK !v1.2.3.
 		document.getElement('.editor-container .resize-bar').set('title', 'edit.resize'.localize());
@@ -189,8 +168,6 @@
 		// cursor = -2 (all) or 0..n (section# - first section is 0)
 		tocCursor = location.search.match(/[&?]section=(\d+)/);
 		snipe.selectTocItem( tocCursor ? tocCursor[1].toInt() : -2 );
-
-		self.initializePreview( snipe );
 	},
 
 	/*
@@ -525,75 +502,7 @@
 		};
 
 		return result;
-	},
-
-	/*
-	Function: initializePreview
-		Initialize textarea preview functionality.
-		When #autopreview checkbox is checked, bind the
-		[refreshPreview] handler to the {{preview}} event
-		of the textarea.
-
-		Finally, send periodically the preview event.
-	*/
-	initializePreview: function( snipe ){
-
-		var autopreview = 'autopreview',
-			self = this,
-			prefs = Wiki.prefs,
-			refreshFn = self.refreshPreview.bind(self);
-
-		$(autopreview)
-			.set('checked', prefs.get(autopreview) || false)
-			.addEvent('click', function(){
-				prefs.set(autopreview, this.checked);
-				refreshFn();
-			})
-			.fireEvent('click');
-
-		refreshFn.periodical(3000);
-		$(snipe).addEvent('change',refreshFn);
-    },
-
-
-	/*
-	Function: refreshPreview
-		Make AJAX call to the backend to convert the contents of the textarea
-		(wiki markup) to HTML.
-
-	*/
-	refreshPreview: function(){
-
-    	var	self = this,
-    		snipe = self.snipEditor,
-    		text = snipe.get('textarea').getValue(),
-    		page = Wiki.PageName,
-    		preview = $('livepreview'),
-    		spin = $('previewspin');
-
-
-		if( !$('autopreview').checked ){
-
-			if( self.previewcache ){
-				preview.empty();
-				self.previewcache = null;
-			}
-
-		} else if( self.previewcache != text ){
-
-			self.previewcache = text;
-
-			new Request.HTML({
-				url:Wiki.BaseUrl + "/Edit.action?ajaxPreview=&page=" + page,
-				data: 'wikiText=' + encodeURIComponent( text ),
-				update: preview,
-				onRequest: function(){ spin.show(); },
-				onComplete: function(){ spin.hide(); Wiki.renderPage(preview, page); }
-			}).send();
-
-		}
 	}
-
 }
 
 /*
@@ -608,7 +517,7 @@
 Class: SnipEditor
 	The SnipEditor class enriches a TEXTAREA object with many capabilities,
 	including tab-autocompletion, auto-indentation, smart typing pairs, suggestion
-	popups, live-preview, textarea resizing, toggle buttons etc.
+	popups, textarea resizing, toggle buttons etc.
 	The configuration of the snip-editor is done through Snippet objects.
 	See [getSnippet] for more info on how to define snippets.
 

Modified: incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-prefs.js
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-prefs.js?rev=912162&r1=912161&r2=912162&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-prefs.js (original)
+++ incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-prefs.js Sat Feb 20 17:57:09 2010
@@ -74,10 +74,6 @@
 			for( var el in prefs ){
 				if( p = $(el) ) wikiprefs.set( prefs[el], p.get('value') );
 			};
-
-			//CHECK: covered by stripes ?
-			//Wiki.submitOnce(this);
-
 		});
 
 		/*
@@ -97,111 +93,3 @@
 
 }
 window.addEvent('domready', WikiPreferences.initialize );
-
-// refactor me
-var WikiGroup =
-{
-	MembersID   : "membersfield",
-	GroupID     : "groupfield",
-	NewGroupID  : "newgroup",
-	GroupInfoID : "groupinfo",
-	CancelBtnID : "cancelButton",
-	SaveBtnID   : "saveButton",
-	CreateBtnID : "createButton",
-	DeleteBtnID : "deleteButton",
-	groups      : { "(new)": { members:"", groupInfo:"" } },
-	cursor      : null,
-	isEditOn    : false,
-	isCreateOn  : false,
-
-	putGroup: function(group, members, groupInfo, isSelected){
-		this.groups[group] = { members: members, groupInfo: groupInfo };
-
-		var g = $("grouptemplate");
-			gg = g.clone().removeProperty('id').set('html',group).inject(g.getParent()).show();
-
-		if(isSelected || !this.cursor) this.onMouseOverGroup(gg);
-	} ,
-
-	onMouseOverGroup: function(node){
-		if(this.isEditOn) return;
-		this.setCursor(node);
-
-		var g = this.groups[ (node.id == this.GroupID) ? "(new)": node.innerHTML ];
-		$(this.MembersID).value = g.members;
-		$(this.GroupInfoID).innerHTML = g.groupInfo;
-	} ,
-
-	setCursor: function(node){
-		if(this.cursor) $(this.cursor).removeClass('cursor');
-		this.cursor = $(node).addClass('cursor');
-	} ,
-
-	//create new group: focus on input field
-	onClickNew: function(){
-		if(this.isEditOn) return;
-
-		this.isCreateOn = true;
-		$(this.MembersID).value = "";
-		this.toggle();
-	} ,
-
-	//toggle edit status of Group Editor
-	toggle: function(){
-		this.isEditOn = !this.isEditOn; //toggle
-
-		$(this.MembersID  ).disabled =
-		$(this.SaveBtnID  ).disabled =
-		$(this.CreateBtnID).disabled =
-		$(this.CancelBtnID).disabled = !this.isEditOn;
-		var del = $(this.DeleteBtnID);
-		if(del) del.disabled = this.isCreateOn || !this.isEditOn;
-
-		if(this.isCreateOn) { $(this.CreateBtnID).toggle(); $(this.SaveBtnID).toggle() };
-
-		var newGrp  = $(this.NewGroupID),
-			members = $(this.MembersID);
-
-		if(this.isEditOn){
-			members.getParent().addClass("cursor");
-
-			newGrp.disabled = !this.isCreateOn;
-			if(this.isCreateOn) { newGrp.focus(); } else { members.focus(); }
-		} else {
-			members.getParent().removeClass("cursor");
-
-			if(this.isCreateOn){
-				this.isCreateOn = false;
-				newGrp.value = newGrp.defaultValue;
-				members.value = "";
-			}
-			newGrp.blur();
-			members.blur();
-			newGrp.disabled = false;
-		}
-	} ,
-
-	// submit form to create new group
-	onSubmitNew: function(form, actionURL){
-		var newGrp = $(this.NewGroupID);
-		if(newGrp.value == newGrp.defaultValue){
-			alert("group.validName".localize());
-			newGrp.focus();
-		} else this.onSubmit(form, actionURL);
-	} ,
-
-	// submit form: fill out actual group and members info
-	onSubmit: function(form, actionURL){
-		if(! this.cursor) return false;
-		var g = (this.cursor.id == this.GroupID) ? $(this.NewGroupID).value: this.cursor.innerHTML;
-
-		/* form.action = actionURL; -- doesn't work in IE */
-		form.setAttribute("action", actionURL) ;
-		form.group.value = g;
-		form.members.value = $(this.MembersID).value;
-		form.action.value = "save";
-
-		Wiki.submitOnce(form);
-		form.submit();
-	}
-}
\ No newline at end of file