setup.js 3.4 KB

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