disk_create.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {% extends theme("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. .btn,
  14. .form-group>div>div,
  15. .form-control {
  16. border-radius: 0;
  17. }
  18. .btn-ability {
  19. margin-right: 16px;
  20. height: 50px;
  21. padding: 8px 50px;
  22. margin-bottom: 30px;
  23. }
  24. </style>
  25. {% endblock head %}
  26. {% block body %}
  27. <script>
  28. $(document).ready(function() {
  29. $('body').addClass('add-transition');
  30. $('.add-page-transition').on('click', function(){
  31. var transAttr = $(this).attr('data-transition');
  32. $('.add-transition').attr('class', 'add-transition');
  33. $('.add-transition').addClass(transAttr);
  34. });
  35. $.ajax({
  36. url: '/api/config',
  37. type : 'GET',
  38. dataType: "json",
  39. error : function(data, textStatus, xhr) {
  40. },
  41. success : function(data, textStatus, xhr) {
  42. if (data['data']['storage_mode'] === 0) {
  43. refresh_hosts_selectpicker($('#node_id'));
  44. } else {
  45. $('#on_host_form').remove();
  46. }
  47. }
  48. });
  49. $('#create_disk_form').formValidation({
  50. framework: 'bootstrap4',
  51. icon: {
  52. valid: 'fa fa-check',
  53. invalid: 'fa fa-times',
  54. validating: 'fa fa-refresh'
  55. },
  56. // Since the Bootstrap Button hides the radio and checkbox
  57. // We exclude the disabled elements only
  58. excluded: ':disabled',
  59. locale: 'zh_CN',
  60. fields: {
  61. size: {
  62. validators: {
  63. between: {
  64. min: 1,
  65. max: 10240
  66. }
  67. }
  68. },
  69. quantity: {
  70. validators: {
  71. between: {
  72. min: 1,
  73. max: 20
  74. }
  75. }
  76. },
  77. remark: {
  78. validators: {
  79. stringLength: {
  80. max: 64
  81. }
  82. }
  83. }
  84. }
  85. }).on('success.field.fv', function(e, data) {
  86. if (data.fv.getInvalidFields().length > 0) { // There is invalid field
  87. data.fv.disableSubmitButtons(true);
  88. }
  89. }).on('success.form.fv', function (e, data) {
  90. create();
  91. });
  92. });
  93. $(function() { "use strict";
  94. $("#size").TouchSpin({
  95. max: 10240,
  96. min: 100,
  97. verticalbuttons: true,
  98. verticalupclass: 'glyph-icon icon-plus',
  99. verticaldownclass: 'glyph-icon icon-minus'
  100. });
  101. });
  102. $(function() { "use strict";
  103. $("#quantity").TouchSpin({
  104. max: 20,
  105. min: 1,
  106. verticalbuttons: true,
  107. verticalupclass: 'glyph-icon icon-plus',
  108. verticaldownclass: 'glyph-icon icon-minus'
  109. });
  110. });
  111. function refresh_hosts_selectpicker(selectpicker) {
  112. $.ajax({
  113. url : '/api/hosts',
  114. type : 'GET',
  115. contentType: "application/json; charset=utf-8",
  116. dataType: 'json',
  117. error : function() {
  118. },
  119. success : function(data, textStatus, xhr) {
  120. selectpicker.empty();
  121. $.each(data.data, function(k, v) {
  122. selectpicker.append(
  123. $('<option>', {value: v['node_id'], text: v['hostname']})
  124. );
  125. });
  126. selectpicker.selectpicker('refresh');
  127. }
  128. });
  129. }
  130. function create() {
  131. var data = {
  132. size: parseInt($('#size').val()),
  133. quantity: parseInt($('#quantity').val()),
  134. remark: $('#remark').val(),
  135. node_id: $('#node_id').val()
  136. };
  137. var go_back_url = '/disks';
  138. $.ajax({
  139. url : '/api/disk',
  140. type : 'POST',
  141. contentType: "application/json; charset=utf-8",
  142. async: false,
  143. dataType: "json",
  144. data : JSON.stringify(data),
  145. error : function(data, textStatus, xhr) {
  146. alter_warning('创建磁盘失败!');
  147. alter_danger(data.responseText);
  148. },
  149. success : function(data, textStatus, xhr) {
  150. alter_success('您所提交的资源正在创建中。根据所提交资源的大小,需要等待几到十几秒钟。页面将在3秒钟后自动跳转到实例列表页面!');
  151. $.ajax({
  152. url: '/api/disks?filter=sequence:eq:-1',
  153. type : 'GET',
  154. dataType: "json",
  155. error : function(data, textStatus, xhr) {
  156. },
  157. success : function(data, textStatus, xhr) {
  158. var page_size = 10;
  159. var last_page = Math.ceil(data['paging']['total'] / page_size);
  160. go_back_url = "/disks?page_size=" + page_size + "&page=" + last_page;
  161. }
  162. });
  163. }
  164. });
  165. setTimeout(function() {
  166. window.location.href=go_back_url;
  167. }, 3000);
  168. }
  169. </script>
  170. <div id="page-content-wrapper">
  171. <div id="alert-success-tip" class="alert alert-success alert-top">
  172. </div>
  173. <div id="alert-warning-tip" class="alert alert-warning alert-top">
  174. </div>
  175. <div id="alert-danger-tip" class="alert alert-danger alert-top">
  176. </div>
  177. </div>
  178. <div class="container" style="padding-top: 100px;">
  179. <div class="panel">
  180. <div class="panel-body">
  181. <h3 class="title-hero" style="display: inline;">
  182. 创建磁盘
  183. </h3>
  184. <a href="/disks" class="btn btn-xs btn-default add-page-transition" data-transition="pt-page-moveFromLeft-init" style="margin-bottom: 4px; margin-left: 10px;">
  185. <span class="glyph-icon icon-separator" style="transform: rotateY(-180deg);">
  186. <i class="glyph-icon icon-level-up"></i>
  187. </span>
  188. <span class="button-content">
  189. 返回磁盘列表
  190. </span>
  191. </a>
  192. <div class="example-box-wrapper">
  193. <form id="create_disk_form" class="form-horizontal bordered-row" action="javascript:;">
  194. <div class="form-group">
  195. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-hdd"></span>&nbsp;&nbsp;磁盘大小 (GB)</label>
  196. <div class="col-sm-6">
  197. <input id="size" title="磁盘大小" class="form-control" type="text" value="100" name="size">
  198. </div>
  199. </div>
  200. <div class="form-group">
  201. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-th-list"></span>&nbsp;&nbsp;数量</label>
  202. <div class="col-sm-6">
  203. <input id="quantity" title="实例数量" class="form-control" type="text" value="1" name="quantity">
  204. </div>
  205. </div>
  206. <div id="on_host_form" class="form-group">
  207. <label class="col-sm-2 control-label"><span class="glyph-icon icon-desktop"></span>&nbsp;&nbsp;计算节点</label>
  208. <div class="col-sm-6">
  209. <select id="node_id" name="node_id" title="计算节点" class="selectpicker">
  210. </select>
  211. </div>
  212. </div>
  213. <div class="form-group">
  214. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-compass-circled"></span>&nbsp;&nbsp;标识</label>
  215. <div class="col-sm-6">
  216. <div style="height: 10px;"></div>
  217. <div class="row form-group">
  218. <label class="col-sm-2 control-label">磁盘标识:</label>
  219. <div class="col-sm-6">
  220. <input id="remark" name="remark" type="text" title="磁盘标识" class="form-control">
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. <div class="form-group">
  226. <label class="col-sm-2 control-label"></label>
  227. <div class="col-sm-3 pull-right">
  228. <button id="create_disk_form_button" type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;">创建</button>
  229. </div>
  230. </div>
  231. </form>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. {% endblock body %}