<!--
	The ID "widget-grid" will start to initialize all widgets below 
	You do not need to use widgets if you dont want to. Simply remove 
	the <section></section> and you can use wells or panels instead 
	-->

<!-- widget grid -->
<section id="widget-grid" class="">

	<!-- row -->
	<div class="row">

		<!-- NEW WIDGET START -->
		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

			<!-- Widget ID (each widget will need unique ID)-->
			<div class="jarviswidget" id="wid-id-0">
				<!-- widget options:
				usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

				data-widget-colorbutton="false"
				data-widget-editbutton="false"
				data-widget-togglebutton="false"
				data-widget-deletebutton="false"
				data-widget-fullscreenbutton="false"
				data-widget-custombutton="false"
				data-widget-collapsed="true"
				data-widget-sortable="false"

				-->
				<header>
					<span class="widget-icon"> <i class="fa fa-table"></i> </span>
					<h2>组织机构管理</h2>

				</header>

				<!-- widget div-->
				<div>

					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<!-- This area used as dropdown edit box -->

					</div>
					<!-- end widget edit box -->

					<!-- widget content -->
					<div class="widget-body">

						<div class="widget-body-toolbar bg-color-white">


							<div class="row">

								<div class="col-sm-12">
									<button class="btn btn-primary" type="button" data-ng-click="getOrganizationTree()">
										<i class="fa fa-refresh"></i>
										刷新
									</button>

									<button type="button" class="btn btn-primary" data-ng-click="openAddModel()" >
										<i class="fa fa-plus"></i> 添加一级组织机构
									</button>

								</div>

							</div>

						</div>

						<div class="tree">
							<ul>
								<li data-ng-repeat="item in organizationList" data-ng-include="'tree_view.html'"></li>
							</ul>
						</div>

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

				</div>
				<!-- end widget div -->

			</div>
			<!-- end widget -->

		</article>
		<!-- WIDGET END -->

	</div>

	<!-- end row -->

</section>
<!-- end widget grid -->
<script type="text/ng-template" id="tree_view.html">
	<span ng-mouseenter="item.show=true" ng-mouseleave="item.show=false">
		<i ng-if="item.nodes && item.nodes.length > 0" class="fa fa-lg fa-plus-circle"></i> {{item.name}}（{{item.description}}）
		<a href="javascript:void(0);" ng-show="item.show" ng-click="updateChildOrganization(item)">修改</a>
		<a ng-show="item.show" > | </a>
		<a href="javascript:void(0);" ng-show="item.show" ng-click="removeNode(item)">删除</a>
		<a ng-show="item.show" > | </a>
		<a href="javascript:void(0);" ng-show="item.show" ng-click="addChildOrganization(item)">添加下级组织</a>
		<!--<a ng-show="item.show" > | </a>-->
		<!--<a href="javascript:void(0);" ng-show="item.show" ng-click="openUserModel(item)">用户</a>-->
	</span>
	<ul ng-if="item.nodes && item.nodes.length > 0" class="tree-hide">
		<li data-ng-repeat="item in item.nodes" data-ng-include="'tree_view.html'"></li>
	</ul>
</script>
<script type="text/ng-template" id="addOrganization.html">
	<div class="modal-header">
		<h3 class="modal-title">新增组织</h3>
	</div>
	<div class="modal-body">
		<div class="widget-body">

			<form class="form-horizontal" ug-validate="addOrganizationForm" name="addOrganizationForm" novalidate="">

				<fieldset>
					<div class="form-group">
						<label class="col-md-2 control-label">组织名称</label>
						<div class="col-md-10">
							<input class="form-control" ng-model="organization.id" name="id" type="hidden">
							<input class="form-control" required="true" ng-model="organization.name" name="name" placeholder="组织名称" type="text">
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">组织描述</label>
						<div class="col-md-10">
							<input class="form-control" required="true" ng-model="organization.description" name="description" placeholder="组织描述" type="text">
						</div>
					</div>

					<div class="form-group" ng-if="organization.parentId">
						<label class="col-md-2 control-label">上级组织</label>
						<div class="col-md-10">
							<input class="form-control" ng-model="organization.parentName" readonly name="parentName" placeholder="上级组织" type="text" >
							<input class="form-control" ng-model="organization.parentId" name="parentId" type="hidden" >
						</div>
					</div>

					<div class="form-group" ng-if="errors">
						<label class="col-md-2 control-label"></label>
						<div class="col-md-10 error">
							{{errors.message}}
						</div>
					</div>
				</fieldset>
			</form>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn btn-primary" type="button" data-ng-click="saveOrganization()">
			<i class="fa fa-save"></i>
			保存
		</button>
		<button class="btn btn-warning" ng-click="cancel()">关闭</button>
	</div>
</script>

<script type="text/ng-template" id="organizationUser.html">
	<div class="modal-header">
		<h3 class="modal-title">机构组织用户</h3>
	</div>
	<div class="modal-body">
		<div class="widget-body">
			<fieldset>
				<div class="form-group">
					<label class="col-md-2 control-label">用户名</label>
					<div class="col-md-10">
						<select multiple ug-select2 style="width: 100%;" required="true" ng-model="choseUser.items" name="userId" >
							<option value="{{user.id}}" ng-repeat="user in userList">{{user.username}}</option>
						</select>
					</div>
				</div>
			</fieldset>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn btn-primary" type="button" data-ng-click="saveOrganizationUser()">
			<i class="fa fa-save"></i>
			保存
		</button>
		<button class="btn btn-warning" ng-click="cancel()">关闭</button>
	</div>
</script>
