<!--{include file="<!--{$oapath}-->public/ins_popup.tpl"}-->
<block name="content">
	<div class="popup-fixed">
		<div class="popup-header clearfix">
			<div class="pull-left">
				<label>
					<input class="ace"  type="radio" id="rb_dept" name="type" value="dept" >
					<span class="lbl">部门</span> </label>
				<label>
					<input  class="ace"  type="radio" id="rb_position" name="type" value="position">
					<span class="lbl">职位</span> </label>
			</div>
			<div class="pull-right">
				<a onclick="save();" class="btn btn-sm btn-primary">确定</a>
				<a onclick="myclose();" class="btn btn-sm btn-default">关闭</a>
			</div>
		</div>
		<div class="popup-body clearfix">
			<div class="col-23 pull-left">
				<b class="popup-label">地址簿</b>
				<div class="popup_tree_menu" >
					<div id="dept" class="hidden" style="height:170px;">
						<!--{$list_dept}-->
					</div>
					<div id="position" class="hidden" style="height:170px;">
						<!--{$list_position}-->
					</div>
				</div>
				<b class="popup-label">&nbsp;</b>
				<div>
					<div id="addr_list" style="width:100%;height:170px;"></div>
				</div>
			</div>
			<div class="col-30 pull-left">
				<div class="col-7 pull-left text-center mid" style="margin-top: 24px;">
					<a onclick="add_address('rc');" class="btn btn-sm btn-primary"><i class="fa fa-angle-double-right"></i></a>
					<a onclick="save();" class="btn btn-sm btn-primary">确定</a>
					<a onclick="myclose();" class="btn btn-sm btn-default">关闭</a>
				</div>
				<div class="clearfix" >
					<b class="popup-label">参与人员</b><span id="rc_count"></span>
					<div class="col-23 pull-right">
						<div id="rc" class="selected" style="width:100%;height:369px;overflow:hidden">
							<ul></ul>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
                                		</div>
		
                		<!-- Mainly scripts -->
                        <script src="<!--{$oapath}-->Ins/js/jquery-2.1.1.js"></script>
                        <script src="<!--{$oapath}-->Ins/js/bootstrap.min.js"></script>
                        <script src="<!--{$oapath}-->Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
                        <script src="<!--{$oapath}-->Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

                        <!-- Custom and plugin javascript -->
                        <script src="<!--{$oapath}-->Ins/js/inspinia.js"></script>
                        <script src="<!--{$oapath}-->Ins/js/common.js"></script>

                        <script src="<!--{$oapath}-->Ins/js/plugins/jquery-ui/jquery-ui.min.js"></script>
                        <script src="<!--{$oapath}-->Ins/js/plugins/nouslider/jquery.nouislider.min.js"></script>



                <script src="<!--{$oapath}-->Ins/js/plugins/toastr/toastr.min.js"></script>
                <script src="<!--{$oapath}-->Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
                <script src="<!--{$oapath}-->Ins/js/plugins/bootbox/bootbox.min.js"></script>

                <script type="text/javascript">
                        $(document).ready(function() {

                        }); 
                </script>
<block name="js">
	<script type="text/javascript">
		function add_address(name) {			
			$("input:checked[name='addr_id']").each(function() {				
				$text = $(this).next().text().trim();
				$val = $(this).val();
				if ($("#" + name + ".selected li[data='" + $val + "']").length == 0) {
					$li = $('<li><span></span><a class="fa fa-times"></a></li>');
					$li.find('span').text($text);
					$li.attr('data', $val);
					$li.appendTo("#" + name + ".selected ul");
					recount();
				};
			});
			$("#addr_list input:checked").prop('checked', false);
		}
			
		$(document).on("click", ".selected a.fa-times", function() {
			$(this).parent().remove();
			recount();
		});

		// 双击添加到收件人 因后添加的数据 所以需要用live函数
		$(document).on("dblclick", "#addr_list label", function() {
			$text = $(this).text();
			$val = $(this).find("input").val();
			if ($("#rc.selected li[data='" + $val + "']").length == 0) {
				$li = $('<li><span></span><a class="fa fa-times"></a></li>');
				$li.find('span').text($text);
				$li.attr('data', $val);
				$li.appendTo("#rc.selected ul");
				recount();
			};
		});
		
		function recount() {
			$("#rc_count").text("(" + $("#rc.selected li").length + ")");
			$("#cc_count").text("(" + $("#cc.selected li").length + ")");
			$("#bcc_count").text("(" + $("#bcc.selected li").length + ")");
		}
		
		function save() {
			$("#rc.selected li").each(function(i) {
				emp_no = $(this).attr('data');
				name = jQuery.trim($(this).text());
				name = name.replace(/<.*>/, '');
				html_string = conv_inputbox_item(name, emp_no);
				$("#actor_wrap .address_list", parent.document).append(html_string);
			});
			myclose();
		}

		function showdata(result) {
			$("#addr_list").html("");
			if ( type = $("input[name='type']:checked").val() == "dept") {
				var dept_id = "dept_" + $("#dept a.active").attr("node");
				var dept_name = $("#dept a.active span").text();
				var email = "dept@group";
				var name = dept_name + "&lt;" + email + "&gt;";
				var html_string = conv_address_item(name, dept_id);
				$("#addr_list").html(html_string);
			}
			for (s in result.data) {
				var user_id = result.data[s].id;
				var position_name = result.data[s].position_name;
				var name = result.data[s].name;
				var name = name + "/" + position_name;
				var html_string = conv_address_item(name, user_id);
				$("#addr_list").append(html_string);
			}
		}

		$(document).ready(function() {
			$("#rb_<!--{$type}-->").prop('checked', true);
			// 选择用户默认选择的类型
			$("#<!--{$type}-->").removeClass("hidden");

			$("input[name='type']").on('click', function() {
				$("input[name='type']").each(function() {
					$("#" + $(this).val()).addClass("hidden");
				});
				$("#" + $(this).val()).removeClass("hidden");
			});

			$(".tree_menu  a").click(function() {
				$(".tree_menu a").removeClass("active");
				var type = $("input[name='type']:checked").val();
				$(this).addClass("active");
				sendAjax("oa.php?c=popup&a=read", "type=" + type + "&id=" + $(this).attr("node"), function(data) {
					showdata(data);
				});
				return false;
				//禁止连接生效
			});
		});
		//最终确认
		//-->
	</script>
</block>
	</body>
</html>