BxTemplFormView.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaTemplate UNA Template Classes
  7. * @{
  8. */
  9. class BxTemplFormView extends BxBaseFormView
  10. {
  11. function __construct($aInfo, $oTemplate = false)
  12. {
  13. parent::__construct($aInfo, $oTemplate);
  14. }
  15. protected function _genWrapperInputAttrs(&$aInput)
  16. {
  17. $aAttrs = parent::_genWrapperInputAttrs($aInput);
  18. if(in_array($aInput['type'], ['password']))
  19. $this->_genWrapperInputAttrsPassword($aAttrs);
  20. if(in_array($aInput['type'], ['checkbox_set', 'radio_set']))
  21. $this->_genWrapperInputAttrsSet($aAttrs);
  22. return $aAttrs;
  23. }
  24. protected function _genWrapperInputAttrsPassword(&$aAttrs)
  25. {
  26. if(!isset($aAttrs['class']))
  27. $aAttrs['class'] = '';
  28. $aAttrs['class'] .= 'relative block w-full py-2 pl-3 pr-8 border border-gray-300 dark:border-gray-700 rounded-md shadow-sm bg-white dark:bg-gray-900 placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-2 focus:text-gray-900 dark:focus:text-gray-100 focus:ring-blue-500 focus:border-opacity-70 focus:ring-opacity-20 focus:border-blue-500 text-sm text-gray-700 dark:text-gray-300';
  29. return $aAttrs;
  30. }
  31. protected function _genWrapperInputAttrsSet(&$aAttrs)
  32. {
  33. if(!isset($aAttrs['class']))
  34. $aAttrs['class'] = '';
  35. $aAttrs['class'] .= 'bx-form-input-wrapper-set relative block w-full py-2 pl-3 pr-8 border border-gray-300 dark:border-gray-700 rounded-md shadow-sm bg-white dark:bg-gray-900 placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 dark:focus:text-gray-100 text-sm text-gray-700 dark:text-gray-300';
  36. return $aAttrs;
  37. }
  38. protected function _genInputStandardAttrs(&$aInput)
  39. {
  40. $aAttrs = parent::_genInputStandardAttrs($aInput);
  41. if(in_array($aInput['type'], ['hidden', 'password']))
  42. return $aAttrs;
  43. if(in_array($aInput['type'], ['checkbox', 'radio']))
  44. return $this->_updateInputAttrsCheckbox($aAttrs);
  45. return $this->_updateInputAttrs($aAttrs);
  46. }
  47. protected function _genInputSelectAttrs(&$aInput, $isMultiple)
  48. {
  49. $aAttrs = parent::_genInputSelectAttrs($aInput, $isMultiple);
  50. return $this->_updateInputAttrs($aAttrs);
  51. }
  52. protected function _genInputTextareaAttrs(&$aInput)
  53. {
  54. $aAttrs = parent::_genInputTextareaAttrs($aInput);
  55. return $this->_updateInputAttrs($aAttrs);
  56. }
  57. protected function _genCustomInputUsernamesSuggestionsAttrs (&$aInput, $bDisabled = false)
  58. {
  59. $aAttrs = parent::_genCustomInputUsernamesSuggestionsAttrs($aInput, $bDisabled);
  60. $aAttrs = $this->_updateInputAttrs($aAttrs);
  61. $aAttrs['class'] .= ' flex flex-wrap items-stretch';
  62. return $aAttrs;
  63. }
  64. protected function _genCustomInputUsernamesSuggestionsTextAttrs (&$aInput, $bDisabled = false)
  65. {
  66. $aAttrs = parent::_genCustomInputUsernamesSuggestionsTextAttrs($aInput, $bDisabled);
  67. if(!isset($aAttrs['class']))
  68. $aAttrs['class'] = '';
  69. $aAttrs['class'] .= ' leading-10';
  70. return $aAttrs;
  71. }
  72. protected function _updateInputAttrs(&$aAttrs)
  73. {
  74. if(!isset($aAttrs['class']))
  75. $aAttrs['class'] = '';
  76. $aAttrs['class'] .= ' block w-full py-2 px-3 border border-gray-300 dark:border-gray-700 rounded-md shadow-sm bg-white dark:bg-gray-900 placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-2 focus:text-gray-900 dark:focus:text-gray-100 focus:ring-blue-500 focus:border-opacity-70 focus:ring-opacity-20 focus:border-blue-500 text-sm text-gray-700 dark:text-gray-300 appearance-none';
  77. return $aAttrs;
  78. }
  79. protected function _updateInputAttrsCheckbox(&$aAttrs)
  80. {
  81. if(!isset($aAttrs['class']))
  82. $aAttrs['class'] = '';
  83. $aAttrs['class'] .= ' block py-2 px-3 border border-gray-300 dark:border-gray-700 rounded-md shadow-sm bg-white dark:bg-gray-900 placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-2 focus:text-gray-900 dark:focus:text-gray-100 focus:ring-blue-500 focus:border-opacity-70 focus:ring-opacity-20 focus:border-blue-500 text-sm text-gray-700 dark:text-gray-300';
  84. return $aAttrs;
  85. }
  86. function genInputSwitcher(&$aInput)
  87. {
  88. $aInput['type'] = 'checkbox';
  89. $sCheckbox = $this->genInputStandard($aInput);
  90. $aInput['type'] = 'switcher';
  91. $sClass = 'off';
  92. $sClassLight = 'bg-gray-200';
  93. $sClassDark = 'bg-gray-900';
  94. $sClass2 = 'translate-x-0';
  95. $sClassLight2 = 'bg-white';
  96. $sClassDark2 = 'bg-gray-500';
  97. if(isset($aInput['checked']) && $aInput['checked']){
  98. $sClass = 'on';
  99. $sClassLight = 'bg-white';
  100. $sClassDark = 'bg-gray-500';
  101. $sClass2 = 'translate-x-5';
  102. $sClassLight2 = 'bg-green-500';
  103. $sClassDark2 = 'bg-green-500';
  104. }
  105. return $this->oTemplate->parseHtmlByName('form_field_switcher.html', [
  106. 'class' => $sClass,
  107. 'class_light' => $sClassLight,
  108. 'class_dark' => $sClassDark,
  109. 'class_light2' => $sClassLight2,
  110. 'class_dark2' => $sClassDark2,
  111. 'class2' => $sClass2,
  112. 'checkbox' => $sCheckbox
  113. ]);
  114. }
  115. }
  116. /** @} */