<mt:unless name="json">
<mt:setvar name="screen_type" value="dialog-screen insert-asset-dialog">
<mt:setvarblock name="page_title"><mt:if name="is_image"><__trans phrase="Insert Image"><mt:else><__trans phrase="Insert Asset"></mt:if></mt:setvarblock>

<mt:setvarblock name="html_head" append="1">
  <script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js?v=<mt:var name="mt_version_id" escape="url">"></script>
  <script type="text/javascript" src="<mt:var name="static_uri">js/dialog.js?v=<mt:var name="mt_version_id" escape="url">"></script>
  <script type="text/javascript" src="<mt:var name="static_uri">js/assetdetail.js?v=<mt:var name="mt_version_id" escape="url">"></script>
  <script type="text/javascript">
  /* <![CDATA[ */
    function dialogClose(data) {
        if (!data) {
            parent.jQuery.fn.mtDialog.close();
            return;
        }
        // user made a selection and clicked insert...
        var f = document.forms['select_asset'];
        var sel = dlg.panel.tableSelect.selected();
        f['id'].value = sel[0].value;
        f.submit();
    }

    function viewChange(ds, fn) {
        checkOpened();
        if (fn) fn(ds);
    }

    var tableSelect;
    var dlg;
    function init() {
        // setup
        // assign isModal variable which is declared in assetdetail.js:
        isModal = getByID("list-assets-dialog");

        dlg = new Dialog.Simple("list-assets");
        var panel = new ListingPanel("asset");
        dlg.panel = panel;

        // hook into view updates so we can close any opened detail panel
        var old_update = panel.datasource.onUpdate;
        panel.datasource.onUpdate = function(ds) { viewChange(ds, old_update) };

        panel.pager.setState(<mt:var name="pager_json">);
        panel.parent = dlg;
        dlg.open({}, dialogClose);
    }
  /* ]]> */
  </script>
</mt:setvarblock>

<mt:setvarblock name="upload_new_file_link">
  <img src="<mt:var name="static_uri">images/status_icons/create.gif" alt="<__trans phrase="Upload New File">" width="9" height="9" />
  <mt:unless name="asset_select"><mt:setvar name="entry_insert" value="1"></mt:unless>
  <a href="<mt:var name="script_url">?__mode=start_upload&amp;_type=asset&amp;blog_id=<mt:var name="blog_id">&amp;no_insert=<mt:var name="no_insert">&amp;dialog_view=1&amp;<mt:if name="asset_select">asset_select=1&amp;<mt:else>entry_insert=1&amp;</mt:if>edit_field=<mt:var name="edit_field" escape="url">&amp;upload_mode=<mt:var name="upload_mode" escape="url">&amp;<mt:if name="require_type">require_type=<mt:var name="require_type">&amp;</mt:if>return_args=<mt:var name="return_args" escape="url"><mt:if name="user_id">&amp;user_id=<mt:var name="user_id" escape="url"></mt:if>" onclick="toggleHidden('list-assets-dialog'); toggleHidden('upload-asset-dialog'); return false"><mt:if name="is_image"><__trans phrase="Upload New Image"><mt:else><__trans phrase="Upload New File"></mt:if></a>
</mt:setvarblock>

<mt:include name="dialog/header.tmpl">

  <div id="list-assets-dialog">
    <div class="mod panel-header">
    <mt:if name="edit_blog_id">
      <mt:if name="can_upload">
      <mt:var name="upload_new_file_link">
      </mt:if>
    <mt:else>
      <mt:var name="upload_new_file_link">
    </mt:if>
    </div>

<mt:if name="object_loop">
  <mt:if name="panel_searchable">
    <form action="" method="get" id="modal-search">
      <input type="text" class="search-input text med" value="" placeholder="<__trans phrase="Search">" />
      <input type="image" class="search-command search-submit" src="<$mt:var name="static_uri"$>images/search-submit-dialog.png" title="<__trans phrase="Search">" />
      <a href="javascript:void(0)" class="search-reset hidden"><__trans phrase="Reset"></a>
    </form>
  </mt:if>
</mt:if>
</mt:unless>

<mt:if name="object_loop">
  <mt:unless name="json">
    <form method="post" action="<mt:var name="script_url">" name="select_asset">
      <input type="hidden" name="__mode" value="<mt:if name="next_mode"><mt:var name="next_mode" escape="html"><mt:else>complete_insert</mt:if>" />
      <input type="hidden" name="_type" value="asset" />
      <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="dialog_view" value="1" />
      <input type="hidden" name="no_insert" value="<mt:var name="no_insert">" />
      <input type="hidden" name="dialog" value="1" />
      <input type="hidden" name="id" value="" />
      <input type="hidden" name="edit_field" value="<mt:var name="edit_field" escape="html">" />
    <mt:if name="edit_blog_id">
      <input type="hidden" name="blog_id" value="<mt:var name="edit_blog_id">" />
      <input type="hidden" name="direct_asset_insert" value="1" />
      <mt:unless name="asset_select">
      <input type="hidden" name="entry_insert" value="1" />
      </mt:unless>
    </mt:if>
    <mt:if name="asset_select">
      <input type="hidden" name="asset_select" value="1" />
    </mt:if>
    <mt:if name="user_id">
      <input type="hidden" name="user_id" value="<mt:var name="user_id" escape="html">" />
    </mt:if>
    </form>

    <div id="selector" class="selector listing list-data">
      <form action="" method="get" onsubmit="return false">
        <table class="listing-table legacy list-heading <mt:unless name="edit_blog_id">show-weblog </mt:unless><mt:if name="view_expanded">expanded<mt:else>compact</mt:if>">

        <mt:setvarblock name="table_header">
          <tr>
            <th class="col head cb">&nbsp;</th>
            <th class="col head si file-status"><img src="<mt:var name="static_uri">images/status_icons/invert-flag.gif" alt="<__trans phrase="Status">" title="<__trans phrase="Status">" width="9" height="9" /></th>
            <th class="col head asset-label primary"><span class="col-label"><__trans phrase="Asset Name"></span></th>
            <th class="col head info num"><span class="col-label"><__trans phrase="Size"></span></th>
          </tr>
        </mt:setvarblock>

          <thead>
            <mt:var name="table_header">
          </thead>
          <tfoot>
            <mt:var name="table_header">
          </tfoot>
  </mt:unless>
          <tbody>
          <mt:loop name="object_loop">
            <tr id="asset-<mt:var name="id" escape="html">" class="<mt:if name="__odd__">odd<mt:else>even</mt:if>">
              <td class="col cb"><input type="hidden" id="asset-<mt:var name="id" escape="html">-json" value="<mt:var name="metadata_json" escape="html">" /><input type="radio" name="id" value="<mt:var name="id" escape="html">" class="select" id="asset-radio-<mt:var name="id" escape="html">" /></td>
              <td class="col si status-<mt:if name="file_is_missing">missing<mt:else>publish</mt:if>">
                <img src="<mt:var name="static_uri">images/spacer.gif" <mt:if name="file_is_missing">alt="<__trans phrase="Pending">"<mt:else>alt="<__trans phrase="Published">"</mt:if> width="9" height="9" />
              </td>
              <td class="col asset-label primary">
                <mt:if name="has_thumbnail">
                  <a href="javascript:void(0)" onclick="return toggleAssetDetails('<mt:var name="id" escape="js">');" title="<$mt:var name="file_name" escape="html"$>"><$mt:var name="label" escape="html"$></a>
                  <div id="asset-<mt:var name="id" escape="html">-preview" class="asset-preview"></div>
                <mt:else>
                  <mt:var name="label" escape="html">
                </mt:if>
              </td>
              <td class="col info num">
                <span class="detail">
                <mt:if name="file_size_formatted">
                  <span class="float_desc" title="<mt:var name="file_size">"><mt:var name="file_size_formatted"></span>
                <mt:else>
                  <span class="float_desc"><mt:var name="file_size"></span>
                </mt:if>
                </span>
              </td>
            </tr>
          </mt:loop>
          </tbody>
  <mt:unless name="json">
        </table>
      </form>
      <div class="pagination"></div>
    </div>
  
    <div class="dialog actions-bar actions-bar-bottom">
      <form action="" method="get" onsubmit="return false">
        <button
           type="submit"
           accesskey="s"
           title="<mt:if name="is_image"><__trans phrase="Next (s)"><mt:else><__trans phrase="Insert (s)"></mt:if>"
           class="action primary button close disabled"
           disabled="true">
          <mt:if name="is_image"><__trans phrase="Continue"><mt:else><__trans phrase="Insert"></mt:if></button>
        <button
           type="submit"
           accesskey="x"
           class="cancel action button mt-close-dialog"
           title="<__trans phrase="Cancel (x)">">
          <__trans phrase="Cancel"></button>
      </form>
    </div>
  </mt:unless>
<mt:else>
    <mtapp:statusmsg
       id="no-assets"
       can_close="0"
       class="info"
       can_close="0">
      <__trans phrase="No assets could be found.">
    </mtapp:statusmsg>
  
  <mt:unless name="json">
    <div class="actions-bar">
      <form action="" method="get" onsubmit="return false">
        <button
           type="submit"
           accesskey="x"
           class="cancel action button mt-close-dialog"
           title="<__trans phrase="Cancel (x)">"
           ><__trans phrase="Cancel"></button>
      </form>
    </div>
  </mt:unless>
</mt:if>

<mt:unless name="json">
  <!-- /List Assets Dialog --></div>
  <div id="upload-asset-dialog" class="hidden">
    <mt:setvar name="included_upload_asset" value="1">
    <mt:include name="include/asset_upload.tmpl">
  <!-- /Upload Asset Dialog --></div>

<mt:setvarblock name="jq_js_include" append="1">
    init();
</mt:setvarblock>

<mt:include name="dialog/footer.tmpl">
</mt:unless>
