<!--
	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">
        <article class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
            <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 col-md-2 text-align-right">-->
                        <!--</div>-->
                        <!--</div>-->
                        <!--</div>-->
                        <div class="tree">
                            <ul>
                                <li data-ng-repeat="organization in organizationList" data-ng-include="'tree_view_table.html'"></li>
                            </ul>
                        </div>
                    </div>
                    <!-- end widget content -->
                </div>
                <!-- end widget div -->
            </div>
        </article>
		<!-- NEW WIDGET START -->
		<article class="col-xs-10 col-sm-10 col-md-10 col-lg-10">

			<!-- Widget ID (each widget will need unique ID)-->
			<div class="jarviswidget" id="wid-id-4">
				<!-- 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 no-padding">
						<div class="dt-toolbar">
							<div class="col-sm-4">
								<div class="dataTables_filter">
									<label>
										<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
										<input type="search" placeholder="用户名/邮箱" data-ng-keyup="getUserList()" ng-model="queryParam.keyword" class="form-control" aria-controls="dt_basic"></label>
								</div>
							</div>
							<div class="col-sm-2">
								<button class="btn btn-primary" type="button" data-ng-click="getUserList()">
									<i class="fa fa-refresh"></i>
									刷新
								</button>
								<button class="btn btn-primary" type="button" permission only="'USER_ADD'" data-ng-click="open()">
									<i class="fa fa-plus"></i>
									新增用户
								</button>
							</div>
						</div>
						<div class="table-responsive">
							<table class="table table-striped table-condensed table-hover smart-form has-tickbox">
								<thead>
								<tr>
									<th>
										<label class="checkbox">
											<input type="checkbox" name="checkbox-inline">
											<i></i>
										</label>
									</th>
									<th width="120">用户名</th>
									<th>邮箱</th>
									<th>真实姓名</th>
									<th>性别</th>
									<th>年龄</th>
									<th>手机号码</th>
									<th>办公电话</th>
                                    <th>用户组</th>
                                    <th>组织</th>
									<th>锁定</th>
									<th width="80">操作</th>
								</tr>
								</thead>
								<tbody>
								<tr ng-repeat="user in userList"  ng-if="userList.length > 0" ng-mouseenter="show=true" ng-mouseleave="show=false">
									<td>
										<label class="checkbox">
											<input type="checkbox" name="checkbox-inline">
											<i></i>
										</label>
									</td>
									<td ng-bind="user.username"></td>
									<td ng-bind="user.email"></td>
									<td ng-bind="user.realName"></td>
									<td ng-bind="user.sex"></td>
									<td ng-bind="user.age"></td>
									<td ng-bind="user.phoneNumber"></td>
									<td ng-bind="user.officeTel"></td>
                                    <td>
                                        <span ng-repeat="group in user.userGroups" >{{group.userGorup}}<br></span>
                                    </td>
                                    <td ng-bind="user.organization"></td>
                                    <td>
										<label class="checkbox">
											<input type="checkbox" ng-model="user.locked" name="checkbox-inline"
												   ng-change="locked($index)"
												   data-ng-checked="user.locked == 1" data-ng-true-value="1" data-ng-false-value="0">
											<i></i>
										</label>
									</td>
									<td>
										<div ng-show="show">
											<a href="javascript:void(0);" data-ng-click="removeUser($index)" title="删除用户：{{user.username}}">
												<span class="glyphicon glyphicon-remove-circle"></span>
											</a>
											<span> | </span>
											<a href="javascript:void(0);" data-ng-click="updateUser($index)" title="编辑用户：{{user.username}}">
												<span class="fa fa-pencil"></span>
											</a>
                                            <span> | </span>
                                            <a href="javascript:void(0);" data-ng-click="resetDefaultPassword($index)" title="重置密码：{{user.username}}">
                                                <span class="fa fa-rotate-right"></span>
                                            </a>
										</div>
									</td>
								</tr>
								<tr ng-if="userList == null || userList.length == 0">
									<td colspan="3">
										<div>暂无数据</div>
									</td>
								</tr>
								</tbody>
							</table>
						</div>
						<div class="dt-toolbar-footer">
							<div class="col-xs-12 col-sm-12">
								<ug-pagination page-info="pageInfoSetting" ></ug-pagination>
							</div>
						</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="addUser.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="addUserForm" name="addUserForm" novalidate="">

				<fieldset>

					<div class="form-group">
						<label class="col-md-2 control-label">用户名<span class="vaild">*</span></label>
						<div class="col-md-10">
							<input class="form-control" ng-model="user.userId" name="id" type="hidden">
							<input class="form-control" required="true" data-rule-minlength="6" data-rule-maxlength="20" ng-model="user.username" name="username" placeholder="用户名" type="text">
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">真实姓名<span class="vaild">*</span></label>
						<div class="col-md-10">
							<input class="form-control" required="true"  ng-model="user.realName" name="realName" 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"  ng-model="user.email" name="email" placeholder="邮箱" type="email">
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">QQ</label>
						<div class="col-md-10">
							<input class="form-control"  ng-model="user.qq" name="qq" placeholder="QQ" type="text">
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">性别</label>
						<div class="col-md-10">
							<label class="radio radio-inline">
								<input type="radio" class="radiobox" value="0" ng-model="user.sex" ng-checked="user.sex==0" name="sex">
								<span>男</span>
							</label>
							<label class="radio radio-inline">
								<input type="radio" class="radiobox" value="1" ng-model="user.sex" ng-checked="user.sex==1" name="sex">
								<span>女</span>
							</label>
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">年龄</label>
						<div class="col-md-10">
							<input class="form-control" data-rule-d  ng-model="user.age" name="age" placeholder="年龄" type="number">
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">手机号码<span class="vaild">*</span></label>
						<div class="col-md-10">
							<input class="form-control" required="" ng-model="user.phoneNumber" data-rule-minlength="11" data-rule-maxlength="11" name="phoneNumber" 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"  ng-model="user.officeTel" name="officeTel" placeholder="办公电话" type="text">
						</div>
					</div>

					<div class="form-group" ng-if="user.id == null">
						<label class="col-md-2 control-label">密码<span class="vaild">*</span></label>
						<div class="col-md-10">
							<input id="password" class="form-control" required="true" data-rule-minlength="6" data-rule-maxlength="20" ng-model="user.password" name="password" placeholder="密码" type="password" >
						</div>
					</div>

					<div class="form-group" ng-if="user.id == null">
						<label class="col-md-2 control-label">确认密码<span class="vaild">*</span></label>
						<div class="col-md-10">
							<input class="form-control" required="true" data-rule-equalTo="#password" data-rule-minlength="6" data-rule-maxlength="20" ng-model="user.confirmPassword" name="confirmPassword_{{$index}}" placeholder="确认密码" type="password">
						</div>
					</div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">所属用户组<span class="vaild">*</span></label>
                        <div class="col-md-10">
                                <select multiple ug-select2 ug-select2-config="ugSelect2Config" style="width: 100%;"
                                        required="true" ng-model="user.userGroupIds" name="userGroupIds" >
                                    <option ng-value="">--请选择--</option>
                                    <option ng-value="{{group.id}}" ng-repeat="group in groupList">{{group.description}}</option>
                                </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">所属组织<span class="vaild">*</span></label>
                        <div class="col-md-10">
                            <input class="form-control" required="true"  ng-focus="chooseCategoryModel()" ng-model="user.organization" name="organization" placeholder="组织" type="text">
                        </div>
                    </div>
					<div class="form-group">
						<label class="col-md-2 control-label">禁用状态</label>
						<div class="col-md-10">
							<div class="checkbox">
								<label>
									<input type="checkbox" ng-model="user.locked" class="checkbox style-0" name="locked" checked="checked" ng-true-value="true" ng-false-value="false">
									<span>禁用用户</span>
								</label>
							</div>
						</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="submit" data-ng-click="saveUser()">
			<i class="fa fa-save"></i>
			保存
		</button>
		<button class="btn btn-warning" ng-click="cancel()">关闭</button>
	</div>
</script>

<script type="text/ng-template" id="tree_view_table.html">
    <span ng-mouseenter="organization.show=true" ng-mouseleave="organization.show=false">
        <i ng-if="organization.nodes && organization.nodes.length > 0" class="fa fa-lg fa-plus-circle"></i>
        <a ng-show="organization.parentId != null" ng-click="getUserList(organization.id)">{{organization.name}}</a>
        <lable ng-show="organization.parentId == null" >{{organization.name}}</lable>
    </span>
    <ul ng-if="organization.nodes && organization.nodes.length > 0" class="tree-hide">
        <li data-ng-repeat="organization in organization.nodes" data-ng-include="'tree_view_table.html'"></li>
    </ul>
</script>

<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>
        <a  ng-show="item.parentId != null" ng-click="chooseCategory(item)">{{item.name}}</a>
		<lable ng-show="item.parentId == null" >{{item.name}}</lable>
		<a href="javascript:void(0);" ng-show="organization.parentId == null && item.show" ng-click="chooseCategory(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="chooseCategory.html">
    <div class="modal-header">
        <h3 class="modal-title">选择组织</h3>
    </div>
    <div class="modal-body">
        <div class="widget-body">
            <div class="tree">
                <ul>
                    <li data-ng-repeat="item in innerOrganizationList" data-ng-include="'tree_view.html'"></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-warning" ng-click="cancel()">关闭</button>
    </div>
</script>

