boot_jobs_show.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. @media (min-width: 768px) {
  6. .form-horizontal .control-label {
  7. text-align: left;
  8. }
  9. }
  10. label>span {
  11. color: deepskyblue;
  12. }
  13. .table {
  14. font-size: 12px;
  15. border-width: 1px;
  16. line-height: 20px;
  17. }
  18. .table > thead > tr > th,
  19. .table > tfoot > tr > th {
  20. color: #999999;
  21. font-weight: normal;
  22. border-bottom: 0 solid #e1e6eb;
  23. background-color: #F5F6FA;
  24. }
  25. .table > tbody > tr > td {
  26. color: #424547;
  27. }
  28. .table-bordered > tbody > tr {
  29. padding-top: 10px;
  30. padding-bottom: 10px;
  31. }
  32. .table-bordered > thead > tr > th,
  33. .table-bordered > tbody > tr > th,
  34. .table-bordered > tfoot > tr > th,
  35. .table-bordered > thead > tr > td,
  36. .table-bordered > tbody > tr > td,
  37. .table-bordered > tfoot > tr > td {
  38. border-style: solid;
  39. border-width: 1px 0 0 0;
  40. }
  41. .btn,
  42. .form-control,
  43. .modal-content {
  44. border-radius: 0 !important;
  45. }
  46. </style>
  47. {% endblock head %}
  48. {% block content %}
  49. <script type="text/javascript">
  50. var page = 1;
  51. var page_size = 10;
  52. var keyword = '';
  53. var resource_path = window.location.pathname;
  54. var cur_url = resource_path;
  55. $(document).ready(function() {
  56. page_size = $('#page_size').val();
  57. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  58. var last_ready = null;
  59. $('#content_search').keydown(function() {
  60. if (last_ready !== null) {
  61. clearTimeout(last_ready);
  62. }
  63. last_ready = setTimeout(function () {
  64. keyword = $('#content_search').val();
  65. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  66. if (keyword.length > 0) {
  67. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  68. }
  69. window.location.href=cur_url;
  70. }, 1000);
  71. });
  72. $('#page_size').change(function () {
  73. keyword = $('#content_search').val();
  74. page_size = $('#page_size').val();
  75. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  76. if (keyword.length > 0) {
  77. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  78. }
  79. window.location.href=cur_url;
  80. });
  81. $('#edit_name_modal').on('show.bs.modal', function (me) {
  82. $('#boot_job_id').val($(me.relatedTarget).parent().parent().prev().text());
  83. $('#edit_name').val($(me.relatedTarget).prev().text());
  84. });
  85. $('#edit_remark_modal').on('show.bs.modal', function (me) {
  86. $('#boot_job_id').val($(me.relatedTarget).parent().parent().prev().prev().prev().text());
  87. $('#edit_remark').val($(me.relatedTarget).prev().text());
  88. });
  89. $('#add_boot_job_modal').on('show.bs.modal', function (me) {
  90. });
  91. $('#update_use_for_modal').on('show.bs.modal', function (me) {
  92. $('#boot_job_id').val($(me.relatedTarget).parent().prev().prev().text());
  93. $('#update_use_for_instance_desc').text($(me.relatedTarget).parent().prev().text());
  94. });
  95. $('#add_boot_job_form').formValidation({
  96. framework: 'bootstrap4',
  97. icon: {
  98. valid: 'fa fa-check',
  99. invalid: 'fa fa-times',
  100. validating: 'fa fa-refresh'
  101. },
  102. // Since the Bootstrap Button hides the radio and checkbox
  103. // We exclude the disabled elements only
  104. excluded: ':disabled',
  105. locale: 'zh_CN',
  106. fields: {
  107. name: {
  108. validators: {
  109. notEmpty: {
  110. },
  111. stringLength: {
  112. min: 1,
  113. max: 255
  114. }
  115. }
  116. },
  117. use_for: {
  118. validators: {
  119. notEmpty: {
  120. }
  121. }
  122. },
  123. remark: {
  124. validators: {
  125. stringLength: {
  126. max: 255
  127. }
  128. }
  129. }
  130. }
  131. })
  132. .on('success.field.fv', function(e, data) {
  133. if (data.fv.getInvalidFields().length > 0) { // There is invalid field
  134. data.fv.disableSubmitButtons(true);
  135. }
  136. });
  137. });
  138. function refresh() {
  139. keyword = $('#content_search').val();
  140. page = $('#pagination li.active a').text();
  141. page_size = $('#page_size').val();
  142. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  143. if (keyword.length > 0) {
  144. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  145. }
  146. window.location.href=cur_url;
  147. }
  148. function row_onmouseover(me) {
  149. $(me).find(".edit_name_trigger, .edit_remark_trigger").css('display','inline-flex');
  150. }
  151. function row_onmouseout(me) {
  152. $(me).find(".edit_name_trigger, .edit_remark_trigger").css('display','none');
  153. }
  154. function name_update(me) {
  155. var boot_job_id = $('#boot_job_id').val();
  156. var name = $('#edit_name').val();
  157. $('#edit_name_modal').modal('hide');
  158. $.ajax({
  159. url : '/api/boot_job/' + boot_job_id,
  160. type : 'PATCH',
  161. contentType: "application/json; charset=utf-8",
  162. data : JSON.stringify({
  163. name: name
  164. }),
  165. error : function() {
  166. alter_danger('启动作业名称更新失败!');
  167. },
  168. success : function() {
  169. alter_success('启动作业名称更新成功!');
  170. refresh()
  171. }
  172. });
  173. }
  174. function remark_update(me) {
  175. var boot_job_id = $('#boot_job_id').val();
  176. var remark = $('#edit_remark').val();
  177. $('#edit_remark_modal').modal('hide');
  178. $.ajax({
  179. url : '/api/boot_job/' + boot_job_id,
  180. type : 'PATCH',
  181. contentType: "application/json; charset=utf-8",
  182. data : JSON.stringify({
  183. remark: remark
  184. }),
  185. error : function() {
  186. alter_danger('启动作业备注更新失败!');
  187. },
  188. success : function() {
  189. alter_success('启动作业备注路径更新成功!');
  190. refresh()
  191. }
  192. });
  193. }
  194. function update_use_for(id) {
  195. $.ajax({
  196. url : '/api/boot_job/' + id,
  197. type : 'PATCH',
  198. contentType: "application/json; charset=utf-8",
  199. data : JSON.stringify({
  200. use_for: parseInt($('#update_use_for').val())
  201. }),
  202. error : function() {
  203. alter_danger('变更启动作业作用域指令发送失败!');
  204. },
  205. success : function() {
  206. alter_success('变更启动作业作用域指令发送成功!');
  207. refresh();
  208. }
  209. });
  210. }
  211. function remove(id) {
  212. $.ajax({
  213. url : '/api/boot_jobs/' + id,
  214. type : 'DELETE',
  215. contentType: "application/json; charset=utf-8",
  216. error : function() {
  217. alter_danger('启动作业删除指令发送失败!');
  218. },
  219. success : function() {
  220. alter_success('启动作业删除指令发送成功!');
  221. refresh();
  222. }
  223. });
  224. }
  225. function delete_at(me) {
  226. var id = $('#boot_job_id').val();
  227. remove(id);
  228. $('#delete_modal').modal('hide');
  229. }
  230. function update_use_for_at(me) {
  231. var id = $('#boot_job_id').val();
  232. update_use_for(id);
  233. $('#update_use_for_modal').modal('hide');
  234. }
  235. </script>
  236. <div class="panel">
  237. <div class="panel-body">
  238. <h3 class="title-hero" style="font-size: 24px;">
  239. 启动作业
  240. </h3>
  241. <div>
  242. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  243. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  244. <div class="col-sm-12" style="padding-right: 0;">
  245. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  246. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  247. </div>
  248. <div class="pull-right">
  249. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  250. <a class="btn btn-info" href="javascript:;" data-toggle="modal" data-target="#add_boot_job_modal" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">添加启动作业</a>
  251. </div>
  252. </div>
  253. </div>
  254. <table id="boot_job_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  255. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  256. <thead>
  257. <tr role="row">
  258. <th style="display: none;">ID</th>
  259. <th width="280px;">名称</th>
  260. <th>作用域</th>
  261. <th width="600px;">备注</th>
  262. <th>操作</th>
  263. </tr>
  264. </thead>
  265. <tbody>
  266. {% for item in boot_jobs_ret.data %}
  267. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  268. <td style="display: none;">{{ item.id }}</td>
  269. <td>
  270. <div>
  271. <a href="/operate_rules?boot_job_id={{ item.id }}"><p style="display: inline-block;">{{ item.name }}</p></a>
  272. <a href="javascript:;" class="edit_name_trigger" data-toggle="modal" data-target="#edit_name_modal" style="display: none; float: right;">
  273. <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>
  274. </a>
  275. </div>
  276. </td>
  277. <td>
  278. <a href="javascript:;" data-toggle="modal" data-target="#update_use_for_modal">
  279. {% if item.use_for == 0 %}
  280. <span style="color: #8800FF;">模板</span>
  281. {% elif item.use_for == 1 %}
  282. <span style="color: #3333FF;">系统</span>
  283. {% elif item.use_for == 2 %}
  284. <span style="color: #00BB00;">用户</span>
  285. {% else %}
  286. <span style="color: #990000;">未知</span>
  287. {% endif %}
  288. </a>
  289. </td>
  290. <td>
  291. <div>
  292. <p style="display: inline-block;">{{ item.remark }}</p>
  293. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  294. <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>
  295. </a>
  296. </div>
  297. </td>
  298. <td>
  299. <div class="dropdown inline-block">
  300. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  301. 更多
  302. </a>
  303. <ul class="dropdown-menu">
  304. <li>
  305. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  306. onclick="$('#boot_job_id').val($(this).parent().parent().parent().parent().parent().children()[0].textContent);
  307. $('#delete_instance_desc').text($(this).parent().parent().parent().parent().parent().children()[1].textContent)">
  308. 删除
  309. </a>
  310. </li>
  311. </ul>
  312. </div>
  313. </td>
  314. </tr>
  315. {% endfor %}
  316. </tbody>
  317. </table>
  318. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  319. <tfoot>
  320. <tr style="height: 70px;">
  321. <th>
  322. <div class="row">
  323. <div class="col-sm-6">
  324. </div>
  325. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  326. 共有{{ boot_jobs_ret.paging.total }}条,每页显示:
  327. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  328. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  329. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  330. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  331. </select>&nbsp;&nbsp;条
  332. </div>
  333. <div class="col-sm-3" style="text-align: left;">
  334. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  335. <ul id="pagination" class="pagination">
  336. <li class="{% if page == 1 %} disabled {% endif %}">
  337. <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>
  338. </li>
  339. {% for item in pages %}
  340. <li class="{% if item == page %} active {% endif %}">
  341. <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>
  342. </li>
  343. {% endfor %}
  344. <li class="{% if page == last_page %} disabled {% endif %}">
  345. <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>
  346. </li>
  347. </ul>
  348. </div>
  349. </div>
  350. </div>
  351. </th>
  352. </tr>
  353. </tfoot>
  354. </table>
  355. </div>
  356. </div>
  357. </div>
  358. </div>
  359. <input id="boot_job_id" title="启动作业 ID" class="form-control" name="boot_job_id" hidden>
  360. <div class="modal" id="edit_name_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  361. <div class="modal-dialog modal-sm">
  362. <div class="modal-content">
  363. <div class="modal-header">
  364. <h4 class="modal-title">编辑启动作业名称:</h4>
  365. </div>
  366. <div class="modal-body">
  367. <input id="edit_name" title="启动作业名称" class="form-control" name="boot_job_name">
  368. </div>
  369. <div class="modal-footer">
  370. <button type="button" class="btn btn-sm btn-primary" onclick="name_update();">确定</button>
  371. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  372. </div>
  373. </div>
  374. </div>
  375. </div>
  376. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  377. <div class="modal-dialog">
  378. <div class="modal-content">
  379. <div class="modal-header">
  380. <h4 class="modal-title">编辑模板路径:</h4>
  381. </div>
  382. <div class="modal-body">
  383. <input id="edit_remark" title="启动作业备注" class="form-control" name="boot_job_remark">
  384. </div>
  385. <div class="modal-footer">
  386. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  387. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  388. </div>
  389. </div>
  390. </div>
  391. </div>
  392. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  393. <div class="modal-dialog">
  394. <div class="modal-content">
  395. <div class="modal-header">
  396. <h4 class="modal-title">删除启动作业:</h4>
  397. </div>
  398. <div class="modal-body">
  399. <p>你确定要删除该启动作业吗?</p>
  400. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  401. </div>
  402. <div class="modal-footer">
  403. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  404. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  405. </div>
  406. </div>
  407. </div>
  408. </div>
  409. <div class="modal" id="add_boot_job_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  410. <div class="modal-dialog modal-lg">
  411. <div class="modal-content">
  412. <div class="modal-header">
  413. <h4 class="modal-title">添加启动作业:</h4>
  414. </div>
  415. <div class="modal-body" style="padding-top: 0; padding-bottom: 0;">
  416. <div class="example-box-wrapper">
  417. <form id="add_boot_job_form" class="form-horizontal bordered-row" action="/boot_job" method="post">
  418. <div class="form-group">
  419. <div class="col-sm-2"></div>
  420. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-compass-circled"></span>&nbsp;&nbsp;启动作业名称</label>
  421. <div class="col-sm-6">
  422. <input id="name" name="name" type="text" title="启动作业名称" class="form-control">
  423. </div>
  424. </div>
  425. <div class="form-group">
  426. <div class="col-sm-2"></div>
  427. <label class="col-sm-2 control-label"><span class="glyph-icon icon-pie-chart"></span>&nbsp;&nbsp;作用域</label>
  428. <div class="col-sm-6">
  429. <select id="use_for" name="use_for" title="作用域" class="selectpicker">
  430. <option value="2" data-subtext="通过重启系统,批量执行用户预定的操作" selected>用户</option>
  431. <option value="0" data-subtext="从模板克隆的虚拟机,首次启动时初始化系统使用">模板</option>
  432. <!--<option value="1" data-subtext="JimV系统平台内置的功能,如重置系统密码,更换IP等操作">系统</option>-->
  433. </select>
  434. </div>
  435. </div>
  436. <div class="form-group">
  437. <div class="col-sm-2"></div>
  438. <label class="col-sm-2 control-label"><span class="glyph-icon icon-newspaper-o"></span>&nbsp;&nbsp;备注</label>
  439. <div class="col-sm-6">
  440. <input id="remark" name="remark" type="text" title="备注" class="form-control">
  441. </div>
  442. </div>
  443. <div class="form-group">
  444. <div class="col-sm-4"></div>
  445. <div class="col-sm-6 pull-right">
  446. <button type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;" disabled>创建</button>
  447. <button class="btn btn-default" style="width: 64px; height: 40px; font-size: 16px;" data-dismiss="modal">取消</button>
  448. </div>
  449. </div>
  450. </form>
  451. </div>
  452. </div>
  453. </div>
  454. </div>
  455. </div>
  456. <div class="modal" id="update_use_for_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  457. <div class="modal-dialog">
  458. <div class="modal-content">
  459. <div class="modal-header">
  460. <h4 class="modal-title">变更作用域:</h4>
  461. </div>
  462. <div class="modal-body" style="padding-top: 0;">
  463. <form class="form-horizontal bordered-row">
  464. <div class="form-group">
  465. <div class="col-sm-1"></div>
  466. <label class="col-sm-3 control-label"><span class="glyph-icon icon-elusive-compass-circled"></span>&nbsp;&nbsp;启动作业名称</label>
  467. <div class="col-sm-8">
  468. <h3 style="color: orangered;" id="update_use_for_instance_desc"></h3>
  469. </div>
  470. </div>
  471. <div class="form-group">
  472. <div class="col-sm-1"></div>
  473. <label class="col-sm-3 control-label"><span class="glyph-icon icon-pie-chart"></span>&nbsp;&nbsp;作用域</label>
  474. <div class="col-sm-8">
  475. <select id="update_use_for" name="use_for" title="作用域" class="selectpicker">
  476. <option value="2" data-subtext="通过重启系统,批量执行用户预定的操作" selected>用户</option>
  477. <option value="0" data-subtext="从模板克隆的虚拟机,首次启动时初始化系统使用">模板</option>
  478. </select>
  479. </div>
  480. </div>
  481. </form>
  482. </div>
  483. <div class="modal-footer">
  484. <button type="button" class="btn btn-sm btn-primary" onclick="update_use_for_at();">确定</button>
  485. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  486. </div>
  487. </div>
  488. </div>
  489. </div>
  490. {% endblock content %}