<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%namespace name="forms" file="/forms.html"/>
<%def name="title()">${_("New page")}</%def>

<%def name="breadcrumbs()">
    ${h.page.breadcrumbs(None)|n} &raquo; ${_("New page")}
</%def>

<%block name="headline">
    <h3>${_(u"Add section to %s") % c.parent.title if c.section else _("Create norm")}</h3>
</%block>


<%block name="main_content">
<form name="create_page" class="inplace" method="POST" action="${h.base_url('/page')}" enctype="multipart/form-data">
    ${h.field_token()|n}
    %if c.proposal:
    <input type="hidden" value="${c.proposal}" name="proposal" />
    %endif

    %if c.section:
    <input type="hidden" name="came_from" value="${h.entity_url(c.parent)}" />
    %endif

    <div class="mainbar">
        %if c.section:
        <input type="hidden" name="title" value="${c.title}" />
        %else:
        <fieldset>
            <legend>${_("Norm title")}</legend>
            <div class="input_wrapper page_title">
                <input type="text" class="title" name="title" ${'' if c.title is None else 'value="%s"' % c.title} placeholder="${_('New norm')}" autofocus />
            </div>
        </fieldset>
        %endif

        %if not c.section:
        <fieldset>
            <legend>${_("Category")}</legend>
            <div class="input_wrapper">
                <select name="category">
                    <option value="">${_("No Category")}</option>
                    %for category in c.categories:
                    <option value="${category.id}">${category.title}</option>
                    %endfor
                </select>
            </div>
        </fieldset>
        %endif

        <fieldset>
            <legend>${_(u"Section content") if c.section else _(u"Norm content")}</legend>
            <textarea class="description normedit" cols="${model.Text.LINE_LENGTH}" name="text"></textarea>
        </fieldset>

        %if h.config.get_bool('adhocracy.page.allow_abstracts') and c.instance.page_index_as_tiles and not c.section:
        <%forms:textarea label="${_('Abstract')}" name="abstract" value=""
        help="${_(u'Page abstract. This is only used if a page is displayed as a tile.')}">
        </%forms:textarea>
        %endif

        <fieldset>
            ${forms.checkbox(_("Use as a container for other norms"), 'container')}
            %if not c.section:
            <div class="input_wrapper">
                <label>
                    <input name="sectionpage" type="checkbox" checked="checked" value="1" />
                    ${_('Display subnorms as sections')}
                </label>
            </div>
            %endif
            <div class="input_wrapper">
                <label>
                    <input name="allow_comment" type="checkbox" checked="checked" value="1" />
                    ${_('Allow Comments')}
                </label>
            </div>
            <div class="input_wrapper">
                <label>
                    <input name="allow_selection" type="checkbox" checked="checked" value="1" />
                    ${_('Allow Amendments')}
                </label>
            </div>
            <%doc>
            # uncomment this when it is actually used
            <div class="input_wrapper">
                <label>
                    <input name="always_show_original" type="checkbox" checked="checked" value="1" />
                    ${_('Always show original variant')}
                </label>
            </div>
            </%doc>
            <div class="input_wrapper">
                <label>
                    <input name="formatting" type="checkbox" checked="checked" value="1" />
                    ${_("Use markdown formatting.")}
                </label>
            </div>
        </fieldset>

        %if c.instance.page_index_as_tiles and not c.section:
        <fieldset class="logo">
            <%forms:input label="Logo" name="logo" type="file"
                          help="${_('Upload a logo for this page')}">
            </%forms:input>
        </fieldset>
        %endif

        %if c.section:
        <input type="hidden" name="tags" value="" />
        %else:
        <fieldset>
            <% h.need.autocomplete %>

            <legend>${_("Tag and classify")}</legend>
            <div class="input_wrapper">
                <input type="text" name="tags" id="tags" class="long" placeholder="${_('Tags')}" data-instance-baseurl="${h.base_url(append_slash=True)}" />
            </div>
        </fieldset>
        %endif

        %if c.section:
        <input type="hidden" name="parent" value="${c.parent.id}"/>
        %else:
        <label for="parent">${_("Parent page:")}</label>
        ${tiles.page.select_page(field_name="parent", functions=model.Page.PARENT_FUNCTIONS)}
        <span class="hint">${_("The new norm will be categorized under the specified parent theme.")}
        </span>
        %endif

        %if not c.section:
        %if c.instance.milestones:
          <label for="milestone">${_("Relates to a milestone")}</label>
          ${tiles.milestone.select(None)}
        %endif
        %endif
    </div>

    <div style="clear:both;"></div>
    <div class="mainbar">
        <div class="submit">
            %if c.section:
            ${components.savebox(h.entity_url(c.parent))}
            %else:
            ${components.savebox(h.base_url('/page'))}
            %endif
        </div>
        ${components.form_watch(None, checked=True)}
    </div>
</form>
</%block>
