version.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Change option.
  3. *
  4. * @param string $option
  5. * @access public
  6. * @return void
  7. */
  8. function changeOption(option)
  9. {
  10. if($(option).val() == 'fixed')
  11. {
  12. $(option).removeClass('unit-col-7').addClass('unit-col-3');
  13. $(option).next().val('').removeClass('hidden').addClass('unit-col-4 border-left');
  14. }
  15. else
  16. {
  17. $(option).removeClass('unit-col-3').addClass('unit-col-7');
  18. $(option).next().val('').removeClass('unit-col-4').addClass('hidden');
  19. }
  20. change();
  21. }
  22. /**
  23. * Add options.
  24. *
  25. * @param string $clickedButton
  26. * @access public
  27. * @return void
  28. */
  29. function addOptions(clickedButton)
  30. {
  31. $(clickedButton).parent().parent().after(itemRow);
  32. change();
  33. }
  34. /**
  35. * Delete options.
  36. *
  37. * @param string $clickedButton
  38. * @access public
  39. * @return void
  40. */
  41. function delOptions(clickedButton)
  42. {
  43. if($('td.unitBox').length == 1) return false;
  44. $(clickedButton).parent().parent().remove();
  45. change();
  46. }
  47. /**
  48. * Change version case.
  49. *
  50. * @access public
  51. * @return void
  52. */
  53. function change()
  54. {
  55. var format = [];
  56. var fixedValue = [];
  57. var padding = $('input[name="padding"]:checked').val();
  58. var version = '1';
  59. if(padding == '1') version = '01';
  60. $("select[name='unit[]']").each(function(){
  61. format.push($(this).val());
  62. })
  63. $("input[name='unit[]']").each(function(){
  64. fixedValue.push($(this).val());
  65. })
  66. text = getVersionCase(format, fixedValue) + version;
  67. $('.versionCase').text(text);
  68. }
  69. /**
  70. * Get version case.
  71. *
  72. * @param array $format
  73. * @param array $value
  74. * @access public
  75. * @return string
  76. */
  77. function getVersionCase(format, value)
  78. {
  79. var text = '';
  80. var now = new Date();
  81. var year = now.getFullYear();
  82. var month = now.getMonth() + 1;
  83. var day = now.getDate();
  84. var time = '';
  85. var unit = $('input[name="unit[]"]').val();
  86. for(var i = 0; i < format.length; i++)
  87. {
  88. if(i%2 == 0 )
  89. {
  90. if(format[i] == 'date1') time = year + '' + month + '' + day;
  91. if(format[i] == 'date2') time = year + '-' + month + '-' + day;
  92. if(format[i] == 'fixed') time = value[i];
  93. if(format[i] == 'user') time = user;
  94. if(format[i] == '0') time = '';
  95. text += time + format[i+1];
  96. }
  97. }
  98. return text;
  99. }
  100. $(function() {
  101. change();
  102. $("input[name='padding']").change(function(){ change();});
  103. $("input[name^='unit']").live('input',function(){ change();});
  104. });