gogs.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. $('.delete-label-button').click(function () {
  48. var $this = $(this);
  49. $('.delete-label.modal').modal({
  50. closable: false,
  51. onApprove: function () {
  52. $.post($this.data('url'), {
  53. "_csrf": csrf,
  54. "id": $this.data("id")
  55. }).done(function (data) {
  56. window.location.href = data.redirect;
  57. });
  58. }
  59. }).modal('show');
  60. return false;
  61. });
  62. $('.edit-label-button').click(function () {
  63. $('#label-modal-id').val($(this).data('id'));
  64. $('#label-modal-title').val($(this).data('title'));
  65. $('#label-modal-color').val($(this).data('color'))
  66. $('.minicolors-swatch-color').css("background-color", $(this).data('color'));
  67. $('.edit-label.modal').modal({
  68. onApprove: function () {
  69. $('.edit-label.form').submit();
  70. }
  71. }).modal('show');
  72. return false;
  73. });
  74. }
  75. // Milestones
  76. if ($('.repository.new.milestone').length > 0) {
  77. var $datepicker = $('.milestone.datepicker')
  78. $datepicker.datetimepicker({
  79. lang: $datepicker.data('lang'),
  80. inline: true,
  81. timepicker: false,
  82. startDate: $datepicker.data('start-date'),
  83. formatDate: 'Y-m-d',
  84. onSelectDate: function (ct) {
  85. $('#deadline').val(ct.dateFormat('Y-m-d'));
  86. }
  87. });
  88. $('#clear-date').click(function () {
  89. $('#deadline').val('');
  90. return false;
  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. initInstall();
  111. initRepository();
  112. });