1
0

setup.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. var dbtypes;
  2. $(document).ready(function() {
  3. dbtypes={
  4. sqlite:!!$('#hasSQLite').val(),
  5. mysql:!!$('#hasMySQL').val(),
  6. postgresql:!!$('#hasPostgreSQL').val(),
  7. oracle:!!$('#hasOracle').val()
  8. };
  9. $('#selectDbType').buttonset();
  10. // change links inside an info box back to their default appearance
  11. $('#selectDbType p.info a').button('destroy');
  12. if($('#hasSQLite').val()){
  13. $('#use_other_db').hide();
  14. $('#use_oracle_db').hide();
  15. } else {
  16. $('#sqliteInformation').hide();
  17. }
  18. $('#adminlogin').change(function(){
  19. $('#adminlogin').val($.trim($('#adminlogin').val()));
  20. });
  21. $('#sqlite').click(function() {
  22. $('#use_other_db').slideUp(250);
  23. $('#use_oracle_db').slideUp(250);
  24. $('#sqliteInformation').show();
  25. $('#dbname').attr('pattern','[0-9a-zA-Z$_-]+');
  26. });
  27. $('#mysql,#pgsql').click(function() {
  28. $('#use_other_db').slideDown(250);
  29. $('#use_oracle_db').slideUp(250);
  30. $('#sqliteInformation').hide();
  31. $('#dbname').attr('pattern','[0-9a-zA-Z$_-]+');
  32. });
  33. $('#oci').click(function() {
  34. $('#use_other_db').slideDown(250);
  35. $('#use_oracle_db').show(250);
  36. $('#sqliteInformation').hide();
  37. $('#dbname').attr('pattern','[0-9a-zA-Z$_-.]+');
  38. });
  39. $('input[checked]').trigger('click');
  40. $('#showAdvanced').click(function(e) {
  41. e.preventDefault();
  42. $('#datadirContent').slideToggle(250);
  43. $('#databaseBackend').slideToggle(250);
  44. $('#databaseField').slideToggle(250);
  45. });
  46. $("form").submit(function(){
  47. // Save form parameters
  48. var post = $(this).serializeArray();
  49. // Show spinner while finishing setup
  50. $('.float-spinner').show(250);
  51. // Disable inputs
  52. $(':submit', this).attr('disabled','disabled').val($(':submit', this).data('finishing'));
  53. $('input', this).addClass('ui-state-disabled').attr('disabled','disabled');
  54. // only disable buttons if they are present
  55. if($('#selectDbType').find('.ui-button').length > 0) {
  56. $('#selectDbType').buttonset('disable');
  57. }
  58. $('.strengthify-wrapper, .tipsy')
  59. .css('-ms-filter', '"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"')
  60. .css('filter', 'alpha(opacity=30)')
  61. .css('opacity', 0.3);
  62. // Create the form
  63. var form = $('<form>');
  64. form.attr('action', $(this).attr('action'));
  65. form.attr('method', 'POST');
  66. for(var i=0; i<post.length; i++){
  67. var input = $('<input type="hidden">');
  68. input.attr(post[i]);
  69. form.append(input);
  70. }
  71. // Add redirect_url
  72. var redirectURL = getURLParameter('redirect_url');
  73. if (redirectURL) {
  74. var redirectURLInput = $('<input type="hidden">');
  75. redirectURLInput.attr({
  76. name: 'redirect_url',
  77. value: redirectURL
  78. });
  79. form.append(redirectURLInput);
  80. }
  81. // Submit the form
  82. form.appendTo(document.body);
  83. form.submit();
  84. return false;
  85. });
  86. // Expand latest db settings if page was reloaded on error
  87. var currentDbType = $('input[type="radio"]:checked').val();
  88. if (currentDbType === undefined){
  89. $('input[type="radio"]').first().click();
  90. }
  91. if (
  92. currentDbType === 'sqlite' ||
  93. (dbtypes.sqlite && currentDbType === undefined)
  94. ){
  95. $('#datadirContent').hide(250);
  96. $('#databaseBackend').hide(250);
  97. $('#databaseField').hide(250);
  98. $('.float-spinner').hide(250);
  99. }
  100. $('#adminpass').strengthify({
  101. zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
  102. titles: [
  103. t('core', 'Very weak password'),
  104. t('core', 'Weak password'),
  105. t('core', 'So-so password'),
  106. t('core', 'Good password'),
  107. t('core', 'Strong password')
  108. ],
  109. drawTitles: true,
  110. });
  111. // centers the database chooser if it is too wide
  112. if($('#databaseBackend').width() > 300) {
  113. // this somehow needs to wait 250 milliseconds
  114. // otherwise it gets overwritten
  115. setTimeout(function(){
  116. // calculate negative left margin
  117. // half of the difference of width and default bix width of 300
  118. // add 10 to clear left side padding of button group
  119. var leftMargin = (($('#databaseBackend').width() - 300) / 2 + 10 ) * -1;
  120. $('#databaseBackend').css('margin-left', Math.floor(leftMargin) + 'px');
  121. }, 250);
  122. }
  123. });