<%inherit file="/base/base.html"/>

<%def name="title()">
    ${_('%s Files Edit') % c.repo_name} &middot; ${c.rhodecode_name}
</%def>

<%def name="js_extra()">
<script type="text/javascript" src="${h.url('/js/codemirror.js')}"></script>
<script type="text/javascript" src="${h.url('/js/codemirror_loadmode.js')}"></script>
<script type="text/javascript" src="${h.url('/js/mode/meta.js')}"></script>
</%def>
<%def name="css_extra()">
<link rel="stylesheet" type="text/css" href="${h.url('/css/codemirror.css')}"/>
</%def>

<%def name="page_nav()">
    ${self.menu('repositories')}
</%def>

<%def name="breadcrumbs_links()">
    ${_('Edit file')} @ ${h.show_id(c.cs)}
</%def>

<%def name="main()">
${self.repo_context_bar('files')}
<div class="box">
    <!-- box / title -->
    <div class="title">
        ${self.breadcrumbs()}
        <ul class="links">
            <li>
              <span style="text-transform: uppercase;">
              <a href="#">${_('Branch')}: ${c.cs.branch}</a></span>
            </li>
        </ul>
    </div>
    <div class="table">
        <div id="files_data">
            <h3 class="files_location">${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.cs.revision,c.file.path)}</h3>
            ${h.form(h.url.current(),method='post',id='eform')}
            <div id="body" class="codeblock">
            <div class="code-header">
                <div class="stats">
                    <div class="left"><img src="${h.url('/images/icons/file.png')}"/></div>
                    <div class="left item">${h.link_to("r%s:%s" % (c.file.changeset.revision,h.short_id(c.file.changeset.raw_id)),h.url('changeset_home',repo_name=c.repo_name,revision=c.file.changeset.raw_id))}</div>
                    <div class="left item">${h.format_byte_size(c.file.size,binary=True)}</div>
                    <div class="left item last">${c.file.mimetype}</div>
                    <div class="buttons">
                      ${h.link_to(_('Show annotation'),h.url('files_annotate_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path),class_="ui-btn")}
                      ${h.link_to(_('Show as raw'),h.url('files_raw_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path),class_="ui-btn")}
                      ${h.link_to(_('Download as raw'),h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path),class_="ui-btn")}
                      % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
                       % if not c.file.is_binary:
                        ${h.link_to(_('Source'),h.url('files_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path),class_="ui-btn")}
                       % endif
                      % endif
                    </div>
                </div>
                <label class="commit" for="set_mode">${_('Editing file')}: ${c.file.unicode_path}</label>
                ${h.select('set_mode','plain',[('plain',_('plain'))])}
            </div>
                <pre id="editor_pre"></pre>
                <textarea id="editor" name="content" style="display:none">${h.escape(c.file.content)|n}</textarea>
                <div style="padding: 10px;color:#666666">${_('Commit message')}</div>
                <textarea id="commit" name="message" style="height: 60px;width: 99%;margin-left:4px" placeholder="${c.default_message}"></textarea>
            </div>
            <div style="text-align: left;padding-top: 5px">
            ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
            ${h.reset('reset',_('Reset'),class_="ui-btn")}
            </div>
            ${h.end_form()}
            <script type="text/javascript">
            var reset_url = "${h.url('files_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.file.path)}";
            var myCodeMirror = initCodeMirror('editor',reset_url);
            CodeMirror.modeURL = "${h.url('/js/mode/%N/%N.js')}";

            //inject new modes
            var modes_select = YUD.get('set_mode');
            for(var i=0;i<CodeMirror.modeInfo.length;i++){
                var m = CodeMirror.modeInfo[i];
                var opt = new Option(m.name, m.mode);
                //try to figure out the mode based on the mime-type
                if(m.mime == "${c.file.mimetype}"){
                    setCodeMirrorMode(myCodeMirror, m.mode);
                    opt.selected = "selected";
                }
                modes_select.options[i+1] = opt
            }
            YUE.on(modes_select, 'change', function(e){
                var selected = e.currentTarget;
                var new_mode = selected.options[selected.selectedIndex].value;
                setCodeMirrorMode(myCodeMirror, new_mode);
            })
            </script>
        </div>
    </div>
</div>
</%def>
