gogs.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // Settings
  81. if ($('.repository.settings').length > 0) {
  82. $('#add-deploy-key').click(function () {
  83. $('#add-deploy-key-panel').show();
  84. });
  85. }
  86. };
  87. $(document).ready(function () {
  88. csrf = $('meta[name=_csrf]').attr("content");
  89. // Semantic UI modules.
  90. $('.dropdown').dropdown();
  91. $('.jump.dropdown').dropdown({
  92. action: 'hide'
  93. });
  94. $('.slide.up.dropdown').dropdown({
  95. transition: 'slide up'
  96. });
  97. $('.ui.accordion').accordion();
  98. $('.ui.checkbox').checkbox();
  99. $('.ui.progress').progress({
  100. showActivity: false
  101. });
  102. $('.poping.up').popup();
  103. // Helpers.
  104. $('.delete-button').click(function () {
  105. var $this = $(this);
  106. $('.delete.modal').modal({
  107. closable: false,
  108. onApprove: function () {
  109. $.post($this.data('url'), {
  110. "_csrf": csrf,
  111. "id": $this.data("id")
  112. }).done(function (data) {
  113. window.location.href = data.redirect;
  114. });
  115. }
  116. }).modal('show');
  117. return false;
  118. });
  119. initInstall();
  120. initRepository();
  121. });