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

gogs.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. $('.color-picker').each(function () {
  40. $(this).minicolors();
  41. });
  42. $('.precolors .color').click(function () {
  43. var color_hex = $(this).data('color-hex')
  44. $('.color-picker').val(color_hex);
  45. $('.minicolors-swatch-color').css("background-color", color_hex);
  46. });
  47. $('.edit-label-button').click(function () {
  48. $('#label-modal-id').val($(this).data('id'));
  49. $('#label-modal-title').val($(this).data('title'));
  50. $('#label-modal-color').val($(this).data('color'))
  51. $('.minicolors-swatch-color').css("background-color", $(this).data('color'));
  52. $('.edit-label.modal').modal({
  53. onApprove: function () {
  54. $('.edit-label.form').submit();
  55. }
  56. }).modal('show');
  57. return false;
  58. });
  59. }
  60. // Milestones
  61. if ($('.repository.milestones').length > 0) {
  62. }
  63. if ($('.repository.new.milestone').length > 0) {
  64. var $datepicker = $('.milestone.datepicker')
  65. $datepicker.datetimepicker({
  66. lang: $datepicker.data('lang'),
  67. inline: true,
  68. timepicker: false,
  69. startDate: $datepicker.data('start-date'),
  70. formatDate: 'Y-m-d',
  71. onSelectDate: function (ct) {
  72. $('#deadline').val(ct.dateFormat('Y-m-d'));
  73. }
  74. });
  75. $('#clear-date').click(function () {
  76. $('#deadline').val('');
  77. return false;
  78. });
  79. }
  80. };
  81. $(document).ready(function () {
  82. csrf = $('meta[name=_csrf]').attr("content");
  83. // Semantic UI modules.
  84. $('.dropdown').dropdown();
  85. $('.jump.dropdown').dropdown({
  86. action: 'hide'
  87. });
  88. $('.slide.up.dropdown').dropdown({
  89. transition: 'slide up'
  90. });
  91. $('.ui.accordion').accordion();
  92. $('.ui.checkbox').checkbox();
  93. $('.ui.progress').progress({
  94. showActivity: false
  95. });
  96. $('.poping.up').popup();
  97. // Helpers.
  98. $('.delete-button').click(function () {
  99. var $this = $(this);
  100. $('.delete.modal').modal({
  101. closable: false,
  102. onApprove: function () {
  103. $.post($this.data('url'), {
  104. "_csrf": csrf,
  105. "id": $this.data("id")
  106. }).done(function (data) {
  107. window.location.href = data.redirect;
  108. });
  109. }
  110. }).modal('show');
  111. return false;
  112. });
  113. initInstall();
  114. initRepository();
  115. });