## 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-2015
## reddit Inc. All Rights Reserved.
###############################################################################

<%!
   from r2.lib.filters import keep_space
   from r2.lib.pages import UserText
   from r2.lib.strings import strings
%>
<%namespace file="utils.html" import="error_field, language_tool, plain_link"/>
<%namespace file="utils.html" import="image_upload"/>
<%namespace file="printablebuttons.html" import="toggle_button, simple_button" />

<%namespace name="utils" file="utils.html"/>
 
<div class="create-reddit fancy-settings thing"
     %if thing.site:
       id="${thing.site._fullname}"
     %endif
     >

<div class="pretty-form" id="sr-form">

%if not thing.site:
    <%utils:line_field title="${_('name')}"
                        description='${_("no spaces, e.g., slashdot")}'>
     <input type="text" name="name" id="name" class="text"
            value="${thing.name}"/>
      %if not thing.site:
        ${error_field("SUBREDDIT_EXISTS", "name")}
        ${error_field("BAD_SR_NAME", "name")}
      %endif
    </%utils:line_field>
%else:
  <input type="hidden" name="sr" id="name" value="${thing.site._fullname}"/>
%endif

  <%utils:line_field title="${_('title')}"
       description='${_("e.g., slashdot: news for nerds, stuff that matters")}'>
    %if thing.site:
      <input id="title" type="text" name="title" class="text"
             value="${thing.site.title}"/>
    %else:
      <input id="title" type="text" name="title" class="text" />
    %endif
    ${error_field("NO_TEXT", "title")}
    ${error_field("TOO_LONG", "title")}
  </%utils:line_field>

  <%utils:line_field title="${_('description')}" css_class="usertext"
                     description="${_('publicly describe your subreddit for all to see. 500 characters max.')}">
    %if thing.site and thing.site.public_description:
     ${UserText(None, text=thing.site.public_description or "", editable=True, creating=True, name="public_description", have_form=False)}
    %else:
     ${UserText(None, text="", creating=True, name="public_description", have_form=False)}
    %endif
  </%utils:line_field>

  <%utils:line_field title="${_('sidebar')}" css_class="usertext"
                     description="${_('shown in the sidebar of your subreddit. 5120 characters max.')}">
    %if thing.site and thing.site.description:
     ${UserText(None, text=thing.site.description or "", editable=True, creating=True, name="description", have_form=False)}
    %else:
     ${UserText(None, text="", creating=True, name="description", have_form=False)}
    %endif
  </%utils:line_field>

  <%utils:line_field title="${_('submission text')}" css_class="usertext"
                     description="${_('text to show on submission page. 1024 characters max.')}">
    %if thing.site and thing.site.submit_text:
     ${UserText(None, text=thing.site.submit_text or "", editable=True, creating=True, name="submit_text", have_form=False)}
    %else:
     ${UserText(None, text="", creating=True, name="submit_text", have_form=False)}
    %endif
  </%utils:line_field>

  <%utils:line_field title="${_('language')}">
    <div class="delete-field">
      <%
         default_lang = thing.site and thing.site.lang or c.lang or ''
         default_lang = default_lang.split('-')[0]
         default_lang = g.lang if len(default_lang) != 2 else default_lang
       %>
      ${language_tool(all_langs = True, default_lang = default_lang)}
    </div>
  </%utils:line_field>

  <%utils:line_field title="${_('type')}">
    <div class="delete-field">
      <table>
      ${utils.radio_type('type', "public", _("public"),
                         _("anyone can view and submit"),
                         (not thing.site or thing.site.type=='public'))}
      ${utils.radio_type('type', "restricted", _("restricted"),
                         _("anyone can view, but only some are approved to submit links"),
                         (thing.site and thing.site.type=='restricted'))}
      ${utils.radio_type('type', "private", _("private"),
                         _("only approved members can view and submit"),
                         (thing.site and thing.site.type=='private'))}

      <% is_archived = thing.site and thing.site.type == 'archived' %>
      %if c.user_is_admin or is_archived:
        ${utils.radio_type('type', "archived", _("archived"),
                           _("anyone can view, but submissions are no longer accepted"),
                           is_archived)}
      %endif

      <% is_gold_restricted = thing.site and thing.site.type == 'gold_restricted' %>
      %if c.user_is_admin or is_gold_restricted:
        ${utils.radio_type('type', "gold_restricted", _("gold restricted"),
                           _("anyone can view, but only reddit gold members can submit or comment"),
                           is_gold_restricted)}
      %endif
      </table>
      ${error_field("INVALID_OPTION", "type")}
    </div>
  </%utils:line_field>

  <%utils:line_field title="${_('content options')}">
    <div class="delete-field">
      <table>
        ${utils.radio_type('link_type', "any", _("any"),
                           _("any link type is allowed"),
                           (not thing.site or thing.site.link_type=='any'))}
        ${utils.radio_type('link_type', "link", _("links only"),
                           _("only links to external sites are allowed"),
                           (thing.site and thing.site.link_type=='link'))}
        ${utils.radio_type('link_type', "self", _("text posts only"),
                           _("only text/self posts are allowed"),
                           (thing.site and thing.site.link_type=='self'))}
      </table>
      ${error_field("INVALID_OPTION", "link_type")}
    </div>
    <div class="usertext-edit">
      <div class="delete-field">
        <label for="submit_link_label">${_('Custom label for submit link button (blank for default):')}</label>
        <input id="submit_link_label" type="text" name="submit_link_label" maxlength="60" placeholder="${strings.submit_link_label}"
            %if thing.site:
                value="${thing.site.submit_link_label}"
            %endif
        >
      </div>
      <div class="delete-field">
        <label for="submit_text_label">${_('Custom label for submit text post button (blank for default):')}</label>
        <input id="submit_text_label" type="text" name="submit_text_label" maxlength="60" placeholder="${strings.submit_text_label}"
            %if thing.site:
                value="${thing.site.submit_text_label}"
            %endif
        >
      </div>
    </div>
  </%utils:line_field>
  <%utils:line_field title="${_('wiki')}">
    <div class="delete-field">
      <table>
        ${utils.radio_type('wikimode', "disabled", _("disabled"),
                           _("Wiki is disabled for all users except mods"),
                           (not thing.site or thing.site.wikimode == 'disabled'))}
        ${utils.radio_type('wikimode', "modonly", _("mod editing"),
                           _("Only mods, approved wiki contributors, or those on a page's edit list may edit"),
                           (thing.site and thing.site.wikimode == 'modonly'))}
        ${utils.radio_type('wikimode', "anyone", _("anyone"),
                           _("Anyone who can submit to the subreddit may edit"),
                           (thing.site and thing.site.wikimode == 'anyone'))}
      </table>
      ${error_field("INVALID_OPTION", "wikimode")}
    </div>
    <div class="usertext-edit">
    <div class="delete-field">
    <label for="wiki_edit_karma">${_('Subreddit karma required to edit and create wiki pages:')}</label>
        %if thing.site:
            <input id="wiki_edit_karma" type="text" name="wiki_edit_karma" 
                   value = "${thing.site.wiki_edit_karma}"/>
        %else:
            <input id="wiki_edit_karma" type="text" name="wiki_edit_karma" value="100" />
        %endif
        ${error_field("BAD_NUMBER", "wiki_edit_karma")}
    </div>
    <div class="delete-field">
    <label for="wiki_edit_age">${_('Account age (days) required to edit and create wiki pages:')}</label>
        %if thing.site:
            <input id="wiki_edit_age" type="text" name="wiki_edit_age" 
                   value = "${thing.site.wiki_edit_age}"/>
        %else:
            <input id="wiki_edit_age" type="text" name="wiki_edit_age" value="0" />
        %endif
        ${error_field("BAD_NUMBER", "wiki_edit_age")}
    </div>
    </div>
  </%utils:line_field>
  
  <%utils:line_field title="${_('spam filter strength')}">
  	<div class="delete-field">
        <p class="little gray">${_("high is the standard filter, low disables most filtering, all will filter every post initially and they will need to be approved manually to be visible.")}</p>
  		<table>
  			<tr>
  				<td>${_("links")}:</td>
  				<td>
  					${utils.inline_radio_type('spam_links', 'low', _("low"),
  						checked=thing.site and thing.site.spam_links == 'low')}
  					${utils.inline_radio_type('spam_links', 'high', _("high"),
  						checked=not thing.site or thing.site.spam_links == 'high')}
  					${utils.inline_radio_type('spam_links', 'all', _("all"),
  						checked=thing.site and thing.site.spam_links == 'all')}
	  			</td>
	  		</tr>
	  		<tr>
	  			<td>${_("self posts")}:</td>
	  			<td>
	  				${utils.inline_radio_type('spam_selfposts', 'low', _("low"),
  						checked=thing.site and thing.site.spam_selfposts == 'low')}
  					${utils.inline_radio_type('spam_selfposts', 'high', _("high"),
  						checked=not thing.site or thing.site.spam_selfposts == 'high')}
  					${utils.inline_radio_type('spam_selfposts', 'all', _("all"),
  						checked=thing.site and thing.site.spam_selfposts == 'all')}
	  			</td>
	  		</tr>
	  		<tr>
	  			<td>${_("comments")}:</td>
	  			<td>
	  				${utils.inline_radio_type('spam_comments', 'low', _("low"),
  						checked=not thing.site or thing.site.spam_comments == 'low')}
  					${utils.inline_radio_type('spam_comments', 'high', _("high"),
  						checked=thing.site and thing.site.spam_comments == 'high')}
  					${utils.inline_radio_type('spam_comments', 'all', _("all"),
  						checked=thing.site and thing.site.spam_comments == 'all')}
	  			</td>
	  		</tr>
		</table>
  	</div>
  </%utils:line_field>
  
  <%utils:line_field title="${_('other options')}">
    <div class="delete-field">
      <ul>
        <li>
          <input class="nomargin" type="checkbox"
                 name="over_18" id="over_18"
                 %if thing.site and thing.site.over_18:
                   checked="checked"
                 %endif
          >
          <label for="over_18">
            ${_("viewers must be over eighteen years old")}
          </label>
        </li>
        <li>
          <input class="nomargin" type="checkbox"
                 name="allow_top" id="allow_top"
                 %if not thing.site or thing.site.allow_top:
                   checked="checked"
                 %endif
          >
          <label for="allow_top">
            ${_("allow this subreddit to be included /r/all as well as the default and trending lists")}
          </label>
        </li>
        <li>
          <input class="nomargin" type="checkbox"
                 name="show_media" id="show_media"
                 %if thing.site and thing.site.show_media:
                   checked="checked"
                 %endif
          >
          <label for="show_media">
            ${_("show thumbnail images of content")}
          </label>
        </li>
        <li>
          <input class="nomargin" type="checkbox"
                 name="exclude_banned_modqueue" id="exclude_banned_modqueue"
                 %if thing.site and thing.site.exclude_banned_modqueue:
                   checked="checked"
                 %endif
          >
          <label for="exclude_banned_modqueue">
            ${_("exclude posts by site-wide banned users from modqueue/unmoderated")}
          </label>
        </li>
        <li>
          <input class="nomargin" type="checkbox"
                 name="public_traffic" id="public_traffic"
                 ${thing.site and thing.site.public_traffic and "checked='checked'" or ""}>
          <label for="public_traffic">
            ${_("make the traffic stats page available to everyone")}
          </label>
        </li>
        <li>
          <input class="nomargin" type="checkbox"
                 name="collapse_deleted_comments" id="collapse_deleted_comments"
                 %if thing.site and thing.site.collapse_deleted_comments:
                   checked="checked"
                 %endif
          >
          <label for="collapse_deleted_comments">
            ${_("collapse deleted and removed comments")}
          </label>
        </li>
      </ul>
    </div>
    <div class="usertext-edit">
      <div class="delete-field">
        <label for="comment_score_hide_mins">${_('Minutes to hide comment scores:')}</label>
            %if thing.site:
                <input id="comment_score_hide_mins" type="text" name="comment_score_hide_mins" placeholder="0" 
                       value = "${thing.site.comment_score_hide_mins}" />
            %else:
                <input id="comment_score_hide_mins" type="text" name="comment_score_hide_mins" value="0" placeholder="0" />
            %endif
            ${error_field("BAD_NUMBER", "comment_score_hide_mins")}
      </div>
    </div>
  </%utils:line_field>

% if thing.site and thing.site.domain != thing.site._defaults['domain']:
  <%utils:line_field title="${_('domain')}" css_class="usertext">
    <div class="delete-field">
      %if thing.site and c.site.domain:
          <input class="nomargin" type="checkbox" 
                 name="css_on_cname" id="css_on_cname"
                 %if thing.site.css_on_cname:
                   checked="checked"
                 %endif
          >
          <label for="css_on_cname">
            ${_("make custom CSS styles apply only when accessed from the cname.")}
          </label>
          <br/>
          <input class="nomargin" type="checkbox"
                 name="show_cname_sidebar" id="show_cname_sidebar"
                 %if thing.site.show_cname_sidebar:
                   checked="checked"
                 %endif
          >
          <label for="show_cname_sidebar">
            ${_("show sidebar when accessed from the cname.")}
          </label>
      %endif
    </div>
    <div class="usertext-edit">
      %if thing.site:
        <input id="domain" type="text" name="domain" class="text"
               value="${getattr(thing.site, 'domain', None) or ""}"/>
      %else:
        <input id="domain" type="text" name="domain" class="text" />
      %endif
      <div class="bottom-area">
        ${toggle_button("help-toggle", _("what's this?"), _("hide help"),
            "helpon", "helpoff")}
      </div>
      <div class="infobar markhelp md" style="display: none">
        ${_("Own a domain?  Enter it here and then go to your DNS provider and add a CNAME record aliasing your domain to rhs.reddit.com. You will be able to access your reddit through your domain.")}
      </div>
    </div>
  </%utils:line_field>
% endif

%if thing.site:
  <input type="hidden" name="sr" value="${thing.site._fullname}"/> 
    <%utils:line_field title="${_('look and feel')}">
      <ul class="upload">
        <li>
        ${plain_link(_("edit the stylesheet"),
                      "/about/stylesheet",
                      _sr_path = True)}
        &#32;
        <span class="gray">(${_("leaves this page")})</span>
        </li>
        <li>
          <label for="header-title">header mouseover text:</label>
          <input type="text" name="header-title" id="header-title"
                 value="${thing.site.header_title}"
                 />
        </li>
        <li>
          <%utils:image_upload post_target="/api/upload_sr_img" 
                               current_image="${thing.site.header}"
                               label="${_('upload header image')}"
                               ask_type="${True}">
            <br/>
            <button id="delete-img" class="delete-img"
                    %if not thing.site.header:
                       style="display: none;"
                    %endif
                    onclick="return post_form(this.form, 'delete_sr_header');">
              ${_('restore default header')}
            </button>
            <div class="clearleft"></div>
            <input type="hidden" name="uh" value="${c.modhash}" />
            <input type="hidden" name="r"  value="${c.site.name}" />
            <input type="hidden" name="header" value="1" />
  
            <script type="text/javascript">
              function on_image_success(img) {
                 $("#header-img").log().attr("src", img.attr("src"));
              }
            </script>
          </%utils:image_upload>
        </li>
      </ul>
    </%utils:line_field>
%endif


  <div class="save-button">
  <%
     if thing.site:
         name = "edit"
         text = _("save options")
     else:
         name = "create"
         text = _("create")
  %>
  <button name="${name}" class="btn" type="button"
          onclick="return post_pseudo_form('#sr-form', 'site_admin')">
    ${text}
  </button>
  &#32;
  <span class="status error"></span>
  ${error_field("RATELIMIT", "ratelimit")}
  </div>
</div>
</div>

