## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer.  The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2012
## reddit Inc. All Rights Reserved.
###############################################################################

<%!
   from r2.lib.strings import strings
   from r2.lib.pages import UserText
   from r2.lib.template_helpers import add_sr
%>

<%namespace file="utils.html" import="error_field, submit_form, _a_buffered, reddit_selector"/>
<%namespace name="utils" file="utils.html"/>

<%
  if thing.default_sr:
    sr = "&#32" + _a_buffered(thing.default_sr.name, href=thing.default_sr.path)
  else:
    sr = _("reddit")
%>
<h1>${unsafe(_("submit to %(sr)s") % dict(sr=sr))}</h1>

<%utils:submit_form onsubmit="return post_form(this, 'submit', linkstatus, null, true)" 
                    action=${add_sr("/submit")},
                    _class="submit content",
                    _id="newlink">

%if thing.show_link and thing.show_self:
${thing.formtabs_menu}
%endif

<div class="formtabs-content">

<div class="spacer">
    %if thing.show_link:
        <div id="link-desc" class="infobar">${strings.submit_link}</div>
    %endif
    %if thing.show_self:
        <div id="text-desc" class="infobar">${strings.submit_text}</div>
    %endif
</div>

<div class="spacer">
  <%utils:round_field title="${_('title')}" id="title-field">
    <textarea name="title" rows="2" cols="1" wrap="hard">${thing.title}</textarea>
    ${error_field("NO_TEXT", "title", "div")}
    ${error_field("TOO_LONG", "title", "div")}
  </%utils:round_field>
</div>

%if thing.show_link:
<div class="spacer">
  <%utils:round_field title="${_('url')}" id="url-field">
    <input name="kind" value="link" type="hidden"/>
    <input id="url" name="url" type="text" value="${thing.url}"/>
    ${error_field("NO_URL", "url", "div")}
    ${error_field("BAD_URL", "url", "div")}
    ${error_field("DOMAIN_BANNED", "url", "div")}
    ${error_field("ALREADY_SUB", "url", "div")}
    ${error_field("NO_LINKS", "sr")}
    ${error_field("NO_SELFS", "sr")}

    <div>
      <button type="button" tabindex="100" onclick="fetch_title()">${_("suggest title")}</button>
      <span class="title-status"></span>
    </div>
  </%utils:round_field>
</div>
%endif

%if thing.show_self:
<div class="spacer">
  <%utils:round_field title="${_('text')}", description="${_('(optional)')}" id="text-field">
    <input name="kind" value="self" type="hidden"/>

    ${UserText(None, text = thing.text, have_form = False, creating = True)}

    ${error_field("NO_SELFS", "sr")}
  </%utils:round_field>
</div>
%endif

<div class="spacer">
  <%utils:round_field title="${_('choose a subreddit')}" id="reddit-field">
    ${reddit_selector(thing.default_sr.name if thing.default_sr else None, thing.sr_searches, thing.subreddits)}
  </%utils:round_field>
</div>

${thing.captcha}
    
</div>
<input name="resubmit" value="${thing.resubmit}" type="hidden"/>
<div class="spacer">
  <button class="btn" name="submit" value="form" type="submit">${_("submit")}</button>
  <span class="status"></span>
  ${error_field("RATELIMIT", "ratelimit")}
  ${error_field("INVALID_OPTION", "sr")}
</div>
</%utils:submit_form>

%if thing.show_self and thing.show_link:
<script type="text/javascript">
  $(function() {
  var form = $("#newlink");
  if(form.length) {
    var default_menu = form.find(".${thing.default_tab}-button:first");
    select_form_tab(default_menu, "${thing.default_show}", "${thing.default_hide}");
    }
  });
</script>
%endif
