clone.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. content.find('output[for="additionalDiskSize"]').prop("id","outputadditionalDiskSize"+index).prop("for","additionalDiskSize"+index);
  125. content.find('input[name="additionalDiskSize"]').prop("name","additionalDiskSize"+index).attr("oninput","outputadditionalDiskSize"+index+".value=additionalDiskSize"+index+".value");
  126. content.find('select[name="additionalDiskBus"]').prop("name","additionalDiskBus"+index);
  127. content.find('select[name="additionalDiskFormat"]').prop("name","additionalDiskFormat"+index);
  128. content.find('input[name="additionalDiskBackup"]').prop("name","additionalDiskBackup"+index);
  129. content.find('input[name="additionalDiskMp"]').prop("name","additionalDiskMp"+index);
  130. $(this).closest('.lu-widget').find('.lu-widget').last().after(content);
  131. $(".pm-disk-content-default ").parent().find(".lu-alert").hide();
  132. });
  133. //delete
  134. $(".mg-wrapper").delegate(".pm-delete-disk-button","click",function (e) {
  135. e.preventDefault();
  136. $(this).closest('.lu-widget').remove();
  137. if($(".pm-disk-content-default ").parent().find(".lu-widget").length <= 1)
  138. {
  139. $(".pm-disk-content-default ").parent().find(".lu-alert").show();
  140. }
  141. });
  142. //cpuPriority change
  143. $(".mg-wrapper").delegate("#cpuPriority","input",function (e) {
  144. e.preventDefault();
  145. var label = $(this).data("label"+$(this).val());
  146. $("#outputcpuPriority").html(label);
  147. });
  148. });
  149. /* VM Create done*/
  150. function pcVmCreatedAjaxDone(data) {
  151. if(data.htmlData.redirectUrl)
  152. {
  153. window.location.href = data.htmlData.redirectUrl;
  154. }
  155. }
  156. function pcOsTemplateLoadShowIsoFields(data) {
  157. if($("#isoImage").size()){
  158. $("#isoImage").closest(".lu-form-group").show();
  159. }
  160. if($("#secondaryIsoImage").size()){
  161. $("#secondaryIsoImage").closest(".lu-form-group").show();
  162. }
  163. // ostype
  164. if($('select[name="ostype"]').size()){
  165. $('select[name="ostype"]').closest(".lu-form-group").show();
  166. }
  167. // password
  168. if($('input[name="password"]').size()){
  169. $('input[name="password"]').closest(".lu-form-group").hide();
  170. }
  171. // sshkeys
  172. if($('textarea[name="sshkeys"]').size()){
  173. $('textarea[name="sshkeys"]').closest(".lu-form-group").hide();
  174. }
  175. // ciuser
  176. if($('input[name="ciuser"]').size()){
  177. $('input[name="ciuser"]').closest(".lu-form-group").hide();
  178. }
  179. // searchdomain
  180. if($('input[name="searchdomain"]').size()){
  181. $('input[name="searchdomain"]').closest(".lu-form-group").hide();
  182. }
  183. // nameserver
  184. if($('input[name="nameserver[0]"]').size()){
  185. $('input[name="nameserver[0]"]').closest(".lu-form-group").hide();
  186. $('input[name="nameserver[1]"]').closest(".lu-form-group").hide();
  187. }
  188. }