<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string encoding="cdata"><![CDATA[

tool = context.getPortalObject().portal_slapos_rest_api\n
return """\n
<script>\n
$(document).ready(function () {\n
  var context = $(".allocable_to_check"),\n
    checkallocable,\n
    timer,\n
    xhr,\n
    key, i,\n
    sla_key_list;\n
\n
  sla_key_list = [\n
    \'cpu_core\',\n
    \'cpu_frequency\',\n
    \'cpu_type\',\n
    \'local_area_network_type\',\n
    \'memory_size\',\n
    \'memory_type\',\n
    \'region\',\n
    \'storage_capacity\',\n
    \'storage_interface\',\n
    \'storage_redundancy\',\n
    \'computer_guid\',\n
    \'group\',\n
    \'network_guid\',\n
  ];\n
\n
  checkallocable = function () {\n
    var context = $(".allocable_to_check"),\n
      sla = {}, val;\n
\n
    if (timer !== undefined) {\n
      clearTimeout(timer);\n
    }\n
    if (xhr !== undefined) {\n
      xhr.abort();\n
    }\n
\n
    for (i=0; i<sla_key_list.length; i+=1) {\n
      key = sla_key_list[i];\n
      val = $(\'[name="field_your_\' + key + \'"]\').val();\n
      if (val) {\n
        sla[key] = val;\n
      }\n
    }\n
    \n
    context.text("checking...");\n
    xhr = $.vifiballocable({\n
      context: context,\n
      url: \'%s/v1/instance/request\', \n
      slave: false, \n
      software_release: context.attr("data-url"), \n
      software_type: "default", \n
      sla: sla,\n
      success: function(data) {\n
        if (data.result === true) {\n
          $(this).text("There is space!");\n
        } else {\n
          $(this).text("Sorry, no space left in the cloud :(");\n
        }\n
      }, \n
      error: function(data) {\n
        $(this).text("Unable to check if there is space");\n
      }, \n
      complete: function () {\n
        timer = setTimeout(function() {\n
          checkallocable();\n
          }, 60000);\n
      },\n
    });\n
  };\n
  for (i=0; i<sla_key_list.length; i+=1) {\n
    key = sla_key_list[i];\n
    $(\'[name="field_your_\' + key + \'"]\').change(checkallocable);\n
  }\n
\n
  checkallocable();\n
});\n
\n
\n
</script>\n
""" % tool.absolute_url()\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string></string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>SoftwareRelease_getRequestDialogJS</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
