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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // Pull request
  94. if ($('.repository.compare.pull').length > 0) {
  95. var $branch_dropdown = $('.choose.branch .dropdown')
  96. $branch_dropdown.dropdown({
  97. fullTextSearch: true,
  98. onChange: function (text, value, $choice) {
  99. window.location.href = $choice.data('url');
  100. },
  101. message: {noResults: $branch_dropdown.data('no-results')}
  102. });
  103. }
  104. };
  105. $(document).ready(function () {
  106. csrf = $('meta[name=_csrf]').attr("content");
  107. // Semantic UI modules.
  108. $('.dropdown').dropdown();
  109. $('.jump.dropdown').dropdown({
  110. action: 'hide'
  111. });
  112. $('.slide.up.dropdown').dropdown({
  113. transition: 'slide up'
  114. });
  115. $('.ui.accordion').accordion();
  116. $('.ui.checkbox').checkbox();
  117. $('.ui.progress').progress({
  118. showActivity: false
  119. });
  120. $('.poping.up').popup();
  121. // Comment form
  122. if ($('.comment.form').length > 0) {
  123. var $form = $(this);
  124. $form.find('.tabular.menu .item').tab();
  125. $form.find('.tabular.menu .item[data-tab="preview"]').click(function () {
  126. var $this = $(this);
  127. $.post($this.data('url'), {
  128. "_csrf": csrf,
  129. "mode": "gfm",
  130. "context": $this.data('context'),
  131. "text": $form.find('.tab.segment[data-tab="write"] textarea').val()
  132. },
  133. function (data) {
  134. $form.find('.tab.segment[data-tab="preview"]').html(data);
  135. }
  136. );
  137. });
  138. // Labels
  139. var $list = $('.ui.labels.list');
  140. var $no_select = $list.find('.no-select');
  141. $('.select-label .item:not(.no-select)').click(function () {
  142. if ($(this).hasClass('checked')) {
  143. $(this).removeClass('checked')
  144. $(this).find('.octicon').removeClass('octicon-check')
  145. } else {
  146. $(this).addClass('checked')
  147. $(this).find('.octicon').addClass('octicon-check')
  148. }
  149. var label_ids = "";
  150. $(this).parent().find('.item').each(function () {
  151. if ($(this).hasClass('checked')) {
  152. label_ids += $(this).data('id') + ",";
  153. $($(this).data('id-selector')).removeClass('hide');
  154. } else {
  155. $($(this).data('id-selector')).addClass('hide');
  156. }
  157. });
  158. if (label_ids.length == 0) {
  159. $no_select.removeClass('hide');
  160. } else {
  161. $no_select.addClass('hide');
  162. }
  163. $($(this).parent().data('id')).val(label_ids);
  164. return false;
  165. });
  166. $('.select-label .no-select.item').click(function () {
  167. $(this).parent().find('.item').each(function () {
  168. $(this).removeClass('checked');
  169. $(this).find('.octicon').removeClass('octicon-check');
  170. });
  171. $list.find('.item').each(function () {
  172. $(this).addClass('hide');
  173. });
  174. $no_select.removeClass('hide');
  175. $($(this).parent().data('id')).val('');
  176. });
  177. }
  178. // Helpers.
  179. $('.delete-button').click(function () {
  180. var $this = $(this);
  181. $('.delete.modal').modal({
  182. closable: false,
  183. onApprove: function () {
  184. $.post($this.data('url'), {
  185. "_csrf": csrf,
  186. "id": $this.data("id")
  187. }).done(function (data) {
  188. window.location.href = data.redirect;
  189. });
  190. }
  191. }).modal('show');
  192. return false;
  193. });
  194. initInstall();
  195. initRepository();
  196. });