{{ header }}
{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-prupletree_multivendor" 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 %}
	{% if success %}
    <div class="alert alert-success"><i class="fa fa-check-circle"></i> {{ success }}
      <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_edit }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-purpletree-multivendor" class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-10">
              <select name="module_purpletree_multivendor_status" id="input-status" class="form-control">
			  {% if module_purpletree_multivendor_status %}
                <option value="1" selected="selected">{{ text_enabled }}</option>
                <option value="0">{{ text_disabled }}</option>
				{% else %}
                <option value="1">{{ text_enabled }}</option>
                <option value="0" selected="selected">{{ text_disabled }}</option>
				{% endif %}
              </select>
            </div>
          </div>
		  <div class="form-group required">
			<label class="col-sm-2 control-label" for="input-status">{{ entry_license }}</label>
			<div class="col-sm-10">
			  <input type="text" name="module_purpletree_multivendor_process_data" value="{{ module_purpletree_multivendor_process_data }}" class="form-control" />
				  {% if process_data_error %}
				<div class="text-danger">{{ process_data_error }}</div>
				{% endif %}
			  <input type="hidden" name="module_purpletree_multivendor_validate_text" value="{{ module_purpletree_multivendor_validate_text }}">
			  <input type="hidden" name="module_purpletree_multivendor_live_validate_text" value="{{ module_purpletree_multivendor_live_validate_text }}">
			  
			  <input type="hidden" name="module_purpletree_multivendor_encypt_text" value="{{ module_purpletree_multivendor_encypt_text }}">
			</div>
		</div>
		  <div class="row">
			<div class="col-sm-12">
				<div class="clearfix">
					<div class="col-sm-12">
						<h3>{{ vendor_heading }}</h3>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_commission }}</label>
							<div class="col-md-9">
								<input type="text" name="module_purpletree_multivendor_commission" class="form-control" value="{{ module_purpletree_multivendor_commission is defined?module_purpletree_multivendor_commission:'' }}"/>
								{% if commission_error %}
									<div class="text-danger">{{ commission_error }}</div>
								{% endif %}
							</div>
						</div>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_seller_manage_order }}</label>
							<div class="col-md-9">
								<select name="module_purpletree_multivendor_seller_manage_order" class="form-control">
									{% if module_purpletree_multivendor_seller_manage_order %}
									<option value="0">{{ text_no }}</option>
									<option value="1" selected="selected">{{ text_yes }}</option>
									{% else %}
									<option value="0" selected="selected">{{ text_no }}</option>
									<option value="1">{{ text_yes }}</option>
									{% endif %}
								</select>
							</div>
						</div>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_seller_approval }}</label>
							<div class="col-md-9">
								<select name="module_purpletree_multivendor_seller_approval" class="form-control">
									{% if module_purpletree_multivendor_seller_approval %}
									<option value="0">{{ text_no }}</option>
									<option value="1" selected="selected">{{ text_yes }}</option>
									{% else %}
									<option value="0" selected="selected">{{ text_no }}</option>
									<option value="1">{{ text_yes }}</option>
									{% endif %}
								</select>
							</div>
						</div>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_product_approval }}</label>
							<div class="col-md-9">
								<select name="module_purpletree_multivendor_product_approval" class="form-control">
								{% if module_purpletree_multivendor_product_approval %}
										<option value="0">{{ text_no }}</option>
										<option value="1" selected="selected">{{ text_yes }}</option>
									{% else %}
										<option value="0" selected="selected">{{ text_no }}</option>
										<option value="1">{{ text_yes }}</option>
								{% endif %}
								</select>
							</div>
						</div>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_allow_category }}</label>
							<div class="col-md-9">
								<select name="module_module_purpletree_multivendor_allow_categorytype" class="form-control">
								{% if module_module_purpletree_multivendor_allow_categorytype %}
										<option value="0">{{ text_selected_categories }}</option>
										<option value="1" selected="selected">{{ text_allowed_categories }}</option>
									{% else %}
										<option value="0" selected="selected">{{ text_selected_categories }}</option>
										<option value="1">{{ text_allowed_categories }}</option>
								{% endif %}
								</select>
								{% if module_module_purpletree_multivendor_allow_categorytype %}
									<input type="text" name="category" value="" disabled id="input-category" class="form-control" />
								{% else %}
									<input type="text" name="category" value="" id="input-category" class="form-control" />
								{% endif %}
								<div id="product-category" class="well well-sm" style="height: 150px; overflow: auto;">
								{% if module_purpletree_multivendor_allow_category %}
									{%	for key, product_category in module_purpletree_multivendor_allow_category %}
									<div id="product-category{{ product_category }}"><i class="fa fa-minus-circle"></i> {{ key }}
									  <input type="hidden" name="module_purpletree_multivendor_allow_category[{{ key }}]" value="{{ product_category }}" />
									</div>
									{% endfor %}
									{% endif %}
								</div>
							</div> 
						</div>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_become_seller }}</label>
							<div class="col-md-9">
								<select name="module_purpletree_multivendor_become_seller" class="form-control">
								{% if module_purpletree_multivendor_become_seller %}
										<option value="0">{{ text_no }}</option>
										<option value="1" selected="selected">{{ text_yes }}</option>
									{% else %}
										<option value="0" selected="selected">{{ text_no }}</option>
										<option value="1">{{ text_yes }}</option>
								{% endif %}
								</select>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="clearfix">
					<div class="col-sm-12">
						<h3>{{ seller_product_heading }}</h3>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_allow_related }}</label>
							<div class="col-md-9">
								<select name="module_purpletree_multivendor_allow_related_product" class="form-control">
								{% if module_purpletree_multivendor_allow_related_product %}
										<option value="0">{{ text_no }}</option>
										<option value="1" selected="selected">{{ text_yes }}</option>
									{% else %}
										<option value="0" selected="selected">{{ text_no }}</option>
										<option value="1">{{ text_yes }}</option>
								{% endif %}
								</select>
							</div>
						</div>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_limit_purchase }}</label>
							<div class="col-md-9">
								<input type="text" name="module_purpletree_multivendor_product_limit" class="form-control" value="{{  module_purpletree_multivendor_product_limit?module_purpletree_multivendor_product_limit:'' }}"/>
								{% if product_limit_error %}
									<div class="text-danger">{{ product_limit_error }}</div>
								{% endif %}
								</select>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="clearfix">
					<div class="col-sm-12">
						<h3>{{ seller_review_heading }}</h3>
					</div>
					<div class="col-sm-12">
						<div class="form-group required">
							<label class="col-md-3 control-label " for="input-name">{{ entry_seller_review }}</label>
							<div class="col-md-9">
								<select name="module_purpletree_multivendor_seller_review" class="form-control">
								{% if module_purpletree_multivendor_seller_review %}
										<option value="0">{{ text_no }}</option>
										<option value="1" selected="selected">{{ text_yes }}</option>
									{% else %}
										<option value="0" selected="selected">{{ text_no }}</option>
										<option value="1">{{ text_yes }}</option>
								{% endif %}
								</select>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="clearfix">
					<div class="col-sm-12">
						<h3>{{ seller_store_heading }}</h3>
					</div>
					<div class="col-sm-12">
						<div class="form-group">
							<label class="col-md-3 control-label " for="input-name">{{ entry_seller_store }}</label>
							<div class="col-md-9">
								<label class="checkbox-inline"><input type="checkbox" value="1" name="module_purpletree_multivendor_store_email" {{ module_purpletree_multivendor_store_email ? 'checked="checked"' : '' }} > {{ text_store_email }}</label>
								
								<label class="checkbox-inline"><input type="checkbox" value="1" name="module_purpletree_multivendor_store_phone" {{ module_purpletree_multivendor_store_phone ? 'checked="checked"' : '' }} > {{ text_store_phone }}</label>
								
								<label class="checkbox-inline"><input type="checkbox" value="1" name="module_purpletree_multivendor_store_address" {{ module_purpletree_multivendor_store_address ? 'checked="checked"' : '' }} > {{ text_store_address }}</label>
							</div>
						</div>
					</div>		
					<div class="col-sm-12">
						<div class="form-group">
							<label class="col-md-3 control-label " for="input-name">{{ entry_seller_invoice }}</label>
							<div class="col-md-9">
								<div class="radio">
									<label><input type="radio" name="module_purpletree_multivendor_seller_invoice" value="1" checked>&nbsp;{{ text_yes }}</label>
									<label><input type="radio" name="module_purpletree_multivendor_seller_invoice" {{ ((module_purpletree_multivendor_seller_invoice=="0")?"checked":"") }} value="0">&nbsp;{{ text_no }}</label>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){ 
	var allowedCat = '{{ module_module_purpletree_multivendor_allow_categorytype }}';
	
	if(!allowedCat){
		$('select[name=\'module_module_purpletree_multivendor_allow_categorytype\']').val(1);
		$('#input-category').prop('disabled', true);
		
		$('#product-category').empty();
		$.ajax({
		url:'index.php?route=extension/purpletree_multivendor/sellerproducts/assignCategory&user_token={{ user_token }}&filter_name=',
			dataType: 'json',
			success: function(json) {
				$.map(json, function(item) {
					$('#product-category').append('<div id="product-category' + item['category_id'] + '"><i class="fa fa-minus-circle"></i> ' + item['name'] + '<input type="hidden" name="module_purpletree_multivendor_allow_category['+item['name']+' ]" value="' + item['category_id'] + '" /></div>');
				});
			}
		});
	}
});
$('select[name=\'module_module_purpletree_multivendor_allow_categorytype\'] option').click(function(){
	var selectid = $(this).val();
	if(selectid=="1"){
		$('#input-category').prop('disabled', true);
		
		$('#product-category').empty();
		$.ajax({
			url:'index.php?route=extension/purpletree_multivendor/sellerproducts/assignCategory&user_token={{ user_token }}&filter_name=',
			dataType: 'json',
			success: function(json) {
				$.map(json, function(item) {
					$('#product-category').append('<div id="product-category' + item['category_id'] + '"><i class="fa fa-minus-circle"></i> ' + item['name'] + '<input type="hidden" name="module_purpletree_multivendor_allow_category['+item['name']+' ]" value="' + item['category_id'] + '" /></div>');
				});
			}
		});
		
	} else{
		$('#input-category').prop('disabled', false);
	}
});
$('input[name=\'category\']').autocomplete({
	'source': function(request, response) {
		$.ajax({
			url:'index.php?route=catalog/category/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item['name'],
						value: item['category_id']
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'category\']').val('');

		$('#product-category' + item['value']).remove();

		$('#product-category').append('<div id="product-category' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="module_purpletree_multivendor_allow_category['+item['label']+' ]" value="' + item['value'] + '" /></div>');
	}
});

$('#product-category').delegate('.fa-minus-circle', 'click', function() {

	var cat_id = $(this).next().val();
	var div_remov = $(this).parent();
	$.ajax({
		url:'index.php?route=extension/purpletree_multivendor/sellerproducts/checkCategoryassign&user_token={{ user_token }}&filter_name='+cat_id,
		type: 'GET',
		success: function(result) {
			if(result > 0){
				alert("{{ text_assign_categories }}");
			} else{ 
				div_remov.remove();
			}
		}
	});
});
</script>
{{ footer }}