<!-- BEGIN: MAIN -->
{FILE "{PHP.cfg.themes_dir}/admin/{PHP.cfg.admintheme}/warnings.tpl"}
<!-- BEGIN: MODLIST --> 
<!-- BEGIN: ADMIN_STRUCTURE_EMPTY -->
<div class="well">{PHP.L.adm_listisempty}</div>
<!-- END: ADMIN_STRUCTURE_EMPTY --> 
<!-- IF {ADMIN_STRUCTURE_EXT_NAME} -->
<div class="list-group"> 
  <!-- BEGIN: ADMIN_STRUCTURE_EXT --> 
  <a href="{ADMIN_STRUCTURE_EXT_URL}" class="list-group-item"> 
  <!-- IF {ADMIN_STRUCTURE_EXT_ICO} --> 
  <img src="{ADMIN_STRUCTURE_EXT_ICO}"/> 
  <!-- ELSE --> 
  <img src="{PHP.cfg.system_dir}/admin/img/plugins32.png"/> 
  <!-- ENDIF --> 
  {ADMIN_STRUCTURE_EXT_NAME} </a> 
  <!-- END: ADMIN_STRUCTURE_EXT --> 
</div>
<!-- ENDIF --> 
<!-- END: MODLIST --> 
<!-- BEGIN: CREATE -->
<div aria-expanded="false" class="collapse in" id="add_cw">
  <div class="box">
    <h4 class="h_title">{PHP.L.new_category}</h4>
    <form name="addstructure" id="addstructure" action="{ADMIN_STRUCTURE_URL_FORM_ADD}" method="post" enctype="multipart/form-data">
      <div class="form-horizontal">
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.Title}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_TITLE}<small>{PHP.L.adm_required}</small> </div>
        </div>
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.Code}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_CODE}<small>({PHP.L.Ea_code_info})</small> </div>
        </div>
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.Ea_parentcat}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_PARENT} </div>
        </div>
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.Locked}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_LOCKED} </div>
        </div>
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.Description}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_DESC} </div>
        </div>
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.Icon}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_ICON} </div>
        </div>
        <div class="row row-box odd-box">
          <div class="col-md-2">{PHP.L.TPL}:</div>
          <div class="col-md-10">{ADMIN_STRUCTURE_TPL}</div>
        </div>
        
        <!-- BEGIN: EXTRAFLD -->
        <div class="row row-box odd-box">
          <div class="col-md-2">{ADMIN_STRUCTURE_EXTRAFLD_TITLE}:</div>
          <div class="col-md-10"> {ADMIN_STRUCTURE_EXTRAFLD} </div>
        </div>
        <!-- END: EXTRAFLD --> 
      </div>
      <div class="row-box">
        <button type="submit" class="submit btn btn-primary">{PHP.L.Add}</button>
      </div>
    </form>
    <script>
      function toTranslit(text) {
          return text.replace(/([а-яё])|([\s_-])|([^a-z\d])/gi,
          function (all, ch, space, words, i) {
              if (space || words) {
                  return space ? '-' : '';
              }
              var code = ch.charCodeAt(0),
                  index = code == 1025 || code == 1105 ? 0 :
                      code > 1071 ? code - 1071 : code - 1039,
                  t = ['yo', 'a', 'b', 'v', 'g', 'd', 'e', 'zh',
                      'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p',
                      'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh',
                      'shch', '', 'y', '', 'e', 'yu', 'ya'
                  ];
              return t[index];
          });
      }

      $('[name="rstructurecode"]').change(function() {
        var thisval = $(this).val();
        thisval = toTranslit(thisval);
        $(this).val(thisval.replace(' ', '-').replace("'", '').toLowerCase().replace("'", ''));

        if(localStorage.getItem('admin_lastcat_prefix') == '' || thisval == '') localStorage.setItem('admin_lastcat_prefix', thisval);
      });

      $('[name="rstructurecode"]').val(localStorage.getItem('admin_lastcat_prefix'));

      $('[name="rstructureparent"]').change(function() {
        localStorage.setItem('admin_lastcat_parent', $(this).val());
      });

      if(localStorage.getItem('admin_lastcat_parent') != '') {
        $('[name="rstructureparent"] option').prop('selected', false).filter('[value="'+localStorage.getItem('admin_lastcat_parent')+'"]').prop('selected', true).parent().change();
      }
    </script>
  </div>
</div>
<!-- END: CREATE -->
<!-- BEGIN: CATS -->
<div class="box">
  <div class="h_title">{PHP.L.Ea_catlist_title} <small><a class="collapsed btn btn-success btn-xs" aria-expanded="false" href="#add_cw" data-parent="#accordion" data-toggle="collapse"><i class="fa fa-plus"></i> Новая категория</a></small></div>
  <div class="box-content"> {CATEGORIES_LIST}
    <div class="panel-footer"> <a class="btn btn-success" id="catsaveorder" href="#">{PHP.L.Ea_save_order}</a> <a class="btn btn-default" id="catresync" href="{RESYNC_URL}">{PHP.L.Resync}</a> </div>
  </div>
</div>
<!-- END: CATS -->
<!-- BEGIN: EDIT -->
{CAT_EDIT}
<!-- END: EDIT -->

<script>
var x = '{PHP.sys.xk}';
var n = '{PHP.n}';

$(document).ready(function(){
	$('.dd').nestable({ maxDepth : 10 });
	$('.dd-handle a').on('mousedown', function(e){
			e.stopPropagation();
		});
		$('.dd-handle button').on('mousedown', function(e){
			e.stopPropagation();
		});
});
$(document).on('click', '.alert .close', function(e) {
	$(this).parent().hide();
});

$(document).on('click', '#catsaveorder', function(e) {
	$.post( "index.php?e=eadmin&r=structure&n="+n+"&a=saveorder", { x: x, data: window.JSON.stringify($('.dd').nestable('serialize')) } )
		.done(function( data ) {
		  $.growl({ title: data.title, message: data.message, style: data.status });
	});
	return false;
});
$(document).on('click', '.edit-cat', function(e) {
	var id = $(this).data('itemid');
	$.post( "index.php?e=eadmin&r=structure&n="+n+"&t=edit&id="+id+"", { x: x } )
		.done(function( data ) {
		  BootstrapDialog.show({
			type: 'type-primary',
			nl2br: false,
			title: 'Редактор категории',
            message: data.content,
            buttons: [{
                label: '{PHP.L.Save}',
                cssClass: 'btn-success',
                autospin: true,
                action: function(dialogRef){
					document.getElementById('edit_cat').submit()
                }
            }, {
                label: '{PHP.L.Close}',
                action: function(dialogRef){
                    dialogRef.close();
                }
            }]
        });
	});
	return false;
});

</script>
<!-- END: MAIN -->