From e71ed3d0a0098564ca83208e1b74343f0d70df82 Mon Sep 17 00:00:00 2001 From: Jeremy Grelle Date: Fri, 18 Apr 2008 20:16:20 +0000 Subject: [PATCH] Refactoring Spring.js API. --- .../hotels/booking/enterBookingDetails.jsp | 52 +++---- .../src/main/webapp/WEB-INF/hotels/index.jsp | 8 +- .../src/main/webapp/WEB-INF/login.jsp | 25 ++-- .../src/main/webapp/spring/Spring-Dojo.js | 134 +++++++----------- .../src/main/webapp/spring/Spring.js | 124 ++++++++++++++++ 5 files changed, 216 insertions(+), 127 deletions(-) create mode 100644 spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring.js diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.jsp index e562f127..cf04dded 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.jsp @@ -44,10 +44,10 @@ @@ -59,10 +59,10 @@ @@ -87,14 +87,14 @@ @@ -107,10 +107,10 @@ @@ -119,13 +119,13 @@
- +
@@ -161,7 +161,7 @@     diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp index 0d95398a..603453e5 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp @@ -12,10 +12,10 @@ diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp index ef10b0a0..a5fedcd8 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp @@ -32,10 +32,10 @@ value="<%= session.getAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY) %>" /> @@ -45,10 +45,10 @@ @@ -58,10 +58,9 @@ @@ -69,7 +68,7 @@
diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring-Dojo.js b/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring-Dojo.js index 5dc2f25c..6ed99692 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring-Dojo.js +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring-Dojo.js @@ -13,69 +13,53 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -Spring.DojoValidatingFieldAdvisor = function(config){ - - dojo.mixin(this, config); -}; - -Spring.DojoValidatingFieldAdvisor.prototype = { - - targetElId : "", - decoratorType : null, - decorator : null, - decoratorAttrs : null, - copyFields : new Array('name', 'value', 'type', 'checked', 'selected', 'readOnly', 'disabled', 'alt', 'maxLength'), - + +dojo.declare("Spring.ElementDecoration", Spring.AbstractElementDecoration, { + constructor : function(config) { + this.copyFields = new Array('name', 'value', 'type', 'checked', 'selected', 'readOnly', 'disabled', 'alt', 'maxLength'); + dojo.mixin(this, config); + }, + apply : function(){ - if (dijit.byId(this.targetElId)) { - dijit.byId(this.targetElId).destroyRecursive(false); + if (dijit.byId(this.elementId)) { + dijit.byId(this.elementId).destroyRecursive(false); } - var targetEl = dojo.byId(this.targetElId); + var element = dojo.byId(this.elementId); for (var copyField in this.copyFields) { copyField = this.copyFields[copyField]; - if (!this.decoratorAttrs[copyField] && targetEl[copyField] && (typeof targetEl[copyField] != 'number' || (typeof targetEl[copyField] == 'number' && targetEl[copyField] >= 0))) { - this.decoratorAttrs[copyField] = targetEl[copyField]; + if (!this.widgetAttrs[copyField] && element[copyField] && (typeof element[copyField] != 'number' || + (typeof element[copyField] == 'number' && element[copyField] >= 0))) { + this.widgetAttrs[copyField] = element[copyField]; } } - this.decorator = new this.decoratorType(this.decoratorAttrs, targetEl); - this.decorator.startup(); + this.widget = new this.widgetType(this.widgetAttrs, element); + this.widget.startup(); //return this to support method chaining return this; }, validate : function(){ - if (!this.decorator.isValid) { - // some decorators cannot be validated + if (!this.widget.isValid) { + // some widgets cannot be validated return true; } - var isValid = this.decorator.isValid(false); + var isValid = this.widget.isValid(false); if (!isValid) { - this.decorator.state = "Error"; - this.decorator._setStateClass(); + this.widget.state = "Error"; + this.widget._setStateClass(); } return isValid; } -}; +}); -Spring.ValidatingFieldAdvisor = Spring.DojoValidatingFieldAdvisor; - -Spring.DojoRemoteEventAdvisor = function(config){ - dojo.mixin(this, config); -}; - -Spring.DojoRemoteEventAdvisor.prototype = { - - event : "", - targetId : "", - sourceId : "", - formId : "", - processIds : "", - renderIds : "", - params : [], - connection : null, +dojo.declare("Spring.RemoteEventDecoration", Spring.AbstractRemoteEventDecoration, { + constructor : function(config){ + this.connection = null; + dojo.mixin(this, config); + }, apply : function() { - this.connection = dojo.connect(dojo.byId(this.targetId), this.event, this, "submit"); + this.connection = dojo.connect(dojo.byId(this.elementId), this.event, this, "submit"); return this; }, @@ -86,26 +70,20 @@ Spring.DojoRemoteEventAdvisor.prototype = { submit : function(){ Spring.RemotingHandler.submitForm(this.sourceId, this.formId, this.processIds, this.renderIds, this.params); } -}; +}); -Spring.RemoteEventAdvisor = Spring.DojoRemoteEventAdvisor; - -Spring.DojoValidateAllAdvisor = function(config){ - dojo.mixin(this, config); -}; - -Spring.DojoValidateAllAdvisor.prototype = { - - event : "", - targetId : "", - originalHandler : null, - connection : null, +dojo.declare("Spring.ValidateAllDecoration", Spring.AbstractValidateAllDecoration, { + constructor : function(config) { + this.originalHandler = null; + this.connection = null; + dojo.mixin(this, config); + }, apply : function() { - var targetEl = dojo.byId(this.targetId); - this.originalHandler = targetEl[this.event]; + var element = dojo.byId(this.elementId); + this.originalHandler = element[this.event]; var context = this; - targetEl[this.event] = function(event){ + element[this.event] = function(event){ context.handleEvent(event, context); }; return this; @@ -118,20 +96,17 @@ Spring.DojoValidateAllAdvisor.prototype = { handleEvent : function(event, context){ if (!Spring.validateAll()) { dojo.stopEvent(event); - } else { + } else if(dojo.isFunction(context.originalHandler)) { var result = context.originalHandler(event); if (result == false) { dojo.stopEvent(event); } } } -}; +}); -Spring.ValidateAllAdvisor = Spring.DojoValidateAllAdvisor; - -Spring.DojoRemotingHandler = function(){}; - -Spring.DojoRemotingHandler.prototype = { +dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, { + constructor : function(){}, submitForm : function(/*String */ sourceId, /*String*/formId, /*String*/ processIds, /*String*/renderIds, /*Array*/ params) { var content = new Object(); @@ -282,28 +257,21 @@ Spring.DojoRemotingHandler.prototype = { }); dialog.show(); } -}; +}); -Spring.RemotingHandler = new Spring.DojoRemotingHandler(); - -Spring.DojoCommandLinkAdvisor = function(config){ - dojo.mixin(this, config); -}; - -Spring.DojoCommandLinkAdvisor.prototype = { - - targetElId : "", - - linkHtml : "", +dojo.declare("Spring.CommandLinkDecoration", Spring.AbstractCommandLinkDecoration, { + constructor : function(config){ + dojo.mixin(this, config); + }, apply : function(){ - var advisedNode = dojo.byId(this.targetElId); + var advisedNode = dojo.byId(this.elementId); if (!dojo.hasClass(advisedNode, "progressiveLink")) { //Node must be replaced var nodeToReplace = new dojo.NodeList(advisedNode); nodeToReplace.addContent(this.linkHtml, "after").orphan("*"); //Get the new node - advisedNode = dojo.byId(this.targetElId); + advisedNode = dojo.byId(this.elementId); } advisedNode.submitFormFromLink = this.submitFormFromLink; //return this to support method chaining @@ -336,8 +304,6 @@ Spring.DojoCommandLinkAdvisor.prototype = { }); } } -}; +}); -Spring.CommandLinkAdvisor = Spring.DojoCommandLinkAdvisor; - -dojo.addOnLoad(Spring.applyAdvisors); \ No newline at end of file +dojo.addOnLoad(Spring.applyDecorations); \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring.js b/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring.js new file mode 100644 index 00000000..81801aec --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/spring/Spring.js @@ -0,0 +1,124 @@ +/* + * Copyright 2004-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "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. + */ +Spring = {}; + +Spring.decorations = []; + +Spring.decorations.applied = false; + +Spring.applyDecorations = function(){ + if (!Spring.decorations.applied) { + for (var x=0; x