<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="Web Script" module="erp5.portal_type"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>_Access_contents_information_Permission</string> </key>
            <value>
              <tuple>
                <string>Anonymous</string>
                <string>Assignee</string>
                <string>Assignor</string>
                <string>Associate</string>
                <string>Auditor</string>
                <string>Manager</string>
                <string>Owner</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>_Add_portal_content_Permission</string> </key>
            <value>
              <tuple>
                <string>Assignee</string>
                <string>Assignor</string>
                <string>Manager</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>_Change_local_roles_Permission</string> </key>
            <value>
              <tuple>
                <string>Assignor</string>
                <string>Manager</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>_Modify_portal_content_Permission</string> </key>
            <value>
              <tuple>
                <string>Assignee</string>
                <string>Assignor</string>
                <string>Manager</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>_View_Permission</string> </key>
            <value>
              <tuple>
                <string>Anonymous</string>
                <string>Assignee</string>
                <string>Assignor</string>
                <string>Associate</string>
                <string>Auditor</string>
                <string>Manager</string>
                <string>Owner</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>content_md5</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>default_reference</string> </key>
            <value> <string>slapos_parameter_form.js</string> </value>
        </item>
        <item>
            <key> <string>description</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>rjs_slapos_parameter_form_js</string> </value>
        </item>
        <item>
            <key> <string>language</string> </key>
            <value> <string>en</string> </value>
        </item>
        <item>
            <key> <string>portal_type</string> </key>
            <value> <string>Web Script</string> </value>
        </item>
        <item>
            <key> <string>short_title</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>text_content</string> </key>
            <value> <string encoding="cdata"><![CDATA[

/*jslint nomen: true, maxlen: 200, indent: 2*/\n
/*global rJS, console, window, document, loopEventListener, $, XMLSerializer, jQuery, URI, vkbeautify */\n
\n
(function (window, document, rJS, loopEventListener, $, XMLSerializer, jQuery, URI, vkbeautify) {\n
  "use strict";\n
\n
  var gk = rJS(window);\n
\n
  function jsonDictToParameterXML(json) {\n
    var parameter_id,\n
      xml_output = $($.parseXML(\'<?xml version="1.0" encoding="utf-8" ?><instance />\'));\n
    // Used by serialisation XML\n
    for (parameter_id in json) {\n
      if (json.hasOwnProperty(parameter_id)) {\n
        $(\'instance\', xml_output).append(\n
          $(\'<parameter />\', xml_output)\n
            .text(json[parameter_id])\n
              .attr({id: parameter_id})\n
        );\n
      }\n
    }\n
    return vkbeautify.xml(\n
      (new XMLSerializer()).serializeToString(xml_output.context)\n
    );\n
  }\n
\n
  function render_selection(json_field) {\n
    var input = document.createElement("select"),\n
      option = document.createElement("option"),\n
      option_index,\n
      optionz;\n
    input.size = 1;\n
    option.selected = "selected";\n
    option.value = "";\n
    input.appendChild(option);\n
    for (option_index in json_field.enum) {\n
      if (json_field.enum.hasOwnProperty(option_index)) {\n
        optionz = document.createElement("option");\n
        optionz.value = json_field.enum[option_index];\n
        optionz.textContent = json_field.enum[option_index];\n
        input.appendChild(optionz);\n
      }\n
    }\n
    return input;\n
  }\n
\n
  function render_field(json_field, default_value) {\n
\n
    if (json_field.enum !== undefined) {\n
      return render_selection(json_field);\n
    }\n
\n
    if (json_field.type === "boolean") {\n
      json_field.enum = [true, false];\n
      return render_selection(json_field);\n
    }\n
\n
    var input = document.createElement("input");\n
\n
    if (default_value !== undefined) {\n
      input.value = default_value;\n
    }\n
\n
    switch (json_field.type) {\n
    case "integer":\n
      input.type = "number";\n
      break;\n
    default:\n
      input.type = "text";\n
    }\n
\n
    return input;\n
  }\n
\n
  function getFormValuesAsJSONDict(element) {\n
    var json_dict = {};\n
    $(element.querySelectorAll(".slapos-parameter")).each(function (key, input) {\n
      if (input.value !== "") {\n
        if (input.type === \'number\') {\n
          json_dict[input.name] = parseInt(input.value, 10);\n
        } else if (input.value === "true") {\n
          json_dict[input.name] = true;\n
        } else if (input.value === "false") {\n
          json_dict[input.name] = false;\n
        } else {\n
          json_dict[input.name] = input.value;\n
        }\n
      }\n
    });\n
    console.log(json_dict);\n
    return json_dict;\n
  }\n
\n
  function validateForm(gadget, json_url) {\n
    return gadget.processValidation(json_url);\n
  }\n
\n
  //function getSoftwareTypeFromForm(element) {\n
  //  var software_type;\n
  //  $(element.querySelectorAll(".slapos-software-type")).each(function (key, input) {\n
  //    software_type = input.value;\n
  //  });\n
  //  return software_type;\n
  //}\n
\n
  gk.ready(function (g) {\n
    g.props = {};\n
    return g.getElement()\n
      .push(function (element) {\n
        g.props.element = element;\n
      });\n
  })\n
\n
\n
    .declareMethod("loadJSONSchema", function (url) {\n
      return this.getDeclaredGadget(\'loadschema\')\n
        .push(function (gadget) {\n
          return gadget.loadJSONSchema(url);\n
        });\n
    })\n
\n
    .declareMethod("validateJSON", function (schema_url, generated_json) {\n
      return this.getDeclaredGadget(\'loadschema\')\n
        .push(function (gadget) {\n
          return gadget.validateJSON(schema_url, generated_json);\n
        });\n
    })\n
\n
    .declareMethod("loadSoftwareJSON", function (url) {\n
      return this.getDeclaredGadget(\'loadschema\')\n
        .push(function (gadget) {\n
          return gadget.loadSoftwareJSON(url);\n
        });\n
    })\n
\n
    .declareAcquiredMethod(\'pleaseRedirectMyHash\', \'pleaseRedirectMyHash\')\n
\n
    .declareMethod(\'processValidation\', function (json_url) {\n
      var g = this,\n
        // software_type = getSoftwareTypeFromForm(g.props.element),\n
        json_dict = getFormValuesAsJSONDict(g.props.element);\n
\n
      return g.validateJSON(json_url, json_dict)\n
        .push(function (validation) {\n
          var error_index,\n
            parameter_input = g.props.element.querySelectorAll(\'.parameter_xml_output\')[0],\n
            field_name,\n
            div,\n
            divm,\n
            missing_index,\n
            missing_field_name;\n
\n
          $(g.props.element.querySelectorAll("span.error")).each(function (i, span) {\n
            span.textContent = "";\n
          });\n
\n
          $(g.props.element.querySelectorAll("div.error-input")).each(function (i, div) {\n
            div.setAttribute("class", "");\n
          });\n
\n
          if (validation.valid) {\n
            parameter_input.value = jsonDictToParameterXML(json_dict);\n
          } else {\n
            for (error_index in validation.errors) {\n
              if (validation.errors.hasOwnProperty(error_index)) {\n
                field_name = validation.errors[error_index].dataPath.slice(1);\n
                div = $(\'.slapos-parameter[name=\' + field_name  + "]")[0].parentNode;\n
                div.setAttribute("class", "slapos-parameter error-input");\n
                div.querySelector("span.error").textContent = validation.errors[error_index].message;\n
              }\n
            }\n
\n
            for (missing_index in validation.missing) {\n
              if (validation.missing.hasOwnProperty(missing_index)) {\n
                missing_field_name = validation.missing[missing_index].dataPath.slice(1);\n
                divm = $(\'.slapos-parameter[name=\' + missing_field_name  + "]")[0].parentNode;\n
                divm.setAttribute("class", "error-input");\n
                divm.querySelector("span.error").textContent = validation.missing[missing_index].message;\n
              }\n
            }\n
            parameter_input.value = "ERROR";\n
          }\n
          console.log(jsonDictToParameterXML(json_dict));\n
          return false;\n
        });\n
    })\n
\n
    .declareMethod(\'renderParameterForm\', function (json_url, default_dict) {\n
\n
      var g = this;\n
      return g.loadJSONSchema(json_url)\n
        .push(function (json) {\n
          var key,\n
            div,\n
            label,\n
            input,\n
            div_input,\n
            span_error,\n
            span_info,\n
            fieldset = document.createElement("fieldset"),\n
            fieldset_optional = document.createElement("fieldset");\n
\n
          for (key in json.properties) {\n
            if (json.properties.hasOwnProperty(key)) {\n
              div = document.createElement("div");\n
              div.setAttribute("class", "field");\n
              div.title = json.properties[key].description;\n
              /* console.log(key); */\n
              label = document.createElement("label");\n
              label.textContent = json.properties[key].title;\n
              div.appendChild(label);\n
              div_input = document.createElement("div");\n
              div.setAttribute("class", "input");\n
              input = render_field(json.properties[key], default_dict[key]);\n
              input.name = key;\n
              input.setAttribute("class", "slapos-parameter");\n
              div_input.appendChild(input);\n
              if (json.properties[key].default !== undefined) {\n
                span_info = document.createElement("span");\n
                span_info.textContent = \'(default = \' + json.properties[key].default + \')\';\n
                div_input.appendChild(span_info);\n
              }\n
\n
              span_error = document.createElement("span");\n
              span_error.setAttribute("class", "error");\n
              div_input.appendChild(span_error);\n
              div.appendChild(div_input);\n
              if (json.properties[key].optional === true) {\n
                fieldset_optional.appendChild(div);\n
              } else {\n
                fieldset.appendChild(div);\n
              }\n
              loopEventListener(\n
                input,\n
                \'change\',\n
                false,\n
                validateForm.bind(g, g, json_url)\n
              );\n
            }\n
          }\n
          return [fieldset, fieldset_optional];\n
        }).push(function (new_fieldset_list) {\n
          var fieldset_list = g.props.element.querySelectorAll(\'fieldset\');\n
\n
          $(fieldset_list[1]).replaceWith(new_fieldset_list[0]);\n
          $(fieldset_list[2]).replaceWith(new_fieldset_list[1]);\n
          return fieldset_list;\n
        });\n
    })\n
\n
    .declareMethod(\'renderFailoverTextArea\', function (content, error) {\n
      var g = this,\n
        div = document.createElement("div"),\n
        div_error = document.createElement("div"),\n
        span_error = document.createElement("span"),\n
        textarea = document.createElement("textarea"),\n
        fieldset = document.createElement("fieldset"),\n
        fieldset_list = g.props.element.querySelectorAll(\'fieldset\');\n
\n
      div.setAttribute("class", "field");\n
      textarea.setAttribute("rows", "10");\n
      textarea.setAttribute("cols", "80");\n
\n
      textarea.setAttribute("name", "field_your_instance_xml");\n
      textarea.textContent = content;\n
\n
      span_error.setAttribute("class", "error");\n
      span_error.textContent = "You got one error when loading json schema, so the form is not going to be rendered: " + error;\n
\n
      div_error.setAttribute("class", "error");\n
\n
      div.appendChild(textarea);\n
      div_error.appendChild(span_error);\n
      div.appendChild(textarea);\n
\n
      fieldset.appendChild(div);\n
      fieldset.appendChild(div_error);\n
\n
      fieldset_list[0].innerHTML = \'\';\n
      $(fieldset_list[1]).replaceWith(fieldset);\n
      fieldset_list[2].innerHTML = \'\';\n
      fieldset_list[3].innerHTML = \'\';\n
\n
      return fieldset;\n
    })\n
    .declareMethod(\'render\', function (options) {\n
      if (options.json_url === undefined) {\n
        throw new Error("undefined json_url");\n
      }\n
\n
      var g = this,\n
        softwaretype;\n
\n
      function updateParameterForm(evt) {\n
        options.parameter.softwaretype = evt.srcElement.value;\n
        return g.render(options);\n
      }\n
\n
      return g.loadSoftwareJSON(options.json_url).push(function (json) {\n
        var option_index,\n
          option,\n
          option_selected = options.parameter.softwaretype,\n
          input = g.props.element.querySelectorAll(\'select\')[0];\n
\n
        if (json.serialisation !== "xml") {\n
          throw new Error("Unsuported serialisation");\n
        }\n
\n
        if (input.children.length === 0) {\n
          for (option_index in json[\'software-type\']) {\n
            if (json[\'software-type\'].hasOwnProperty(option_index)) {\n
              option = document.createElement("option");\n
              option.value = option_index;\n
              option.textContent = json[\'software-type\'][option_index].title;\n
              option.index = json[\'software-type\'][option_index].index;\n
\n
              if (option_selected === undefined) {\n
                option_selected = option_index;\n
              }\n
\n
              if (softwaretype === undefined) {\n
                softwaretype = option_selected;\n
              }\n
\n
              if (option_index === option_selected) {\n
                option.selected = "selected";\n
              }\n
              input.appendChild(option);\n
            }\n
          }\n
        }\n
\n
        if (softwaretype === undefined) {\n
          softwaretype = option_selected;\n
        }\n
\n
        return json[\'software-type\'][softwaretype].request;\n
      })\n
        .push(function (parameter_json_schema_url) {\n
          var parameter_dict = {}, json_url_uri, prefix;\n
\n
          if (options.parameter.parameter_xml !== undefined) {\n
            $(jQuery.parseXML(options.parameter.parameter_xml)\n
              .querySelectorAll("parameter"))\n
                .each(function (key, p) {\n
                parameter_dict[p.id] = p.textContent;\n
              });\n
          }\n
\n
          if (URI(parameter_json_schema_url).protocol() === "") {\n
            // URL is relative, turn into absolute\n
            json_url_uri = URI(options.json_url);\n
            prefix = json_url_uri.path().split("/");\n
            prefix.pop();\n
            prefix = options.json_url.split(json_url_uri.path())[0] + prefix.join("/");\n
            parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;\n
          }\n
\n
          return g.renderParameterForm(parameter_json_schema_url, parameter_dict);\n
        })\n
        .push(function () {\n
          var element = g.props.element.getElementsByTagName(\'select\')[0];\n
          console.log("INITIATING A LOOP EVENT LISTENER FOR OPTION CHANGE");\n
          return loopEventListener(\n
            element,\n
            \'change\',\n
            false,\n
            updateParameterForm.bind(g)\n
          );\n
        })\n
        .fail(function (error) {\n
          console.error(error.stack);\n
          return g.renderFailoverTextArea(\'\', error.toString());\n
        });\n
    });\n
\n
}(window, document, rJS, loopEventListener, $, XMLSerializer, jQuery, URI, vkbeautify));

]]></string> </value>
        </item>
        <item>
            <key> <string>title</string> </key>
            <value> <string>slapos_parameter_form.js</string> </value>
        </item>
        <item>
            <key> <string>version</string> </key>
            <value> <string>001</string> </value>
        </item>
        <item>
            <key> <string>workflow_history</string> </key>
            <value>
              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
  <record id="2" aka="AAAAAAAAAAI=">
    <pickle>
      <global name="PersistentMapping" module="Persistence.mapping"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>data</string> </key>
            <value>
              <dictionary>
                <item>
                    <key> <string>document_publication_workflow</string> </key>
                    <value>
                      <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
                    </value>
                </item>
                <item>
                    <key> <string>edit_workflow</string> </key>
                    <value>
                      <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
                    </value>
                </item>
                <item>
                    <key> <string>processing_status_workflow</string> </key>
                    <value>
                      <persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
                    </value>
                </item>
              </dictionary>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
  <record id="3" aka="AAAAAAAAAAM=">
    <pickle>
      <global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
    </pickle>
    <pickle>
      <tuple>
        <none/>
        <list>
          <dictionary>
            <item>
                <key> <string>action</string> </key>
                <value> <string>publish_alive</string> </value>
            </item>
            <item>
                <key> <string>actor</string> </key>
                <value> <string>zope</string> </value>
            </item>
            <item>
                <key> <string>comment</string> </key>
                <value> <string></string> </value>
            </item>
            <item>
                <key> <string>error_message</string> </key>
                <value> <string></string> </value>
            </item>
            <item>
                <key> <string>time</string> </key>
                <value>
                  <object>
                    <klass>
                      <global name="DateTime" module="DateTime.DateTime"/>
                    </klass>
                    <tuple>
                      <none/>
                    </tuple>
                    <state>
                      <tuple>
                        <float>1420555875.95</float>
                        <string>UTC</string>
                      </tuple>
                    </state>
                  </object>
                </value>
            </item>
            <item>
                <key> <string>validation_state</string> </key>
                <value> <string>published_alive</string> </value>
            </item>
          </dictionary>
        </list>
      </tuple>
    </pickle>
  </record>
  <record id="4" aka="AAAAAAAAAAQ=">
    <pickle>
      <global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
    </pickle>
    <pickle>
      <tuple>
        <none/>
        <list>
          <dictionary>
            <item>
                <key> <string>action</string> </key>
                <value> <string>edit</string> </value>
            </item>
            <item>
                <key> <string>actor</string> </key>
                <value> <string>zope</string> </value>
            </item>
            <item>
                <key> <string>comment</string> </key>
                <value>
                  <none/>
                </value>
            </item>
            <item>
                <key> <string>error_message</string> </key>
                <value> <string></string> </value>
            </item>
            <item>
                <key> <string>serial</string> </key>
                <value> <string>941.46904.21655.48418</string> </value>
            </item>
            <item>
                <key> <string>state</string> </key>
                <value> <string>current</string> </value>
            </item>
            <item>
                <key> <string>time</string> </key>
                <value>
                  <object>
                    <klass>
                      <global name="DateTime" module="DateTime.DateTime"/>
                    </klass>
                    <tuple>
                      <none/>
                    </tuple>
                    <state>
                      <tuple>
                        <float>1426596317.01</float>
                        <string>UTC</string>
                      </tuple>
                    </state>
                  </object>
                </value>
            </item>
          </dictionary>
        </list>
      </tuple>
    </pickle>
  </record>
  <record id="5" aka="AAAAAAAAAAU=">
    <pickle>
      <global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
    </pickle>
    <pickle>
      <tuple>
        <none/>
        <list>
          <dictionary>
            <item>
                <key> <string>action</string> </key>
                <value> <string>detect_converted_file</string> </value>
            </item>
            <item>
                <key> <string>actor</string> </key>
                <value> <string>zope</string> </value>
            </item>
            <item>
                <key> <string>comment</string> </key>
                <value> <string></string> </value>
            </item>
            <item>
                <key> <string>error_message</string> </key>
                <value> <string></string> </value>
            </item>
            <item>
                <key> <string>external_processing_state</string> </key>
                <value> <string>converted</string> </value>
            </item>
            <item>
                <key> <string>serial</string> </key>
                <value> <string>0.0.0.0</string> </value>
            </item>
            <item>
                <key> <string>time</string> </key>
                <value>
                  <object>
                    <klass>
                      <global name="DateTime" module="DateTime.DateTime"/>
                    </klass>
                    <tuple>
                      <none/>
                    </tuple>
                    <state>
                      <tuple>
                        <float>1420555828.84</float>
                        <string>UTC</string>
                      </tuple>
                    </state>
                  </object>
                </value>
            </item>
          </dictionary>
        </list>
      </tuple>
    </pickle>
  </record>
</ZopeData>
