/templates/type/edition/edit.tmpl
Type: /type/template
body: value: $def with (page, action=None, title=None)

$ _t = i18n.get_namespace('/type/edition')
$ _ = i18n.get_namespace('/mode/edit')

$ title = title or safeadd(_.editing, ' ', page.title)
 
$var title: $title

$add_javascript('/static/js/jquery/jquery.js')

$add_javascript('/static/js/jquery/freebase.suggest.js')

$add_javascript('/static/js/jquery/freebase.controls.js')
$add_javascript('/static/js/jquery/freebase.select.js')

<style type="text/css">

.toc-class {
width: 100px;
}

.toc-label {
width: 100px;
}
.toc-pagenum {
width: 50px;
}
.toc-title {}

</style>

$def display_toc():
    $ toc = page.table_of_contents or [""]
    $if toc and not hasattr(toc[0], '__setitem__'):
        $ toc = [{'class': 'section', 'label': '', 'title': x, 'pagenum': ''} for x in toc]
    <tbody>
    <tr>
        <td valign="middle" class="formheader" style="padding-top: 3px;">$_t.table_of_contents</td>
        <td valign="top" class="formfield" style="margin-right: 0px; padding-right: 0px;">
            <table border="0" style="width: 100%">
            <tbody>
            <tr>
                <td>class</td>
                <td>label</td>
                <td>title</td>
                <td>page #</td>
            </tr>
            </tbody>
            <tbody id="tbody_toc">
            $for i, x in enumerate(toc):
                $ prefix = 'table_of_contents#' + str(i)
                <tr>
                    <td style="display: none;"></td>
                    <td valign="top" class="toc-class">$:thinginput(x.get('class'), expected_type='/type/string', name=prefix + '.class', options=["part", "chapter", "section", "subsection"])</td>
                    <td valign="top" class="toc-label">$:thinginput(x.get('label'), expected_type='/type/string', name=prefix + '.label')</td>
                    <td valign="top" class="toc-title">$:thinginput(x.get('title'), expected_type='/type/string', name=prefix + '.title')</td>
                    <td valign="top" class="toc-pagenum">$:thinginput(x.get('pagenum'), expected_type='/type/string', name=prefix + '.pagenum')</td>
                    <td valign="top" class="formbuttons-identifier" style="width: 18px; padding-right: 0px; margin-right: 0px;">
                        $if i == len(toc) - 1:
                            <button class="control" onClick="add_row('toc')" type="button"><img src="/static/images/+.gif" alt="+" width="18" height="18" /></button>
                    </td>
                </tr>
            </tbody>
            </table>
        </td>
    </tr> 
    </tbody>

<script type="text/javascript">
<!--
function next(key) {
    if (!key)
       return "";
    
    var tokens = key.split('#');

    try { 
        if (tokens.length == 2) {
             var prefix = tokens[0];
             tokens = tokens[1].split('.');
             var x = tokens[0];
             var suffix = tokens[1];

             x = prefix + '#' + (1 + eval(x)); // there must be better way to convert a string to integer than using eval
             if (suffix) {
                 x = x + '.' + suffix;
             }
             return x;
        }
    }
    catch (e) {
    }
    return key;
}

function add_row(name) {
    var tbody = \$("#tbody_" + name);
    
    var rows = tbody.children();
    var row = \$(rows[rows.length-1]);
    var newrow = row.clone();
    tbody.append(newrow);

    \$("td:last", row).html("");
    \$("td:first", newrow).html("");

    \$("input", newrow).map(function() { 
        \$(this).attr('id', next(\$(this).attr('id'))); 
        \$(this).attr('name', next(\$(this).attr('name'))); 
        \$(this).attr('ac_name', next(\$(this).attr('ac_name')));
        \$(this).attr('value', ''); 
    });
    
    // auto complete is not working for newly added rows.
    // Explicitly enabling autocomplete.
    setup_autocomplete(\$("input[@ac_enabled=true]", newrow));
    
    // fix autocomplete for authors
    \$("input[@freebase_suggest=true]", newrow).map(function() {
        setup_freebase_suggest(this);
    });
}

jQuery(function(\$) {
    \$("#table_toc button.plus").bind("click", function(e) {
        \$("div#log").append(this + "<br/>");

    });
});
-->
</script>

<div id="log"></div>

<form method="POST" name="edit" action="$(action or '')">

    <div id="slickbox" style="overflow: hidden">
        $:macros.TypeChanger(page.type)
    </div>

    <!-- WIKI EDIT SECTION -->
    <div id="biblio-form-body">    
        <table cellspacing="0" cellpadding="0" border="0" width="100%">
        <tr>
            <td valign="top">
                <div id="header">               
                    <span class="pretitle">$_.pretitle:<br /></span>             
                    <div id="title">$page.title</div>            
                </div>
                
                <!-- begin left table -->
                <table cellspacing="0" cellpadding="0" border="0" width="100%">
                    <tr>
                       <td valign="top" colspan="3" height="8"></td>
                    </tr>
                    
                    $:macros.EditionEditRow(page, 'title_prefix', True)
                    $:macros.EditionEditRow(page, 'title', True)
                    $:macros.EditionEditRow(page, 'subtitle', True)
                    $:macros.EditionEditRow(page, 'by_statement', True)
                    $:macros.EditionEditRow(page, 'authors', False)
                    $:macros.EditionEditRow(page, 'contributions', False)

                    <tr><td valign="top" colspan="4" class="vertspace24"></td></tr>

                    $:macros.EditionEditRow(page, 'publish_date', True)
                    $:macros.EditionEditRow(page, 'publishers', False)
                    $:macros.EditionEditRow(page, 'publish_places', False)

                    $:macros.EditionEditRow(page, 'series', False)
                    $:macros.EditionEditRow(page, 'edition_name', True)
                    $:macros.EditionEditRow(page, 'languages', False)
                    $:macros.EditionEditRow(page, 'work_titles', False)
                    $:macros.EditionEditRow(page, 'collections', False)
                    $:macros.EditionEditRow(page, 'uris', False)
                    $:macros.EditionEditRow(page, 'works', False)

                    <tr><td valign="top" colspan="3" height="22"></td></tr>
                    </table>


                    <!-- ADDITIONAL METADATA -->

                 <div style="padding-left: 10px;">

<table cellspacing="0" cellpadding="0" border="0">
     <tr>
       <td valign="middle" class="formheader" style="padding-left: 0px;">$_t.pagination</td>
       <td valign="top"><input type="text" name="pagination" value="$page['pagination']"  size="8" /></td>
       <td valign="middle" class="formheader">$_t.size</td>
       <td valign="top"><input type="text" name="physical_dimensions" value="$page['physical_dimensions']" size="8" /></td>
       <td valign="middle" class="formheader">$_t.physical_format</td>
       <td valign="top"><input type="text" name="physical_format" value="$page['physical_format']" size="8" /></td>
       <td valign="middle" class="formheader">$_t.number_of_pages</td>
       <td valign="top"><input type="text" name="number_of_pages" value="$page['number_of_pages']"  size="8" /></td>
       <td valign="middle" class="formheader">$_t.weight</td>
       <td valign="top"><input type="text" name="weight" value="$page['weight']"  size="8" /></td>
       <td valign="top" width="100%"></td>
     </tr>
</table>
<br />
                    <!-- description -->
                    <span class="formheader-edit">$_t.description</span>
                    <br /><textarea name="description" rows="6" cols="20">$page.description</textarea>
                
                    <!-- first_sentence -->
                    <span class="formheader-edit">$_t.first_sentence</span>
                    <br /><textarea name="first_sentence" rows="6" width="100%">$page.first_sentence</textarea>                

                    <!-- notes -->
                    <span class="formheader-edit">$_t.notes</span>
                    <br /><textarea name="notes" rows="6" width="100%">$page.notes</textarea><br />

                 </div>
<br />

                <table cellspacing="0" cellpadding="0" border="0" width="100%">
                    <tr> <!-- begin table of contents -->
                        <td valign="top" colspan="4" width="100%" class="formheader">
                        $:display_toc()
                        </td>
                    </tr> <!-- end table of contents -->
                </table> <!-- end left table -->
            </td>
            <td valign="top" class="form-margin">
                <br />
                $ olid = page.key.split('/')[-1]
                $if olid:
                    <div style="padding: 8px; border: solid 1px #ccc; background-color: #fff; width: 180px"><img width="180" src="http://covers.openlibrary.org/b/olid/$olid-M.jpg"/></div>
                    <div style="padding-top: 8px; margin-left: 0; padding-left: 0;"><button onclick="change_cover();" style="width: 180px;" type="button">Change Cover</button></div>

<script type="text/javascript">
function change_cover() {
    window.location.href = "$:changequery(m='change_cover')";
}
</script>

                <br />

               <!-- begin right table -->
                <table cellspacing="0" cellpadding="0" border="0">
                    <tr>
                        <td valign="top" colspan="4" width="100%" class="vertspace9">

                    		<br /><br /><br />
                            </td>
                    </tr>

                    $:macros.EditionEditRow(page, "dewey_decimal_class", unique=False, right=True)
                    $:macros.EditionEditRow(page, "lc_classifications", unique=False, right=True)
                    $:macros.EditionEditRow(page, "isbn_10", unique=False, right=True)
                    $:macros.EditionEditRow(page, "isbn_13", unique=False, right=True)
                    $:macros.EditionEditRow(page, "lccn", unique=False, right=True)
                    $:macros.EditionEditRow(page, "ocaid", unique=True, right=True)
                    $:macros.EditionEditRow(page, "oclc_numbers", unique=False, right=True)

                    <tr><td valign="middle" class="vertspace24"></td></tr>

                    $:macros.EditionEditRow(page, "subjects", unique=False, right=True)
                    $:macros.EditionEditRow(page, "genres", unique=False, right=True)
                </table>
                <!-- end right table -->

                <br />
            </td>
        </tr>
        </table>
            
        <!-- edit summary and buttons -->
                 <div style="padding-left: 10px;">
                    $:macros.EditButtons(comment=page.comment_)
                 </div>

    </div>
</form>

$if page.key:
    <div class="copyright-footer">
        <div style="float: right; padding-bottom: 9px;">
            <a href="/clonebook?key=$page.key">$_.clone_book</a> &rarr;
        </div>
    </div>
title: edit template for /type/edition