setup.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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() {
  41. $('#datadirContent').slideToggle(250);
  42. $('#databaseBackend').slideToggle(250);
  43. $('#databaseField').slideToggle(250);
  44. });
  45. $("form").submit(function(){
  46. // Save form parameters
  47. var post = $(this).serializeArray();
  48. // Show spinner while finishing setup
  49. $('.float-spinner').show(250);
  50. // Disable inputs
  51. $(':submit', this).attr('disabled','disabled').val($(':submit', this).data('finishing'));
  52. $('input', this).addClass('ui-state-disabled').attr('disabled','disabled');
  53. // only disable buttons if they are present
  54. if($('#selectDbType').find('.ui-button').length > 0) {
  55. $('#selectDbType').buttonset('disable');
  56. }
  57. $('.strengthify-wrapper, .tipsy')
  58. .css('-ms-filter', '"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"')
  59. .css('filter', 'alpha(opacity=30)')
  60. .css('opacity', .3);
  61. // Create the form
  62. var form = $('<form>');
  63. form.attr('action', $(this).attr('action'));
  64. form.attr('method', 'POST');
  65. for(var i=0; i<post.length; i++){
  66. var input = $('<input type="hidden">');
  67. input.attr(post[i]);
  68. form.append(input);
  69. }
  70. // Submit the form
  71. form.appendTo(document.body);
  72. form.submit();
  73. return false;
  74. });
  75. // Expand latest db settings if page was reloaded on error
  76. var currentDbType = $('input[type="radio"]:checked').val();
  77. if (currentDbType === undefined){
  78. $('input[type="radio"]').first().click();
  79. }
  80. if (
  81. currentDbType === 'sqlite' ||
  82. (dbtypes.sqlite && currentDbType === undefined)
  83. ){
  84. $('#datadirContent').hide(250);
  85. $('#databaseBackend').hide(250);
  86. $('#databaseField').hide(250);
  87. $('.float-spinner').hide(250);
  88. }
  89. $('#adminpass').strengthify({
  90. zxcvbn: OC.linkTo('core','vendor/zxcvbn/zxcvbn.js'),
  91. titles: [
  92. t('core', 'Very weak password'),
  93. t('core', 'Weak password'),
  94. t('core', 'So-so password'),
  95. t('core', 'Good password'),
  96. t('core', 'Strong password')
  97. ]
  98. });
  99. // centers the database chooser if it is too wide
  100. if($('#databaseBackend').width() > 300) {
  101. // this somehow needs to wait 250 milliseconds
  102. // otherwise it gets overwritten
  103. setTimeout(function(){
  104. // calculate negative left margin
  105. // half of the difference of width and default bix width of 300
  106. // add 10 to clear left side padding of button group
  107. var leftMargin = (($('#databaseBackend').width() - 300) / 2 + 10 ) * -1;
  108. $('#databaseBackend').css('margin-left', Math.floor(leftMargin) + 'px');
  109. }, 250);
  110. }
  111. });