/upstream/templates/books/edit.tmpl
Type: /type/template
body: value: $def with (work, edition=None)

$ this_title = work.title + ': ' + work.subtitle if work.get('subtitle', None) else work.title

$var title: $this_title
$putctx("robots", "noindex,nofollow")

<script type="text/javascript">
<!--
\$().ready(Tabs);
\$().ready(function(){
    if(jQuery.support.opacity){
        \$("#tabsAddbook").tabs({fx:{opacity:'toggle'}});
    } else {
        \$("#tabsAddbook").tabs();
    };
});
\$().ready(boxPop);
\$().ready(function(){\$("#coverPop").colorbox({inline:true, opacity:"0.5", href:"#addCover"});});

function limitChars(textid, limit, infodiv) {
    var text = \$('#'+textid).val(); 
    var textlength = text.length;
    if(textlength > limit) {
        \$('#'+infodiv).html('Maximum length is '+limit+' characters');
        \$('#'+textid).val(text.substr(0,limit));
        return false;
    } else {
        \$('#'+infodiv).html('You have '+ (limit - textlength) +' characters left');
        return true;
    }
};
\$().ready(function(){\$('#excerpt').keyup(function(){limitChars('excerpt', 2000, 'charLimit');});});

\$().ready(function() {
    var hash = document.location.hash || "#edition";
    var tab = hash.split("/")[0]
    var link = "#" + "link_" + tab.substr(1);
    var fieldname = ":input" + hash.replace('/', '-');
    
    \$(link).click();
        
    // input field is enabled only after the tab is selected and that takes some time after clicking the link.
    // wait for 1 sec after clicking the link and focus the input field
    setTimeout(function() {
        // scroll such that top of the content is visible    
        if (\$(fieldname).length != 0) {
            \$(fieldname).focus();   
        }
        else {
            \$("#tabsAddbook > div:visible :input:first").focus();
        }
        \$(window).scrollTop(\$("#contentHead").offset().top);        
    }, 1000);
});
//-->
</script>

<div id="contentHead">
    $code: 
        def find_mode():
            mode = query_param("mode")
            if not edition or not work.key:
                return "other"
            if mode == "found":
                return "existing_record"
            if mode == "add-work" and work.revision == 1 and work.edition_count == 1 and edition.revision == 1:
                return "new_work"
            if mode == "add-book" and edition.revision == 1:
                return "new_edition"
            return "other"
            
        mode = find_mode()
        if mode == "new_work":
            title = _("Add a little more?")
            note = _('<p class="alert thanks">Thank you for adding that book! Any more information you could provide would be wonderful!</p>')
        elif mode == "new_edition":
            title = _("Add a little more?")
            note = _('<p class="alert thanks">We already know about <b>%s</b>, but not the <b>%s %s edition</b>. Thanks! Do you know any more about this edition?</p>', work.title, edition.publish_date, "; ".join(edition.publishers))
        elif mode == "existing_record":
            title = _("Add a little more?")
            note = _('<p class="alert info">We already know about the <b>%s %s edition</b> of <b>%s</b>, but please, tell us more!</p>', edition.publish_date, "; ".join(edition.publishers), work.title)
        else:
            title = _("Editing...")
            note = ""
    <h1>$:title</h1>
    $if not ctx.user:
        $:render_template("lib/not_logged")
    $:note
</div>

<script type="text/javascript">
<!--
\$(function() {
    function update_visible() {
        if (\$("#authors div.input").length > 1) {
            \$("#authors a.remove").show();
        }
        else {
            \$("#authors a.remove").hide();
        }

        \$("#authors a.add:not(:last)").hide();
        \$("#authors a.add:last").show();
    }
    
    update_visible();
    
    \$("#authors a.remove").live("click", function() {
        if (\$("#authors div.input").length > 1) {
            \$(this).closest("div.input").remove();
            update_visible();
        }
    });

    \$("#authors a.add").live("click", function(event) {
        event.preventDefault();
        
        var n = \$("#authors div.input:last").attr("id").substr("author-input-".length);
        n = parseInt(n);
        
        \$("#authors").append(render_author(n+1, {key:"", name: ""}));
        \$("#authors input.author-autocomplete:last").author_autocomplete();
        update_visible();
    });
    
});
//-->
</script>

$jsdef render_author(i, author):
    <div class="input" id="author-input-$i">
        <input name="authors--$i" class="author author-autocomplete" type="text" id="author-$i" value="$author.name"/>
        <input name="work--authors--$i--author--key" type="hidden" id="author-$i-key" value="$author.key" />
        <a href="javascript:;" class="remove red plain hidden" title="$_('Remove this author')">[x]</a>&nbsp;
        <a href="javascript:;" class="add hidden">Add another author?</a>
    </div>

<div id="contentBody">
    <form method="post" id="addWork" class="olform books validate" name="edit" action="">

    <div class="formElement title">
        <div class="TitleAuthor sansserif">
            <div class="label">
                <label for="work-title">Title</label> <span class="tip">Use <b><i>Title: Subtitle</i></b> to add a subtitle.</span> <span class="red">*<span class="tip">$_("Required field")</span></span>
            </div>
            <div class="input">
                <input name="work--title" type="text" id="work-title" class="required" value="$this_title"/>
            </div>
            <div class="label">
                <label for="author-$0">Author</label>
            </div>
            $ authors = work.authors and [a.author for a in work.authors]            
            <div id="authors">
                $if authors:
                    $for i, author in enumerate(authors):
                        $:render_author(i, author)
                $else:
                    $:render_author(0, storage(name="", key=""))
            </div>
        </div>
    </div>
        
        <div id="tabsAddbook">
            <ul>
                <li><a href="#about" id="link_about">$_("What's It About?")</a></li>
                <li><a href="#excerpts" id="link_excerpts">$_("Add Excerpts")</a></li>
                <li><a href="#web" id="link_web">$("Links")</a></li>
                $if edition:
                    $if edition.publishers:
                        $ edition_name = "; ".join(edition.publishers) + ' edition'
                    $else:
                        $ edition_name = "Unknown publisher" + ' edition'
                    
                    $if edition.publish_date:
                        $ edition_name = truncate(edition_name, 20) + ", " + edition.publish_date
                    
                    <li><a href="#edition" id="link_edition">$edition_name</a></li>
            </ul>

            <div id="about">
                $:render_template("books/edit/about", work)
            </div>

            <div id="excerpts">
                $:render_template("books/edit/excerpts", work)
            </div>

            <div id="web">
                $:render_template("books/edit/web", work, prefix="work--")
            </div>
        
            $if edition:
                <div id="edition">
                    $:render_template("books/edit/edition", work, edition)
                </div>
        </div>

        $:macros.EditButtons(comment=work.comment_)

        $if ctx.user and ctx.user.is_admin():
            <div class="adminOnly" style="position:absolute;top:20px;right:20px;"><button type="submit" value="$_('Delete Record')" name="_delete" title="$_('Delete this book?')" id="deleteTop">$_("Delete Record")</button></div>
        
    </form>

    $if edition:
        $:render_template("books/edit/addfield", edition)

</div>
plugin: upstream
title: Work (edit)
m: edit