jaller94/cs2d-webadmin

View on GitHub
views/console.ejs

Summary

Maintainability
Test Coverage
<html>
<head>
    <title>CS2D Console - CS2D Webadmin</title>
    <link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<% if (!user) { %>
    <p>Welcome! Please <a href="/login">log in</a>.</p>
<% } else { %>
    <script>
    function httpGet(theUrl, callback) {
        const xmlHttp = new XMLHttpRequest();
        if (callback) {
            xmlHttp.onreadystatechange = callback.bind(xmlHttp.target);
        }
        xmlHttp.open( 'GET', theUrl );
        xmlHttp.send( null );
    }

    function httpPostJSON(theUrl, data, callback) {
        const xmlHttp = new XMLHttpRequest();
        xmlHttp.open( 'POST', theUrl );
        xmlHttp.setRequestHeader('Content-Type', 'application/json');
        xmlHttp.send( JSON.stringify(data) );
    }

    function httpPostPlain(theUrl, data, callback) {
        const xmlHttp = new XMLHttpRequest();
        xmlHttp.open( 'POST', theUrl );
        xmlHttp.setRequestHeader('Content-Type', 'text/plain');
        xmlHttp.send( data );
    }

    function message() {
        const input = document.getElementById('input_message');
        const message = input.value;
        httpPostJSON('/message', {message});
    }
    </script>
    <% include includes/header.ejs %>
    <h1>CS2D Console</h1>
    <div>
        <label for="input_message">Global message</label>
        <input id="input_message" type="text" placeholder="Type a message">
        <button onclick="message();">Send</button>
    </div>
<% } %>
</body>
</html>