lillianchou94/csua169

View on GitHub
app/views/elections/show.html.erb

Summary

Maintainability
Test Coverage

<head><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!-- <script data-dojo-config="async: 1, dojoBlankHtmlUrl: '/blank.html',
        packages: [ {
            name: 'custom',
            location: location.pathname.replace(/\/[^/]+$/, '') + '/js/custom'
        } ]"
    src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script> -->
</head>
<body>
    <div id="header" style="height: 100px">
    <h1> CSUA Voting System </h1>
    <div style="text-align:right">
      <% if current_user != nil %>
      <% puts "this is #{current_user}" %>
        Hello, <strong><%= current_user.user_name.partition(" ").first %></strong>.
        <%= link_to "Sign out", signout_path, id: "sign_out" %>
      <% else %>
        <%= link_to "Sign in with Google", "/auth/google_oauth2", id: "sign_in" %>
      <% end %>
    </div>
    <div>
    <%= yield %>
    </div>
    </div>
    <% if current_user != nil %>
        <div id="body" style="width:100%; height:100%">
            <div id="elections" style="border:1px solid gray; width:200px; height:100%;float:left">
                <!-- election panel code -->
                <div class="election_column" id="election_content" style="float:left"></div>

                
              <div id="electionmodal" title="Add Election" style="display:none">
                <form action="/election_add_election" method="post" target="hiddenFrame" id="electionform" onsubmit="set_election_id(); setTimeout(function () { window.location.reload(); }, 10)">
                      <input type='hidden' name='<%=request_forgery_protection_token.to_s%>' value='<%=form_authenticity_token%>'>
                      <label>Organization:</label>
                      <!--<input id="new_election_org" name="new_election_org" type="text" autofocus><br>-->
                    <select type="text" name="new_election_org" id="new_election_org">
                    <% User.where(:user_email => current_user.user_email, :admin_status => 1).each do |user| %>
                      <% puts "this is #{user}" %>
                      <option value="<%=user.organization%>"><%=user.organization%></option>
                      <% end %>
                        </select>
                        <br>
                    <label>New election name:</label>
                    <input id="new_election_name" name="new_election_name" type="text"><br>
                    <label>YT livestream (optional):</label>
                    <input id="new_election_livestream" name="new_election_livestream" type="text"><br>
                    <input id="election_submit" type="submit" value="Create">
                  </form>
                </div>
                
                <div id="confirmVoteModal" title="Confirm Vote" style="display:none">
                <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
                <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
                <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
                <script>
                function set_vote_position() {
                        var encodeuri = btoa($("#password_id").val())
                        var key = CryptoJS.enc.Base64.parse(encodeuri.toString());
                        var iv  = CryptoJS.enc.Base64.parse("EBESExQVFhcYGRobHB0eHw==");
                        var text = "2"
                        // var step_text = CryptoJS.AES.decrypt(text, key, {iv: iv});
                        // var decrypted_text = step_text.toString(CryptoJS.enc.Utf8);
                        // decrypted_text = decrypted_text + "{" + election_id + "{" + position_id + ":" + "3" +  ","; // TODO: Need to find alternative way to retrieve prime
                        var encrypted;
                        var encrypted = CryptoJS.AES.encrypt(text, key, {iv : iv});
                        alert($("#button_id").val())
                    };
                </script>
                <form method="post" target="hiddenFrame" id="voteFrame" onsubmit="set_vote_position(); setTimeout(function () { window.location.reload(); }, 10)">
                      <input type='hidden' name='<%=request_forgery_protection_token.to_s%>' value='<%=form_authenticity_token%>'>
                    <label>Password</label>
                    <input id="password_id" name="password_value" type="password"><br>
                    <input id="election_submit" type="submit" value="Submit">
                  </form>
                </div>
                
            <div id="positionmodal" title="Add Position" style="display:none">
                <script>
                function set_election_id() {
                        if ( $("#button_election_id").length ) {
                        $("#election_id").val($("#button_election_id").val());
                        }
                    };
                </script>
                  <form action="/election_add_position" method="post" target="hiddenFrame" id="positionform" onsubmit="set_election_id(); setTimeout(function () { window.location.reload(); }, 10)">
                      <input type='hidden' name='<%=request_forgery_protection_token.to_s%>' value="<%=form_authenticity_token%>">
                    <label>New position:</label>
                    <input id="new_position_name" name="new_position_name" type="text">
                    <input id="election_id" name="election_id" type="hidden" value=""><br>
                    <input id="eap_submit" type="submit" value="Create">
                  </form>
                </div>
            </div>
            <div style="width:10px">    </div>
            <div id="main_page" style="border:1px solid gray; height:100%">
                <!-- main dashboard -->
                <div class="election_dashboard" id="election_dashboard" style="float:left"></div>
                <div class="election_embed_livestream" id="election_embed_livestream" style="float:right"></div>
            </div> 
        </div>
        
        <script>
        $(document).ready(function() {
            function set_election_id() {
                if ( $("#button_id").length ) {
                    $("#election_id").val($("#button_id").val());
                }
            };

            function open_organization_modal() {
                $(function() {
                      $("#hiddenFrameID").empty();
                      $("#organizationmodal").dialog({autoOpen: false, modal:true});
                      $("#organizationmodal").dialog("open");
                      $("#org_submit").click(function(e) {
                            $("#organizationmodal").dialog("close");
                            $("#hiddenFrameID").empty();
                    });
                  });
            };

            function open_position_modal(button_id) {
                $(function(button_id) {
                    $("#hiddenFrameID").empty();
                    $("#positionmodal").dialog({autoOpen: false, modal:true});
                    $("#election_id").value(button_id);
                    $("#eap_submit").click(function(e) {
                        $("#positionmodal").dialog("close");
                        $("#hiddenFrameID").empty();
                    });
                });
            };
            function get_election_content() {
                $.ajax({
                  type: 'GET',
                  url: '/election_show_elections',
                  data: {},
                  cache: false,
                  success: function(result) {
                      $('#election_content').html(result);
                  }
              });
            };
            get_election_content();
            function get_election_dashboard() {
                 $.ajax({
                  type: 'GET',
                  url: '/election_dashboard',
                  data: {},
                  cache: false,
                  success: function(result) {
                      $('#election_dashboard').html(result);
                  }
              });
            };
            get_election_dashboard();
            function get_election_embed_livestream() {
                
                $.ajax({
                  type: 'GET',
                  url: '/election_embed_livestream',
                  data: {},
                  cache: false,
                  success: function(result) {
                      $('#election_embed_livestream').html(result);
                  }
              });
            };
            get_election_embed_livestream();
            setInterval(function() {get_election_content()},5000);
        });
        </script>
    <% end %>
</body>
<iframe name="hiddenFrame" class="hide" id="hiddenFrameID" style="display:none;height:1;width:1;"></iframe>