{% extends "base.html" %}

{% block title %}IceProd{% end %}

{% block page_title %}Site {{ url }}{% end %}

{% block body %}



<div class = "content_box">
    <div class="header"><p>Modules</p></div>
    <ul class="content">
        {% for m in modules %}
        <li>
            <input onclick='javascript:toggle_module("{{ m[0] }}");' type="checkbox" id="{{ m[0] }}" {{ ['', 'checked'][m[1]] }} >
                <label for = '{{ m[0] }}'> {{ m[0] }} </label>
                
                </li>
        {% end %}
        
    </ul>
</div>

<div class = "content_box">
    <div class="header" id="config_header"><p>Config<a href="javascript:update_config();" class = "box_menu">Update</a></p></div>
<p contentEditable="true" class="code" id="config_text" >
{{ config }}
</p>
</div>
{% end %}

{% block body_scripts %}
<script type="text/javascript" src="/static/json-rpc.js"></script>
<script type="text/javascript">
    
  function toggle_module(module_name)
  {
      var checkbox = document.getElementById(module_name);
      checkbox.disabled = true;
      var function_name = checkbox.checked ? 'start_module': 'stop_module';
      RPCclient(function_name, {passkey: "{{ passkey }}", module_name:module_name }, callback=function(return_data){
              
              document.getElementById(module_name).disabled = false;

              
              });
  }
    function update_config()
    {
        // TODO feedback would be nice
        //$('#config_header').addClass("inactive");
        var config_text = document.getElementById("config_text").innerHTML;
        RPCclient('update_config', {passkey: "{{ passkey }}", config_text:config_text }, callback=function(return_data){
                  
                  if (return_data) alert(return_data);
                  /*
                  setTimeout(function() {
                  
                  $('#config_header').removeClass("inactive");
                             }, 100);
                  */

                  });
                  
    }
  
</script>

{% end %}
