user.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <title>Weavi Database</title>
  6. <link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css"/>
  7. <link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css"/>
  8. <link rel="stylesheet" type="text/css" href="../easyui/themes/color.css"/>
  9. <script type="text/javascript" src="../easyui/jquery.min.js"></script>
  10. <script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
  11. <script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script>
  12. <style type="text/css">
  13. body {
  14. font-family: microsoft yahei;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div style="width:100%">
  20. <h2>Weavi Database </h2>
  21. <table class="easyui-datagrid" title="Customer list" style="width: 700px;height: 500px"
  22. data-options="singleSelect:true,collapsible:true,url:'/user/list',method:'get'">
  23. <thread>
  24. <tr>
  25. <th data-options="field:'id',width:100">ID</th>
  26. <th data-options="field:'firstName',width:100">First Name</th>
  27. <th data-options="field:'lastName',width:100">Last Name</th>
  28. <th data-options="field:'phone',width:100">Phone</th>
  29. <th data-options="field:'email',width:100">Email</th>
  30. </tr>
  31. </thread>
  32. </table>
  33. <div id="toolbar">
  34. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">添加</a>
  35. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
  36. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
  37. </div>
  38. <div id="dlg" class="easyui-dialog" style="width:400px"
  39. data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
  40. <form id="fm" method="post" style="margin:0;padding:20px 50px">
  41. <h3>User Information</h3>
  42. <div style="margin-bottom:10px">
  43. <input name="firstName" class="easyui-textbox" required="true" label="First Name:" style="width:100%"/>
  44. </div>
  45. <div style="margin-bottom:10px">
  46. <input name="lastName" class="easyui-textbox" required="true" label="Last Name:" style="width:100%"/>
  47. </div>
  48. <div style="margin-bottom:10px">
  49. <input name="phone" class="easyui-textbox" required="true" label="Phone:" style="width:100%"/>
  50. </div>
  51. <div style="margin-bottom:10px">
  52. <input name="email" class="easyui-textbox" required="true" validType="email" label="Email:" style="width:100%"/>
  53. </div>
  54. </form>
  55. </div>
  56. <div id="dlg-buttons">
  57. <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
  58. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
  59. onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
  60. </div>
  61. </div>
  62. <script type="text/javascript">
  63. var url;
  64. function newUser() {
  65. $('#dlg').dialog('open').dialog('center').dialog('setTitle', 'New User');
  66. $('#fm').form('clear');
  67. url = '/user/add';
  68. }
  69. function editUser() {
  70. var row = $('#dg').datagrid('getSelected');
  71. if (row) {
  72. $('#dlg').dialog('open').dialog('center').dialog('setTitle', 'Edit User');
  73. $('#fm').form('load', row);
  74. url = '/user/save';
  75. }
  76. }
  77. function saveUser() {
  78. $('#fm').form('submit', {
  79. url: url,
  80. onSubmit: function () {
  81. return $(this).form('validate');
  82. },
  83. success: function (result) {
  84. var result = eval('(' + result + ')');
  85. if (result.errorMsg) {
  86. $.messager.show({
  87. title: 'Error',
  88. msg: result.errorMsg
  89. });
  90. } else {
  91. $('#dlg').dialog('close'); // close the dialog
  92. $('#dg').datagrid('reload'); // reload the user data
  93. }
  94. }
  95. });
  96. }
  97. function destroyUser() {
  98. var row = $('#dg').datagrid('getSelected');
  99. if (row) {
  100. $.messager.confirm('Confirm', 'Are you sure you want to destroy this user?', function (r) {
  101. if (r) {
  102. $.post('/user/delete', {id: row.id}, function (result) {
  103. if (result.success) {
  104. $('#dg').datagrid('reload'); // reload the user data
  105. } else {
  106. $.messager.show({ // show error message
  107. title: 'Error',
  108. msg: result.errorMsg
  109. });
  110. }
  111. }, 'json');
  112. }
  113. });
  114. }
  115. }
  116. </script>
  117. </body>
  118. </html>