create.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*Create VM*/
  2. $(document).ready(function () {
  3. //change os template
  4. $("#osTemplate").change(function (e) {
  5. console.log($(this).val() );
  6. //show
  7. if($(this).val() == "installationFromIso"){
  8. if($("#isoImage").size()){
  9. $("#isoImage").closest(".lu-form-group").show();
  10. }
  11. if($("#secondaryIsoImage").size()){
  12. $("#secondaryIsoImage").closest(".lu-form-group").show();
  13. }
  14. // ostype
  15. if($('select[name="ostype"]').size()){
  16. $('select[name="ostype"]').closest(".lu-form-group").show();
  17. }
  18. // password
  19. if($('input[name="password"]').size()){
  20. $('input[name="password"]').closest(".lu-form-group").hide();
  21. }
  22. // sshkeys
  23. if($('textarea[name="sshkeys"]').size()){
  24. $('textarea[name="sshkeys"]').closest(".lu-form-group").hide();
  25. }
  26. // ciuser
  27. if($('input[name="ciuser"]').size()){
  28. $('input[name="ciuser"]').closest(".lu-form-group").hide();
  29. }
  30. // searchdomain
  31. if($('input[name="searchdomain"]').size()){
  32. $('input[name="searchdomain"]').closest(".lu-form-group").hide();
  33. }
  34. // nameserver
  35. if($('input[name="nameserver[0]"]').size()){
  36. $('input[name="nameserver[0]"]').closest(".lu-form-group").hide();
  37. $('input[name="nameserver[1]"]').closest(".lu-form-group").hide();
  38. }
  39. //hide
  40. } else {
  41. if($("#isoImage").size()){
  42. $("#isoImage").closest(".lu-form-group").hide();
  43. }
  44. if($("#secondaryIsoImage").size()){
  45. $("#secondaryIsoImage").closest(".lu-form-group").hide();
  46. }
  47. // ostype
  48. if($('select[name="ostype"]').size()){
  49. $('select[name="ostype"]').closest(".lu-form-group").hide();
  50. }
  51. // password
  52. if($('input[name="password"]').size()){
  53. $('input[name="password"]').closest(".lu-form-group").show();
  54. }
  55. // sshkeys
  56. if($('textarea[name="sshkeys"]').size()){
  57. $('textarea[name="sshkeys"]').closest(".lu-form-group").show();
  58. }
  59. // ciuser
  60. if($('input[name="ciuser"]').size()){
  61. $('input[name="ciuser"]').closest(".lu-form-group").show();
  62. }
  63. // searchdomain
  64. if($('input[name="searchdomain"]').size()){
  65. $('input[name="searchdomain"]').closest(".lu-form-group").show();
  66. }
  67. // nameserver
  68. if($('input[name="nameserver[0]"]').size()){
  69. $('input[name="nameserver[0]"]').closest(".lu-form-group").show();
  70. $('input[name="nameserver[1]"]').closest(".lu-form-group").show();
  71. }
  72. }
  73. });
  74. //fire event
  75. $("#osTemplate").trigger("change");
  76. //virtual network
  77. var selectizedInstance = $('.pm-virtual-network-content-default .selectized').selectize();
  78. selectizedInstance.each(function(){
  79. this.selectize.destroy();
  80. });
  81. //create
  82. $("#pm-add-new-virtual-network-button").on("click",function (e) {
  83. e.preventDefault();
  84. var content = $('.pm-virtual-network-content-default').clone();
  85. content.removeClass("hidden");
  86. content.removeClass("pm-virtual-network-content-default");
  87. var index = $("#pm-add-new-virtual-network-button").closest('.lu-widget').find('.lu-widget').size();
  88. content.find('select[name="virtualNetwork[id]"]').prop("name","virtualNetwork"+index+"[id]");
  89. content.find('select[name="virtualNetwork[ip]"]').prop("name","virtualNetwork"+index+"[ip]");
  90. $(this).closest('.lu-widget').find('.lu-widget').last().after(content);
  91. $(this).closest('.lu-widget').find('.pm-vn-select').trigger("change");
  92. $(this).closest('.lu-widget').find('.lu-alert').hide();
  93. $(".pm-virtual-network-content-default").parent().find(".lu-alert").hide();
  94. });
  95. //delete
  96. $(".mg-wrapper").delegate(".pm-delete-virtual-network-button","click",function (e) {
  97. e.preventDefault();
  98. $(this).closest('.lu-widget').remove();
  99. if($(".pm-virtual-network-content-default").parent().find(".lu-widget").length <= 1)
  100. {
  101. $(".pm-virtual-network-content-default").parent().find(".lu-alert").show();
  102. }
  103. });
  104. //change
  105. $(".mg-wrapper").delegate(".pm-vn-select","change",function (e) {
  106. var show = '.vn-ip-'+$(this).val();
  107. $(this).closest('.lu-widget__content').find('.pm-vn-ip-select option').hide();
  108. $(this).closest('.lu-widget__content').find(show).show();
  109. var firstOption = $(this).closest('.lu-widget__content').find('.pm-vn-ip-select '+show+':first').val();
  110. $(this).closest('.lu-widget__content').find('.pm-vn-ip-select').val(firstOption);
  111. });
  112. //disk
  113. var selectizedInstance = $('.pm-disk-content-default .selectized').selectize();
  114. selectizedInstance.each(function(){
  115. this.selectize.destroy();
  116. });
  117. //create
  118. $("#pm-add-disk-button").on("click",function (e) {
  119. e.preventDefault();
  120. var content = $('.pm-disk-content-default').clone();
  121. content.removeClass("hidden");
  122. content.removeClass("pm-disk-content-default");
  123. var index = $("#pm-add-disk-button").closest('.lu-widget').find('.lu-widget').size();
  124. var myinput = content.find('input[name="additionalDiskSize"]');
  125. content.find('output[for="additionalDiskSize"]').prop("id","outputadditionalDiskSize"+index).prop("for","additionalDiskSize"+index);
  126. myinput.prop("name","additionalDiskSize"+index).attr("oninput","outputadditionalDiskSize"+index+".value=additionalDiskSize"+index+".value");
  127. content.find('select[name="additionalDiskBus"]').prop("name","additionalDiskBus"+index);
  128. content.find('select[name="additionalDiskFormat"]').prop("name","additionalDiskFormat"+index);
  129. content.find('select[name="additionalDiskBackup"]').prop("name","additionalDiskBackup"+index);
  130. content.find('input[name="additionalDiskMp"]').prop("name","additionalDiskMp"+index);
  131. $(this).closest('.lu-widget').find('.lu-widget').last().after(content);
  132. $(".pm-disk-content-default ").parent().find(".lu-alert").hide();
  133. $('input[name^="outputadditionalDiskSize"]').not(myinput).attr("max", myinput.attr("max") - myinput.attr("value"));
  134. $('input[name="disk"]').not(myinput).attr("max", myinput.attr("max") - myinput.attr("value"));
  135. });
  136. //delete
  137. $(".mg-wrapper").delegate(".pm-delete-disk-button","click",function (e) {
  138. e.preventDefault();
  139. $(this).closest('.lu-widget').remove();
  140. if($(".pm-disk-content-default ").parent().find(".lu-widget").length <= 1)
  141. {
  142. $(".pm-disk-content-default ").parent().find(".lu-alert").show();
  143. }
  144. });
  145. //cpuPriority change
  146. $(".mg-wrapper").delegate("#cpuPriority","input",function (e) {
  147. e.preventDefault();
  148. var label = $(this).data("label"+$(this).val());
  149. $("#outputcpuPriority").html(label);
  150. });
  151. });
  152. /* VM Create done*/
  153. function pcVmCreatedAjaxDone(data) {
  154. if(data.htmlData.redirectUrl)
  155. {
  156. window.location.href = data.htmlData.redirectUrl;
  157. }
  158. }
  159. function pcOsTemplateLoadShowIsoFields(data) {
  160. if($("#isoImage").size()){
  161. $("#isoImage").closest(".lu-form-group").show();
  162. }
  163. if($("#secondaryIsoImage").size()){
  164. $("#secondaryIsoImage").closest(".lu-form-group").show();
  165. }
  166. // ostype
  167. if($('select[name="ostype"]').size()){
  168. $('select[name="ostype"]').closest(".lu-form-group").show();
  169. }
  170. // password
  171. if($('input[name="password"]').size()){
  172. $('input[name="password"]').closest(".lu-form-group").hide();
  173. }
  174. // sshkeys
  175. if($('textarea[name="sshkeys"]').size()){
  176. $('textarea[name="sshkeys"]').closest(".lu-form-group").hide();
  177. }
  178. // ciuser
  179. if($('input[name="ciuser"]').size()){
  180. $('input[name="ciuser"]').closest(".lu-form-group").hide();
  181. }
  182. // searchdomain
  183. if($('input[name="searchdomain"]').size()){
  184. $('input[name="searchdomain"]').closest(".lu-form-group").hide();
  185. }
  186. // nameserver
  187. if($('input[name="nameserver[0]"]').size()){
  188. $('input[name="nameserver[0]"]').closest(".lu-form-group").hide();
  189. $('input[name="nameserver[1]"]').closest(".lu-form-group").hide();
  190. }
  191. }