gogs.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. 'use strict';
  2. var csrf;
  3. function initInstall() {
  4. if ($('.install').length == 0) {
  5. return;
  6. }
  7. // Database type change detection.
  8. $("#db_type").change(function () {
  9. var db_type = $('#db_type').val();
  10. if (db_type === "SQLite3") {
  11. $('#sql_settings').hide();
  12. $('#pgsql_settings').hide();
  13. $('#sqlite_settings').show();
  14. return;
  15. }
  16. var mysql_default = '127.0.0.1:3306';
  17. var postgres_default = '127.0.0.1:5432';
  18. $('#sqlite_settings').hide();
  19. $('#sql_settings').show();
  20. if (db_type === "PostgreSQL") {
  21. $('#pgsql_settings').show();
  22. if ($('#db_host').val() == mysql_default) {
  23. $('#db_host').val(postgres_default);
  24. }
  25. } else {
  26. $('#pgsql_settings').hide();
  27. if ($('#db_host').val() == postgres_default) {
  28. $('#db_host').val(mysql_default);
  29. }
  30. }
  31. });
  32. };
  33. function initRepository() {
  34. if ($('.repository').length == 0) {
  35. return;
  36. }
  37. // Labels
  38. if ($('.repository.labels').length > 0) {
  39. // Create label
  40. var $new_label_panel = $('.new-label.segment');
  41. $('.new-label.button').click(function () {
  42. $new_label_panel.show();
  43. });
  44. $('.new-label.segment .cancel').click(function () {
  45. $new_label_panel.hide();
  46. });
  47. $('.color-picker').each(function () {
  48. $(this).minicolors();
  49. });
  50. $('.precolors .color').click(function () {
  51. var color_hex = $(this).data('color-hex')
  52. $('.color-picker').val(color_hex);
  53. $('.minicolors-swatch-color').css("background-color", color_hex);
  54. });
  55. $('.edit-label-button').click(function () {
  56. $('#label-modal-id').val($(this).data('id'));
  57. $('.edit-label .new-label-input').val($(this).data('title'));
  58. $('.minicolors-swatch-color').css("background-color", $(this).data('color'));
  59. $('.edit-label.modal').modal({
  60. onApprove: function () {
  61. $('.edit-label.form').submit();
  62. }
  63. }).modal('show');
  64. return false;
  65. });
  66. }
  67. // Milestones
  68. if ($('.repository.milestones').length > 0) {
  69. }
  70. if ($('.repository.new.milestone').length > 0) {
  71. var $datepicker = $('.milestone.datepicker')
  72. $datepicker.datetimepicker({
  73. lang: $datepicker.data('lang'),
  74. inline: true,
  75. timepicker: false,
  76. startDate: $datepicker.data('start-date'),
  77. formatDate: 'Y-m-d',
  78. onSelectDate: function (ct) {
  79. $('#deadline').val(ct.dateFormat('Y-m-d'));
  80. }
  81. });
  82. $('#clear-date').click(function () {
  83. $('#deadline').val('');
  84. return false;
  85. });
  86. }
  87. // Settings
  88. if ($('.repository.settings').length > 0) {
  89. $('#add-deploy-key').click(function () {
  90. $('#add-deploy-key-panel').show();
  91. });
  92. }
  93. };
  94. $(document).ready(function () {
  95. csrf = $('meta[name=_csrf]').attr("content");
  96. // Semantic UI modules.
  97. $('.dropdown').dropdown();
  98. $('.jump.dropdown').dropdown({
  99. action: 'hide'
  100. });
  101. $('.slide.up.dropdown').dropdown({
  102. transition: 'slide up'
  103. });
  104. $('.ui.accordion').accordion();
  105. $('.ui.checkbox').checkbox();
  106. $('.ui.progress').progress({
  107. showActivity: false
  108. });
  109. $('.poping.up').popup();
  110. // Helpers.
  111. $('.delete-button').click(function () {
  112. var $this = $(this);
  113. $('.delete.modal').modal({
  114. closable: false,
  115. onApprove: function () {
  116. $.post($this.data('url'), {
  117. "_csrf": csrf,
  118. "id": $this.data("id")
  119. }).done(function (data) {
  120. window.location.href = data.redirect;
  121. });
  122. }
  123. }).modal('show');
  124. return false;
  125. });
  126. initInstall();
  127. initRepository();
  128. });