main.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_docker(){
  3. switch($.urlParam('page')){
  4. case 'sheet.docker.environment':
  5. docker_environment_change_ssl();
  6. $('#docker-environment-tab li a').click(function(){
  7. var tab = $(this).attr("href").substring(1);
  8. $("#docker-environment-tab-content").load("action.php?action=docker_environment_tab&id="+$.urlParam('id')+"&tab="+tab,function(){
  9. init_components("#docker-environment-tab-content");
  10. });
  11. });
  12. if($.urlParam('id')){
  13. $('.docker .environment-detail').removeClass('hidden');
  14. $('#docker-environment-tab li:eq(0) a').click();
  15. }
  16. break;
  17. default:
  18. break;
  19. }
  20. }
  21. //Enregistrement des configurations
  22. function docker_setting_save(){
  23. $.action({
  24. action : 'docker_setting_save',
  25. fields : $('#docker-setting-form').toJson()
  26. },function(){ $.message('info','Configuration enregistrée'); });
  27. }
  28. /** DOCKERENVIRONMENT **/
  29. //Récuperation d'une liste de dockerenvironment dans le tableau #dockerenvironments
  30. function docker_environment_search(callback,exportMode){
  31. var box = new FilterBox('#filters');
  32. $('#docker-environments').fill({
  33. action:'docker_environment_search',
  34. filters : box.filters(),
  35. sort : $('#docker-environments').sortable_table('get'),
  36. export: !exportMode ? false : exportMode
  37. },function(response){
  38. $('.results-count span').text(response.pagination.total);
  39. if(callback!=null) callback();
  40. });
  41. }
  42. //Ajout ou modification d'élément dockerenvironment
  43. function docker_environment_save(){
  44. var data = $('#docker-environment-form').toJson();
  45. $.action(data,function(r){
  46. $('#docker-environment-form').attr('data-id',r.id);
  47. $.urlParam('id',r.id);
  48. $.message('success','Enregistré');
  49. $('.docker .environment-detail').removeClass('hidden');
  50. });
  51. }
  52. function docker_environment_docker_create(event){
  53. event.stopPropagation();
  54. var data = $('#docker-environment-form').toJson();
  55. data.action='docker_environment_docker_create';
  56. $('.btn-docker-create').addClass('btn-preloader');
  57. $.action(data,function(r){
  58. $('#logs').html(r.logs);
  59. $.message('success','Créé');
  60. });
  61. }
  62. function docker_environment_docker_remove(event){
  63. if(!confirm('Êtes vous sûr de vouloir supprimer ce conteneur ? Toutes les données seront supprimées')) return;
  64. event.stopPropagation();
  65. var data = $('#docker-environment-form').toJson();
  66. data.action='docker_environment_docker_remove';
  67. $('.btn-docker-remove').addClass('btn-preloader');
  68. $.action(data,function(r){
  69. $('#logs').html(r.logs);
  70. $.message('success','Supprimé');
  71. });
  72. }
  73. function docker_environment_pma_create(event){
  74. event.stopPropagation();
  75. var data = $('#docker-environment-form').toJson();
  76. data.action='docker_environment_pma_create';
  77. $('.btn-pma-create').addClass('btn-preloader');
  78. $.action(data,function(r){
  79. $('#logs').html(r.logs);
  80. $.message('success','Créé');
  81. });
  82. }
  83. function docker_environment_pma_remove(event){
  84. event.stopPropagation();
  85. var data = $('#docker-environment-form').toJson();
  86. data.action='docker_environment_pma_remove';
  87. $('.btn-pma-remove').addClass('btn-preloader');
  88. $.action(data,function(r){
  89. $('#logs').html(r.logs);
  90. $.message('success','Créé');
  91. });
  92. }
  93. function docker_environment_utm_create(event){
  94. event.stopPropagation();
  95. var data = $('#docker-environment-form').toJson();
  96. data.action='docker_environment_utm_create';
  97. $('.btn-utm-create').addClass('btn-preloader');
  98. $.action(data,function(r){
  99. $('#logs').html(r.logs);
  100. $.message('success','Créé');
  101. });
  102. }
  103. function docker_environment_domain_create(event){
  104. event.stopPropagation();
  105. var data = $('#docker-environment-form').toJson();
  106. data.action='docker_environment_domain_create';
  107. $('.btn-domain-create').addClass('btn-preloader');
  108. $.action(data,function(r){
  109. $('#logs').html(r.logs);
  110. $.message('success','Créé');
  111. });
  112. }
  113. function docker_environment_git_create(event){
  114. event.stopPropagation();
  115. var data = $('#docker-environment-form').toJson();
  116. data.action='docker_environment_git_create';
  117. $('.btn-git-create').addClass('btn-preloader');
  118. $.action(data,function(r){
  119. $('#logs').html(r.logs);
  120. document.location.reload(true);
  121. $.message('success','Créé');
  122. });
  123. }
  124. function docker_environment_migrate_path(){
  125. var tpl = $('template.migrationPath').html();
  126. var data = {};
  127. data.login = $('#login').val();
  128. data.password = $('#password').val();
  129. data.ip = $('#ip').val();
  130. data.root = $('#root').val();
  131. data.relative_destination = data.root.split('/');
  132. data.relative_destination = data.relative_destination.splice(-1,1);
  133. data.relative_destination = data.relative_destination[0];
  134. var chain = Mustache.render(tpl,data);
  135. $('code.migrationPath').html(chain);
  136. }
  137. function docker_environment_change_ssl(){
  138. var ssl = $('#ssl').prop('checked');
  139. if(!ssl){
  140. $('#certificate-block').addClass('hidden');
  141. return;
  142. }
  143. $('#certificate-block').removeClass('hidden');
  144. $('#certificate').html('<option>Chargement...</option>');
  145. $.action({
  146. action : 'docker_environment_certificate_search',
  147. },function(r){
  148. $('#certificate').html('');
  149. var preset = $('#certificate').attr('data-value');
  150. for(var k in r.rows){
  151. $('#certificate').append('<option value="'+r.rows[k].ref+'" '+(preset==r.rows[k].ref?' selected="selected" ':'')+'>'+r.rows[k].label+'</option>');
  152. }
  153. });
  154. }
  155. //Suppression d'élement dockerenvironment
  156. function docker_environment_delete(element){
  157. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  158. var line = $(element).closest('tr');
  159. $.action({
  160. action : 'docker_environment_delete',
  161. id : line.attr('data-id')
  162. },function(r){
  163. line.remove();
  164. $.message('info','Élement supprimé');
  165. });
  166. }
  167. /** MACHINE **/
  168. //Récuperation d'une liste machine dans le tableau #machines
  169. function docker_machine_search(callback,exportMode){
  170. var box = new FilterBox('#filters');
  171. $('#machines').fill({
  172. action:'docker_machine_search',
  173. filters: box.filters(),
  174. sort: $('#machines').sortable_table('get'),
  175. export: !exportMode ? false : exportMode
  176. },function(response){
  177. $('.results-count span').text(response.pagination.total);
  178. if(callback!=null) callback();
  179. });
  180. }
  181. //Ajout ou modification machine
  182. function docker_machine_save(){
  183. var data = $('#machine-form').toJson();
  184. $.action(data,function(r){
  185. $('#machine-form').attr('data-id',r.id);
  186. $.urlParam('id',r.id);
  187. $.message('success','Enregistré');
  188. });
  189. }
  190. //Suppression machine
  191. function docker_machine_delete(element){
  192. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  193. var line = $(element).closest('.item-line');
  194. $.action({
  195. action: 'docker_machine_delete',
  196. id: line.attr('data-id')
  197. },function(r){
  198. line.remove();
  199. $.message('info','Item supprimé');
  200. });
  201. }