<mt:setvarblock name="page_title"><__trans phrase="Export [_1] Themes" params="<mt:if name="blog_id"><mt:if name="is_blog"><__trans phrase="Blog"><mt:else><__trans phrase="Website"></mt:if><mt:else><__trans phrase="Global"></mt:if>"></mt:setvarblock>

<mt:setvar name="export_theme" value="1">

<mt:setvarblock name="html_head" append="1">
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/dialog.js"></script>
</mt:setvarblock>

<mt:setvarblock name="system_msg">
<div id="msg-block">
  <mt:if name="save_success">
    <mtapp:statusmsg
       id="saved-theme"
       class="success">
      <__trans phrase="Theme package have been saved.">
    </mtapp:statusmsg>
  </mt:if>
</div>
</mt:setvarblock>

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

<form id="theme_settings" method="post" enctype="multipart/form-data" action="<mt:var name="script_url">">
  <input type="hidden" name="__mode" value="do_export_theme" />
  <input type="hidden" name="blog_id" value="<mt:var name="blog_id">" />
  <input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
  <input type="hidden" name="theme_class" value="<mt:var name="theme_class" escape="html"/>" />
<mt:unless name="select_output_method">
<mt:loop name="output_methods">
  <input type="hidden" name="output" value="<mt:var name="id" />" />
</mt:loop>
</mt:unless>

  <fieldset>
    <mtapp:setting
       id="theme-name-field"
       required="1"
       label="<__trans phrase="Name">"
       hint="<__trans phrase="The name of your theme.">">
      <input type="text" name="theme_name" id="theme_name" class="text required" value="<mt:var name="theme_name" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
       id="theme-id-field"
       required="1"
       label="<__trans phrase="Basename">"
       show_hint="1"
       hint="<__trans phrase="Use letters, numbers, dash or underscore only (a-z, A-Z, 0-9, '-' or '_').">">
      <input type="text" name="theme_id" id="theme_id" class="text required" value="<mt:var name="theme_id" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
       id="theme-version-field"
       required="1"
       label="<__trans phrase="Version">"
       hint="<__trans phrase="A version number for this theme.">">
       <input type="text" name="theme_version" id="theme_version" class="text required" value="<mt:var name="theme_version" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
       id="theme-description-field"
       label="<__trans phrase="Description">"
       hint="<__trans phrase="A description for this theme.">">
       <textarea name="description" id="description" class="text low"><mt:var name="description" escape="html"></textarea>
    </mtapp:setting>

    <mtapp:setting
       id="theme-author-name-field"
       label="<__trans phrase="_THEME_AUTHOR">"
       hint="<__trans phrase="The author of this theme.">">
       <input type="text" name="theme_author_name" id="theme_author_name" class="text" value="<mt:var name="theme_author_name" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
       id="theme-author-link-field"
       label="<__trans phrase="Author link">"
       hint="<__trans phrase="The author's website.">">
      <input type="text" name="theme_author_link" id="theme_author_link" class="text" value="<mt:var name="theme_author_link" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
       id="theme-options-field"
       label="<__trans phrase="Options">"
       hint="<__trans phrase="Additional assets to be included in the theme.">"
       content_class="field-content-text">
      <ul>
      <mt:loop name="exporters">
        <li>
          <label for="<mt:var name="id">-include"><input type="checkbox" id="<mt:var name="id">-include" name="include" value="<mt:var name="id">" onclick="toggleActive('<mt:var name="id">-detail')" <mt:if name="included">checked="checked"</mt:if>> <mt:var name="label"></label>
        <mt:if name="template">
          <span id="<mt:var name="id">-detail" class="theme-option-detail <mt:unless name="include"> active</mt:unless>">
            <a href="<mt:var name="script_url">?__mode=theme_element_detail&exporter_id=<mt:var name="id">&blog_id=<mt:var name="blog_id">" class="mt-open-dialog"><__trans phrase="Details"></a>
          </span>
        </mt:if>
        </li>
      </mt:loop>
      </ul>
    </mtapp:setting>

  <mt:if name="select_output_method">
    <mtapp:setting
       id="theme-output-field"
       label="<__trans phrase="Destination">"
       hint="<__trans phrase="Select How to get theme.">">
      <select name="output" id="output">
      <mt:loop name="output_methods">
        <option value="<mt:var name="id">"<mt:if name="output" eq="$id"> selected="selected"</mt:if>>
          <mt:var name="label">
        </option>
      </mt:loop>
      </select>
    </mtapp:setting>
  </mt:if>
  </fieldset>

<mt:loop name="exporters">
  <div id="<mt:var name="id">" class="panel" style="display: none;">
    <h3><__trans phrase="Setting for [_1]" params="<mt:var name="label">"></h3>
    <div id="<mt:var name="id">-setting"></div>
  </div>
</mt:loop>

<mt:setvarblock name="action_buttons">
  <button
     type="submit"
     accesskey="s"
     title="<__trans phrase="Export Theme">"
     class="export action button primary">
    <__trans phrase="Export Theme"></button>
</mt:setvarblock>
<mt:include name="include/actions_bar.tmpl" bar_position="bottom" hide_pager="1" settings_bar="1">

</form>

<script type="text/javascript">
/* <![CDATA[ */
jQuery.mtCheckbox();

var existing_ids = <mt:Var name="existing_ids" to_json="1" />;
jQuery(function() {
    function is_valid_basename(name) {
        return name.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/);
    }
    function is_valid_version(name) {
        return name.match(/^[\w\._-]+$/);
    }
    function is_duplicated_basename() {
        var current_id = jQuery('#theme_id').val();
        var destination = jQuery('#output').val() || 'themedir';
        return (existing_ids[current_id] && ( destination == 'themedir' ));
    }
    jQuery.mtValidateAddRules({
        '#theme_id': function ($e) {
            if ( !is_valid_basename( $e.val() ) ) {
                return this.raise('<__trans phrase="Basename may only contain letters, numbers, and the dash or underscore character. The basename must begin with a letter." escape="singlequotes">');
            }
            if ( is_duplicated_basename( $e.val() ) ) {
                return this.raise('<__trans phrase="Cannot install new theme with existing (and protected) theme's basename." escape="singlequotes">');
            }
            return true;
        },
        '#theme_version': function ($e) {
            return is_valid_version($e.val()) ? true : false;
        }
    });
    jQuery.mtValidateAddMessages({
        '#theme_name': '<__trans phrase="You must set Theme Name." escape="singlequotes">',
        '#theme_version': '<__trans phrase="Theme version may only contain letters, numbers, and the dash or underscore character." escape="singlequotes">'
    });
    jQuery('#theme_settings').submit( function() {
        return jQuery(this).find('input, select').mtValidate('simple') ? true : false;
    });
});
    <mt:var name="js_include_footer" />
/* ]]> */
</script>
<mt:include name="include/footer.tmpl">
