<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="DTMLMethod" module="OFS.DTMLMethod"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>_Cacheable__manager_id</string> </key>
            <value> <string>http_cache</string> </value>
        </item>
        <item>
            <key> <string>__name__</string> </key>
            <value> <string>vifib_monitoring.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
Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.\n
\n
This program is Free Software; you can redistribute it and/or\n
modify it under the terms of the GNU General Public License\n
as published by the Free Software Foundation; either version 2\n
of the License, or (at your option) any later version.\n
\n
This program is distributed in the hope that it will be useful,\n
but WITHOUT ANY WARRANTY; without even the implied warranty of\n
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n
GNU General Public License for more details.\n
\n
You should have received a copy of the GNU General Public License\n
along with this program; if not, write to the Free Software\n
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n
*/\n
"use strict";\n
\n
(function (window, $) {\n
\n
  var methods,\n
    Base61,\n
    update_status,\n
    search_document_list;\n
\n
  // http://stackoverflow.com/a/246813\n
  Base61 = {\n
    // private property\n
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",\n
    // public method for encoding\n
    encode : function (input) {\n
        var output = "";\n
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;\n
        var i = 0;\n
\n
    //     input = Base64._utf8_encode(input);\n
\n
        while (i < input.length) {\n
\n
            chr1 = input.charCodeAt(i++);\n
            chr2 = input.charCodeAt(i++);\n
            chr3 = input.charCodeAt(i++);\n
\n
            enc1 = chr1 >> 2;\n
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n
            enc4 = chr3 & 60;\n
\n
            if (isNaN(chr2)) {\n
                enc3 = enc4 = 61;\n
            } else if (isNaN(chr3)) {\n
                enc4 = 61;\n
            }\n
\n
            output = output +\n
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +\n
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);\n
\n
        }\n
\n
        return output;\n
    },\n
  };\n
\n
\n
  update_status = function (context) {\n
    var status_url = decodeURIComponent(context.attr("data-url"));\n
    context.attr("class", "check_monitoring")\n
           .attr("title", "Checking status");\n
    $.ajax({\n
      type: \'GET\',\n
      url: status_url,\n
      dataType: \'json\',\n
      async: true,\n
      context: context, \n
      success: function(data) {\n
        var created_at = new Date(Date.parse(data.created_at)),\n
          now = new Date(),\n
          context = $(this);\n
        // 5 minute for computer. 1 day for instance.\n
        if (/#access/.test(data.text) & /computer_module/.test(data[\'@document\']) & (now - created_at < 300000)) {\n
          $(this).attr("class", "monitoring_ok")\n
                 .attr("title", data.text + " (" + created_at + ")" )\n
                 .attr("href", data[\'@document\']);\n
        } else if (/#access/.test(data.text) & /software_instance_module/.test(data[\'@document\']) & (now - created_at < 86400000)) {\n
          $(this).attr("class", "monitoring_ok")\n
                 .attr("title", data.text + " (" + created_at + ")" )\n
                 .attr("href", data[\'@document\']);\n
        } else if (/#access/.test(data.text) & /software_installation_module/.test(data[\'@document\']) & (now - created_at < 86400000)) {\n
          $(this).attr("class", "monitoring_ok")\n
                 .attr("title", data.text + " (" + created_at + ")" )\n
                 .attr("href", data[\'@document\']);\n
        } else {\n
          $(this).attr("class", "monitoring_error")\n
                 .attr("title", data.text + " (" + created_at + ")" )\n
                 .attr("href", data[\'@document\']);\n
        }\n
        setTimeout(function () {\n
          update_status(context);\n
        }, 60000);\n
      },\n
      error: function(jqXHR, textStatus, errorThrown) {\n
        // XXX Drop content instead\n
        // $(this).attr("class", "monitoring_failed");\n
        var context = $(this);\n
        if (jqXHR.status === 404) {\n
          context.remove()\n
        } else {\n
          $(this).attr("class", "monitoring_failed")\n
                 .attr("title", "Unable to fetch content");\n
          setTimeout(function () {\n
            update_status(context);\n
          }, 60000);\n
        }\n
        \n
      },\n
    });\n
  };\n
\n
  search_document_list = function (context, list_url) {\n
\n
    context.attr(\'data-list-url\', list_url);\n
    $.ajax({\n
      type: \'GET\',\n
      url: list_url,\n
      dataType: \'json\',\n
      async: true,\n
      context: context, \n
      success: function(data) {\n
        var result_list = data.list || [],\n
          i;\n
\n
        for (i=0; i<result_list.length; i += 1) {\n
          var status_url = result_list[i],\n
            status_id,\n
            status_context;\n
          status_id = encodeURIComponent(Base61.encode(status_url)),\n
          status_context = $(this).find(\'#\' + status_id);\n
          if (!status_context[0]) {\n
            status_context = $(this).append(\'<li><a class="check_monitoring" id="\'\n
+ status_id + \'" data-url="\' + encodeURIComponent(status_url) + \'"></a></li>\')\n
                                    .find(\'#\' + status_id);\n
            (function(new_context) {\n
              setTimeout(function () {\n
                update_status(new_context);\n
              });\n
            })(status_context);\n
          }\n
        }\n
      },\n
      complete: function() {\n
        var context = $(this);\n
        setTimeout(function () {\n
          search_document_list(context, context.attr(\'data-list-url\'));\n
        }, 60000);\n
      },\n
    });\n
  };\n
\n
\n
\n
  methods = {\n
    fill_list: function (base_url) {\n
      var context = $(this),\n
        list_url = base_url + "/v1/status/"; // XXX Hardcoded\n
      setTimeout(function () {\n
        search_document_list(context, list_url);\n
      });\n
      return context;\n
    },\n
    check_status: function (base_url, relative_path) {\n
      var context = $(this),\n
        status_url = base_url + "/v1/status/" + relative_path; // XXX Hardcoded\n
      context.attr("data-url", encodeURIComponent(status_url));\n
      setTimeout(function () {\n
        update_status(context);\n
      });\n
      return context;\n
    },\n
  };\n
\n
  $.fn.vifibmonitoring = function (method) {\n
    var result;\n
    if (methods.hasOwnProperty(method)) {\n
      result = methods[method].apply(\n
        this,\n
        Array.prototype.slice.call(arguments, 1)\n
      );\n
    } else {\n
      $.error(\'Method \' + method +\n
              \' does not exist on jQuery.vifibmonitoring\');\n
    }\n
    return result;\n
  };\n
}(window, jQuery));\n


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