<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="DTMLDocument" module="OFS.DTMLDocument"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>__name__</string> </key>
            <value> <string>activity-watcher-gadget.js</string> </value>
        </item>
        <item>
            <key> <string>_vars</string> </key>
            <value>
              <dictionary/>
            </value>
        </item>
        <item>
            <key> <string>globals</string> </key>
            <value>
              <dictionary/>
            </value>
        </item>
        <item>
            <key> <string>raw</string> </key>
            <value> <string encoding="cdata"><![CDATA[

/*\n
  This script generate a lot of html tags inside a div.\n
  It would be better to use templates (like mustache)\n
*/\n
(function () {\n
  var interval = 1000,\n
  div = \'#activity_watcher_gadget\',\n
  html_content = \'\',\n
  basedir = location.pathname.split(\'/\').slice(0,-1).join(\'/\') + \'/\',\n
  fillMessageList = function (data,messagetype,string) {\n
    if (data[string] && data[string].line_list) {\n
      for (i = 0; i < data[string].line_list.length; i++) {\n
        var key_list = [\'message\',\'method_id\',\'node\',\'min_pri\',\'max_pri\'], j;\n
        html_content +=\n
        \'<tr>\' +\n
          \'<td>\' + messagetype + \'</td>\';\n
        for (j = 0; j < key_list.length; j++) {\n
          html_content +=\n
          \'<td>\' + data[string].line_list[i][key_list[j]] + \'</td>\';\n
        }\n
        html_content +=\n
        \'</tr>\';\n
      }\n
    }\n
  },\n
  fillMessagePri = function (data,messagetype,string) {\n
    if (data[string] && data[string].line_list) {\n
      for (i = 0; i < data[string].line_list.length; i++) {\n
        var key_list = [\'min\',\'avg\',\'max\'], j;\n
        html_content +=\n
        \'<tr>\' +\n
          \'<td>\' + messagetype + \'</td>\' +\n
          \'<td>\' + data[string].line_list[i].pri + \'</td>\';\n
        for (j = 0; j < key_list.length; j++) {\n
          html_content +=\n
          \'<td>\' + data[string].line_list[i][key_list[j]] + \'</td>\';\n
        }\n
        html_content +=\n
        \'</tr>\';\n
      }\n
    }\n
  },\n
  watcher = function () {\n
    $.ajax({\n
      url: basedir + \'ActivityTool_getSqlStatisticList\',\n
      type: \'POST\',\n
      timeout: 10000,\n
      success: function (response) {\n
        var i, data, today = new Date();\n
        data = JSON.parse(response);\n
        html_content =\n
          \'Date : \' + today.toTimeString() +\n
          \'<table>\' +\n
          \'  <tr>\' +\n
          \'    <th>Type</th>\'+\n
          \'    <th>Message</th>\'+\n
          \'    <th>Method Id</th>\'+\n
          \'    <th>Processing Node</th>\'+\n
          \'    <th>Min pri</th>\'+\n
          \'    <th>Max pri</th>\' +\n
          \'  </tr>\';\n
        fillMessageList (data,\'dict\',\'SQLDict\');\n
        fillMessageList (data,\'queue\',\'SQLQueue\');\n
        html_content +=\n
        \'  </table>\' +\n
          \'<table>\'+\n
          \'  <tr>\'+\n
          \'    <th>Type</th>\'+\n
          \'    <th>Pri</th>\'+\n
          \'    <th>Min</th>\'+\n
          \'    <th>Avg</th>\'+\n
          \'    <th>Max</th>\'+\n
          \'  </tr>\';\n
        fillMessagePri (data,\'dict\',\'SQLDict2\');\n
        fillMessagePri (data,\'queue\',\'SQLQueue2\');\n
        html_content +=\n
        \'  </table>\';\n
        $(div).html(html_content);\n
        setTimeout(watcher,interval);\n
      },\n
      error: function (type) {\n
        if (!html_content) {\n
          $(div).html(\'ERROR \' + type.status + \': \' + type.statusText);\n
        } else {\n
          $(div).html(\'ERROR \' + type.status + \': \' + type.statusText +\n
                      \'<br />\' + html_content);\n
        }\n
        if (type.status < 400) {\n
          setTimeout(watcher,interval);\n
        }\n
      }\n
    });\n
  };\n
  watcher();\n
}());\n


]]></string> </value>
        </item>
        <item>
            <key> <string>title</string> </key>
            <value> <string></string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
