os_template_show.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. .table {
  6. font-size: 12px;
  7. border-width: 1px;
  8. line-height: 20px;
  9. }
  10. .table > thead > tr > th,
  11. .table > tfoot > tr > th {
  12. color: #999999;
  13. font-weight: normal;
  14. border-bottom: 0 solid #e1e6eb;
  15. background-color: #F5F6FA;
  16. }
  17. .table > tbody > tr > td {
  18. color: #424547;
  19. }
  20. .table-bordered > tbody > tr {
  21. padding-top: 10px;
  22. padding-bottom: 10px;
  23. }
  24. .table-bordered > thead > tr > th,
  25. .table-bordered > tbody > tr > th,
  26. .table-bordered > tfoot > tr > th,
  27. .table-bordered > thead > tr > td,
  28. .table-bordered > tbody > tr > td,
  29. .table-bordered > tfoot > tr > td {
  30. border-style: solid;
  31. border-width: 1px 0 0 0;
  32. }
  33. .btn,
  34. .form-control,
  35. .modal-content {
  36. border-radius: 0 !important;
  37. }
  38. .btn-shortcut {
  39. font-size: 12px !important;
  40. padding: 0 26px;
  41. }
  42. .show {
  43. display: inline-block !important;
  44. }
  45. .tr-selected td,
  46. .tr-selected {
  47. color: #000 !important;
  48. background: #fffdf4 !important;
  49. }
  50. </style>
  51. {% endblock head %}
  52. {% block content %}
  53. <script type="text/javascript">
  54. var page = 1;
  55. var page_size = 10;
  56. var keyword = '';
  57. var resource_path = window.location.pathname;
  58. var cur_url = resource_path;
  59. $(document).ready(function() {
  60. page_size = $('#page_size').val();
  61. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  62. var last_ready = null;
  63. $('#content_search').keydown(function() {
  64. if (last_ready !== null) {
  65. clearTimeout(last_ready);
  66. }
  67. last_ready = setTimeout(function () {
  68. keyword = $('#content_search').val();
  69. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  70. if (keyword.length > 0) {
  71. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  72. }
  73. window.location.href=cur_url;
  74. }, 1000);
  75. });
  76. $('#page_size').change(function () {
  77. keyword = $('#content_search').val();
  78. page_size = $('#page_size').val();
  79. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  80. if (keyword.length > 0) {
  81. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  82. }
  83. window.location.href=cur_url;
  84. });
  85. $("thead").on('click', ".all_selector", function() {
  86. if ($("thead .all_selector").is(':checked')) {
  87. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  88. $(".all_selector").prop('checked', true);
  89. } else {
  90. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  91. $(".all_selector").prop('checked', false);
  92. }
  93. select_item_action();
  94. });
  95. $("tfoot").on('click', ".all_selector", function() {
  96. if ($("tfoot .all_selector").is(':checked')) {
  97. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  98. $(".all_selector").prop('checked', true);
  99. } else {
  100. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  101. $(".all_selector").prop('checked', false);
  102. }
  103. select_item_action();
  104. });
  105. $("tbody tr").on('click', "input[type='checkbox']", function() {
  106. select_item_action();
  107. });
  108. $('body').addClass('add-transition');
  109. $('.add-page-transition').on('click', function(){
  110. var transAttr = $(this).attr('data-transition');
  111. $('.add-transition').attr('class', 'add-transition');
  112. $('.add-transition').addClass(transAttr);
  113. });
  114. $('#edit_remark_modal').on('show.bs.modal', function (me) {
  115. $('#instance_uuid').val($(me.relatedTarget).parent().parent().find('div a')[0].text);
  116. $('#edit_remark').val($(me.relatedTarget).prev().text());
  117. });
  118. });
  119. function refresh() {
  120. keyword = $('#content_search').val();
  121. page = $('#pagination li.active a').text();
  122. page_size = $('#page_size').val();
  123. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  124. if (keyword.length > 0) {
  125. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  126. }
  127. window.location.href=cur_url;
  128. }
  129. function row_onmouseover(me) {
  130. $(me).find(".edit_remark_trigger").css('display','inline-flex');
  131. }
  132. function row_onmouseout(me) {
  133. $(me).find(".edit_remark_trigger").css('display','none');
  134. }
  135. function remark_update(me) {
  136. var uuid = $('#instance_uuid').val();
  137. var remark = $('#edit_remark').val();
  138. $('#edit_remark_modal').modal('hide');
  139. $.ajax({
  140. url : '/api/os_template/' + uuid,
  141. type : 'PATCH',
  142. contentType: "application/json; charset=utf-8",
  143. data : JSON.stringify({
  144. remark: remark
  145. }),
  146. error : function() {
  147. alter_danger('模板名称更新失败!');
  148. },
  149. success : function() {
  150. $('#disk_list tbody').find('td:contains(' + uuid + ')').find('p').text(remark);
  151. alter_success('模板名称更新成功!');
  152. }
  153. });
  154. }
  155. function get_selected_element(checked) {
  156. if (checked === null) {
  157. checked = true;
  158. }
  159. if (checked) {
  160. return $('tbody :checked');
  161. } else {
  162. return $('tbody input:not(:checked)');
  163. }
  164. }
  165. function highlight_selected_element() {
  166. var selected_element = get_selected_element(true);
  167. var no_selected_element = get_selected_element(false);
  168. selected_element.each(function(i, e) {
  169. $(e).parent().parent().toggleClass('tr-selected', true);
  170. });
  171. no_selected_element.each(function(i, e) {
  172. $(e).parent().parent().toggleClass('tr-selected', false);
  173. });
  174. }
  175. function shortcut_bar_enable() {
  176. var selected_element = get_selected_element(true);
  177. if (selected_element.length > 0) {
  178. $('.btn-shortcut').toggleClass('disabled', false);
  179. } else {
  180. $('.btn-shortcut').toggleClass('disabled', true);
  181. }
  182. }
  183. function select_item_action() {
  184. highlight_selected_element();
  185. shortcut_bar_enable();
  186. }
  187. function mount(uuid, disk_uuid) {
  188. $.ajax({
  189. url : '/api/guest/_attach_disk/' + uuid + '/' + disk_uuid,
  190. type : 'PUT',
  191. contentType: "application/json; charset=utf-8",
  192. error : function() {
  193. alter_danger('实例挂载指令发送失败!');
  194. },
  195. success : function() {
  196. alter_success('实例挂载指令发送成功!');
  197. }
  198. });
  199. }
  200. </script>
  201. <div class="panel">
  202. <div class="panel-body">
  203. <h3 class="title-hero" style="font-size: 24px;">
  204. 虚拟机模板
  205. </h3>
  206. <div>
  207. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  208. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  209. <div class="col-sm-12" style="padding-right: 0;">
  210. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  211. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  212. </div>
  213. <div class="pull-right">
  214. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  215. <a class="btn btn-info add-page-transition" href="/os_templates/create" data-transition="pt-page-moveFromRight-init" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">添加模板</a>
  216. </div>
  217. </div>
  218. </div>
  219. <table id="os_template_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  220. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  221. <thead>
  222. <tr role="row">
  223. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  224. <th width="180px;">名称</th>
  225. <th>状态</th>
  226. <th>路径</th>
  227. <th>ICON</th>
  228. <th>初始化作业</th>
  229. <th>操作</th>
  230. </tr>
  231. </thead>
  232. <tbody>
  233. {% for item in os_templates_ret.data %}
  234. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  235. <td><input title="选中" type="checkbox"></td>
  236. <td>
  237. <div>
  238. <p style="display: inline-block;">{{ item.label }}</p>
  239. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  240. <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>
  241. </a>
  242. </div>
  243. </td>
  244. <td>{% if item.active == 0 %}
  245. <span style="color: #990000;">未启用</span>
  246. {% else %}
  247. <span style="color: #00BB00;">启用</span>
  248. {% endif %}
  249. </td>
  250. <td>{{ item.path }}</td>
  251. <td><span class="{{ item.icon }}"></span></td>
  252. <td>{{ item.boot_job_id }}</td>
  253. <td>
  254. <div class="dropdown inline-block">
  255. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  256. 更多
  257. </a>
  258. <ul class="dropdown-menu">
  259. <li class="{% if item.state not in [1] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  260. <a href="javascript:;" data-toggle="modal" data-target="#mount_modal"
  261. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);">
  262. 启用
  263. </a>
  264. </li>
  265. <li class="{% if item.state not in [1] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  266. <a href="javascript:;" data-toggle="modal" data-target="#mount_modal"
  267. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);">
  268. 禁用
  269. </a>
  270. </li>
  271. <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
  272. <li class="{% if item.state not in [1] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  273. <a href="javascript:;" data-toggle="modal" data-target="#mount_modal"
  274. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);">
  275. 变更初始化作业
  276. </a>
  277. </li>
  278. <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
  279. <li class="{% if item.state not in [1, 255] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
  280. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  281. onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);
  282. $('#delete_instance_desc').text($('#instance_uuid').val().split('-')[0] + '/' + $($(this).parent().parent().parent().parent().parent().children()[1]).find('div p')[0].textContent)">
  283. 删除
  284. </a>
  285. </li>
  286. </ul>
  287. </div>
  288. </td>
  289. </tr>
  290. {% endfor %}
  291. </tbody>
  292. </table>
  293. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  294. <tfoot>
  295. <tr style="height: 70px;">
  296. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  297. <th>
  298. <div class="row">
  299. <div class="col-sm-6">
  300. <button class="btn btn-default btn-shortcut disabled" onclick="batch_boot();">编辑名称</button>
  301. </div>
  302. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  303. 共有{{ os_templates_ret.paging.total }}条,每页显示:
  304. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  305. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  306. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  307. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  308. </select>&nbsp;&nbsp;条
  309. </div>
  310. <div class="col-sm-3" style="text-align: left;">
  311. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  312. <ul id="pagination" class="pagination">
  313. <li class="{% if page == 1 %} disabled {% endif %}">
  314. <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">«</a>
  315. </li>
  316. {% for item in pages %}
  317. <li class="{% if item == page %} active {% endif %}">
  318. <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">{{ item }}</a>
  319. </li>
  320. {% endfor %}
  321. <li class="{% if page == last_page %} disabled {% endif %}">
  322. <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">»</a>
  323. </li>
  324. </ul>
  325. </div>
  326. </div>
  327. </div>
  328. </th>
  329. </tr>
  330. </tfoot>
  331. </table>
  332. </div>
  333. </div>
  334. </div>
  335. </div>
  336. <input id="instance_uuid" title="模板 ID" class="form-control" name="uuid" hidden>
  337. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  338. <div class="modal-dialog modal-sm">
  339. <div class="modal-content">
  340. <div class="modal-header">
  341. <h4 class="modal-title">编辑模板名称:</h4>
  342. </div>
  343. <div class="modal-body">
  344. <input id="edit_remark" title="实例名称" class="form-control" name="remark">
  345. </div>
  346. <div class="modal-footer">
  347. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  348. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  349. </div>
  350. </div>
  351. </div>
  352. </div>
  353. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  354. <div class="modal-dialog">
  355. <div class="modal-content">
  356. <div class="modal-header">
  357. <h4 class="modal-title">删除模板:</h4>
  358. </div>
  359. <div class="modal-body">
  360. <p>你确定要删除该模板吗?</p>
  361. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  362. </div>
  363. <div class="modal-footer">
  364. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  365. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  366. </div>
  367. </div>
  368. </div>
  369. </div>
  370. {% endblock content %}