You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/02/23 01:22:11 UTC
svn commit: r380001 -
/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js
Author: werpu
Date: Wed Feb 22 16:22:06 2006
New Revision: 380001
URL: http://svn.apache.org/viewcvs?rev=380001&view=rev
Log:
fixed
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js?rev=380001&r1=380000&r2=380001&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js Wed Feb 22 16:22:06 2006
@@ -1,3 +1,4 @@
+
/**
* Copyright 2006 The Apache Software Foundation.
*
@@ -13,153 +14,124 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-dojo.provide("org.apache.myfaces.StateChangedNotifier");
-
-org.apache.myfaces.StateChangedNotifier = function(notifierName, formId, hiddenFieldId, message, excludeCommandIdList)
-{
- this.notifierName = notifierName;
- this.formId = formId;
- this.hiddenFieldId = hiddenFieldId;
- this.message = message;
- this.excludeCommandIdList = excludeCommandIdList;
-
- var arrCommandIds = null;
-
- var objectsToConfirmList = new Array();
- var objectsToConfirmBeforeExclusion = new Array();
-
- this.prepareNotifier = function ()
- {
- var form = document.getElementById(formId);
-
- addOnChangeListener("input");
- addOnChangeListener("textarea");
- addOnChangeListener("select");
-
- if (excludeCommandIdList != null)
- {
- arrCommandIds = excludeCommandIdList.split(",");
- addObjectsToConfirmList("a");
- addObjectsToConfirmList("input");
- addObjectsToConfirmList("button");
-
- putConfirmExcludingElements();
- }
- }
-
- this.showMessage = function()
- {
- var hiddenField = getHiddenElement();
-
- if (hiddenField.value == "true")
- {
- //if (!confirm(message)) return false;
- return confirm(message);
- }
-
- return true;
-
- }
-
- function addOnChangeListener(tagName)
- {
-
- var arrElements = document.getElementsByTagName(tagName);
-
- for (var i=0; i<arrElements.length; i++)
- {
- dojo.event.browser.addListener(arrElements[i], "onchange", changeHiddenValue);
- }
-
- }
-
- function addObjectsToConfirmList(tagName)
- {
- var arrElements = document.getElementsByTagName(tagName);
-
- for (var i=0; i<arrElements.length; i++)
- {
- var elementId = arrElements[i].id;
- var onclick = arrElements[i].onclick;
-
- if (elementId != null && onclick != null && elementId != '')
- {
- objectsToConfirmBeforeExclusion.push(elementId);
- }
- }
- }
-
- function putConfirmExcludingElements()
- {
- for (var i=0; i<objectsToConfirmBeforeExclusion.length; i++)
- {
- var elementId = objectsToConfirmBeforeExclusion[i];
-
- if (!isElementExcluded(elementId))
- {
- objectsToConfirmList.push(elementId);
- }
+dojo.require("dojo.debug");
+dojo.require("dojo.html");
+/**
+* central function definition for the state change notifier
+*/
+function org_apache_myfaces_StateChangedNotifier(paramnotifierName, paramformId, paramhiddenFieldId, parammessage, paramexcludeCommandIdList) {
+ dojo.debug("org.apache.myfaces.StateChangedNotifier:begin");
+ this.notifierName = paramnotifierName;
+ this.formId = paramformId;
+ this.hiddenFieldId = paramhiddenFieldId;
+ this.message = parammessage;
+ this.excludeCommandIdList = paramexcludeCommandIdList;
+ this.arrCommandIds = null;
+ this.objectsToConfirmList = new Array();
+ this.objectsToConfirmBeforeExclusion = new Array();
+}
+/**
+* prepares the notifier entry fields
+* and trigger filters
+* for the entire mechanism
+*/
+org_apache_myfaces_StateChangedNotifier.prototype.prepareNotifier = function () {
+ dojo.debug("this.prepareNotifier:begin");
+ dojo.debug(this.excludeCommandIdList);
+ var form = dojo.byId(this.formId);
+ dojo.debug("this.prepareNotifier:formfound" + form);
+ this.addOnChangeListener("input");
+ this.addOnChangeListener("textarea");
+ this.addOnChangeListener("select");
+ if (this.excludeCommandIdList !== null) {
+ dojo.debug(this.excludeCommandIdList);
+ this.arrCommandIds = this.excludeCommandIdList.split(",");
+ this.addObjectsToConfirmList("a");
+ this.addObjectsToConfirmList("input");
+ this.addObjectsToConfirmList("button");
+ this.putConfirmExcludingElements();
+ }
+};
+org_apache_myfaces_StateChangedNotifier.prototype.changeHiddenValue = function (evt) {
+ var hiddenField = dojo.byId(this.hiddenFieldId);
+ hiddenField.value = "true";
+};
+org_apache_myfaces_StateChangedNotifier.prototype.addOnChangeListener = function (tagName) {
+ dojo.debug("addOnChangeListener:" + tagName);
+ var arrElements = document.getElementsByTagName(tagName);
+ dojo.debug("addOnChangeListener arrElements.length" + arrElements.length);
+ for (var i = 0; i < arrElements.length; i += 1) {
+ dojo.debug("adding change listener to:" + arrElements[i].id);
+ dojo.event.connect(arrElements[i], "onchange", this, "changeHiddenValue");
+ }
+};
+org_apache_myfaces_StateChangedNotifier.prototype.addObjectsToConfirmList = function (tagName) {
+ var arrElements = document.getElementsByTagName(tagName);
+ for (var i = 0; i < arrElements.length; i += 1) {
+ var elementId = arrElements[i].id;
+ var onclick = arrElements[i].onclick;
+ if (elementId !== null && onclick !== null && elementId !== "") {
+ this.objectsToConfirmBeforeExclusion.push(elementId);
+ }
+ }
+};
+org_apache_myfaces_StateChangedNotifier.prototype.putConfirmExcludingElements = function () {
+ for (var cnt = 0; cnt < this.objectsToConfirmBeforeExclusion.length; cnt += 1) {
+ var elementId = this.objectsToConfirmBeforeExclusion[cnt];
+ if (!this.isElementExcluded(elementId)) {
+ dojo.debug("adding confirm listener:" + elementId);
+ this.objectsToConfirmList.push(elementId);
+ }
+ }
+ for (var cnt2 = 0; cnt2 < this.objectsToConfirmList.length; cnt2 += 1) {
+ var objectToConfirm = this.objectsToConfirmList[cnt2];
+ this.putConfirmInElement(objectToConfirm);
+ }
+};
+org_apache_myfaces_StateChangedNotifier.prototype.isElementExcluded = function (elementId) {
+ dojo.debug(this.arrCommandIds);
+ if (this.arrCommandIds === null || (this.arrCommandIds.length == 1 && (this.arrCommandIds[0] === null || this.arrCommandIds[0] === ""))) {
+ return false;
+ }
+ for (var i = 0; i < this.arrCommandIds.length; i += 1) {
+ var excludedId = this.arrCommandIds[i];
+ var idRegex = null;
+ if (elementId.indexOf(":") > -1) {
+ idRegex = new RegExp(".*" + excludedId + "([\\d+])?");
+ } else {
+ idRegex = new RegExp(excludedId + "([\\d+])?");
}
-
- for (var i=0; i<objectsToConfirmList.length; i++)
- {
- var objectToConfirm = objectsToConfirmList[i];
- putConfirmInElement(objectToConfirm);
+ if (elementId.match(idRegex) !== null) {
+ return true;
}
}
-
- function changeHiddenValue()
- {
- var hiddenField = getHiddenElement();
- hiddenField.value = "true";
- }
-
- function isElementExcluded(elementId)
- {
- for (var i=0; i<arrCommandIds.length; i++)
- {
- var excludedId = arrCommandIds[i];
- var idRegex = null;
-
- if (elementId.indexOf(":") > -1)
- {
- idRegex = new RegExp(".*"+excludedId+"([\\d+])?")
- }
- else
- {
- idRegex = new RegExp(excludedId+"([\\d+])?")
- }
-
- if (elementId.match(idRegex) != null)
- {
- return true;
- }
- }
+};
+/**
+* builds up a show message function
+* dependend on the correct browser
+*/
+org_apache_myfaces_StateChangedNotifier.prototype.showMessage = function () {
+ var hiddenField = dojo.byId(this.hiddenFieldId);
+ if (hiddenField.value == "true") {
+ //if (!confirm(message)) return false;
+ return confirm(this.message);
}
-
-
- function putConfirmInElement(commandId)
- {
- var command = document.getElementById(commandId);
- if (command != null)
- {
- var onclick = command.getAttribute("onclick");
- var onclickstr = onclick+"";
-
-
- if(dojo.render.html.ie) {
- onclickstr = onclickstr.replace(/function anonymous\(\)/,"");
- onclickstr = "if ("+notifierName+".showMessage()) { "+onclickstr+" }";
-
- command.setAttribute("onclick", new Function("",onclickstr));
- } else {
- command.setAttribute("onclick", "if ("+notifierName+".showMessage()) { "+onclick+" }");
- }
+ return false;
+};
+org_apache_myfaces_StateChangedNotifier.prototype.putConfirmInElement = function (commandId) {
+ var command = dojo.byId(commandId);
+ if (command !== null) {
+ var onclick = command.getAttribute("onclick");
+ var onclickstr = onclick + "";
+ dojo.debug("adding confirm to" + commandId);
+ if (dojo.render.html.ie) {
+ onclickstr = onclickstr.replace(/function anonymous\(\)/, "");
+ onclickstr = "if (" + this.notifierName + ".showMessage()) { " + onclickstr + " }";
+ dojo.debug("onclickst" + onclickstr);
+ command.setAttribute("onclick", new Function("", onclickstr));
+ } else {
+ command.setAttribute("onclick", "if (" + this.notifierName + ".showMessage()) { " + onclick + " }");
}
}
+};
- function getHiddenElement()
- {
- return document.getElementById(hiddenFieldId);
- }
-}
\ No newline at end of file