<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%namespace name="forms" file="/forms.html"/>

<%def name="title()">${_("Variant: %s") % c.text.title|n}</%def>

<%def name="breadcrumbs()">${h.text.breadcrumbs(c.text)|n} &raquo; ${_("Edit variant")}</%def>


<%block name="main_content">
<form name="edit_page" class="inplace" method="POST" action="${h.entity_url(c.page, in_context=False)}" enctype="multipart/form-data">

    <h2>${_(u"Edit section") if c.section else _(u"Norm: %s") % c.page.title}</h2>
    ${h.field_token()|n}
    <input type="hidden" name="parent_text" value="${c.text.id}" />
    <input type="hidden" name="branch" value="${c.branch}" />

    %if c.text.is_head and not c.branch:
    <input type="hidden" name="variant" value="${c.variant}"/>
    %else:
    <label for="variant">${_("Variant Name")}</label>
    <input type="text" name="variant" value="${c.variant}" ${'readonly=readonly' if not c.branch else ''} />
    %endif

    %if c.text.is_head and h.has_permission('instance.admin') and not c.section:
    <label for="title">${_("Title")}</label>
    <input type="text" name="title" value="${c.text.title}"/>
    %else:
    <input type="hidden" name="title" value="${c.text.title}"/>
    %endif

    %if c.proposal:
        <input type="hidden" value="${c.proposal}" name="proposal" />
    %endif

    <input type="hidden" name="_method" value="PUT" />
    <input type="hidden" name="came_from" value="${c.came_from}" />

    <label for="text">${_("Text")}</label>
    <textarea rows="${c.text_rows}"
              cols="${model.Text.LINE_LENGTH}"
              name="text">${c.text.text if c.text.text is not None else ''}</textarea>
    %if c.page.formatting:
    ${components.formatting()}
    %endif

    %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="${c.page.abstract if c.page.abstract else ''}"
    help="${_(u'Page abstract. This is only used if a page is displayed as a tile.')}">
    </%forms:textarea>
    %endif


    %if can.page.manage(c.page):
    <fieldset>
        %if not c.section and not c.container:
        <div class="input_wrapper">
            <label>
                <input name="sectionpage" type="checkbox" ${'checked="checked"' if c.page.sectionpage else '' | n} value="1" />
                ${_('Display subnorms as sections')}
            </label>
        </div>
        %endif
        %if not c.container:
        <div class="input_wrapper">
            <label>
                <input name="allow_comment" type="checkbox" ${'checked="checked"' if c.page.allow_comment else '' | n} value="1" />
                ${_('Allow Comments')}
            </label>
        </div>
        %endif
        %if not c.container and (c.instance.allow_propose_changes or c.page.is_sectionpage()):
        <div class="input_wrapper">
            <label>
                <input name="allow_selection" type="checkbox" ${'checked="checked"' if c.page.allow_selection else '' | n} value="1" />
                ${_('Allow Amendments')}
            </label>
        </div>
        %endif
        <%doc>
        # uncomment this when it is actually used
        <div class="input_wrapper">
            <label>
                <input name="always_show_original" type="checkbox" ${'checked="checked"' if c.page.always_show_original else '' | n} value="1" />
                ${_('Always show original variant')}
            </label>
        </div>
        </%doc>
        %if not c.container:
        <div class="input_wrapper">
            <label>
                <input name="formatting" type="checkbox" ${'checked="checked"' if c.page.formatting else '' | n} value="1" />
                ${_("Use markdown formatting.")}
            </label>
        </div>
        %else:
        <input name="formatting" type="hidden" ${'checked="checked"' if c.page.formatting else '' | n} value="1" />
        %endif
    </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. Please note that the logo will only be displayed in the pages index.')}">
        </%forms:input>
        %if c.logo:
        <div class="current">
            ${h.literal(c.logo)}
            <br />
            <input type="submit" name="delete_logo" value="${_('Delete current logo')}" />
        </div>
        %endif
    </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}" ${'selected="selected"' if category==c.category else '' | n}>${category.title}</option>
                %endfor
            </select>
        </div>
    </fieldset>
    %endif

    %if not c.section:
    <label for="parent">${_("Parent page:")}</label>
    ${tiles.page.select_page(field_name="parent_page", select=c.page.parent, functions=model.Page.PARENT_FUNCTIONS)}
    %endif

    %endif

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

    ${components.savebox(c.came_from)}
    ${components.form_watch(c.page)}

</form>
</%block>
