Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move JS event handlers out of HTML and into App.js #76

Merged
merged 1 commit into from Feb 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions examples/simple/src/main/javascript/client/App.js
Expand Up @@ -28,7 +28,7 @@ function errorCallback(msgOrError) {

var client;
var dbgCtx;
function onload() {
function main() {
var exampleUrl = 'http://localhost:' + SimpleConstants.SERVER_PORT + '/msl-example-server/';
var targetUrl = getQueryParam('url', exampleUrl);
document.querySelector("#url").setAttribute("value", targetUrl);
Expand Down Expand Up @@ -317,6 +317,25 @@ function showResponse(mis) {
// Notify of timeout.
errorCallback("Timed out reading the response.");
},
error: errorCallback,
error: errorCallback
});
}

function createClickHandler(type) {
return function () {
setRequestType(type);
};
}

// set up event handlers
window.onload = main;
document.querySelector("#username").onchange = checkUsername;
document.querySelector("#identity").onchange = setIdentity;
document.querySelector("#echo").onclick = createClickHandler("echo");
document.querySelector("#log").onclick = createClickHandler("log");
document.querySelector("#profile").onclick = createClickHandler("profile");
document.querySelector("#query").onclick = createClickHandler("query");
document.querySelector("#quit").onclick = createClickHandler("quit");
document.querySelector("#advanced").onclick = createClickHandler("advanced");


22 changes: 10 additions & 12 deletions examples/simple/src/main/javascript/client/SimpleClient.html
Expand Up @@ -140,12 +140,9 @@
<script type="text/javascript" src="util/SimpleMslContext.js"></script>
<script type="text/javascript" src="SimpleClient.js"></script>

<!-- Page Script -->
<script type="text/javascript" src="./App.js"></script>

<link href="./style.css" rel="stylesheet" type="text/css"></link>
</head>
<body onload="onload();">
<body>

<h1>Example JavaScript Client</h1>

Expand Down Expand Up @@ -191,17 +188,17 @@ <h1>Example JavaScript Client</h1>
</table>
</td>
</tr>
<tr><td><b>Username:</b></td><td><input type="text" id="username" name="username" width="10" onchange="javascript:checkUsername();"/></td></tr>
<tr><td><b>Username:</b></td><td><input type="text" id="username" name="username" width="10"/></td></tr>
<tr><td><b>Password:</b></td><td><input type="text" id="password" name="password" width="10"/><input type="submit" id="logout" value="Logout" onclick="logoutUser();" disabled="disabled"></td></tr>
<tr><td colspan="3">
<input type="hidden" id="type" name="type" value=""/>
<ul class="tabs">
<li id="echo" class="tab" onclick="javascript:setRequestType('echo')">Echo Text</li>
<li id="log" class="tab" onclick="javascript:setRequestType('log')">Log Message</li>
<li id="profile" class="tab" onclick="javascript:setRequestType('profile')">Get Profile</li>
<li id="query" class="tab" onclick="javascript:setRequestType('query')">Lookup Word</li>
<li id="quit" class="tab" onclick="javascript:setRequestType('quit')">Terminate Server</li>
<li id="advanced" class="tab" onclick="javascript:setRequestType('advanced')">Advanced</li>
<li id="echo" class="tab">Echo Text</li>
<li id="log" class="tab">Log Message</li>
<li id="profile" class="tab">Get Profile</li>
<li id="query" class="tab">Lookup Word</li>
<li id="quit" class="tab">Terminate Server</li>
<li id="advanced" class="tab">Advanced</li>
</ul>
<div class="request">
<table>
Expand Down Expand Up @@ -236,7 +233,7 @@ <h1>Example JavaScript Client</h1>
<tr>
<td><b>Entity Identity:</b></td>
<td>
<input id='identity' type='text' size='40' onchange='javascript:setIdentity()'/>
<input id='identity' type='text' size='40'/>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -289,5 +286,6 @@ <h1>Example JavaScript Client</h1>

</form>

<script type="text/javascript" src="./App.js"></script>
</body>
</html>