[% IF bare %][% wrapper="_conf_bare.tt" %][% ELSE %][% wrapper="_conf_objects_frame.tt" %][% END %]
[% WRAPPER $wrapper %]

[% IF show_object %]

[% UNLESS object.defined('file') %]
<script type="text/javascript">
<!--
    var data = [% filenames_json %];
-->
</script>
[% END %]

[% duplicate_keys = {} %]
<form action="conf.cgi" method="POST" onsubmit="return conf_validate_object_form(this);">
<input type="submit" name="send" value="save" style="display:none">
<input type="hidden" name="sub" value="objects">
<input type="hidden" name="type" value="[% type %]">
<input type="hidden" name="data.id" value="[% object.get_id() %]">
<input type="hidden" name="action" value="store">
<input type="hidden" name="referer" value="[% referer %]">
  <table border="0" class='data conftoolobj'[% IF bare %] width="100%"[% END %]>
    <tr>
      <th class='data[% IF subcat == 'config'    %] confSelected[% END %]' style="width:33%" id="sub_1" onclick="window.location.hash='#config';set_sub(1)"><a href="#config">Config</a></th>
      <th class='data[% IF subcat == 'templates' %] confSelected[% END %]' style="width:33%" id="sub_2" onclick="window.location.hash='#templates';set_sub(2)"><a href="#templates">Templates</a></th>
      <th class='data[% IF subcat == 'comp'      %] confSelected[% END %]' style="width:33%" id="sub_3" onclick="window.location.hash='#comp';set_sub(3)"><a href="#comp">Computed</a></th>
    </tr>
    <tr>
      <td colspan=3>
        <table style="width:100%">
          <tr>
            <td style="width: 50px;" class="data dataSubmit sub_1">
              [% IF referer %]
              <button class="conf_back_button conf_button" onclick="window.location='[% referer %]'; return false;">back</button>
              [% END %]
            </td>
            <td class='dataVar dataUserVar'>
              [% IF object.defined('file') %]
                [% object.get_type() | ucfirst %][% IF object.conf.defined('register') && object.conf.register == 0 %]&nbsp;Template[% END %]:&nbsp;
                [% object.get_long_name('&nbsp;') %]
              [% ELSE %]
                new [% type %]
              [% END %]
              <span style="[% IF subcat != 'config' && subcat != 'comp' %]display:none;[% END %] font-weight:normal; font-size:smaller;" class="sub_1 sub_3">
                <br>
                [% IF object.defined('file') %]
                  [% object.file.path %] [% IF object.line > 0 %] line [% object.line %][% END %][% IF object.file.readonly %] <span style="color: #EB6900"> (read-only)</span>[% END %]
                [% ELSE %]
                  <span style="[% IF subcat != 'config' %]display:none;[% END %]" class="sub_1">
                  save to: <input type="text" class="deletable" placeholder="enter filename" name="data.file" id="fileselect" value="[% new_file %]" onclick="ajax_search.init(this, 'file', { striped:false, autosubmit:false, templates:false, data:data, emptymsg:'file will be created'})">
                  </span>
                [% END %]
              </span>
            </td>
            <td style="width: 50px;" class="data dataSubmit sub_1">
              [% IF ! object.defined('file') || ! object.file.readonly %]
              <button class="conf_save_button conf_button">save</button>
              [% END %]
            </td>
          </tr>
        </table>
      </td>
    </tr>

    <tr style="[% IF subcat != 'config' %]display:none[% END %]" class="sub_1">
      <td class='dataVal' colspan=3 style="text-align: center;">
        <div align="center">
        [% IF object.defined('file') && object.file.readonly %]
          [% PROCESS _conf_object_view.tt obj = object conf = "obj" %]
        [% ELSE %]
          [% PROCESS _conf_object_edit.tt obj = object %]
        [% END %]
        </div>
      </td>
    </tr>

    [% IF used_templates.size > 0 %]
    <tr style="[% IF subcat != 'templates' %]display:none[% END %]" class="sub_2">
      <td colspan=3>
        <div align="center">
        <table>
          [% FOREACH key = used_templates %]
          [% SET objs = c.obj_db.get_objects_by_name(type, key, 1) %]
          [% SET obj_id = "new" %]
          <tr>
            <td class='dataVal' colspan=3 style="text-align:center">
              <span style="font-weight:normal;">
                [% IF objs.size > 0 %]
                [% objs.0.file.path %] line [% objs.0.line %]
                [% IF objs.0.file.readonly %]<span style="color: #EB6900"> (read-only)</span>[% END %]
                [% SET obj_id = objs.0.get_id() %]
                [% ELSE %]
                object does not exist
                [% END %]
              </span>
            </td>
          </tr>
          <tr>
            <td class='dataVar' style="text-align: left; white-space: nowrap;">
              <a href="conf.cgi?sub=objects&amp;type=[% type %]&amp;data.id=[% obj_id %]&amp;data.name=[% key | uri %]">
                [% IF objs.size > 0 && objs.0.file.readonly %]
                <img src='[% url_prefix %]thruk/themes/[% theme %]/images/detail.gif' alt='View Template' title='View Template' width="16" height="16" style="vertical-align: middle">
                [% ELSE %]
                <img src='[% url_prefix %]thruk/themes/[% theme %]/images/edit.png' alt='Edit Template' title='Edit Template' width="16" height="16" style="vertical-align: middle">
                [% END %]
              </a>
              &nbsp;[% key %]
            </td>
            <td class='dataVal' colspan=2>
              [% IF objs.size > 0 %]
                 [% PROCESS _conf_object_view.tt obj = objs.0 conf = "obj" %]
              [% ELSE %]
                Template does not exist
              [% END %]
            </td>
          </tr>
          [% UNLESS loop.last %]
          <tr style="[% IF subcat != 'templates' %]display:none[% END %]" class="sub_2"><td colspan=3><hr></td></tr>
          [% END %]
          [% END %]
        </table>
        </div>
      </td>
    </tr>
    [% ELSE %]
    <tr style="[% IF subcat != 'templates' %]display:none[% END %]" class="sub_2">
      <td class='dataVar' colspan=3 style="text-align:center">This object does not use templates</td>
    </tr>
    [% END %]

    <tr style="[% IF subcat != 'comp' %]display:none[% END %]" class="sub_3">
      <td class='dataVal' colspan=3 style="text-align: center;">
        <div align="center">
        [% SET duplicate_keys = {} %]
        [% PROCESS _conf_object_view.tt obj = object conf = "computed" %]
        </div>
      </td>
    </tr>

    [% IF ! object.defined('file') || ! object.file.readonly %]
    <tr style="[% IF subcat != 'config' %]display:none[% END %]" class="sub_1">
      <td colspan=3 class="data dataSubmit">
        [% IF object.get_id() != 'new' && ! bare %]
        <input type="submit" name="send" value="raw edit" style="width:90px" class="conf_button">
        [% END %]
        <button class="conf_save_button conf_button" style="width:90px">save</button>
      </td>
    </tr>
    [% END %]
  </table>
</form>

[% END %]

<script type="text/javascript">
<!--
  if(window.location.hash == '#config')    { set_sub(1); }
  if(window.location.hash == '#templates') { set_sub(2); }
  if(window.location.hash == '#comp')      { set_sub(3); }

  init_conf_tool_buttons();

  jQuery('input,select').each(function() {
    var $input = jQuery(this);
    if($input.attr("tabindex") == 13 ) {
      $input.attr("tabindex", -1);
    }
  });

-->
</script>

[% END %]
