{{ 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/webinewsletter/toolbar.twig' %} #}
						<div class="sidebar-nav">
							<ul class="nav nav-pills nav-stacked">
								{% if menus is defined %}
									{% for key,menu in menus %}
										{% set class_active = '' %}
										{% if menu_active is defined and menu_active == key %} {% set class_active = 'active' %} {% endif %}
										<li class="{{ class_active }}"><a href="{{ menu.link }}">{{ menu.title }}</a></li>
									{% endfor %}
								{% endif %}
							</ul>
						</div>
					</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/webinewsletter/action_bar.twig' %} #}
						<div class="pull-right webibtn">
							{% if menu_active is defined %}

								{% if menu_active == 'subscribes' %}
									<a onclick="$('#action').val('delete');$('#form').submit();" class="btn btn-danger">{{ button_delete }}</a>
								{% elseif menu_active == 'modules' %}
									<a onclick="$('#form').submit();" class="btn btn-primary">{{ button_save }}</a>&nbsp;&nbsp;
									<a href="{{ cancel }}" class="btn btn-danger">{{ button_cancel }}</a>&nbsp;&nbsp;
								{% elseif menu_active == 'templates' %}
									<a onclick="$('#action').val('copy_default');$('#form').submit();" class="btn btn-primary">{{ button_copy_default }}</a>&nbsp;&nbsp;
									<a onclick="$('#action').val('copy');$('#form').submit();" class="btn btn-success">{{ button_copy }}</a>&nbsp;&nbsp;
									<a href="{{ insert_link }}" class="btn btn-success">{{ button_insert }}</a>&nbsp;&nbsp;
									<a onclick="$('#action').val('delete');$('#form').submit();" class="btn btn-danger">{{ button_delete }}</a>&nbsp;&nbsp;
								{% elseif menu_active == 'template' %}
									<a onclick="$('#form').submit();" class="btn btn-success">{{ button_save }}</a>&nbsp;&nbsp;
									<a href="{{ cancel }}" class="btn btn-danger">{{ button_cancel }}</a>&nbsp;&nbsp;
								{% elseif menu_active == 'create_newsletter' %}
									<a onclick="$('#action').val('save_draft');$('#form').submit();" class="btn btn-primary">{{ button_save_draft }}</a>&nbsp;&nbsp;
									<a onclick="$('#action').val('send');$('#form').submit();" class="btn btn-success">{{ button_send }}</a>&nbsp;&nbsp;
									<a onclick="$('#action').val('check_spam');$('#form').submit();" class="btn btn-warning">{{ button_check }}</a>&nbsp;&nbsp;
								{% elseif menu_active == 'draft' %}
									<a onclick="$('#action').val('delete');$('#form').submit();" class="btn btn-danger">{{ button_delete }}</a>
								{% elseif menu_active == 'config' %}
									<a onclick="$('#form').submit();" class="btn btn-primary">{{ button_save }}</a>&nbsp;&nbsp;
									<a href="{{ cancel }}" class="btn btn-danger">{{ button_cancel }}</a>
								{% elseif menu_active == 'contact' %}
									<button id="button-send" data-toggle="tooltip" title="{{ button_send }}" class="btn btn-primary" onclick="send('{{ url_send }}');"><i class="fa fa-envelope"></i> {{ button_send }}</button>
									<button id="button-draft" data-toggle="tooltip" title="{{ button_draft }}" class="btn btn-success" onclick="draft('{{ url_draft }}');"><i class="fa fa-save"></i> {{ button_draft }}</button>&nbsp;&nbsp;
								{% elseif menu_active == 'draft_contact' %}
									<a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a> <a href="{{ repair }}" data-toggle="tooltip" title="{{ button_rebuild }}" class="btn btn-default"><i class="fa fa-refresh"></i></a>
									<button type="button" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-draft').submit() : false;"><i class="fa fa-trash-o"></i></button>
								{% endif %}

							{% endif %}
						</div>
					</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 }}





