<mt:setvar name="page_title" value="<__trans phrase="Edit Asset">">
<$mt:setvar name="position_actions_bottom" value="1"$>
<MTSetVarBlock name="system_msg">
    <mt:if name="error">
        <mtapp:statusmsg
            id="generic-error"
            class="error">
            <mt:var name="error">
        </mtapp:statusmsg>
    </mt:if>
    <mt:if name="saved">
        <mtapp:statusmsg
            id="saved"
            class="success"
            rebuild="all">
            <__trans phrase="Your asset changes have been made.">
        </mtapp:statusmsg>
    </mt:if>
</MTSetVarBlock>

<mt:setvarblock name="related_content">
    <mtapp:widget
        id="asset-stats-widget"
        class="stats-widget"
        label="<__trans phrase="Stats">">
        <ul class="object-stats">
            <li><__trans phrase="[_1] - Created by [_2]" params="<$mt:date ts="$created_on_ts" relative="1" _default="$created_on_formatted" format="%b %e %Y"$>%%<$mt:var name="created_by" escape="html" escape="html"$>"></li>
        <mt:if name="modified_by">
            <li><__trans phrase="[_1] - Modified by [_2]" params="<$mt:date ts="$modified_on_ts" relative="1" _default="$modified_on_formatted" format="%b %e %Y"$>%%<$mt:var name="modified_by" escape="html" escape="html"$>"></li>
        </mt:if>
        </ul>
    </mtapp:widget>

    <mtapp:widget
        id="appears-in"
        label="<__trans phrase="Appears in...">">
    <mt:if name="appears_in">
        <mt:loop name="appears_in">
        <mt:if name="__first__">
        <ul>
        </mt:if>
            <li><a href="<mt:var name="script_url">?__mode=edit&amp;_type=<mt:var name="class">&amp;blog_id=<mt:var name="blog_id" escape="url">&amp;id=<mt:var name="id" escape="url">" class="icon-left icon-<mt:var name="class" lower_case="1">"><mt:var name="title" escape="html" default="..."></a></li>
        <mt:if name="__last__">
        </ul>
        </mt:if>
        </mt:loop>
        <mt:if name="appears_in_more">
        <p><a href="<mt:var name="script_url">?__mode=list_entry&amp;blog_id=<mt:var name="blog_id" escape="url">&amp;filter=asset_id&amp;filter_val=<mt:var name="id" escape="url">"><__trans phrase="Show all entries"></a></p>
        <p><a href="<mt:var name="script_url">?__mode=list_page&amp;blog_id=<mt:var name="blog_id" escape="url">&amp;filter=asset_id&amp;filter_val=<mt:var name="id" escape="url">"><__trans phrase="Show all pages"></a></p>
        </mt:if>
    <mt:else>
        <span class="hint"><__trans phrase="This asset has not been used."></span>
    </mt:if>
    </mtapp:widget>

<mt:if name="related">
    <mtapp:widget
        id="related-assets"
        label="<__trans phrase="Related Assets">">
        <mt:loop name="related">
        <div class="asset asset-type-<mt:var name="asset_type" escape="html" lower_case="1"> <mt:if name="has_thumbnail">asset-thumbnail<mt:else>asset-no-thumbnail</mt:if>">
            <div class="asset-thumb picture small">
                <a href="<$mt:var name="script_url"$>?__mode=view&amp;_type=<mt:var name="object_type">&amp;id=<$mt:var name="id" escape="url"$>&amp;blog_id=<$mt:var name="blog_id" escape="url"$>" title="<$mt:var name="file_name" escape="html"$>">
    <mt:if name="has_thumbnail">
                    <img src="<mt:var name="thumbnail_url" escape="html">?ts=<mt:var name="modified_on" escape="url">" width="<mt:var name="thumbnail_width" escape="html">" height="<mt:var name="thumbnail_height" escape="html">"<mt:if name="thumbnail_width"> style="padding: <$mt:var name="thumbnail_height_offset"$>px <$mt:var name="thumbnail_width_offset"$>px"</mt:if> />
    <mt:else>
                    <span><__trans phrase="No thumbnail image"></span>
    </mt:if>
                </a>
            </div>
            <div class="asset-metadata">
                <h4 class="asset-label"><a href="<$mt:var name="script_url"$>?__mode=view&amp;_type=<mt:var name="object_type">&amp;id=<$mt:var name="id" escape="url"$>&amp;blog_id=<$mt:var name="blog_id"$>" title="<$mt:var name="file_name" escape="html"$>"><mt:var name="label" escape="html"></a></h4>
                <ul class="asset-size">
                    <li class="datetime"><mt:var name="created_on_formatted"></li>
                    <li class="size"><mt:if name="class" eq="image"><mt:var name="image_width" escape="html"> &times; <mt:var name="image_height" escape="html">px</mt:if></li>
                    <li class="file-size"><mt:var name="file_size_formatted" escape="html"></li>
                    <!-- <mt:if var="is_parent">(parent)</mt:if><mt:if var="is_child">(child)</mt:if><mt:if var="is_sibling">(sibling)</mt:if> -->
                </ul>
            </div>
        </div>
        </mt:loop>
    </mtapp:widget>
</mt:if>
    <$MTApp:PageActions$>
</mt:setvarblock>

<mt:setvarblock name="html_head" append="1">
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/focus.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/tagcomplete.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
var tag_delim = '<mt:var name="auth_pref_tag_delim">';

// array of tag names
var tagList;

function tagSplit(str) {
    var delim = RegExp.escape(tag_delim);
    var delim_scan = new RegExp('^((([\'"])(.*?)\\3[^' + delim + ']*?|.*?)(' + delim + '\\s*|$))', '');
    str = str.replace(/(^\s+|\s+$)/g, '');
    var tags = [];
    while (str.length && str.match(delim_scan)) {
        str = str.substr(RegExp.$1.length);
        var tag = RegExp.$4 ? RegExp.$4 : RegExp.$2;
        tag = tag.replace(/(^\s+|\s+$)/g, '');
        tag = tag.replace(/\s+/g, ' ');
        if (tag != '') tags.push(tag);
    }
    return tags;
}

var autoTag;
<mt:if name="tags_js">
tagList = <mt:var name="tags_js">;
</mt:if>

function init()
{
    <mt:if name="tags_js">initTags();</mt:if>
}

var tagPos = 0;
function initTags() {
    var t = getByID('tags-cache');
    if ( t ) {
        log('tag cache:'+t.value);
        var v = getByID('tags');
        if ( t.value )
            v.value = t.value;
        DOM.addEventListener( v, "change", function() { log('caching tags'); t.value = v.value; } );
    }
    if (!tagList || tagList.length == 0) return;

    autoTag = new TC.TagComplete("tags", tagList);
    autoTag.delimiter = tag_delim;
}

TC.attachLoadEvent( init );
/* ]]> */
</script>
</mt:setvarblock>
<mt:include name="include/header.tmpl">

<div id="asset" class="status-<mt:if name="file_is_missing">missing<mt:else>publish</mt:if><mt:unless name="file_is_missing"> <mt:if name="has_thumbnail">asset-thumbnail<mt:else>asset-no-thumbnail</mt:if></mt:unless>">
    <form id="edit_asset" method="post" action="<mt:var name="script_url">">
        <input type="hidden" name="blog_id" value="<mt:var name="blog_id">" />
        <input type="hidden" name="__mode" value="save" />
        <input type="hidden" name="_type" value="<mt:var name="object_type">" />
        <input type="hidden" name="id" value="<mt:var name="id" escape="html">" />
        <input type="hidden" name="return_args" value="<mt:var name="return_args" escape="html">" />
        <input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
        <input type="hidden" name="asset_type" value="<mt:var name="asset_type" escape="html">" />

        <div class="asset-preview asset-type-<mt:var name="asset_type" escape="html" lower_case="1">">
            <div class="asset-thumb">
<mt:if name="has_thumbnail">
                <img src="<mt:var name="thumbnail_url" escape="html">" width="<mt:var name="thumbnail_width" escape="html">" height="<mt:var name="thumbnail_height" escape="html">"<mt:if name="thumbnail_width"> style="padding: <$mt:var name="thumbnail_height_offset"$>px <$mt:var name="thumbnail_width_offset"$>px"</mt:if> />
<mt:else>
                <span><__trans phrase="No thumbnail image"></span>
</mt:if>
<mt:if name="file_is_missing">
                <span class="asset-missing-msg"><mt:if name="file_is_missing"><__trans phrase="[_1] is missing" params="<mt:var name="asset_class_label" escape="html">"><mt:else><mt:var name="asset_class_label" escape="html"></mt:if></span>
</mt:if>
            </div>
            <div class="asset-thumb-metadata">
                <div class="asset-size">
                    <mt:if name="class" eq="image"><mt:var name="image_width" escape="html"> &times; <mt:var name="image_height" escape="html">px<mt:if name="file_size_formatted"> - </mt:if></mt:if><mt:var name="file_size_formatted" escape="html">
                </div>
            </div>
        </div>

        <div class="asset-metadata">
            <mtapp:setting
                id="type"
                label="<__trans phrase="Type">"
                label_class="text-top"
                content_class="field-content-text">
                <mt:var name="asset_class_label" escape="html">
            </mtapp:setting>

            <mtapp:setting
                id="label"
                label="<__trans phrase="Label">"
                label_class="text-top"
                help_page="assets"
                help_section="asset_label">
                <input type="text" name="label" id="label" value="<mt:var name="label" escape="html">" class="full-width" />
            </mtapp:setting>

            <mtapp:setting
                id="description"
                label_class="text-top"
                label="<__trans phrase="Description">">
                <textarea name="description" id="description" rows="" cols="" class="full-width short"><mt:var name="description" escape="html"></textarea>
            </mtapp:setting>

            <mtapp:setting
                id="tags"
                label_class="text-top"
                label="<__trans phrase="Tags">">
                <input type="text" name="tags" id="tags" class="full-width" value="<$mt:var name="tags" escape="html"$>" autocomplete="off" />
                <input type="hidden" name="_ignore_tags" id="tags-cache" value="<$mt:var name="tags" escape="html"$>" />
                <div id="tags-suggestion">
                    <div id="tags_completion"></div>
                </div>
            </mtapp:setting>

        <mt:unless name="file_is_missing">
            <mtapp:setting
                id="asset-url"
                label_class="text-top"
                label="<__trans phrase="Embed Asset">">
                <input type="text" readonly="readonly" name="asset-url" id="asset-url" value="<mt:var name="url" escape="html">" /> <a href="<mt:var name="url" encode_html="1">" class="view-asset-link" title="<__trans phrase="View this asset.">"><__trans phrase="View"></a>
            </mtapp:setting>
        </mt:unless>
        </div>

        <mt:setvarblock name="action_buttons">
            <button
                type="submit"
                accesskey="s"
                title="<__trans phrase="Save changes to this asset (s)">"
                class="save action primary-button"
                ><__trans phrase="Save Changes"></button>
        </mt:setvarblock>
        <mt:include name="include/actions_bar.tmpl" bar_position="bottom" hide_pager="1">
    </form>
</div>

<mt:setvarblock name="jq_js_include" append="1">
    jQuery('#edit_asset').validate({
        rules: {
            label: 'required'
        },
        messages: {
            label: '<__trans phrase="You must specify a name for the asset." escape="singlequotes">'
        },
        errorClass: "msg-error",
        errorPlacement: function(error, element) {
            element.parents('div.field').addClass('error-field');
            error.removeAttr('generated').insertAfter(element);
        }
    });
</mt:setvarblock>
<mt:include name="include/footer.tmpl">
