Should rely on the versions in spring-js.jar
This commit is contained in:
@@ -1,309 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
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.elementId)) {
|
||||
dijit.byId(this.elementId).destroyRecursive(false);
|
||||
}
|
||||
var element = dojo.byId(this.elementId);
|
||||
for (var copyField in this.copyFields) {
|
||||
copyField = this.copyFields[copyField];
|
||||
if (!this.widgetAttrs[copyField] && element[copyField] && (typeof element[copyField] != 'number' ||
|
||||
(typeof element[copyField] == 'number' && element[copyField] >= 0))) {
|
||||
this.widgetAttrs[copyField] = element[copyField];
|
||||
}
|
||||
}
|
||||
this.widget = new this.widgetType(this.widgetAttrs, element);
|
||||
this.widget.startup();
|
||||
//return this to support method chaining
|
||||
return this;
|
||||
},
|
||||
|
||||
validate : function(){
|
||||
if (!this.widget.isValid) {
|
||||
// some widgets cannot be validated
|
||||
return true;
|
||||
}
|
||||
var isValid = this.widget.isValid(false);
|
||||
if (!isValid) {
|
||||
this.widget.state = "Error";
|
||||
this.widget._setStateClass();
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
});
|
||||
|
||||
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.elementId), this.event, this, "submit");
|
||||
return this;
|
||||
},
|
||||
|
||||
cleanup : function(){
|
||||
dojo.disconnect(this.connection);
|
||||
},
|
||||
|
||||
submit : function(){
|
||||
Spring.RemotingHandler.submitForm(this.sourceId, this.formId, this.processIds, this.renderIds, this.params);
|
||||
}
|
||||
});
|
||||
|
||||
dojo.declare("Spring.ValidateAllDecoration", Spring.AbstractValidateAllDecoration, {
|
||||
constructor : function(config) {
|
||||
this.originalHandler = null;
|
||||
this.connection = null;
|
||||
dojo.mixin(this, config);
|
||||
},
|
||||
|
||||
apply : function() {
|
||||
var element = dojo.byId(this.elementId);
|
||||
this.originalHandler = element[this.event];
|
||||
var context = this;
|
||||
element[this.event] = function(event){
|
||||
context.handleEvent(event, context);
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
||||
cleanup : function(){
|
||||
dojo.disconnect(this.connection);
|
||||
},
|
||||
|
||||
handleEvent : function(event, context){
|
||||
if (!Spring.validateAll()) {
|
||||
dojo.stopEvent(event);
|
||||
} else if(dojo.isFunction(context.originalHandler)) {
|
||||
var result = context.originalHandler(event);
|
||||
if (result == false) {
|
||||
dojo.stopEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, {
|
||||
constructor : function(){},
|
||||
|
||||
submitForm : function(/*String */ sourceId, /*String*/formId, /*String*/ processIds, /*String*/renderIds, /*Array*/ params) {
|
||||
var content = new Object();
|
||||
var sourceComponent = dojo.byId(sourceId);
|
||||
content['processIds'] = processIds;
|
||||
content['renderIds'] = renderIds;
|
||||
|
||||
if (sourceComponent != null){
|
||||
if(sourceComponent.value) {
|
||||
content[sourceId] = sourceComponent.value;
|
||||
} else {
|
||||
content[sourceId] = sourceId;
|
||||
}
|
||||
}
|
||||
|
||||
dojo.forEach(params, function(param){
|
||||
content[param.name] = param.value;
|
||||
});
|
||||
|
||||
content['ajaxSource'] = sourceId;
|
||||
|
||||
dojo.xhrPost({
|
||||
|
||||
content: content,
|
||||
|
||||
form: formId,
|
||||
|
||||
handleAs: "text",
|
||||
|
||||
headers: {"Accept" : "text/html;type=ajax"},
|
||||
|
||||
// The LOAD function will be called on a successful response.
|
||||
load: this.handleResponse,
|
||||
|
||||
// The ERROR function will be called in an error case.
|
||||
error: this.handleError
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
getLinkedResource: function(/*String */ linkId, /*boolean*/ modal) {
|
||||
this.getResource(dojo.byId(linkId).href, modal);
|
||||
},
|
||||
|
||||
getResource: function(/*String */ resourceUri, /*boolean*/ modal) {
|
||||
|
||||
dojo.xhrGet({
|
||||
|
||||
url: resourceUri,
|
||||
|
||||
handleAs: "text",
|
||||
|
||||
load: this.handleResponse,
|
||||
|
||||
error: this.handleError,
|
||||
|
||||
modal: modal
|
||||
});
|
||||
},
|
||||
|
||||
handleResponse: function(response, ioArgs) {
|
||||
|
||||
//First check if this response should redirect
|
||||
var redirectURL = ioArgs.xhr.getResponseHeader('Flow-Redirect-URL');
|
||||
var modalViewHeader = ioArgs.xhr.getResponseHeader('Flow-Modal-View');
|
||||
var modalView = ((dojo.isString(modalViewHeader) && modalViewHeader.length > 0) || ioArgs.args.modal);
|
||||
|
||||
if (dojo.isString(redirectURL) && redirectURL.length > 0) {
|
||||
if (modalView) {
|
||||
//render a popup with the new URL
|
||||
Spring.RemotingHandler.renderURLToModalDialog(redirectURL, ioArgs);
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
window.location = window.location.protocol + "//" + window.location.host + redirectURL;
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
//Extract and store all <script> elements from the response
|
||||
var scriptPattern = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
|
||||
var extractedScriptNodes = [];
|
||||
var matchAll = new RegExp(scriptPattern, 'img');
|
||||
var matchOne = new RegExp(scriptPattern, 'im');
|
||||
|
||||
var scriptNodes = response.match(matchAll);
|
||||
if (scriptNodes != null)
|
||||
{
|
||||
for (var i=0; i<scriptNodes.length; i++)
|
||||
{
|
||||
var script = (scriptNodes[i].match(matchOne) || ['',''])[1];
|
||||
script = script.replace(/<!--/mg,'').replace(/\/\/-->/mg,'');
|
||||
extractedScriptNodes.push(script);
|
||||
}
|
||||
}
|
||||
response = response.replace(matchAll, '');
|
||||
|
||||
//Extract the new DOM nodes from the response
|
||||
var tempDiv = dojo.doc.createElement("div");
|
||||
tempDiv.id="ajaxResponse";
|
||||
tempDiv.style.visibility= "hidden";
|
||||
document.body.appendChild(tempDiv);
|
||||
var tempContainer = new dojo.NodeList(tempDiv);
|
||||
var newNodes = tempContainer.addContent(response, "first").query("#ajaxResponse > *").orphan();
|
||||
tempContainer.orphan();
|
||||
|
||||
//For a modal view, just dump the new nodes into a modal dialog
|
||||
if (modalView) {
|
||||
Spring.RemotingHandler.renderNodeListToModalDialog(newNodes);
|
||||
}
|
||||
else {
|
||||
|
||||
//Insert the new DOM nodes and update the Form's action URL
|
||||
newNodes.forEach(function(item){
|
||||
if (item.id != null && item.id != "") {
|
||||
var target = dojo.byId(item.id);
|
||||
target.parentNode.replaceChild(item, target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Evaluate any script code
|
||||
dojo.forEach(extractedScriptNodes, function(script){
|
||||
dojo.eval(script);
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
handleError: function(response, ioArgs) {
|
||||
console.error("HTTP status code: ", ioArgs.xhr.status);
|
||||
return response;
|
||||
},
|
||||
|
||||
renderURLToModalDialog: function(url, ioArgs) {
|
||||
url = url + "&"+dojo.objectToQuery(ioArgs.args.content);
|
||||
|
||||
Spring.RemotingHandler.getResource(url, true);
|
||||
},
|
||||
|
||||
renderNodeListToModalDialog: function(nodes) {
|
||||
dojo.require("dijit.Dialog");
|
||||
|
||||
var dialog = new dijit.Dialog({});
|
||||
dialog.setContent(nodes);
|
||||
dojo.connect(dialog, "hide", dialog, function(){
|
||||
this.destroyRecursive(false);
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
dojo.declare("Spring.CommandLinkDecoration", Spring.AbstractCommandLinkDecoration, {
|
||||
constructor : function(config){
|
||||
dojo.mixin(this, config);
|
||||
},
|
||||
|
||||
apply : function(){
|
||||
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.elementId);
|
||||
}
|
||||
advisedNode.submitFormFromLink = this.submitFormFromLink;
|
||||
//return this to support method chaining
|
||||
return this;
|
||||
},
|
||||
|
||||
submitFormFromLink : function(/*String*/ formId, /*String*/ sourceId, /*Array of name,value params*/ params){
|
||||
var addedNodes = [];
|
||||
var formNode = dojo.byId(formId);
|
||||
var linkNode = document.createElement("input");
|
||||
linkNode.name = sourceId;
|
||||
linkNode.value = "submitted";
|
||||
addedNodes.push(linkNode);
|
||||
|
||||
dojo.forEach(params, function(param){
|
||||
var paramNode = document.createElement("input");
|
||||
paramNode.name=param.name;
|
||||
paramNode.value=param.value;
|
||||
addedNodes.push(paramNode);
|
||||
});
|
||||
|
||||
dojo.forEach(addedNodes, function(nodeToAdd){
|
||||
dojo.addClass(nodeToAdd, "SpringLinkInput");
|
||||
dojo.place(nodeToAdd, formNode, "last");
|
||||
});
|
||||
|
||||
if ((formNode.onsubmit ? !formNode.onsubmit() : false) || !formNode.submit()) {
|
||||
dojo.forEach(addedNodes, function(hiddenNode){
|
||||
formNode.removeChild(hiddenNode);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dojo.addOnLoad(Spring.applyDecorations);
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* 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<Spring.decorations.length; x++) {
|
||||
Spring.decorations[x].apply();
|
||||
}
|
||||
Spring.decorations.applied = true;
|
||||
}
|
||||
};
|
||||
|
||||
Spring.validateAll = function(){
|
||||
var valid = true;
|
||||
for(x in Spring.decorations) {
|
||||
if (Spring.decorations[x].widget &&
|
||||
!Spring.decorations[x].validate()) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
};
|
||||
|
||||
Spring.validateRequired = function(){
|
||||
var valid = true;
|
||||
for(x in Spring.decorations) {
|
||||
if(Spring.decorations[x].decorator &&
|
||||
Spring.decorations[x].isRequired() &&
|
||||
!Spring.decorations[x].validate())
|
||||
valid = false;
|
||||
}
|
||||
return valid;
|
||||
};
|
||||
|
||||
Spring.AbstractElementDecoration = function(){};
|
||||
|
||||
Spring.AbstractElementDecoration.prototype = {
|
||||
|
||||
elementId : "",
|
||||
widgetType : null,
|
||||
widget : null,
|
||||
widgetAttrs : {},
|
||||
|
||||
apply : function(){},
|
||||
|
||||
validate : function(){},
|
||||
|
||||
isRequired : function(){}
|
||||
};
|
||||
|
||||
Spring.AbstractValidateAllDecoration = function(){};
|
||||
|
||||
Spring.AbstractValidateAllDecoration.prototype = {
|
||||
|
||||
event : "",
|
||||
elementId : "",
|
||||
|
||||
apply : function() {},
|
||||
|
||||
cleanup : function(){},
|
||||
|
||||
handleEvent : function(event){}
|
||||
};
|
||||
|
||||
Spring.AbstractCommandLinkDecoration = function(){};
|
||||
|
||||
Spring.AbstractCommandLinkDecoration.prototype = {
|
||||
|
||||
elementId : "",
|
||||
linkHtml : "",
|
||||
|
||||
apply : function(){},
|
||||
|
||||
submitFormFromLink : function(/*String*/ formId, /*String*/ sourceId, /*Array of name,value params*/ params){}
|
||||
};
|
||||
|
||||
Spring.AbstractRemoteEventDecoration = function(){};
|
||||
|
||||
Spring.AbstractRemoteEventDecoration.prototype = {
|
||||
|
||||
event : "",
|
||||
elementId : "",
|
||||
sourceId : "",
|
||||
formId : "",
|
||||
processIds : "",
|
||||
params : [],
|
||||
|
||||
apply : function(){},
|
||||
|
||||
cleanup : function(){},
|
||||
|
||||
submit : function(event){}
|
||||
};
|
||||
|
||||
Spring.AbstractRemotingHandler = function(){};
|
||||
|
||||
Spring.AbstractRemotingHandler.prototype = {
|
||||
|
||||
submitForm : function(/*String */ sourceId, /*String*/formId, /*String*/ processIds, /*Array*/ params){},
|
||||
|
||||
getResource : function(/*String */ sourceId, /*String*/ processIds) {},
|
||||
|
||||
handleResponse : function() {},
|
||||
|
||||
handleError : function() {}
|
||||
};
|
||||
Reference in New Issue
Block a user