<%! from django.utils.translation import ugettext as _ %>
<%inherit file="base.html" />
<%! from django.core.urlresolvers import reverse %>

<%block name="title">${_("Sign Up")}</%block>
<%block name="bodyclass">not-signedin view-signup</%block>

<%block name="content">

<div class="wrapper-content wrapper">
  <section class="content">
    <header>
      <h1 class="title title-1">${_("Sign Up for edX Studio")}</h1>
      <a href="${reverse('login')}" class="action action-signin">${_("Already have a Studio Account? Sign in")}</a>
    </header>

    <p class="introduction">${_("Ready to start creating online courses? Sign up below and start creating your first edX course today.")}</p>

    <article class="content-primary" role="main">
      <form id="register_form" method="post" action="register_post">
        <div id="register_error" name="register_error" class="message message-status message-status error">
        </div>

        <fieldset>
          <legend class="sr">${_("Required Information to Sign Up for edX Studio")}</legend>

          <ol class="list-input">
            <li class="field text required" id="field-email">
              <label for="email">${_("Email Address")}</label>
              <input id="email" type="email" name="email" placeholder="e.g. jane.doe@gmail.com" />
            </li>

            <li class="field text required" id="field-password">
              <label for="password">${_("Password")}</label>
              <input id="password" type="password" name="password" />
            </li>

            <li class="field text required" id="field-username">
              <label for="username">${_("Public Username")}</label>
              <input id="username" type="text" name="username" placeholder="e.g. janedoe" />
              <span class="tip tip-stacked">${_("This will be used in public discussions with your courses and in our edX101 support forums")}</span>
            </li>

            <li class="field text required" id="field-name">
              <label for="name">${_("Full Name")}</label>
              <input id="name" type="text" name="name" placeholder="e.g. Jane Doe" />
            </li>

            <li class="field-group">
              <div class="field text" id="field-location">
                <label for="location">${_("Your Location")}</label>
                <input class="short" id="location" type="text" name="location" />
              </div>

              <div class="field text" id="field-language">
                <label for="language">${_("Preferred Language")}</label>
                <input class="short" id="language" type="text" name="language" />
              </div>
            </li>

            <li class="field checkbox required" id="field-tos">
              <input id="tos" name="terms_of_service" type="checkbox" value="true" />
              <label for="tos">
                ${_("I agree to the {a_start} Terms of Service {a_end}").format(a_start='<a data-rel="edx.org" href="{}">'.format(marketing_link('TOS')), a_end="</a>")}
              </label>
            </li>
          </ol>
        </fieldset>

        <div class="form-actions">
          <button type="submit" id="submit" name="submit" class="action action-primary">${_("Create My Account &amp; Start Authoring Courses")}</button>
        </div>

        <!-- no honor code for CMS, but need it because we're using the lms student object -->
        <input name="honor_code" type="checkbox" value="true" checked="true" hidden="true">
      </form>
    </article>

    <aside class="content-supplementary" role="complimentary">
      <h2 class="sr">${_("Common Studio Questions")}</h2>

      <div class="bit">
        <h3 class="title-3">${_("Who is Studio for?")}</h3>
        <p>${_("Studio is for anyone that wants to create online courses that leverage the global edX platform. Our users are often faculty members, teaching assistants and course staff, and members of instructional technology groups.")}</p>
      </div>

      <div class="bit">
        <h3 class="title-3">${_("How technically savvy do I need to be to create courses in Studio?")}</h3>
        <p>${_("Studio is designed to be easy to use by almost anyone familiar with common web-based authoring environments (Wordpress, Moodle, etc.). No programming knowledge is required, but for some of the more advanced features, a technical background would be helpful. As always, we are here to help, so don't hesitate to dive right in.")}</p>
      </div>

      <div class="bit">
        <h3 class="title-3">${_("I've never authored a course online before. Is there help?")}</h3>
        <p>${_("Absolutely. We have created an online course, edX101, that describes some best practices: from filming video, creating exercises, to the basics of running an online course. Additionally, we're always here to help, just drop us a note.")}</p>
      </div>
    </aside>
  </section>
</div>
</%block>

<%block name="jsextra">
  <script type="text/javascript">
require(["jquery", "jquery.cookie"], function($) {
  $("form :input").focus(function() {
    $("label[for='" + this.id + "']").addClass("is-focused");
  }).blur(function() {
    $("label").removeClass("is-focused");
  });

  // form validation
  function postJSON(url, data, callback) {
    $.ajax({type:'POST',
      url: url,
      dataType: 'json',
      data: data,
      success: callback,
      headers : {'X-CSRFToken': $.cookie('csrftoken')}
    });
  }

  $('form#register_form').submit(function(e) {
    e.preventDefault();
    var submit_data = $('#register_form').serialize();

    postJSON('/create_account',
      submit_data,
      function(json) {
        if(json.success) {
          location.href = "${'/course'}";
        } else {
          $('#register_error').html(json.value).stop().addClass('is-shown');
        }
      }
    );
  });
});
  </script>
</%block>
