{{ header }}
{{ column_left }}

<div id="content">
	<div class="page-header">
		<div class="container-fluid">
			<h1>{{ heading_title }}</h1>
			<ul class="breadcrumb">
				{% for breadcrumb in breadcrumbs %}
				<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
				{% endfor %}
			</ul>
		</div>
	</div><!-- end div .page-header -->
	<div id="page-content" class="container-fluid">
		{% if error_warning %}
	    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
	      <button type="button" class="close" data-dismiss="alert">&times;</button>
	    </div>
	    {% endif %}

		{% if success and success is not empty %}
		<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> {{ heading_title }}</h3>
			</div>
			<div class="panel-body" >

				<div class="col-sm-2">
					<div class="logo"><h3>{{ heading_title }}</h3></div>
					<div class="slidebar">{% include '/extension/module/inspirenewsletter/toolbar.twig' %}</div>
					<div class="clear clr"></div>
				</div>

				<div class="col-sm-10">
					<div class="heading">
						<h3>{{ text_create_newsletter }}</h1>
					</div>
					<div class="toolbar">{% include '/extension/module/inspirenewsletter/action_bar.twig' %}</div>
					
					<div class="content">
						<form action="{{ action }}" method="post" enctype="multipart/form-data" id="form">
							<input type="hidden" name="id" value="{{ id }}" />
							<input type="hidden" name="spam_check" value="" />
							<input type="hidden" id="action" name="action" value=""/>

							<table class="table">
								<tr>
									<td>{{ entry_template }}</td>
									<td><select class="form-control" name="template_id">
										<option value="9999">{{ entry_template_default }}</option>
										{% for template in templates %}
										{% if template.template_id == template_id %}
										<option value="{{ template.template_id }}" selected="selected">{{ template.name }}</option>
										{% else %}
										<option value="{{ template.template_id }}">{{ template.name }}</option>
										{% endif %}
										{% endfor %}
										</select>
									</td>
								</tr>
								<tr>
									<td>{{ entry_language }}</td>
									<td><select class="form-control" name="language_id">
										{% for language in languages %}
										{% if language.language_id == language_id %}
										<option value="{{ language.language_id }}" selected="selected">{{ language.name }}</option>
										{% else %}
										<option value="{{ language.language_id }}">{{ language.name }}</option>
										{% endif %}
										{% endfor %}
										</select><br/>
										{% if only_selected_language %}
										<label><input type="checkbox" name="only_selected_language" value="1" checked="checked" />
										{% else %}
										<label><input type="checkbox" name="only_selected_language" value="1" />
										{% endif %}
										{{ text_only_selected_language }}</label>
									</td>
								</tr>
								<tr>
									<td>{{ entry_currency }}</td>
									<td><select class="form-control" name="currency">
										{% for cur in currencies %}
										{% if cur.code == currency %}
										<option value="{{ cur.code }}" selected="selected">{{ cur.title }}</option>
										{% else %}
										<option value="{{ cur.code }}">{{ cur.title }}</option>
										{% endif %}
										{% endfor %}
									</select></td>
								</tr>
								<tr>
									<td>{{ entry_store }}</td>
									<td><select class="form-control" name="store_id">
										{% for store in stores %}
										{% if store.store_id == store_id %}
										<option value="{{ store.store_id }}" selected="selected">{{ store.name }}</option>
										{% else %}
										<option value="{{ store.store_id }}">{{ store.name }}</option>
										{% endif %}
										{% endfor %}
									</select></td>
								</tr>
								<tr>
									<td>{{ entry_to }}</td>
									<td><select id="groupto" class="form-control" name="to">
										{% if to == 'newsletter' %}
										<option value="newsletter" selected="selected">{{ text_newsletter }}</option>
										{% else %}
										<option value="newsletter">{{ text_newsletter }}</option>
										{% endif %}

										{% if to == 'customer_all' %}
										<option value="customer_all" selected="selected">{{ text_customer_all }}</option>
										{% else %}
										<option value="customer_all">{{ text_customer_all }}</option>
										{% endif %}

										{% if to == 'customer_group' %}
										<option value="customer_group" selected="selected">{{ text_customer_group }}</option>
										{% else %}
										<option value="customer_group">{{ text_customer_group }}</option>
										{% endif %}

										{% if to == 'customer' %}
										<option value="customer" selected="selected">{{ text_customer }}</option>
										{% else %}
										<option value="customer">{{ text_customer }}</option>
										{% endif %}

										{% if to == 'product' %}
										<option value="product" selected="selected">{{ text_product }}</option>
										{% else %}
										<option value="product">{{ text_product }}</option>
										{% endif %}

									</select></td>
								</tr>
								<!-- to-customer-group -->
								<tbody id="to-customer-group" class="to">
									<tr>
									<td>{{ entry_customer_group }}</td>
									<td><select class="form-control" name="customer_group_id">
										{% for customer_group in customer_groups %}
										{% if customer_group.customer_group_id == customer_group_id and to == 'customer_group' %}
										<option value="{{ customer_group.customer_group_id }}" selected="selected">{{ customer_group.name }}</option>
										{% else %}
										<option value="{{ customer_group.customer_group_id }}">{{ customer_group.name }}</option>
										{% endif %}
										{% endfor %}
										</select>&nbsp;
										{% if customer_group_only_subscribers %}
										<label><input type="checkbox" name="customer_group_only_subscribers" value="1" checked="checked" />
										{% else %}
										<label><input type="checkbox" name="customer_group_only_subscribers" value="1" />
										{% endif %}
										{{ text_only_subscribers }}</label>
										</td>
									</tr>
								</tbody>

								<!-- to-customer -->
								<tbody id="to-customer" class="to" style="display: none;">
									<tr>
										<td><label class="col-sm-2 control-label" for="input-customer"><span data-toggle="tooltip" title="{{ help_customer }}">{{ entry_customer }}</span></label></td>
										<td>
											<input type="text" name="customers" value="" placeholder="{{ entry_customer }}" id="input-customer" class="form-control" />
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td>
											<div id="items-customer" class="well well-sm" style="height: 150px; overflow: auto;">
												{% for customer in customers %}
												<div id="item-customer{{ customer.customer_id }}"><i class="fa fa-minus-circle"></i> {{ customer.name }}
													<input type="hidden" name="customer[]" value="{{ customer.customer_id }}" />
												</div>
												{% endfor %}
											</div>
										</td>
									</tr>
								</tbody>
							
								<!-- to-product -->
								<tbody id="to-product" class="to" style="display: none;">
									<tr>
										<td><label class="col-sm-2 control-label" for="input-product"><span data-toggle="tooltip" title="{{ help_customer }}">{{ entry_product }}</span></label></td>
										<td>
											<input type="text" name="products" value="" placeholder="{{ entry_product }}" id="input-product" class="form-control" />
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td>
											<div id="items-product" class="well well-sm" style="height: 150px; overflow: auto;">
												{% for product in products %}
												<div id="item-product{{ product.product_id }}"><i class="fa fa-minus-circle"></i> {{ product.name }}
													<input type="hidden" name="product[]" value="{{ product.product_id }}" />
												</div>
												{% endfor %}
											</div>
										</td>
									</tr>
								</tbody>

								<tr>
									<td>{{ entry_special }}</td>
									<td>
										{% if special %} 
											{% set checked1 = ' checked="checked"' %}
											{% set checked0 = '' %}
										{% else %}
											{% set checked0 = ' checked="checked"' %}
											{% set checked1 = '' %}
										{% endif %}
										
										<label for="special_1">{{ entry_yes }}</label>
										<input type="radio"{{ checked1 }} id="special_1" name="special" value="1" />
										<label for="special_0">{{ entry_no }}</label>
										<input type="radio"{{ checked0 }} id="special_0" name="special" value="0" />
									</td>
								</tr>
								<tr>
									<td>{{ entry_latest }}</td>
									<td>
										{% if latest %} 
											{% set checked1 = ' checked="checked"' %}
											{% set checked0 = '' %}
										{% else %}
											{% set checked0 = ' checked="checked"' %}
											{% set checked1 = '' %}
										{% endif %}
										
										<label for="latest_1">{{ entry_yes }}</label>
										<input type="radio"{{ checked1 }} id="latest_1" name="latest" value="1" />
										<label for="latest_0">{{ entry_no }}</label>
										<input type="radio"{{ checked0 }} id="latest_0" name="latest" value="0" />
									</td>
								</tr>
								<tr>
									<td>{{ entry_popular }}</td>
									<td>
										{% if popular %} 
											{% set checked1 = ' checked="checked"' %}
											{% set checked0 = '' %}
										{% else %}
											{% set checked0 = ' checked="checked"' %}
											{% set checked1 = '' %}
										{% endif %}

										<label for="popular_1">{{ entry_yes }}</label>
										<input type="radio"{{ checked1 }} id="popular_1" name="popular" value="1" />
										<label for="popular_0">{{ entry_no }}</label>
										<input type="radio"{{ checked0 }} id="popular_0" name="popular" value="0" />
									</td>
								</tr>
							
								<tr>
									<td><span class="required">*</span> {{ entry_subject }}</td>
									<td>
										<input type="text" name="subject" value="{{ subject }}" size="60" />
										{% if error_subject %}
										<span class="error">{{ error_subject }}</span>
										{% endif %}
									</td>
								</tr>

								<tr>
									<td><span class="required">*</span> {{ entry_message }}</td>
									<td>
										<textarea name="message" rows="5" placeholder="{{ entry_message }}" id="input-message" class="form-control">{{ message }}</textarea>
										{% if error_message %}
										<span class="error">{{ error_message }}</span>
										{% endif %}
										<p>{{ text_message_info }}</p>
									</td>
								</tr>
							</table>

						</form>
					</div>
				</div>

			</div><!-- end div .panel-body -->
		</div><!-- end div .panel -->
	</div><!-- end div #page-content -->

</div><!-- end div #content -->



<script type="text/javascript">

// Customer Auto Complete
$('#items-customer').delegate('.fa-minus-circle', 'click', function() {
	$(this).parent().remove();
});
$('input[name=\'customers\']').autocomplete({
	'source': function(request, response) {
		$.ajax({
			url: 'index.php?route=sale/customer/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['customer_id']
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'customers\']').val('');
		
		$('#items-customer' + item['value']).remove();
		
		$('#items-customer').append('<div id="item-customer' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="customer[]" value="' + item['value'] + '" /></div>');	
	}	
});

// product Auto Complete
$('#items-product').delegate('.fa-minus-circle', 'click', function() {
	$(this).parent().remove();
});
$('input[name=\'products\']').autocomplete({
	'source': function(request, response) {
		$.ajax({
			url: 'index.php?route=catalog/product/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['product_id']
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'products\']').val('');
		
		$('#items-product' + item['value']).remove();
		
		$('#items-product').append('<div id="item-product' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="product[]" value="' + item['value'] + '" /></div>');	
	}	
});

$('#input-message').summernote({height: 300});

$('#groupto').bind('change', function() {
	var val = $(this).val();
	if(val == "customer") {
		$("#to-customer").show();
		$("#to-product").hide();
	} else if(val == "product"){
		$("#to-product").show();
		$("#to-customer").hide();
	} else {
		$("#to-customer").hide();
		$("#to-product").hide();
	}
});
</script>
{{ footer }}





