{{header}}{{column_left}}

<div id="content">
	<style>
.CodeMirror {
	height: auto;
	border: 1px solid #cccccc;
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
}
.CodeMirror-scroll { 
	max-height: 300px; 
}
</style>
<script>
function updateTextArea() {
	editor.save();
}
</script>
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <a type="button" onclick="update()" data-toggle="tooltip" title="{{button_update}}" class="btn btn-success"><i class="fa fa-check"></i></a>
        <button type="submit" form="form-modification" data-toggle="tooltip" title="{{button_save}}" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="{{cancel}}" data-toggle="tooltip" title="{{button_cancel}}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{heading_title}}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> {{error_warning}}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{text_form}}</h3>
      </div>
      <div class="panel-body">
        <form action="{{action}}" method="post" enctype="multipart/form-data" id="form-modification" class="form-horizontal">
          <ul class="nav nav-tabs">
            <li class="active"><a href="#tab-general" data-toggle="tab">{{tab_general}}</a></li>
            <li><a href="#tab-backup" data-toggle="tab">{{tab_backup}}</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane active" id="tab-general">
              <div class="form-group required">
                <label class="col-sm-2 control-label" for="input-name">{{entry_name}}</label>
                <div class="col-sm-10">
                  <input type="text"  name="name" value="{{ name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control" />
                </div>
              </div>
			  <div class="form-group required">
                <label class="col-sm-2 control-label" for="input-code">{{entry_code}}</label>
                <div class="col-sm-10">
                  <input type="text"  name="code" value="{{ newxml.code }}" placeholder="{{ entry_code }}" id="input-name" class="form-control" />
                </div>
              </div>
			  <div class="form-group required">
                <label class="col-sm-2 control-label" for="input-version">{{entry_version}}</label>
                <div class="col-sm-10">
                  <input type="text"  name="version" value="{{ newxml.version }}" placeholder="{{ entry_version }}" id="input-name" class="form-control" />
                </div>
              </div>
			  <div class="form-group">
                <label class="col-sm-2 control-label" for="input-author">{{entry_author}}</label>
                <div class="col-sm-10">
                  <input type="text"  name="author" value="{{ newxml.author }}" placeholder="{{ entry_author }}" id="input-name" class="form-control" />
                </div>
              </div>
			  <div class="form-group">
                <label class="col-sm-2 control-label" for="input-link">{{entry_link}}</label>
                <div class="col-sm-10">
                  <input type="text"  name="link" value="{{ newxml.link }}" placeholder="{{ entry_link }}" id="input-name" class="form-control" />
                </div>
              </div>
				
				<div class="panel-group" id="accordion-modification-files" role="tablist" aria-multiselectable="true">
				  
				  {% set file_row = 0 %}
				  {% for file in newxml.file %}
					
					
					{% include 'marketplace/modification_file.twig' %}
					
					
				  
				  {% set file_row = file_row + 1 %}
				  {% endfor %}
				<div class="form-group col-sm-12">
					<button type="button" class="btn btn-primary" onclick="FileAdd(this)">{{ text_file_add }}</button>
				</div>
				</div>
				
				
			  
			  
			 
			  
			 
            </div>
            <div class="tab-pane" id="tab-backup">
              <div class="table-responsive">
                <table class="table table-bordered table-hover">
                  <thead>
                  <tr>
                    <td class="text-left">{{column_id}}</td>
                    <td class="text-left">{{column_code}}</td>
                    <td class="text-left">{{column_date_added}}</td>
                    <td class="text-right">{{column_restore}} <a type="button" href="{{history}}" data-toggle="tooltip" title="{{button_history}}" class="btn btn-default"><i class="fa fa-trash"></i></a></td>
                  </tr>
                  </thead>
                  <tbody>
                  {% if backups %}
                    {% for backup in backups %}
                      <tr>
                        <td class="text-left">{{backup['backup_id']}}</td>
                        <td class="text-left">{{backup['code']}}</td>
                        <td class="text-left">{{backup['date_added']}}</td>
                        <td class="text-right"><a href="{{backup['restore']}}" data-toggle="tooltip" title="{{button_restore}}" class="btn btn-primary"><i class="fa fa-share-square"></i></a></td>
                      </tr>
                    {% endfor %}
                  {% else %}
                  <tr>
                    <td class="text-center" colspan="4">{{text_no_results}}</td>
                  </tr>
                  {% endif %}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
  function UpdateTextOperation(element){
	var span = $(element).attr("data-id-text");
	switch($(element).val()){
		case 'after':
			$(span).text('{{ text_help_after }}');
		break;
		case 'before':
			$(span).text('{{ text_help_before }}');
		break;
		case 'replace':
			$(span).text('{{ text_help_replace }}');
		break;
	}
  }
  $("#form-modification").on("change", "select.select-operation", function(){
	UpdateTextOperation(this);
  })
  $(document).ready(function(){
	$("#form-modification select.select-operation").each(function(){
		UpdateTextOperation(this);
	})
  })
  
 function OperationRemove(operation_row, file_row){
	
	$("[data-file='"+file_row+"'] [data-operation='"+operation_row+"']").remove();
 }
 
 function OperationAdd(file_row, element){
			
			
			
			
			
			
			var data = {
				operation_row: parseInt($("[data-file='"+file_row+"'] [data-operation]").last().attr('data-operation')) + 1,
				file_row: file_row,
			};
			$.ajax({
				url: 'index.php?route=marketplace/modification/addoperation&user_token={{ user_token }}',
				dataType: 'json',
				type: 'post',
				data: data,
				success: function(json) {
					if(json['prepend']){
						$(element).parent().before(json['prepend']);
					}
				}
			});
 }
 
  function FileAdd(element){
			
			
			
			var data = {
				file_row: parseInt($("[data-file").last().attr('data-file')) + 1,
			};
			$.ajax({
				url: 'index.php?route=marketplace/modification/addfile&user_token={{ user_token }}',
				dataType: 'json',
				type: 'post',
				data: data,
				success: function(json) {
					
					if(json['prepend']){
						$(element).parent().before(json['prepend']);
						
					}
				}
			});
 }
 
 
 function FileRemove(file_row){
	$("[data-file='"+file_row+"']").remove();
 }
 


  function update () {
      var action = $('form#form-modification').attr('action');
      $('form#form-modification').attr('action', action+"&update=1");
      $('form#form-modification').submit();
  }
--></script>
{{footer}}