guest_show.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. {% extends "layout.html" %}
  2. {% block title %} Guest {% endblock %}
  3. {% block head %}
  4. {{ super() }}
  5. <style type="text/css">
  6. .table {
  7. font-size: 12px;
  8. border-width: 1px;
  9. line-height: 20px;
  10. }
  11. .table > thead > tr > th,
  12. .table > tfoot > tr > th {
  13. color: #999999;
  14. font-weight: normal;
  15. border-bottom: 0 solid #e1e6eb;
  16. background-color: #F5F6FA;
  17. }
  18. .table > tbody > tr > td {
  19. color: #6d6e6f;
  20. }
  21. .table-bordered > tbody > tr {
  22. padding-top: 10px;
  23. padding-bottom: 10px;
  24. height: 106px;
  25. }
  26. .table-bordered > thead > tr > th,
  27. .table-bordered > tbody > tr > th,
  28. .table-bordered > tfoot > tr > th,
  29. .table-bordered > thead > tr > td,
  30. .table-bordered > tbody > tr > td,
  31. .table-bordered > tfoot > tr > td {
  32. border-style: solid;
  33. border-width: 1px 0 0 0;
  34. }
  35. .btn,
  36. .form-control,
  37. .modal-content {
  38. border-radius: 0;
  39. }
  40. </style>
  41. {% endblock head %}
  42. {% block content %}
  43. <script type="text/javascript">
  44. var page = 1;
  45. var page_size = 10;
  46. var keyword = '';
  47. var cur_url = '/guests';
  48. $(document).ready(function() {
  49. page_size = $('#page_size').val();
  50. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  51. var last_ready = null;
  52. $('#content_search').keydown(function() {
  53. if (last_ready !== null) {
  54. clearTimeout(last_ready);
  55. }
  56. last_ready = setTimeout(function () {
  57. keyword = $('#content_search').val();
  58. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  59. if (keyword.length > 0) {
  60. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  61. }
  62. window.location.href=cur_url;
  63. }, 1000);
  64. });
  65. $('#page_size').change(function () {
  66. keyword = $('#content_search').val();
  67. page_size = $('#page_size').val();
  68. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  69. if (keyword.length > 0) {
  70. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  71. }
  72. window.location.href=cur_url;
  73. });
  74. $("thead").on('click', ".all_selector", function() {
  75. if ($("thead .all_selector").is(':checked')) {
  76. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  77. $(".all_selector").prop('checked', true);
  78. } else {
  79. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  80. $(".all_selector").prop('checked', false);
  81. }
  82. });
  83. $("tfoot").on('click', ".all_selector", function() {
  84. if ($("tfoot .all_selector").is(':checked')) {
  85. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  86. $(".all_selector").prop('checked', true);
  87. } else {
  88. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  89. $(".all_selector").prop('checked', false);
  90. }
  91. });
  92. $('body').addClass('add-transition');
  93. $('.add-page-transition').on('click', function(){
  94. var transAttr = $(this).attr('data-transition');
  95. $('.add-transition').attr('class', 'add-transition');
  96. $('.add-transition').addClass(transAttr);
  97. });
  98. $('#edit_remark_modal').on('show.bs.modal', function (me) {
  99. $('#instance_uuid').val($(me.relatedTarget).parent().parent().prev().prev().text());
  100. $('#edit_remark').val($(me.relatedTarget).prev().text());
  101. })
  102. });
  103. function refresh() {
  104. keyword = $('#content_search').val();
  105. page = $('#pagination li.active a').text();
  106. page_size = $('#page_size').val();
  107. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  108. if (keyword.length > 0) {
  109. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  110. }
  111. window.location.href=cur_url;
  112. }
  113. function row_onmouseover(me) {
  114. $(me).find(".edit_remark_trigger").css('display','inline-flex');
  115. }
  116. function row_onmouseout(me) {
  117. $(me).find(".edit_remark_trigger").css('display','none');
  118. }
  119. function remark_update(me) {
  120. var uuid = $('#instance_uuid').val();
  121. var remark = $('#edit_remark').val();
  122. $('#edit_remark_modal').modal('hide');
  123. $.ajax({
  124. url : '/api/guest/' + uuid,
  125. type : 'PATCH',
  126. contentType: "application/json; charset=utf-8",
  127. data : JSON.stringify({
  128. remark: remark
  129. }),
  130. error : function() {
  131. insert_warning_window($('#header'), '<strong>更新用户信失败, 请联系管理员! </strong>');
  132. },
  133. success : function() {
  134. $('#guest_list tbody').find('td:contains(' + uuid + ')').next().next().find('label').text(remark)
  135. }
  136. });
  137. }
  138. </script>
  139. <div class="panel">
  140. <div class="panel-body">
  141. <h3 class="title-hero" style="font-size: 24px;">
  142. 虚拟机实例
  143. </h3>
  144. <div>
  145. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  146. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  147. <div class="col-sm-12" style="padding-right: 0;">
  148. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  149. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  150. </div>
  151. <div class="pull-right">
  152. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  153. <a class="btn btn-info add-page-transition" href="/guests/create" data-transition="pt-page-moveFromRight-init" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">创建实例</a>
  154. </div>
  155. </div>
  156. </div>
  157. <table id="guest_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  158. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  159. <thead>
  160. <tr role="row">
  161. <th style="display: none;">UUID</th>
  162. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  163. <th width="180px;">名称</th>
  164. <th></th>
  165. <th>状态</th>
  166. <th>计算节点</th>
  167. <th>配置</th>
  168. <th>IP</th>
  169. <th>密码</th>
  170. <th>创建时间</th>
  171. <th>操作</th>
  172. </tr>
  173. </thead>
  174. <tbody>
  175. {% for item in guests_ret.data %}
  176. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  177. <td style="display: none;">{{ item.uuid }}</td>
  178. <td><input title="选中" type="checkbox"></td>
  179. <td>
  180. <div>
  181. <a href="javascript:;">{{ item.name }}</a>
  182. </div>
  183. <div>
  184. <label style="display: inline-block;">{{ item.remark }}</label>
  185. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  186. <span class="glyph-icon icon-elusive-pencil" style="width: 20px; height: 20px; margin-left: 10px; border-radius: 0; border: 1px solid rgb(220, 233, 255); background-color: #ffffff;"></span>
  187. </a>
  188. </div>
  189. </td>
  190. <td><span class="{{ os_template_mapping_by_id[item.os_template_id].icon }}"></span></td>
  191. <td>{{ format_guest_status(item.status)|safe }}</td>
  192. <td>{{ item.on_host }}</td>
  193. <td>CPU :&nbsp;&nbsp;{{ item.cpu }}&nbsp;核<br />内存 :&nbsp;&nbsp;{{ item.memory }}&nbsp;GB</td>
  194. <td>{{ item.ip }}</td>
  195. <td>{{ item.password }}</td>
  196. <td>{{ format_datetime_by_tus(item.create_time) }}</td>
  197. <td>
  198. <div class="dropdown inline-block">
  199. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  200. 更多
  201. </a>
  202. <ul class="dropdown-menu">
  203. <li>
  204. <a href="javascript:;">
  205. <span>启用</span>
  206. </a>
  207. </li>
  208. <li>
  209. <a href="javascript:;">
  210. <span>禁用</span>
  211. </a>
  212. </li>
  213. <li class="">
  214. <a href="javascript:;">
  215. <span>编辑</span>
  216. </a>
  217. </li>
  218. <li class="">
  219. <a href="javascript:;">
  220. <span>密码重置</span>
  221. </a>
  222. </li>
  223. <li class="">
  224. <a href="javascript:;">
  225. <span>删除</span>
  226. </a>
  227. </li>
  228. </ul>
  229. </div>
  230. </td>
  231. </tr>
  232. {% endfor %}
  233. </tbody>
  234. </table>
  235. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  236. <tfoot>
  237. <tr>
  238. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  239. <th>
  240. <div class="row">
  241. <div class="col-sm-8" style="font-size: 12px; padding-top: 5px; text-align: right;">
  242. 共有{{ guests_ret.paging.total }}条,每页显示:
  243. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  244. <option value="1" {% if page_size == 1 %} selected {% endif %}>1</option>
  245. <option value="2" {% if page_size == 2 %} selected {% endif %}>2</option>
  246. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  247. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  248. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  249. </select>&nbsp;&nbsp;条
  250. </div>
  251. <div class="col-sm-4" style="text-align: left;">
  252. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  253. <ul id="pagination" class="pagination">
  254. <li class="{% if page == 1 %} disabled {% endif %}">
  255. <a href="/guests?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">«</a>
  256. </li>
  257. {% for item in pages %}
  258. <li class="{% if item == page %} active {% endif %}">
  259. <a href="/guests?page={{ item }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">{{ item }}</a>
  260. </li>
  261. {% endfor %}
  262. <li class="{% if page == last_page %} disabled {% endif %}">
  263. <a href="/guests?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">»</a>
  264. </li>
  265. </ul>
  266. </div>
  267. </div>
  268. </div>
  269. </th>
  270. </tr>
  271. </tfoot>
  272. </table>
  273. </div>
  274. </div>
  275. </div>
  276. </div>
  277. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog">
  278. <div class="modal-dialog modal-sm">
  279. <div class="modal-content">
  280. <div class="modal-header">
  281. <h4 class="modal-title">编辑实例名称:</h4>
  282. </div>
  283. <div class="modal-body">
  284. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  285. <input id="edit_remark" title="实例名称" class="form-control" name="remark">
  286. </div>
  287. <div class="modal-footer">
  288. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  289. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  290. </div>
  291. </div>
  292. </div>
  293. </div>
  294. {% endblock content %}