You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gogs.js 4.4 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. onShow: function() {
  101. $('.poping.up').popup('hide');
  102. }
  103. });
  104. $('.slide.up.dropdown').dropdown({
  105. transition: 'slide up'
  106. });
  107. $('.ui.accordion').accordion();
  108. $('.ui.checkbox').checkbox();
  109. $('.ui.progress').progress({
  110. showActivity: false
  111. });
  112. $('.poping.up').popup();
  113. $('.top.menu .poping.up').popup({
  114. onShow: function() {
  115. if ( $('.top.menu .menu.transition').hasClass('visible') ) {
  116. return false;
  117. }
  118. }
  119. });
  120. // Helpers.
  121. $('.delete-button').click(function () {
  122. var $this = $(this);
  123. $('.delete.modal').modal({
  124. closable: false,
  125. onApprove: function () {
  126. $.post($this.data('url'), {
  127. "_csrf": csrf,
  128. "id": $this.data("id")
  129. }).done(function (data) {
  130. window.location.href = data.redirect;
  131. });
  132. }
  133. }).modal('show');
  134. return false;
  135. });
  136. initInstall();
  137. initRepository();
  138. });