guest_boot_jobs.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 resource_path = window.location.pathname;
  51. var cur_url = resource_path;
  52. $(document).ready(function() {
  53. $('#add_boot_job_modal').on('show.bs.modal', function (me) {
  54. refresh_boot_job_selectpicker($('#boot_job_selector'));
  55. });
  56. $('#add_guest_boot_job_form').formValidation({
  57. framework: 'bootstrap4',
  58. icon: {
  59. valid: 'fa fa-check',
  60. invalid: 'fa fa-times',
  61. validating: 'fa fa-refresh'
  62. },
  63. // Since the Bootstrap Button hides the radio and checkbox
  64. // We exclude the disabled elements only
  65. excluded: ':disabled',
  66. locale: 'zh_CN',
  67. fields: {
  68. boot_job_selector: {
  69. validators: {
  70. notEmpty: {}
  71. }
  72. }
  73. }
  74. })
  75. .on('success.field.fv', function(e, data) {
  76. if (data.fv.getInvalidFields().length > 0) { // There is invalid field
  77. data.fv.disableSubmitButtons(true);
  78. }
  79. });
  80. });
  81. function refresh() {
  82. cur_url = resource_path;
  83. window.location.href=cur_url;
  84. }
  85. function refresh_boot_job_selectpicker(selectpicker) {
  86. $.ajax({
  87. url : '/api/boot_jobs?filter=use_for:eq:2',
  88. type : 'GET',
  89. contentType: "application/json; charset=utf-8",
  90. dataType: 'json',
  91. error : function() {
  92. },
  93. success : function(data, textStatus, xhr) {
  94. selectpicker.empty();
  95. $.each(data.data, function(k, v) {
  96. selectpicker.append(
  97. $('<option>', {value: v['id'], text: v['name'], 'data-subtext': v['remark']})
  98. );
  99. });
  100. selectpicker.selectpicker('refresh');
  101. }
  102. });
  103. }
  104. function add_boot_job(id) {
  105. $.ajax({
  106. url : '/api/guests/_boot_jobs/{{ uuid }}/' + id,
  107. type : 'PUT',
  108. contentType: "application/json; charset=utf-8",
  109. error : function() {
  110. alter_danger('启动作业添加指令发送失败!');
  111. },
  112. success : function() {
  113. alter_success('启动作业添加指令发送成功!');
  114. refresh();
  115. }
  116. });
  117. }
  118. function remove(id) {
  119. $.ajax({
  120. url : '/api/guests/_boot_jobs/{{ uuid }}/' + id,
  121. type : 'DELETE',
  122. contentType: "application/json; charset=utf-8",
  123. error : function() {
  124. alter_danger('启动作业删除指令发送失败!');
  125. },
  126. success : function() {
  127. alter_success('启动作业删除指令发送成功!');
  128. refresh();
  129. }
  130. });
  131. }
  132. function delete_at(me) {
  133. var id = $('#boot_job_id').val();
  134. remove(id);
  135. $('#delete_modal').modal('hide');
  136. }
  137. function add_boot_job_at(me) {
  138. var id = $('#boot_job_selector').val();
  139. add_boot_job(id);
  140. $('#add_boot_job_modal').modal('hide');
  141. }
  142. </script>
  143. <div class="panel">
  144. <div class="panel-body">
  145. <h3 class="title-hero" style="font-size: 24px;">
  146. 启动作业(<a href="/guest/detail/{{ guest_ret.data.uuid }}" style="color: #0275d8;">{{ guest_ret.data.label }}/{{ guest_ret.data.remark }}</a>)
  147. </h3>
  148. <div>
  149. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  150. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  151. <div class="col-sm-12" style="padding-right: 0;">
  152. <h4 style="color: orange; {% if guest_boot_jobs_ret.data.ttl < 1 %}display: none;{% endif %}">下列启动作业将在
  153. <span style="color: #b94a48; {% if guest_boot_jobs_ret.data.ttl // 60 == 0 %}display: none;{% endif %}">{{ guest_boot_jobs_ret.data.ttl // 60 }}分</span>
  154. <span style="color: #b94a48; {% if guest_boot_jobs_ret.data.ttl % 60 == 0 %}display: none;{% endif %}">{{ guest_boot_jobs_ret.data.ttl % 60 }}秒</span>
  155. <span>后失效</span>
  156. </h4>
  157. <div class="pull-right">
  158. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  159. <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>
  160. </div>
  161. </div>
  162. </div>
  163. <table id="boot_job_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  164. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  165. <thead>
  166. <tr role="row">
  167. <th style="display: none;">ID</th>
  168. <th width="280px;">名称</th>
  169. <th>作用域</th>
  170. <th width="600px;">备注</th>
  171. <th>操作</th>
  172. </tr>
  173. </thead>
  174. <tbody>
  175. {% for item in guest_boot_jobs_ret.data.boot_jobs %}
  176. <tr role="row" class="odd">
  177. <td style="display: none;">{{ item }}</td>
  178. <td>
  179. <div>
  180. <a href="/operate_rules?boot_job_id={{ item }}"><p style="display: inline-block;">{{ boot_jobs_mapping_by_id[item | int].name }}</p></a>
  181. </div>
  182. </td>
  183. <td>
  184. {% if boot_jobs_mapping_by_id[item | int].use_for == 0 %}
  185. <span style="color: #8800FF;">模板</span>
  186. {% elif boot_jobs_mapping_by_id[item | int].use_for == 1 %}
  187. <span style="color: #3333FF;">系统</span>
  188. {% elif boot_jobs_mapping_by_id[item | int].use_for == 2 %}
  189. <span style="color: #00BB00;">用户</span>
  190. {% else %}
  191. <span style="color: #990000;">未知</span>
  192. {% endif %}
  193. </td>
  194. <td>
  195. <div>
  196. <p style="display: inline-block;">{{ boot_jobs_mapping_by_id[item | int].remark }}</p>
  197. </div>
  198. </td>
  199. <td>
  200. <div class="dropdown inline-block">
  201. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  202. 更多
  203. </a>
  204. <ul class="dropdown-menu">
  205. <li>
  206. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  207. onclick="$('#boot_job_id').val($(this).parent().parent().parent().parent().parent().children()[0].textContent);
  208. $('#delete_instance_desc').text($(this).parent().parent().parent().parent().parent().children()[1].textContent)">
  209. 删除
  210. </a>
  211. </li>
  212. </ul>
  213. </div>
  214. </td>
  215. </tr>
  216. {% endfor %}
  217. </tbody>
  218. </table>
  219. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  220. <tfoot>
  221. <tr style="height: 70px;">
  222. <th>
  223. <div class="row">
  224. <div class="col-sm-6">
  225. </div>
  226. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  227. </div>
  228. <div class="col-sm-3" style="text-align: left;">
  229. </div>
  230. </div>
  231. </th>
  232. </tr>
  233. </tfoot>
  234. </table>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. <input id="boot_job_id" title="启动作业 ID" class="form-control" name="boot_job_id" hidden>
  240. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  241. <div class="modal-dialog">
  242. <div class="modal-content">
  243. <div class="modal-header">
  244. <h4 class="modal-title">删除启动作业:</h4>
  245. </div>
  246. <div class="modal-body">
  247. <p>你确定要删除该启动作业吗?</p>
  248. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  249. </div>
  250. <div class="modal-footer">
  251. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  252. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. <div class="modal" id="add_boot_job_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  258. <div class="modal-dialog modal-lg">
  259. <div class="modal-content">
  260. <div class="modal-header">
  261. <h4 class="modal-title">添加启动作业:</h4>
  262. </div>
  263. <div class="modal-body" style="padding-top: 0; padding-bottom: 0;">
  264. <div class="example-box-wrapper">
  265. <form id="add_guest_boot_job_form" class="form-horizontal bordered-row">
  266. <div class="form-group">
  267. <div class="col-sm-2"></div>
  268. <label class="col-sm-2 control-label"><span class="glyph-icon icon-list-alt"></span>&nbsp;&nbsp;启动作业</label>
  269. <div class="col-sm-6">
  270. <select id="boot_job_selector" name="boot_job_selector" title="启动作业" class="selectpicker">
  271. </select>
  272. </div>
  273. </div>
  274. <div class="form-group">
  275. <div class="col-sm-4"></div>
  276. <div class="col-sm-6 pull-right">
  277. <button type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;" onclick="add_boot_job_at();" disabled>添加</button>
  278. <button class="btn btn-default" style="width: 64px; height: 40px; font-size: 16px;" data-dismiss="modal">取消</button>
  279. </div>
  280. </div>
  281. </form>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. </div>
  287. {% endblock content %}