[wsas-java-dev] svn commit r3640 - in
trunk/wsas/java/modules/samples/Chad/www: . js xslt
svn at wso2.org
svn at wso2.org
Sun Jun 10 21:50:06 PDT 2007
Author: saminda
Date: Sun Jun 10 21:48:28 2007
New Revision: 3640
Removed:
trunk/wsas/java/modules/samples/Chad/www/js/wso2wsas.js
Modified:
trunk/wsas/java/modules/samples/Chad/www/index.html
trunk/wsas/java/modules/samples/Chad/www/js/chad.js
trunk/wsas/java/modules/samples/Chad/www/xslt/administrators.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/create_poll.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls_admin.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_admin.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_all.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/list_stopped_polls.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/results.xsl
trunk/wsas/java/modules/samples/Chad/www/xslt/vote.xsl
Log:
1. Chad used WSRequst
2. Cleanup the code in chad.js and it is now follow OO
3. Cleanup the xls
4. Cleanup the back button handling code
Modified: trunk/wsas/java/modules/samples/Chad/www/index.html
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/index.html (original)
+++ trunk/wsas/java/modules/samples/Chad/www/index.html Sun Jun 10 21:48:28 2007
@@ -22,14 +22,15 @@
<link rel="stylesheet" type="text/css" href="extensions/core/css/wso2wsas.css" media="screen, projection"></link>
<link rel="stylesheet" type="text/css" href="extensions/core/css/chad.css" media="screen, projection"></link>
- <script language="javascript" src="extensions/core/js/wso2wsas.js"></script>
<script language="javascript" src="extensions/core/js/chad.js"></script>
<script language="javascript" src="extensions/core/js/progressbar.js"></script>
-
<script language="javascript" src="js/main.js"></script>
+ <script language="javascript" src="js/WSRequest.js"></script>
<script language="javascript" src="js/dhtmlHistory.js"></script>
- </head>
- <body onload="javascript:initChad();">
+ <script language="javascript" src="global_params.js"></script>
+
+ </head>
+ <body onload="javascript:wso2.wsas.Chad.static.init();">
<div id="wrapper">
<div id="header">
@@ -45,17 +46,17 @@
<div id="menuChad1">
<ul class="submenu">
<li></li>
- <li><a id="menu_active_polls" href="#" onclick="javascript:showActivePolls(); return false;" title="Active Chad Polls"> Active Polls</a></li>
+ <li><a id="menu_active_polls" href="#" onclick="javascript:chadInstance.showActivePolls(); return false;" title="Active Chad Polls"> Active Polls</a></li>
</ul>
</div>
<div id="menuChad">
<ul id="menuChad" class="submenu">
<li></li>
- <li><a id="menu_active_polls" href="#" onclick="javascript:showActivePolls(); return false;" title="Active Chad Polls"> Active Polls</a></li>
- <li><a id="menu_create_poll" href="#" onclick="javascript:createPoll(); return false;" title="Create Poll"> Create Poll</a></li>
- <li><a id="menu_list_poll" href="#" onclick="javascript:listAllPollsAdmin(); return false;" title="List Polls"> All Polls</a></li>
- <li><a id="menu_stopped_polls" href="#" onclick="javascript:listStoppedPolls(); return false;" title="List stopped Poll"> Stopped Polls</a></li>
- <li><a id="menu_adminstrators" href="#" onclick="javascript:showAdminstrators(); return false;" title="Administrators" > Administrators</a></li>
+ <li><a id="menu_active_polls" href="#" onclick="javascript:chadInstance.showActivePolls(); return false;" title="Active Chad Polls"> Active Polls</a></li>
+ <li><a id="menu_create_poll" href="#" onclick="javascript:chadInstance.createPoll(); return false;" title="Create Poll"> Create Poll</a></li>
+ <li><a id="menu_list_poll" href="#" onclick="javascript:chadInstance.listAllPollsAdmin(); return false;" title="List Polls"> All Polls</a></li>
+ <li><a id="menu_stopped_polls" href="#" onclick="javascript:chadInstance.listStoppedPolls(); return false;" title="List stopped Poll"> Stopped Polls</a></li>
+ <li><a id="menu_adminstrators" href="#" onclick="javascript:chadInstance.showAdminstrators(); return false;" title="Administrators" > Administrators</a></li>
</ul>
</div>
</div><!-- /navigation -->
@@ -81,7 +82,7 @@
<p>Default username/password is admin/admin</p>
<div><label for="txtUserName">Username:</label> <input type="text" id="txtUserName" name="txtUserName" size="10"/></div>
<div><label for="txtPassword">Password:</label> <input type="password" id="txtPassword" name="txtPassword" size="10"/></div>
- <div><input id="signin" type="submit" value="Sign In" onclick="javascript:chadLogin(document.chadFormLogin.txtUserName.value, document.chadFormLogin.txtPassword.value);return false;"/></div>
+ <div><input id="signin" type="submit" value="Sign In" onclick="javascript:wso2.wsas.Chad.static.login(document.chadFormLogin.txtUserName.value, document.chadFormLogin.txtPassword.value);return false;"/></div>
</fieldset>
</form>
</div>
Modified: trunk/wsas/java/modules/samples/Chad/www/js/chad.js
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/js/chad.js (original)
+++ trunk/wsas/java/modules/samples/Chad/www/js/chad.js Sun Jun 10 21:48:28 2007
@@ -1,10 +1,4 @@
-var chadURL;
-var chadServiceURL;
-var _url;
-var chadXhReq;
-
/*Adminstration check varaiable*/
-
var isAuthorized = false;
var adminUserInUse;
@@ -13,846 +7,711 @@
var currentPollId;
-/*
- ****************************************
- Setting for ServiceURL
- ****************************************
- Thus can be found in the WSO2WSAS_HOME/conf/axis2.xml. See the relevant segment
- in this file below
-
- <!-- setting contextPath and servicePath-->
- <parameter name="contextRoot" locked="false">/</parameter>
- <parameter name="servicePath" locked="false">services</parameter>
+/**
+ * chadInstance {wso2.wsas.Chad} instance.
+ */
+var chadInstance;
-*/
-var CONTEXT_PATH_DEFAULT = "/";
-var SERVICE_PATH_DEFAULT = "services";
-var contextPath = CONTEXT_PATH_DEFAULT;
-var servicePath = SERVICE_PATH_DEFAULT;
+/**
+ * Namespace qualifying. Chad will come under wso2.wsas
+ */
+if (typeof(wso2) == "undefined") {
+ var wso2 = {};
+}
-var serviceURL =
- (contextPath != "/")? ( contextPath + "/" + servicePath +"/") : "/" + servicePath + "/";
+wso2["wsas"] = wso2["wsas"] || {};
-// This version assumes that the communication between the server and the client happens in an unsecure manner.
-function sendUnsecured(operationName, body_xml, xslFileName, callURL, objDiv, callBack) {
- chadXhReq = createXMLHttpRequest();
- if (callBack != null){
- chadXhReq.onreadystatechange = callBack;
- } else {
- chadXhReq.onreadystatechange = function() {
- if (!non_auth_check_error()) {
- return;
- }
-// alert("XML = " + (new XMLSerializer()).serializeToString(chadXhReq.responseXML));
- //alert("Response" + (new XMLSerializer()).serializeToString(getBody(xhReq.responseXML)));
- if (xslFileName != "" && objDiv != null){
- var data = getBody(chadXhReq.responseXML);
-// alert("Response" + xmlSerializerToString(data));
- processXML(data, xslFileName, objDiv);
- showOnlyOneMain(objDiv);
- }
- };
- }
- try {
- chadXhReq.open("POST", callURL, true);
- } catch(e){
+/*Chad's constrctor */
+wso2.wsas.Chad = function() {
+ wso2.wsf.Util.initURLs();
+ this.req = null;
+ this._options = new Object();
+ this._options["useBindng"] = "SOAP 1.2";
+ this.onLoad = null;
+ this.onError = null;
+ this._chadServiceURL = serverURL + "/Chad";
+}
- alertWarning("Error while opening connection. ERROR message = " + e.message);
- return false;
- }
- chadXhReq.setRequestHeader('Content-Type', "text/xml");
- chadXhReq.setRequestHeader("SOAPAction", operationName);
+wso2.wsas.Chad.prototype = {
+/*
+This method always invoke asynchronously. Thus, onLoad method should be given.
+*/
+ send : function(action, xmlPayload, onLoad, onError) {
+
+ try {
+ this.onLoad = (onLoad) ? onLoad : this._defaultOnload;
+ this.onError = (onError) ? onError : this._defaultError;
+
+ this.req = new WSRequest();
+ var _loader = this;
+ this.req.onreadystatechange = function() {
+ _loader._onReadyState.call(_loader);
+ }
+ this._options["action"] = action;
+ this.req.open(this._options, this._chadServiceURL, true);
+ this.req.send(xmlPayload);
+ } catch(e) {
+ wso2.wsf.Util.alertWarning("Errors encountered when connecting to the server. " +
+ e.toString());
+
+ }
- var xml_to_send = '<?xml version="1.0" encoding="UTF-8"?>' +
- ' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
- ' <soapenv:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">';
- xml_to_send +=' <wsa:To>' + callURL + '</wsa:To>' +
- ' <wsa:Action>' + operationName + '</wsa:Action>' +
- ' <wsa:ReplyTo>' +
- ' <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>' +
- ' </wsa:ReplyTo>' +
- ' <wsa:MessageID>uuid:BABE23A9BE85EA7AE011327368520801</wsa:MessageID>' +
- ' </soapenv:Header>' +
- ' <soapenv:Body>'+ body_xml +
- ' </soapenv:Body>' +
- ' </soapenv:Envelope>';
-
- chadXhReq.send(xml_to_send);
-}
+ },
-function onErrorUnsecured(){
- if (chadXhReq.readyState != 4) { return false ; }
- var wso2wsasError = "";
- var wso2wsasErrorMessage = "";
- try {
- if (chadXhReq.status != 200 && chadXhReq.status != 202) {
-// alert((new XMLSerializer()).serializeToString(chadXhReq.responseXML));
- if (chadXhReq.responseXML != null){
- if (chadXhReq.responseXML.getElementsByTagName("Reason")[0] != null) {
- wso2wsasErrorMessage = chadXhReq.responseXML.getElementsByTagName("Reason")[0].childNodes[0].nodeValue;
- } else {
- if (chadXhReq.responseXML.getElementsByTagName("faultstring")[0] != null) {
- wso2wsasErrorMessage = chadXhReq.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue;
- }
- }
- var errNode = getExceptionNode(chadXhReq.responseXML);
- if (errNode != null){
- try {
- wso2wsasError = (new XMLSerializer()).serializeToString(errNode);
- } catch (e) {
- try{
- wso2wsasError = errNode.xml;
- } catch(e) {
- wso2wsasErrorMessage = "The Chad application encountered an error and the browser you are using does not suport the error reporting code. \n" +
- "Logging in again should fix this, since the most common error is the a session time out error.";
- alertWarning(wso2wsasErrorMessage);
- return false;
- }
- }
- /*if (wso2wsasError.indexOf("Invalid Service Group Id") != -1){
- alertMessage("Your session has expired please login.");
- logoutVisual();
- return false;
- }*/
- } else {
- wso2wsasErrorMessage =
- "\n The Chad application encountered an unknown error.";
+ _onReadyState : function() {
+ try {
+ var ready = this.req.readyState;
+ if (ready == 4) {
+ var status = this.req._xmlhttp.status;
+ if ((status == 200 || status == 202)) {
+ this.onLoad.call(this);
+ } else if (status >= 400) {
+ this.onError.call(this);
}
- } else {
-// logoutVisual();
- alertWarning("Your session has expired please login");
- return false;
}
- alertWarning(wso2wsasErrorMessage);
-// alert((new XMLSerializer()).serializeToString(errNode))
- return false;
+ } catch(e) {
+ wso2.wsf.Util.alertWarning("Errors encountered when processing the response XML. " +
+ e.toString());
}
- } catch(e){
- if (!restarting_the_server){
- if (e.message.indexOf("NS_ERROR_NOT_AVAILABLE")>0){
- alertWarning("Could not connect to the server. Please try again in a moment.");
- return false;
- } else {
- alertWarning("An unknown error occured. In line number " + e.lineNumber + " the error message was " + e.message);
- return false;
- }
- } else {
- alertMessage("The server is being restarted. <br/> Please login in a few seconds.");
- restarting_the_server = false;
- }
- }
- return true;
-}
-
+ },
+ initLogin : function() {
+ var loginString = "<a href=\"#\" onclick=\"javascript:wso2.wsas.Chad.static.fireLogin();return false;\">Adminstrator Login</a>";
+ document.getElementById("meta").innerHTML = loginString;
+ document.getElementById('menuChad').style.display = 'none';
+ document.getElementById('menuChad1').style.display = 'inline';
+ },
+
+ _defaultError : function () {
+ var error = this.req.error;
+ if (!error) {
+ wso2.wsf.Util.alertMessage("Console has received an error. Please refer" +
+ " to system admin for more details.");
+ return;
+ }
-function initChad(){
- chadURL = locationString.substring(0, locationString.lastIndexOf('/'));
+ wso2.wsf.Util.alertMessage("Reason : " + error.reason);
+ },
- if (chadURL.lastIndexOf('wservices') > 0) {
- chadServiceURL = chadURL.substring(0, chadURL.lastIndexOf('wservices') - 1);
- _url = chadServiceURL;
- } else {
- chadServiceURL = chadURL.substring(0, chadURL.lastIndexOf('Chad') - 1);
- _url = chadServiceURL;
- }
- if (wso2wsas_war_name != "") {
- chadServiceURL += "/" + wso2wsas_war_name;
- }
+ _defaultOnload : function() {
+ //Do nothing.
+ },
- chadServiceURL += serviceURL + "Chad";
- if (servicePath == "" || servicePath == null ) {
- alertWarning("Service path is not specified.\n"+
- "Please specify the 'servicePath' variable in 'main.js' to proceed");
- return false;
- }
+ listAllPolls : function () {
+ var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
+ this.send("listPolls", body_xml, listPollsAllCallback);
+ },
-// initialize();
- URL = _url + "/wservices/Chad";
+ listActivePollsAdmin : function() {
+ var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
+ this.send("listPolls", body_xml, listActivePollsAdminCallback);
- initLogin();
+ },
- listAllPolls();
-}
+ showActivePolls : function() {
+ if (isAuthorized) {
+ this.listActivePollsAdmin();
+ } else {
+ this.listAllPolls();
+ }
-function initDhtmlHistory() {
- /*intitialize the hashing*/
- runPoleHash = true;
- // initialize our DHTML history
- dhtmlHistory.initialize();
- // subscribe to DHTML history change
- // events
- historyStorage.reset();
- dhtmlHistory.addListener(handleHistoryChangeChad);
+ },
-}
+ createPoll : function() {
+ /*
+ CreatePoll with xsl
+ */
+
+ var tmpTransformationNode;
+
+ if (window.XMLHttpRequest && !wso2.wsf.Util.isIE()) {
+ tmpTransformationNode =
+ document.implementation.createDocument("", "createPoll", null);
+ } else if (wso2.wsf.Util.isIEXMLSupported()) {
+ tmpTransformationNode = new ActiveXObject("Microsoft.XmlDom");
+ var sXml = "<createPoll></createPoll>";
+ tmpTransformationNode.loadXML(sXml);
+ } else {
+ wso2.wsf.Util.alertWarning("This browser does not support XML");
+ return;
+ }
+ var objDiv = document.getElementById("divCreatPoll");
+ wso2.wsf.Util.processXML(tmpTransformationNode, "create_poll.xsl", objDiv);
+ wso2.wsf.Util.showOnlyOneMain(objDiv);
-/** A function that is called whenever the user
- presses the back or forward buttons. This
- function will be passed the newLocation,
- as well as any history data we associated
- with the location. */
-function handleHistoryChangeChad(newLocation,
- historyData) {
- if (!isAuthorized) {
- return;
- }
- var actDivName = newLocation.substring(3, newLocation.length);
- // This is done to stop the screen from jumping about.
- eval("showOnlyOneMain(document.getElementById('" + actDivName + "'), true)");
- // lastHash from mf_ui; main.js
- lastHash = newLocation;
-}
+ },
-function listAllPolls() {
+ listAllPollsAdmin : function() {
+ var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
- var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
+ this.send("listPolls", body_xml, listAllPollsAdminCallback);
- sendUnsecured("listPolls", body_xml, "", chadServiceURL, "",listPollsAllCallback);
+ },
-}
+ listStoppedPolls : function() {
+ var body_xml = '<req:getStoppedPolls xmlns:req="http://www.wso2.org/types"/>';
+ this.send("getStoppedPolls", body_xml, listStoppedPollsPollsCallback);
+ },
-function listPollsAllCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("list_polls_all.xsl",document.getElementById("divChadListPolls"));
+ showAdminstrators : function () {
+ var body_xml = '<req:listAdminUsers xmlns:req="http://www.wso2.org/types"/>';
+ this.send("listAdminUsers", body_xml, listAdminUsersCallback);
+ },
-}
+ createPollSave : function() {
+ if (!this._createPollSaveValidator()) {
+ return false;
-function listAllPollsAdmin() {
- var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
+ }
+ var body_xml = '<req:createPoll xmlns:req="http://www.wso2.org/types">\n' +
+ '<req:title><![CDATA[' + document.getElementById("txtPollTitle").value +
+ ']]></req:title>\n' +
+ '<req:description><![CDATA[' +
+ document.getElementById("txtPollDescription").value +
+ ']]></req:description>\n' +
+ '<req:isSingleVote>' + document.getElementById("cmbPollSingleVote").value +
+ '</req:isSingleVote>\n';
+ var inputs = document.getElementById("frmCreatePoll").getElementsByTagName("input");
+ var count;
+ for (count = 0; count < inputs.length; count++) {
+ if (inputs[count].attributes.getNamedItem("name") != null) {
+ if (inputs[count].attributes.getNamedItem("name").nodeValue == "txtPollChoices") {
+ body_xml += '<req:choices>' + inputs[count].value + '</req:choices>\n';
+ }
+ }
+ }
+ body_xml += '</req:createPoll>\n';
+ this.send("createPoll", body_xml, createPollSaveCallback);
- sendUnsecured("listPolls", body_xml, "", chadServiceURL, "",listAllPollsAdminCallback);
-}
+ },
-function listAllPollsAdminCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("list_polls_admin.xsl",document.getElementById("divAllPolls"));
-}
+ _createPollSaveValidator : function() {
+ var titleObj = document.getElementById('txtPollTitle');
-function listActivePollsAdmin() {
- var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
- sendUnsecured("listPolls", body_xml, "", chadServiceURL, "",listActivePollsAdminCallback);
-}
+ var titleObjValue = "";
+ titleObjValue = titleObj.value;
-function listActivePollsAdminCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("list_active_polls_admin.xsl",document.getElementById("divChadListPolls"));
-}
+ if (wso2.wsf.Util.trim(titleObjValue) == "" || titleObjValue == null) {
+ wso2.wsf.Util.alertWarning("Please enter a valid title.");
+ return false;
-function listActivePolls() {
- var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
- sendUnsecured("listPolls", body_xml, "", chadServiceURL, "",listActivePollsCallback);
-}
+ }
-function listActivePollsCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("list_active_polls.xsl",document.getElementById("divChadListPolls"));
-}
+ var choicesObj = document.getElementsByName('txtPollChoices');
+ var numOfValidChoices = 0;
+ for (var i = 0; i < choicesObj.length; i++) {
+ if (wso2.wsf.Util.trim(choicesObj[i].value) != "") {
+ numOfValidChoices ++;
+ }
+ }
+ if (numOfValidChoices < 2) {
+ wso2.wsf.Util.alertWarning("A valid poll should contain more than one choice. <br/>Please add at least two choices.");
+ return false;
+ }
+ return true;
-function initLogin() {
- /*
- Login settings
- */
- var loginString = "<a href=\"#\" onclick=\"javascript:fireLogin();return false;\">Adminstrator Login</a>";
- document.getElementById("meta").innerHTML = loginString;
- document.getElementById('menuChad').style.display = 'none';
- document.getElementById('menuChad1').style.display = 'inline';
-}
-
-function showChadLogout() {
- /*logout setting */
- var loginString = "<a href=\"#\" onclick=\"javascript:fireLogin();return false;\">Adminstrator Login</a>";
- document.getElementById("meta").innerHTML = loginString;
- document.getElementById('menuChad').style.display = 'none';
- document.getElementById('menuChad1').style.display = 'inline';
+ },
- /*Logout SOAP Call */
- var body_xml = '<req:logout xmlns:req="http://www.wso2.org/types"/>';
- sendUnsecured("logout", body_xml, "", chadServiceURL, "",showChadLogoutCallback);
+ showVoteScreen : function(pollId) {
+ currentPollId = pollId;
+ var body_xml = '<req:getResultMessage xmlns:req="http://www.wso2.org/types">\n' +
+ '<pollID>' + pollId + '</pollID>\n' +
+ '</req:getResultMessage>\n';
+ this.send("getResult", body_xml, showVoteScreenCallback);
-}
+ },
-function showChadLogoutCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- isAuthorized = false;
- runPoleHash = false;
- historyStorage.reset();
- listAllPolls();
-}
+ getCurrentPollId : function() {
+ return currentPollId;
+ },
-function showChadLogin() {
- /*
- Login settings
- */
- var loginString =
- "Signed in as "+getCurrentLoginAdmin()+" | <a href=\"#\" onclick=\"javascript:showChadLogout();return false;\">Sign Out</a>";
- document.getElementById("meta").innerHTML = loginString;
- document.getElementById('menuChad').style.display = 'inline';
- document.getElementById('menuChad1').style.display = 'none';
+ viewPollDetailsForVoted : function(pollId) {
+ var body_xml = '<req:getResultMessage xmlns:req="http://www.wso2.org/types">\n' +
+ '<pollID>' + pollId + '</pollID>\n' +
+ '</req:getResultMessage>\n';
+ this.send("getResult", body_xml, viewPollDetailsForVotedCallback);
- /*Cleraring the Password fileld*/
- document.chadFormLogin.txtPassword.value = '';
-}
+ },
-function fireLogin() {
- var obj = document.getElementById('divLogincontainer');
- showOnlyOneMain(obj,true);
-}
-function chadLogin(userNameValue,passwordValue) {
+ vote : function(pollId) {
+ var body_xml = '<req:vote xmlns:req="http://www.wso2.org/types">\n' +
+ '<req:pollID>' + pollId + '</req:pollID>\n';
+ var choicesSelected = document.getElementsByName("selectBoxForVotes");
+ var count;
+ var currentChoice;
+ for (count = 0; count < choicesSelected.length; count++) {
+ currentChoice = choicesSelected[count];
+ // alert(currentChoice.checked + " " + count + currentChoice.id);
+ if (currentChoice.checked) {
+ body_xml += '<req:choices>' + currentChoice.id + '</req:choices>\n';
+ }
+ }
- currentLoginAdmin = userNameValue;
+ body_xml += '</req:vote>\n';
+ // alert(body_xml);
+ this.send("vote", body_xml, voteCallback);
- var body_xml = '<req:login xmlns:req="http://www.wso2.org/types">' +
- '<req:username><![CDATA['+userNameValue+']]></req:username>'+
- '<req:password><![CDATA['+passwordValue+']]></req:password>'+
- '</req:login>';
+ },
- sendUnsecured("login", body_xml, "", chadServiceURL, "", chadLoginCallback);
-}
+ listActivePolls : function() {
+ var body_xml = '<req:listPollsMessage xmlns:req="http://www.wso2.org/types"/>';
+ this.send("listPolls", body_xml, listActivePollsCallback);
+ },
-function chadLoginCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- if (chadXhReq.responseXML.getElementsByTagName("return")[0] != null){
- if (chadXhReq.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue == "true"){
-// alertMessage("Login Successful");
- isAuthorized = true;
- showChadLogin();
- // place to init the history
- initDhtmlHistory();
- listActivePollsAdmin();
- } else {
- alertWarning("Login failed!");
- isAuthorized = false;
- listAllPolls();
+ changePassword : function(password, rePassword, oldPassword) {
+ if (!this._changePasswordValidator(password, rePassword, oldPassword)) {
+ return false;
}
- }
+ var body_xml = '<req:changePassword xmlns:req="http://www.wso2.org/types">' +
+ '<username><![CDATA[' + this.getAdminUserInUse() + ']]></username>' +
+ '<oldPassword><![CDATA[' + oldPassword + ']]></oldPassword>' +
+ '<newPassword><![CDATA[' + password + ']]></newPassword>' +
+ '</req:changePassword>';
+ this.send("changePassword", body_xml, changePasswordCallback);
+ },
-}
+ getAdminUserInUse : function() {
+ return adminUserInUse;
-function showActivePolls() {
- if (isAuthorized) {
- listActivePollsAdmin();
- } else {
- listAllPolls();
- }
-}
+ },
-//@private helper method
-function chadCallbackHelper(xsltFile, objDiv, doNotLoadDiv) {
- var xml = getBody(chadXhReq.responseXML);
- processXML(xml, xsltFile, objDiv);
- if (!doNotLoadDiv){
- showOnlyOneMain(objDiv);
- }
+ getCurrentLoginAdmin : function() {
+ return currentLoginAdmin;
-}
+ },
-function listStartedPolls() {
- var body_xml = '<req:getStartedPolls xmlns:req="http://www.wso2.org/types"/>';
- sendUnsecured("getStartedPolls", body_xml, "", chadServiceURL, "", listStartedPollsCallback);
+ _changePasswordValidator : function(password, rePassword, oldPassword) {
+ if (password == null || wso2.wsf.Util.trim(password) == "") {
+ wso2.wsf.Util.alertWarning("Please enter the new password.");
+ return false;
+ }
-}
+ if (rePassword == null || rePassword == "") {
+ wso2.wsf.Util.alertWarning("Please re-enter the password.");
+ return false;
+ }
-function listStartedPollsCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("list_polls_admin.xsl",document.getElementById("divChadStartedPolls"));
-}
+ if (oldPassword == null || oldPassword == "") {
+ wso2.wsf.Util.alertWarning("Please enter the old password.");
+ return false;
+ }
-function listStoppedPolls() {
+ if (password != rePassword) {
+ wso2.wsf.Util.alertWarning("The new password and the re-entered password do not match.");
+ return false;
+ }
+ return true;
- var body_xml = '<req:getStoppedPolls xmlns:req="http://www.wso2.org/types"/>';
- sendUnsecured("getStoppedPolls", body_xml, "", chadServiceURL, "",listStoppedPollsPollsCallback);
+ },
-}
+ addAdminUser : function(userNameObj, passwordObj, rePasswordObj) {
+ var userNameValue = userNameObj.value;
+ var passwordValue = passwordObj.value;
+ var rePasswordValue = rePasswordObj.value;
-function listStoppedPollsPollsCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("list_stopped_polls.xsl",document.getElementById("divChadStopedPolls"));
-}
+ if (!this._validateAddAdminUser(userNameValue, passwordValue, rePasswordValue)) {
+ return false;
+ }
+ var body_xml = '<req:addAdminUser xmlns:req="http://www.wso2.org/types">' +
+ '<username><![CDATA[' + userNameValue + ']]></username>' +
+ '<password><![CDATA[' + passwordValue + ']]></password>' +
+ '</req:addAdminUser>';
+
+ this.send("addAdminUser", body_xml, addAdminUserCallback);
+
+ },
+
+ _validateAddAdminUser : function(userNameValue, passwordValue, rePasswordValue) {
+ if (userNameValue == null || wso2.wsf.Util.trim(userNameValue) == "") {
+ wso2.wsf.Util.alertWarning("Please enter the username.");
+ return false;
+ }
+ if (passwordValue == null || passwordValue == "") {
+ wso2.wsf.Util.alertWarning("Please enter the password.");
+ return false;
+ }
+ if (rePasswordValue == null || rePasswordValue == "") {
+ wso2.wsf.Util.alertWarning("Please re-enter the password.");
+ return false;
+ }
-function createPollSave() {
+ if (passwordValue != rePasswordValue) {
+ wso2.wsf.Util.alertWarning("The password and the re-entered password do not match.");
+ return false;
+ }
+ return true;
- if (!createPollSaveValidator()) {
- return false;
+ },
- }
- var body_xml = '<req:createPoll xmlns:req="http://www.wso2.org/types">\n' +
- '<req:title><![CDATA[' + document.getElementById("txtPollTitle").value + ']]></req:title>\n' +
- '<req:description><![CDATA[' + document.getElementById("txtPollDescription").value + ']]></req:description>\n' +
- '<req:isSingleVote>' + document.getElementById("cmbPollSingleVote").value + '</req:isSingleVote>\n';
- var inputs = document.getElementById("frmCreatePoll").getElementsByTagName("input");
- var count;
- for (count=0; count < inputs.length; count++){
- if (inputs[count].attributes.getNamedItem("name") != null){
- if (inputs[count].attributes.getNamedItem("name").nodeValue == "txtPollChoices"){
- body_xml += '<req:choices>' + inputs[count].value + '</req:choices>\n';
- }
- }
- }
- body_xml += '</req:createPoll>\n';
- sendUnsecured("createPoll", body_xml, "", chadServiceURL, "", createPollSaveCallback);
- return false;
-}
-
-//@private validator
-function createPollSaveValidator() {
-
- var titleObj = document.getElementById('txtPollTitle');
-
- var titleObjValue = "";
- titleObjValue = titleObj.value;
-
- if (trim(titleObjValue) == "" || titleObjValue == null ) {
- alertWarning("Please enter a valid title.");
- return false;
+ deleteAdminUser : function(adminUserName) {
+ if (adminUserName == "admin") {
+ wso2.wsf.Util.alertWarning("You are not permitted to delete the default adminstrator 'admin'");
+ return false;
+ }
- }
+ var boolConfirm = confirm("Do you want to permanently delete Administrator account '" +
+ adminUserName + "?'");
- var choicesObj = document.getElementsByName('txtPollChoices');
- var numOfValidChoices = 0;
- for(var i=0; i < choicesObj.length; i++){
- if(trim(choicesObj[i].value) != ""){
- numOfValidChoices ++;
+ if (!boolConfirm) {
+ return false;
}
- }
- if(numOfValidChoices < 2){
- alertWarning("A valid poll should contain more than one choice. <br/>Please add at least two choices.");
- return false;
- }
- return true;
-}
-
-function createPollSaveCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- alertMessage("Poll created successfully");
- listActivePollsAdmin();
-}
-
-function addNewChoice(){
- var objDiv = document.getElementById("choicesDiv");
- var blankLabelElem = document.createElement('label');
- blankLabelElem.innerHTML = " ";
- var elem = document.createElement('input');
- var brElem = document.createElement('br');
- var nameAttr = document.createAttribute('name');
- nameAttr.value = "txtPollChoices";
- var sizeAttr = document.createAttribute('size');
- sizeAttr.value = "50";
- var typeAttr = document.createAttribute('type');
- typeAttr.value = "text";
- elem.attributes.setNamedItem(nameAttr);
- elem.attributes.setNamedItem(sizeAttr);
- elem.attributes.setNamedItem(typeAttr);
- objDiv.appendChild(brElem);
- objDiv.appendChild(blankLabelElem);
- objDiv.appendChild(elem);
-}
-
-function startPoll(pollId){
- var body_xml = '<req:startPollMessage xmlns:req="http://www.wso2.org/types">\n' +
- '<req:pollID>' + pollId + '</req:pollID>\n' +
- '</req:startPollMessage>\n';
- sendUnsecured("startPoll", body_xml, "", chadServiceURL, "", startPollCallback);
-}
-
-function startPollCallback(){
- if (!onErrorUnsecured()) {
- return;
- }
- alertMessage("Poll started successfully.");
- listActivePollsAdmin();
-}
+ var body_xml = '<req:deleteAdminUser xmlns:req="http://www.wso2.org/types">' +
+ '<username><![CDATA[' + adminUserName + ']]></username>' +
+ '</req:deleteAdminUser>';
-function stopPoll(pollId){
- var body_xml = '<req:stopPollMessage xmlns:req="http://www.wso2.org/types">\n' +
- '<req:pollID>' + pollId + '</req:pollID>\n' +
- '</req:stopPollMessage>\n';
- sendUnsecured("stopPoll", body_xml, "", chadServiceURL, "", stopPollCallback);
-}
+ this.send("deleteAdminUser", body_xml, deleteAdminUserCallback);
-function stopPollCallback(){
- if (!onErrorUnsecured()) {
- return;
}
- alertMessage("Poll stopped successfully.");
- listActivePollsAdmin();
}
-function createPoll(){
+/* Chads static methods */
+wso2.wsas.Chad.static = {
+ init : function() {
+ // place to init the history
+ wso2.wsas.Chad.static.initDhtmlHistory();
+ wso2.wsf.XSLTHelper.init();
+ chadInstance = new wso2.wsas.Chad();
+ chadInstance.initLogin();
+ chadInstance.listAllPolls();
+ },
- /*
- CreatePoll with xsl
- */
- var tmpTransformationNode;
+ fireLogin : function () {
+ var obj = document.getElementById('divLogincontainer');
+ wso2.wsf.Util.showOnlyOneMain(obj, true);
+ },
- if (window.XMLHttpRequest && !isIE()) {
- tmpTransformationNode =
- document.implementation.createDocument("", "createPoll", null);
- } else if (window.ActiveXObject) {
- tmpTransformationNode = new ActiveXObject("Microsoft.XmlDom");
- var sXml = "<createPoll></createPoll>";
- tmpTransformationNode.loadXML(sXml);
- }
- var objDiv = document.getElementById("divCreatPoll");
- processXML(tmpTransformationNode, "create_poll.xsl", objDiv);
- showOnlyOneMain(objDiv);
-}
+ login : function(userNameValue, passwordValue) {
-function showVoteScreen(pollId){
+ currentLoginAdmin = userNameValue;
- currentPollId = pollId;
-
- var body_xml = '<req:getResultMessage xmlns:req="http://www.wso2.org/types">\n' +
- '<req:pollID>' + pollId + '</req:pollID>\n' +
- '</req:getResultMessage>\n';
- sendUnsecured("getResult", body_xml, "", chadServiceURL, "",showVoteScreenCallback);
-}
+ var body_xml = '<req:login xmlns:req="http://www.wso2.org/types">' +
+ '<username><![CDATA[' + userNameValue + ']]></username>' +
+ '<password><![CDATA[' + passwordValue + ']]></password>' +
+ '</req:login>';
-function showVoteScreenCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("vote.xsl",document.getElementById("divVoteForPoll"));
-}
+ chadInstance.send("login", body_xml, chadLoginCallback);
+ },
+ showChadLogin : function() {
+ /*
+ Login settings
+ */
+ var loginString =
+ "Signed in as " + chadInstance.getCurrentLoginAdmin() +
+ " | <a href=\"#\" onclick=\"javascript:wso2.wsas.Chad.static.showChadLogout();return false;\">Sign Out</a>";
+ document.getElementById("meta").innerHTML = loginString;
+
+ document.getElementById('menuChad').style.display = 'inline';
+ document.getElementById('menuChad1').style.display = 'none';
+
+ /*Cleraring the Password fileld*/
+ document.chadFormLogin.txtPassword.value = '';
+
+ },
+
+ initDhtmlHistory : function() {
+ /*intitialize the hashing*/
+ runPoleHash = true;
+ // initialize our DHTML history
+ dhtmlHistory.initialize();
+ // subscribe to DHTML history change
+ // events
+ historyStorage.reset();
+ dhtmlHistory.addListener(wso2.wsas.Chad.static.handleHistoryChangeChad);
-function viewPollDetails(pollId){
- var body_xml = '<req:getResultMessage xmlns:req="http://www.wso2.org/types">\n' +
- '<req:pollID>' + pollId + '</req:pollID>\n' +
- '</req:getResultMessage>\n';
- sendUnsecured("getResult", body_xml, "", chadServiceURL, "",viewPollDetailsCallback);
-}
+ },
-function viewPollDetailsForVoted(pollId) {
- var body_xml = '<req:getResultMessage xmlns:req="http://www.wso2.org/types">\n' +
- '<req:pollID>' + pollId + '</req:pollID>\n' +
- '</req:getResultMessage>\n';
- sendUnsecured("getResult", body_xml, "", chadServiceURL, "",viewPollDetailsForVotedCallback);
-}
+/** A function that is called whenever the user
+ presses the back or forward buttons. This
+ function will be passed the newLocation,
+ as well as any history data we associated
+ with the location. TOdO */
+ handleHistoryChangeChad : function(newLocation, historyData) {
+
+ var actDivName = newLocation.substring(3, newLocation.length);
+ if (!isAuthorized) {
+ /*Allow back butten to work only on this occasion. This is treated specially.*/
+ if (actDivName != "divChadListPolls") {
+ return;
+ }
+ }
+ // This is done to stop the screen from jumping about.
+ eval("wso2.wsf.Util.showOnlyOneMain(document.getElementById('" + actDivName + "'), true)");
+ // lastHash from mf_ui; main.js
+ lastHash = newLocation;
+
+ },
+
+ showChadLogout : function() {
+ /*logout setting */
+ var loginString = "<a href=\"#\" onclick=\"javascript:wso2.wsas.Chad.static.fireLogin();return false;\">Adminstrator Login</a>";
+ document.getElementById("meta").innerHTML = loginString;
+ document.getElementById('menuChad').style.display = 'none';
+ document.getElementById('menuChad1').style.display = 'inline';
+ /*Logout SOAP Call */
+ var body_xml = '<req:logout xmlns:req="http://www.wso2.org/types"/>';
+ chadInstance.send("logout", body_xml, showChadLogoutCallback);
+
+
+ },
+
+ addNewChoice: function () {
+ var objDiv = document.getElementById("choicesDiv");
+ var blankLabelElem = document.createElement('label');
+ blankLabelElem.innerHTML = " ";
+ var elem = document.createElement('input');
+ var brElem = document.createElement('br');
+ var nameAttr = document.createAttribute('name');
+ nameAttr.value = "txtPollChoices";
+ var sizeAttr = document.createAttribute('size');
+ sizeAttr.value = "50";
+ var typeAttr = document.createAttribute('type');
+ typeAttr.value = "text";
+ elem.attributes.setNamedItem(nameAttr);
+ elem.attributes.setNamedItem(sizeAttr);
+ elem.attributes.setNamedItem(typeAttr);
+ objDiv.appendChild(brElem);
+ objDiv.appendChild(blankLabelElem);
+ objDiv.appendChild(elem);
+ },
+
+ viewPollDetails : function(pollId) {
+ var body_xml = '<req:getResultMessage xmlns:req="http://www.wso2.org/types">\n' +
+ '<pollID>' + pollId + '</pollID>\n' +
+ '</req:getResultMessage>\n';
+ chadInstance.send("getResult", body_xml, viewPollDetailsCallback);
+
+ },
+ _viewPollDetailsUtil : function(xml) {
+ var choicesObjects = document.getElementsByName('pollProgressingBarId');
+
+ var votePercentageObjects = xml.getElementsByTagName('votePercentage');
+
+ // in all occasions choicesObjects == votePercentageObjects
-function viewPollDetailsForVotedCallback() {
+ for (var i = 0; i < choicesObjects.length; i++) {
- if (!onErrorUnsecured()) {
- return;
- }
+ var valueOfVotePercentage = votePercentageObjects[i].firstChild.nodeValue;
+ var txt = progressBarDivObj('predone' + i);
- chadCallbackHelper("results.xsl",document.getElementById("divPollDetails"));
+ choicesObjects[i].innerHTML = txt;
+ incrCount(valueOfVotePercentage, 'predone' + i);
- // filling the placeholding div named pollProgressingBarId with proper values
- // Dom manupiulation
- var xml = getBody(chadXhReq.responseXML);
+ }
- viewPollDetailsUtil(xml);
+ },
- var voteResultsDivObj = document.getElementById('voteResultsDivId');
- voteResultsDivObj.innerHTML =
- '<label><nobr><strong>We have already received a vote for this poll from your IP address.</nobr>'+
- '<nobr> Hence you are not eligible for voting.</strong></nobr></label>';;
-}
+ stopPoll : function(pollId) {
+ var body_xml = '<req:stopPollMessage xmlns:req="http://www.wso2.org/types">\n' +
+ '<pollID>' + pollId + '</pollID>\n' +
+ '</req:stopPollMessage>\n';
+ chadInstance.send("stopPoll", body_xml, stopPollCallback);
+
+ },
+
+ eligibleForVoting : function(pollId) {
+ currentPollId = pollId;
+
+ var body_xml = '<req:eligibleForVoting xmlns:req="http://www.wso2.org/types">\n' +
+ '<pollId>' + pollId + '</pollId>\n' +
+ '</req:eligibleForVoting>\n';
+ chadInstance.send("isEligibleForVoting", body_xml, eligibleForVotingCallback);
+ },
+
+ editAdminProperties :function(adminUserName) {
+ adminUserInUse = adminUserName;
+
+ var tmpTransformationNode;
+
+ if (window.XMLHttpRequest && !wso2.wsf.Util.isIE()) {
+ tmpTransformationNode =
+ document.implementation.createDocument("", "editAdminProperties", null);
+ } else if (wso2.wsf.Util.isIEXMLSupported()) {
+ tmpTransformationNode = new ActiveXObject("Microsoft.XmlDom");
+ var sXml = "<editAdminProperties></editAdminProperties>";
+ tmpTransformationNode.loadXML(sXml);
+ } else {
+ wso2.wsf.Util.alertWarning("This browser does not support XML");
+ }
+ var objDiv = document.getElementById("divEditAdminProps");
+ wso2.wsf.Util.processXML(tmpTransformationNode, "administrators.xsl", objDiv);
+ wso2.wsf.Util.showOnlyOneMain(objDiv);
+ },
+ startPoll : function(pollId) {
+ var body_xml = '<req:startPollMessage xmlns:req="http://www.wso2.org/types">\n' +
+ '<pollID>' + pollId + '</pollID>\n' +
+ '</req:startPollMessage>\n';
+ chadInstance.send("startPoll", body_xml, startPollCallback);
-function viewPollDetailsCallback() {
- if (!onErrorUnsecured()) {
- return;
}
- chadCallbackHelper("results.xsl",document.getElementById("divPollDetails"));
-
- // filling the placeholding div named pollProgressingBarId with proper values
- // Dom manupiulation
- var xml = getBody(chadXhReq.responseXML);
-
- viewPollDetailsUtil(xml);
}
-//@private Util function
-function viewPollDetailsUtil(xml) {
-
- var choicesObjects = document.getElementsByName('pollProgressingBarId');
-
- var votePercentageObjects = xml.getElementsByTagName('votePercentage');
-
- // in all occasions choicesObjects == votePercentageObjects
-
- for ( var i = 0 ; i < choicesObjects.length; i++) {
-
- var valueOfVotePercentage = votePercentageObjects[i].firstChild.nodeValue;
- var txt = progressBarDivObj('predone' + i);
-
- choicesObjects[i].innerHTML = txt;
- incrCount(valueOfVotePercentage,'predone' + i);
-
- }
+/*============= Following list all the callbacks used in the Chad Application ====================================*/
+/*callback method*/
+function listPollsAllCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "list_polls_all.xsl", document.getElementById("divChadListPolls"));
}
-
-function vote(pollId){
- var body_xml = '<req:vote xmlns:req="http://www.wso2.org/types">\n' +
- '<req:pollID>' + pollId + '</req:pollID>\n';
- var choicesSelected = document.getElementsByName("selectBoxForVotes");
- var count;
- var currentChoice;
- for (count = 0; count < choicesSelected.length;count++){
- currentChoice = choicesSelected[count];
-// alert(currentChoice.checked + " " + count + currentChoice.id);
- if (currentChoice.checked){
- body_xml += '<req:choices>' + currentChoice.id + '</req:choices>\n';
- }
- }
-
- body_xml += '</req:vote>\n';
-// alert(body_xml);
- sendUnsecured("vote", body_xml, "", chadServiceURL, "", voteCallback);
-}
-
-function voteCallback(){
- if (!onErrorUnsecured()) {
- return;
- }
- if (chadXhReq.responseXML.getElementsByTagName("return")[0] != null){
- if (chadXhReq.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue == "Vote successful"){
- alertMessage("Your vote was successfully registered.");
- } else {
- alertWarning(chadXhReq.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue);
- }
- }
- if (isAuthorized) {
- listActivePollsAdmin();
- } else {
- listActivePolls();
- }
+/*callback*/
+function listAllPollsAdminCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "list_polls_admin.xsl", document.getElementById("divAllPolls"));
}
-
-function showAdminstrators() {
- var body_xml = '<req:listAdminUsers xmlns:req="http://www.wso2.org/types"/>';
- sendUnsecured("listAdminUsers", body_xml, "", chadServiceURL, "", listAdminUsersCallback);
+/*callback*/
+function listActivePollsAdminCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "list_active_polls_admin.xsl", document.getElementById("divChadListPolls"));
}
-function listAdminUsersCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- chadCallbackHelper("administrators.xsl",document.getElementById("divAdminstrators"));
+/*callback*/
+function listActivePollsCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "list_active_polls.xsl", document.getElementById("divChadListPolls"));
}
-function addAdminUser(userNameObj,passwordObj,rePasswordObj) {
-
- var userNameValue = userNameObj.value;
- var passwordValue = passwordObj.value;
- var rePasswordValue = rePasswordObj.value;
-
- if (!validateAddAdminUser(userNameValue,passwordValue,rePasswordValue)) {
- return false;
- }
- var body_xml = '<req:addAdminUser xmlns:req="http://www.wso2.org/types">' +
- '<username><![CDATA['+userNameValue+']]></username>'+
- '<password><![CDATA['+passwordValue+']]></password>'+
- '</req:addAdminUser>';
-
- sendUnsecured("addAdminUser", body_xml, "", chadServiceURL, "", addAdminUserCallback);
- return false;
+/*callback*/
+function showChadLogoutCallback() {
+ isAuthorized = false;
+ runPoleHash = false;
+ historyStorage.reset();
+ this.listAllPolls();
}
-function validateAddAdminUser(userNameValue,passwordValue,rePasswordValue) {
- if (userNameValue == null || trim(userNameValue) == "" ) {
- alertWarning("Please enter the username.");
- return false;
- }
- if (passwordValue == null || passwordValue == "" ) {
- alertWarning("Please enter the password.");
- return false;
+/*logincallback*/
+function chadLoginCallback() {
+ if (this.req.responseXML.getElementsByTagName("return")[0] != null) {
+ if (this.req.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue == "true") {
+ // alertMessage("Login Successful");
+ isAuthorized = true;
+ wso2.wsas.Chad.static.showChadLogin();
+ this.listActivePollsAdmin();
+ } else {
+ wso2.wsf.Util.alertWarning("Login failed!");
+ isAuthorized = false;
+ this.listAllPolls();
+ }
}
- if (rePasswordValue == null || rePasswordValue == "") {
- alertWarning("Please re-enter the password.");
- return false;
- }
- if (passwordValue != rePasswordValue) {
- alertWarning("The password and the re-entered password do not match.");
- return false;
- }
- return true;
}
-function addAdminUserCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- alertMessage("New administration account successfully created.");
- showAdminstrators();
+/*callback*/
+function listStoppedPollsPollsCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "list_stopped_polls.xsl", document.getElementById("divChadStopedPolls"));
}
-function deleteAdminUser(adminUserName) {
- if (adminUserName == "admin") {
- alertWarning("You are not permitted to delete the default adminstrator 'admin'");
- return false;
- }
-
- var boolConfirm = confirm("Do you want to permanently delete Administrator account '" +
- adminUserName+"?'");
-
- if (!boolConfirm) {
- return false;
- }
-
- var body_xml = '<req:deleteAdminUser xmlns:req="http://www.wso2.org/types">' +
- '<username><![CDATA['+adminUserName+']]></username>'+
- '</req:deleteAdminUser>';
-
- sendUnsecured("deleteAdminUser", body_xml, "", chadServiceURL, "", deleteAdminUserCallback);
-
+/*callback*/
+function createPollSaveCallback() {
+ wso2.wsf.Util.alertMessage("Poll created successfully");
+ this.listActivePollsAdmin();
}
-function deleteAdminUserCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- alertMessage("Administrator account successfully removed.");
- showAdminstrators();
+/*callback*/
+function startPollCallback() {
+ wso2.wsf.Util.alertMessage("Poll started successfully.");
+ this.listActivePollsAdmin();
}
-function changePassword(password, rePassword,oldPassword) {
- if(!changePasswordValidator(password, rePassword,oldPassword)) {
- return false;
- }
- var body_xml = '<req:changePassword xmlns:req="http://www.wso2.org/types">' +
- '<username><![CDATA['+getAdminUserInUse()+']]></username>'+
- '<oldPassword><![CDATA['+oldPassword+']]></oldPassword>'+
- '<newPassword><![CDATA['+password+']]></newPassword>'+
- '</req:changePassword>';
-
- sendUnsecured("changePassword", body_xml, "", chadServiceURL, "", changePasswordCallback);
- return false;
+/*callback*/
+function stopPollCallback() {
+ wso2.wsf.Util.alertMessage("Poll stopped successfully.");
+ this.listActivePollsAdmin();
}
-function changePasswordCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- alertMessage("Administrator password successfully changed.");
- showAdminstrators();
+/*callback*/
+function showVoteScreenCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "vote.xsl", document.getElementById("divVoteForPoll"));
}
-function changePasswordValidator(password, rePassword, oldPassword) {
- if (password == null || trim(password) == "" ) {
- alertWarning("Please enter the new password.");
- return false;
- }
-
- if (rePassword == null || rePassword == "" ) {
- alertWarning("Please re-enter the password.");
- return false;
- }
-
- if (oldPassword == null || oldPassword == "") {
- alertWarning("Please enter the old password.");
- return false;
- }
+/*callback*/
+function viewPollDetailsForVotedCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "results.xsl", document.getElementById("divPollDetails"));
- if (password != rePassword) {
- alertWarning("The new password and the re-entered password do not match.");
- return false;
- }
- return true;
+ wso2.wsas.Chad.static._viewPollDetailsUtil(this.req.responseXML);
+ var voteResultsDivObj = document.getElementById('voteResultsDivId');
+ voteResultsDivObj.innerHTML =
+ '<label><nobr><strong>We have already received a vote for this poll from your IP address.</nobr>' +
+ '<nobr> Hence you are not eligible for voting.</strong></nobr></label>';
}
-function editAdminProperties(adminUserName) {
- adminUserInUse = adminUserName;
-
- var tmpTransformationNode;
- if (window.XMLHttpRequest && !isIE()) {
- tmpTransformationNode =
- document.implementation.createDocument("", "editAdminProperties", null);
- } else if (window.ActiveXObject) {
- tmpTransformationNode = new ActiveXObject("Microsoft.XmlDom");
- var sXml = "<editAdminProperties></editAdminProperties>";
- tmpTransformationNode.loadXML(sXml);
- }
- var objDiv = document.getElementById("divEditAdminProps");
- processXML(tmpTransformationNode, "administrators.xsl", objDiv);
- showOnlyOneMain(objDiv);
+/*callback*/
+function viewPollDetailsCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "results.xsl", document.getElementById("divPollDetails"));
+ wso2.wsas.Chad.static._viewPollDetailsUtil(this.req.responseXML);
}
-function eligibleForVoting(pollId) {
- currentPollId = pollId;
-
- var body_xml = '<req:eligibleForVoting xmlns:req="http://www.wso2.org/types">\n' +
- '<pollId>' + pollId + '</pollId>\n' +
- '</req:eligibleForVoting>\n';
- sendUnsecured("isEligibleForVoting", body_xml, "", chadServiceURL, "",eligibleForVotingCallback);
+/*callback*/
+function voteCallback() {
-
-}
-
-function eligibleForVotingCallback() {
- if (!onErrorUnsecured()) {
- return;
- }
- if (chadXhReq.responseXML.getElementsByTagName("return")[0] != null){
- if (chadXhReq.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue == "true"){
- // eligible for voting
- showVoteScreen(getCurrentPollId());
+ if (this.req.responseXML.getElementsByTagName("return")[0] != null) {
+ if (this.req.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue ==
+ "Vote successful") {
+ wso2.wsf.Util.alertMessage("Your vote was successfully registered.");
} else {
- // this ip has already been used for voting.
- viewPollDetailsForVoted(getCurrentPollId());
+ wso2.wsf.Util.alertWarning(chadXhReq.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue);
}
- }
-
-
+ }
+ if (isAuthorized) {
+ this.listActivePollsAdmin();
+ } else {
+ this.listActivePolls();
+ }
}
-function getAdminUserInUse() {
- return adminUserInUse;
+/*callback*/
+function listAdminUsersCallback() {
+ wso2.wsf.Util.callbackhelper(this.req.responseXML, "administrators.xsl", document.getElementById("divAdminstrators"));
}
-function getCurrentLoginAdmin() {
- return currentLoginAdmin;
+/*callback*/
+function addAdminUserCallback() {
+ wso2.wsf.Util.alertMessage("New administration account successfully created.");
+ this.showAdminstrators();
}
-function getCurrentPollId() {
- return currentPollId;
+/*callback*/
+function deleteAdminUserCallback() {
+ wso2.wsf.Util.alertMessage("Administrator account successfully removed.");
+ this.showAdminstrators();
}
+/*callback*/
+function changePasswordCallback() {
+ wso2.wsf.Util.alertMessage("Administrator password successfully changed.");
+ this.showAdminstrators();
+}
+/*callback*/
+function eligibleForVotingCallback() {
-
+ if (this.req.responseXML.getElementsByTagName("return")[0] != null) {
+ if (this.req.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue ==
+ "true") {
+ // eligible for voting
+ this.showVoteScreen(this.getCurrentPollId());
+ } else {
+ // this ip has already been used for voting.
+ this.viewPollDetailsForVoted(this.getCurrentPollId());
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/administrators.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/administrators.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/administrators.xsl Sun Jun 10 21:48:28 2007
@@ -25,14 +25,14 @@
  
<a id="edit_link">
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:editAdminProperties('<xsl:value-of select="."/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.editAdminProperties('<xsl:value-of select="."/>'); return false;</xsl:attribute>
<xsl:attribute name="title">Edit Adminstrator <xsl:value-of select="."/></xsl:attribute>
    
</a>
    
<a id="cancel_link">
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:deleteAdminUser('<xsl:value-of select="."/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:chadInstance.deleteAdminUser('<xsl:value-of select="."/>'); return false;</xsl:attribute>
<xsl:attribute name="title">Delete Adminstrator <xsl:value-of select="."/></xsl:attribute>
    
</a>
@@ -59,7 +59,7 @@
<div><label>Re-enter Password<font color='red'>*</font></label><input id='addRePasswordId' type='password' tabindex='3' /></div>
<div class='buttonrow'>
<input type='button' value='Add'>
- <xsl:attribute name="onclick">javascript:return addAdminUser(document.getElementById('addUserNameId'),document.getElementById('addPasswordId'),document.getElementById('addRePasswordId'));</xsl:attribute>
+ <xsl:attribute name="onclick">javascript:return chadInstance.addAdminUser(document.getElementById('addUserNameId'),document.getElementById('addPasswordId'),document.getElementById('addRePasswordId'));</xsl:attribute>
</input>
</div>
</fieldset>
@@ -68,7 +68,7 @@
</xsl:template>
<xsl:template match="editAdminProperties">
- <h4><a href="#" onClick="javascript:showAdminstrators(); return false;">Administrators</a> > Edit</h4>
+ <h4><a href="#" onClick="javascript:chadInstance.showAdminstrators(); return false;">Administrators</a> > Edit</h4>
<div id='formset'>
<form>
<fieldset>
@@ -79,7 +79,7 @@
<div class='buttonrow'>
<input type='button' value='Change Password'>
- <xsl:attribute name="onclick">javascript:return changePassword(document.getElementById('editPasswordId').value,document.getElementById('editRePasswordId').value,document.getElementById('oldPasswordId').value);</xsl:attribute>
+ <xsl:attribute name="onclick">javascript:return chadInstance.changePassword(document.getElementById('editPasswordId').value,document.getElementById('editRePasswordId').value,document.getElementById('oldPasswordId').value);</xsl:attribute>
</input>
</div>
</fieldset>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/create_poll.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/create_poll.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/create_poll.xsl Sun Jun 10 21:48:28 2007
@@ -9,7 +9,7 @@
<legend>Enter Poll Details</legend>
<div><label>Title<font color="red">*</font></label><input size='50' id='txtPollTitle' tabindex='1' type='text'/></div>
<div><label>Description</label><input size='50' id='txtPollDescription' tabindex='2' type='text'/></div>
- <div><label>Choices<font color="red">*</font></label><input size='50' id='txtPollChoices1' name='txtPollChoices' tabindex='3' type='text'/>[<a href='#' onclick='javascript:addNewChoice();'>add</a>]</div>
+ <div><label>Choices<font color="red">*</font></label><input size='50' id='txtPollChoices1' name='txtPollChoices' tabindex='3' type='text'/>[<a href='#' onclick='javascript:wso2.wsas.Chad.static.addNewChoice();'>add</a>]</div>
<div id='choicesDiv'>
<label> <font color="red">*</font></label><input size='50' id='txtPollChoices0' name='txtPollChoices' tabindex='3' type='text'/>
</div>
@@ -21,7 +21,7 @@
</div>
<div class='buttonrow'>
<input type='button' value='Create'>
- <xsl:attribute name="onclick">javascript:return createPollSave();</xsl:attribute>
+ <xsl:attribute name="onclick">javascript:return chadInstance.createPollSave();</xsl:attribute>
</input>
</div>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls.xsl Sun Jun 10 21:48:28 2007
@@ -36,7 +36,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
@@ -46,7 +46,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Vote</xsl:text>
</a>
</td>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls_admin.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls_admin.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/list_active_polls_admin.xsl Sun Jun 10 21:48:28 2007
@@ -34,7 +34,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
@@ -44,12 +44,12 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:stopPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.stopPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Stop</xsl:text>
</a>  
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Vote</xsl:text>
</a>
</td>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_admin.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_admin.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_admin.xsl Sun Jun 10 21:48:28 2007
@@ -22,7 +22,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
@@ -44,19 +44,19 @@
<xsl:when test="isStopped = 'true'">
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:startPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.startPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Start</xsl:text>
</a>
</xsl:when>
<xsl:when test="isStopped = 'false'">
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:stopPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.stopPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Stop</xsl:text>
</a>  
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Vote</xsl:text>
</a>
</xsl:when>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_all.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_all.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/list_polls_all.xsl Sun Jun 10 21:48:28 2007
@@ -35,7 +35,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
@@ -45,7 +45,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.eligibleForVoting('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Vote</xsl:text>
</a>
</td>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/list_stopped_polls.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/list_stopped_polls.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/list_stopped_polls.xsl Sun Jun 10 21:48:28 2007
@@ -22,7 +22,7 @@
<td>
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.viewPollDetails('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
@@ -41,7 +41,7 @@
<xsl:when test="isStopped = 'true'">
<a>
<xsl:attribute name="href">#</xsl:attribute>
- <xsl:attribute name="onClick">javascript:startPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
+ <xsl:attribute name="onClick">javascript:wso2.wsas.Chad.static.startPoll('<xsl:value-of select="pollId"/>'); return false;</xsl:attribute>
<xsl:text>Start</xsl:text>
</a>
</xsl:when>
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/results.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/results.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/results.xsl Sun Jun 10 21:48:28 2007
@@ -3,7 +3,7 @@
<xsl:output method="html"/>
<xsl:template match="ns1:getResultResponse" xmlns:ns1="http://www.wso2.org/types">
<!-- There's gonna be only one return element -->
- <h4><a href="#" onClick="javascript:showActivePolls(); return false;">Active Polls</a> > Results</h4>
+ <h4><a href="#" onClick="javascript:chadInstance.showActivePolls(); return false;">Active Polls</a> > Results</h4>
<h2>Results</h2>
<fieldset style="border:none;">
<div id="formset">
Modified: trunk/wsas/java/modules/samples/Chad/www/xslt/vote.xsl
==============================================================================
--- trunk/wsas/java/modules/samples/Chad/www/xslt/vote.xsl (original)
+++ trunk/wsas/java/modules/samples/Chad/www/xslt/vote.xsl Sun Jun 10 21:48:28 2007
@@ -2,7 +2,7 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
- <h4><a href="#" onClick="javascript:showActivePolls(); return false;">Active Polls</a> > Vote</h4>
+ <h4><a href="#" onClick="javascript:chadInstance.showActivePolls(); return false;">Active Polls</a> > Vote</h4>
<h2>Vote</h2>
<div id="formset">
<form id="frmVoteForPoll">
@@ -60,7 +60,7 @@
<div class="buttonrow">
<input type="button" value="Vote">
- <xsl:attribute name="onclick">javascript:vote('<xsl:value-of select="pollId"/>');</xsl:attribute>
+ <xsl:attribute name="onclick">javascript:chadInstance.vote('<xsl:value-of select="pollId"/>');</xsl:attribute>
</input>
</div>
</xsl:for-each>
More information about the Wsas-java-dev
mailing list