{% extends '../template.html' %}
{% block title %}Edit User{% endblock %}
{% block subcontent %}
		{% if session.flash.error != "" %}
			{{ session.flash.error | safe }}
		{% endif %}
		<h1>Edit User</h1>
		<form method="post">
			<table class="data" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td>Username</td>
					<td><input type="text" name="username" value="{{ data.username }}"/></td>
				</tr>
				<tr>
					<td>Password</td>
					<td><input type="text" name="password" value="{{ data.password }}"/></td>
				</tr>
				<tr>
					<td>Role</td>
					<td>
						<select id="role" name="role">
							{% if users.inbound == "1" %}<option value="inbound" {% if data.role == "inbound"%}selected="selected"{%endif%}>Inbound</option>{%endif%}
							{% if users.outbound == "1" %}<option value="outbound" {% if data.role == "outbound"%}selected="selected"{%endif%}>Outbound</option>{%endif%}
							{% if users.store == "1" %}<option value="store" {% if data.role == "store"%}selected="selected"{%endif%}>Store</option>{%endif%}
							{% if users.supervisor == "1" %}<option value="supervisor" {% if data.role == "supervisor"%}selected="selected"{%endif%}>Agent Supervisor</option>{%endif%}
							{% if users.admin == "1" %}<option value="admin" {% if data.role == "admin"%}selected="selected"{%endif%}>Super Admin</option>{%endif%}
							{% if users.management == "1" %}<option value="management" {% if data.role == "management"%}selected="selected"{%endif%}>Management</option>{%endif%}
						</select>
					</td>
				</tr>
				<tr class="manager" style="display:none;">
					<td></td>
					<td>
						<label><input class="pilihan" value="admin" type="radio" name="pilihan" {% if data.id_store == 0 %}checked="checked"{% endif %}/>Admin</label>
						<label><input class="pilihan" value="store" type="radio" name="pilihan" {% if data.id_store != 0 %}checked="checked"{% endif %}/>Store Manager</label>
					</td>
				</tr>
				<tr class="store" style="display:none;">
					<td>Store</td>
					<td>
						<select id="id_store" name="id_store" class="id_store_select">
						{% for s in stores %}
							<option {% if s.id == data.id_store %}selected="selected"{% endif %} value="{{s.id}}">{{s.kode}} - {{s.nama}}</option>
						{% endfor %}
						</select>
						<input type="hidden" class="id_store_hidden" name="id_store_" value="0"/>
					</td>
				</tr>
				<tr class="admin" style="display:none;">
					<td>Permition</td>
					<td>
						<table>
							<tr>
								<td>
									<input type="checkbox" name="edit1" value="1" class="edit1"{% if access.edit.user == "1" %}checked="checked"{% endif %}/> edit - User
										<select id="user" name="user" class="user_permit" disabled=true>
											<option value="all" {% if access.allUser == "1"%}selected="selected"{%endif%}>All</option>
											<option value="custom" {% if access.allUser == "0"%}selected="selected"{%endif%}>Custom</option>
										</select>
										<table class="show" style="margin-left:15px;display:none;">
											<tr>
												<td>
													<input class="users" type="checkbox" name="user1" disabled=true value="1" {% if access.eUser.management == "1"%}checked="checked"{%endif%}/> Management<br />
													<input class="users" type="checkbox" name="user2" disabled=true value="1" {% if access.eUser.supervisor == "1"%}checked="checked"{%endif%}/> Agent Supervisor<br />
													<input class="users" type="checkbox" name="user3" disabled=true value="1" {% if access.eUser.inbound == "1"%}checked="checked"{%endif%}/> Inbound<br />
													<input class="users" type="checkbox" name="user4" disabled=true value="1" {% if access.eUser.outbound == "1"%}checked="checked"{%endif%}/> Outbound<br />
													<input class="users" type="checkbox" name="user5" disabled=true value="1" {% if access.eUser.store == "1"%}checked="checked"{%endif%}/> Store<br />
												</td>
											</tr>
										</table><br />
									<input type="checkbox" name="edit2" value="1" {% if access.edit.store == "1" %}checked="checked"{% endif %}/> edit - Store<br />
									<input type="checkbox" name="edit3" value="1" {% if access.edit.menu == "1" %}checked="checked"{% endif %}/> edit - Menu<br />
									<input type="checkbox" name="edit4" value="1" {% if access.edit.shift == "1" %}checked="checked"{% endif %}/> edit - Shift<br />
									<input type="checkbox" name="edit5" value="1" {% if access.edit.customer == "1" %}checked="checked"{% endif %}/> edit - Customer<br />
									<input type="checkbox" name="edit6" value="1" {% if access.edit.order == "1" %}checked="checked"{% endif %}/> edit - Order<br />
									<input type="checkbox" name="edit7" value="1" {% if access.edit.complaint == "1" %}checked="checked"{% endif %}/> edit - Complaint<br />
									<input type="checkbox" name="edit8" value="1" {% if access.edit.rider == "1" %}checked="checked"{% endif %}/> edit - Rider<br />
									<input type="checkbox" name="edit9" value="1" {% if access.edit.blacklist == "1" %}checked="checked"{% endif %}/> edit - Blacklist<br />
								</td>
								<td>
									<input type="checkbox" name="report1" value="1" {% if access.report.customer == "1" %}checked="checked"{% endif %}/> Report - Customer<br />
									<input type="checkbox" name="report2" value="1" {% if access.report.agent == "1" %}checked="checked"{% endif %}/> Report - Agent<br />
									<input type="checkbox" name="report3" value="1" {% if access.report.complaint == "1" %}checked="checked"{% endif %}/> Report - Complaint<br />
									<input type="checkbox" name="report4" value="1" {% if access.report.callhistory == "1" %}checked="checked"{% endif %}/> Report - Call History<br />
									<input type="checkbox" name="report5" value="1" {% if access.report.orderhistory == "1" %}checked="checked"{% endif %}/> Report - Order History<br />
									<input style="display:none;" type="checkbox" name="report6" value="1" {% if access.report.sales == "1" %}checked="checked"{% endif %}/>
									<input type="checkbox" name="report7" value="1" {% if access.report.callstats == "1" %}checked="checked"{% endif %}/> Report - Call Statistic<br />
									<input type="checkbox" name="report8" value="1" {% if access.report.orderstats == "1" %}checked="checked"{% endif %}/> Report - Order Statistic<br />
									<input type="checkbox" name="report9" value="1" {% if access.report.salesstats == "1" %}checked="checked"{% endif %}/> Report - Sales Statistic<br />
									<input type="checkbox" name="report10" value="1" {% if access.report.rider == "1" %}checked="checked"{% endif %}/> Report - Absensi Rider<br />
								</td>
							</tr>	
						</table>
					</td>
				</tr>
			</table>
			<br/><input type="submit" value="Submit" /> <a href="{% nav user_list %}">Cancel</a>
		</form>
{% endblock %}
{% block script %}
<script type="text/javascript">
	$(document).ready(function() {
		if ($("#role").val() == "store") {
			$(".store").show();
			$(".admin").hide();
			$(".manager").hide();
			$(".id_store_select").attr("name","id_store");
			$(".id_store_hidden").attr("name","id_store_");
		} else if ($("#role").val() == "management"){
			$(".manager").show();
			$(".admin").show();
			if ($("input[@name=pilihan]:checked").val() == "store") {
				$(".store").show();
			} else {
				$(".pilihan[value='admin']").attr("checked","checked");
				$(".store").hide();
			}
		} else {
			$(".manager").hide();
			$(".admin").hide();
			$(".store").hide();
			$(".id_store_select").attr("name","id_store_");
			$(".id_store_hidden").attr("name","id_store");
		}
		if ($(".edit1").is(":checked")) {
			$(".user_permit").removeAttr("disabled");
			$(".show").show();
		} else {
			$(".user_permit").attr("disabled",true);
			$(".show").hide();
		}
		if ($("#user").val() == 'all') {
			$(".users").attr("disabled",true);
		} else {
			$(".users").removeAttr("disabled");
		}
		$("#role").change(function() {
			if ($(this).val() == "store") {
				$(".store").show();
				$(".admin").hide();
				$(".manager").hide();
				$(".id_store_select").attr("name","id_store");
				$(".id_store_hidden").attr("name","id_store_");
			} else if ($("#role").val() == "management"){
				$(".manager").show();
				$(".admin").show();
				if ($("input[@name=pilihan]:checked").val() == "store") {
					$(".store").show();
				} else {
					$(".pilihan[value='admin']").attr("checked","checked");
					$(".store").hide();
				}
			} else {
				$(".manager").hide();
				$(".admin").hide();
				$(".store").hide();
				$(".id_store_select").attr("name","id_store_");
				$(".id_store_hidden").attr("name","id_store");
			}
		});
		$(".pilihan").live("click",function() {
			if ($(this).val() == 'store') {
				$(".store").show();
				$(".id_store_select").attr("name","id_store");
				$(".id_store_hidden").attr("name","id_store_");
			} else {
				$(".store").hide();
				$(".id_store_select").attr("name","id_store_");
				$(".id_store_hidden").attr("name","id_store");
			}
		});
		$(".edit1").live("click",function() {
			if ($(this).is(":checked")) {
				$(".user_permit").removeAttr("disabled");
				$(".show").show();
			} else {
				$(".user_permit").attr("disabled",true);
				$(".show").hide();
			}
		});
		$("#user").change(function() {
			if ($(this).val() == 'all') {
				$(".users").attr("disabled",true);
			} else {
				$(".users").removeAttr("disabled");
			}
		});
	});
</script>
{% endblock %}