

function MaillistCreateInitEnterInformation(wizard, properties)
{
  var container = $("#template-maillist-create-from").tmpl(); 
    
  container.find("form").bind("submit", function(event)
  {
    event.preventDefault();
    wizard.Next();
  });
    
  wizard.Show(container);
}

function MaillistCreateValidateEnterInformation(wizard, properties)
{
  var name = "";
  var from = "";
  
  jQuery.each($(".popup-form-input"), function(n, element)
  {
    element = $(element);

    if (element.attr("name") == "name")
    {
      name = element.val();
    }
    else if (element.attr("name") == "from")
    {
      from = element.val();
    }
  });

  if ("" == name || "" == from)
  {
    return false;
  }

  properties["name"] = name;
  properties["from"] = from;

  return true;
}

function MaillistCreateInitCreate(wizard, properties)
{
  var in_node = { 
    "type" : "maillist", 
    "name" : properties["name"],
    "attributes" : {
      "From" : properties["from"]
    }
  };
 
  db.CreateNode(in_node, function(transaction_id, result_code, out_node)
  {
    if (MURRIX_RESULT_CODE_OK == result_code)
    {
      wizard.Show($("#template-maillist-create-done").tmpl({ "maillist" : out_node }));
    }
    else
    {
      wizard.Show($("#template-maillist-create-error").tmpl({ "result_code" : result_code }));
    }
  });  
}

var maillist_create_wizard = [
  { "init" : MaillistCreateInitEnterInformation,  "validate" : MaillistCreateValidateEnterInformation },
  { "init" : MaillistCreateInitCreate,            "validate" : null }
];


