PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/BlogEngine/BlogEngine.NET/admin/Users/Users.aspx

#
ASP.NET | 140 lines | 133 code | 7 blank | 0 comment | 16 complexity | d3daf5fe06891f368b9a011bc2c77e6f MD5 | raw file
  1<%@ Page Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="Users.aspx.cs" Inherits="Admin.Users.Users" Title="Create new user" %>
  2<asp:Content ID="Content1" ContentPlaceHolderID="cphAdmin" runat="Server">
  3    <script type="text/javascript">
  4        function AddUser(obj) {
  5            var txtUser = $('#txtUserName').val();
  6            var txtPwd = $('#txtPassword').val();
  7            var txtPwd2 = $('#txtPassword2').val();
  8            var txtEmail = $('#txtEmail').val();
  9
 10            var roles = new Array();
 11            var cnt = 0;
 12            $.each($('.chkRole:checked'), function (i, v) {
 13                roles[cnt] = v.id;
 14                cnt++;
 15            });
 16
 17            if (txtUser.length == 0) {
 18                $('#txtUserNameReq').removeClass('hidden');
 19                $('#txtUserName').focus().select();
 20                return false;
 21            }
 22            else if (txtPwd.length == 0 || txtPwd2.length == 0) {
 23                $('#txtPasswordReq').removeClass('hidden');
 24                $('#txtPassword').focus().select();
 25                return false;
 26            }
 27            else if (txtPwd != txtPwd2) {
 28                $('#txtPasswordMatch').removeClass('hidden');
 29                $('#txtPassword').focus().select();
 30                return false;
 31            }
 32            else if (txtEmail.length == 0) {
 33                $('#txtEmailReq').removeClass('hidden');
 34                $('#txtEmail').focus().select();
 35                return false;
 36            }
 37            else {
 38                var dto = { "user": txtUser, "pwd": txtPwd, "email": txtEmail, "roles": roles };
 39                $.ajax({
 40                    url: SiteVars.ApplicationRelativeWebRoot + "api/UserService.asmx/Add",
 41                    data: JSON.stringify(dto),
 42                    type: "POST",
 43                    contentType: "application/json; charset=utf-8",
 44                    dataType: "json",
 45                    beforeSend: onAjaxBeforeSend,
 46                    success: function (result) {
 47                        var rt = result.d;
 48                        if (rt.Success) {
 49                            LoadUsers();
 50                            ShowStatus("success", rt.Message);
 51                        }
 52                        else {
 53                            ShowStatus("warning", rt.Message);
 54                        }
 55                    }
 56                });
 57            }
 58            closeOverlay();
 59            return false;
 60        }
 61
 62        function OnAdminDataSaved() {
 63            LoadUsers();
 64        }
 65    </script>
 66
 67    <script type="text/javascript" src="../jquery.colorbox.js"></script>
 68    <script type="text/javascript">
 69        $(document).ready(function () {
 70            $(".addNew").colorbox({ width: "550px", inline: true, href: "#frmAddNew" });
 71        });
 72
 73        function closeOverlay() {
 74            $('#txtUserNameReq').addClass('hidden');
 75            $('#txtPasswordReq').addClass('hidden');
 76            $('#txtPasswordMatch').addClass('hidden');
 77            $('#txtEmailReq').addClass('hidden');
 78
 79            $('#txtUserName').val('');
 80            $('#txtPassword').val('');
 81            $('#txtPassword2').val('');
 82            $('#txtEmail').val('');
 83
 84            $.colorbox.close();
 85        }
 86    </script>
 87	<div class="content-box-outer">
 88		<div class="content-box-right">
 89            <ul>
 90			    <li class="content-box-selected"><a href="Users.aspx"><%=Resources.labels.users %></a></li>
 91			    <li><a href="Roles.aspx" class="selected"><%=Resources.labels.roles %></a></li>
 92            </ul>
 93		</div>
 94		<div class="content-box-left">
 95            <h1><%=Resources.labels.users %><a href="#" class="addNew"><%=Resources.labels.addNewUser %></a></h1>
 96            <div style="display:none;">
 97            <div id="frmAddNew" class="overlaypanel" >
 98                <h2><%=Resources.labels.addNewUser %></h2>
 99                <table class="tblForm">
100                    <tr>
101                        <td>
102				            <label for="txtUserName" class="lbl"><%=Resources.labels.name %></label>
103				            <input type="text" id="txtUserName" class="txt200"/>
104				            <span id="txtUserNameReq" class="req hidden">*</span>
105				        </td>
106				        <td>
107				            <label for="txtEmail" class="lbl"><%=Resources.labels.email %></label>
108				            <input type="text" id="txtEmail" class="txt200"/>
109				            <span id= "txtEmailReq" class="req hidden">*</span>
110                        </td>
111                    </tr>
112                    <tr>
113                        <td>
114				                <label for="txtPassword" class="lbl"><%=Resources.labels.password %></label>
115				                <input type="password" id="txtPassword" class="txt200"/>
116                        </td>
117                        <td>
118                                <label for="txtPassword2" class="lbl"><%=Resources.labels.confirmPassword %></label>
119				                <input type="password" id="txtPassword2" class="txt200"/>
120				                <span  id= "txtPasswordReq" class="req hidden">*</span>
121				                <span  id= "txtPasswordMatch" class="req hidden"><%=Resources.labels.passwordAndConfirmPasswordMismatch %></span>
122                        </td>
123                    </tr>
124                </table>
125                <asp:PlaceHolder ID="phNewUserRoles" runat="server">
126                    <h2><%=Resources.labels.newUserRoles %></h2>
127                    <div id="rolelist" style="margin:0 0 20px;"><%=RolesList%></div>
128                </asp:PlaceHolder>
129				<input type="submit" class="btn primary rounded" value="<%=Resources.labels.save %>" onclick="return AddUser(this);" id="btnNewUser" />
130				<%=Resources.labels.or %> <a href="#" onclick="closeOverlay();"><%=Resources.labels.cancel %></a>
131                <br /><br />
132			</div>
133            </div>
134            <div id="Container"></div>
135		</div>
136	</div>
137    <script type="text/javascript">
138        LoadUsers();
139    </script>
140</asp:Content>