v1.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * The formBatch widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. require_once dirname(__DIR__) . DS . 'control' . DS . 'v1.php';
  13. /**
  14. * 批量编辑表单项(formBatchItem)部件类。
  15. * The batch edit form item widget class.
  16. *
  17. * @author Hao Sun
  18. */
  19. class formBatchItem extends wg
  20. {
  21. /**
  22. * Define widget properties.
  23. *
  24. * @var array
  25. * @access protected
  26. */
  27. protected static $defineProps = array(
  28. 'name: string', // 表单项名称,无需包含 `[]`。
  29. 'label: string|bool', // 列标题。
  30. 'labelClass?: string', // 列标题类名。
  31. 'labelProps?: string', // 列标题属性,例如 `array('data-toggle' => 'tooltip', 'data-title' 。=> 'This is a tip')`
  32. 'required?:bool|string="auto"', // 是否必填,如果设置为 `"auto"`,则自动从当前模块 config 中查询。
  33. 'control?: array|string|false', // 控件类型或控件配置。
  34. 'width?: number|string', // 列宽度,如果设置为 `"auto"` 则自动填充剩余宽度。
  35. 'minWidth?: number|string', // 列最小宽度。
  36. 'value?: string|array', // 默认值。
  37. 'disabled?: bool', // 是否禁用。
  38. 'items?: array', // 选项,当控件类型为下拉菜单时使用此属性指定下拉菜单项。
  39. 'placeholder?: string', // 占位文本。
  40. 'tip?: string', // 显示在列标题上的提示文本。
  41. 'tipClass?: string', // 列标题上的提示触发按钮类名。
  42. 'tipIcon?: string="info-sign"', // 列标题上的提示触发按钮图标。
  43. 'tipProps?: string', // 列标题上的提示触发按钮其他属性。
  44. 'ditto?: bool', // 是否显示同上按钮。
  45. 'defaultDitto?:string="on"', // 同上按钮的默认值。
  46. 'hidden?: bool', // 是否隐藏
  47. 'readonly?: bool=false' // 是否只读
  48. );
  49. /**
  50. * Define default properties.
  51. *
  52. * @access protected
  53. */
  54. protected function build()
  55. {
  56. list($name, $label, $labelClass, $labelProps, $required, $tip, $tipClass, $tipProps, $tipIcon, $control, $width, $strong, $value, $disabled, $items, $placeholder, $ditto, $defaultDitto, $hidden, $readonly, $multiple, $checkboxName, $checkboxValue, $checkboxText, $checkboxChecked) = $this->prop(array('name', 'label', 'labelClass', 'labelProps', 'required', 'tip', 'tipClass', 'tipProps', 'tipIcon', 'control', 'width', 'strong', 'value', 'disabled', 'items', 'placeholder', 'ditto', 'defaultDitto', 'hidden', 'readonly', 'multiple', 'checkboxName', 'checkboxValue', 'checkboxText', 'checkboxChecked'));
  57. if($required === 'auto') $required = isFieldRequired($name);
  58. if($control !== false)
  59. {
  60. if(is_string($control)) $control = array('control' => $control, 'name' => $name);
  61. else if(empty($control)) $control = array();
  62. if(!isset($control['required']) && $required !== null) $control['required'] = $required;
  63. if(!isset($control['control'])) $control['control'] = 'text';
  64. if($name !== null) $control['name'] = $name;
  65. if($value !== null) $control['value'] = $value;
  66. if($disabled !== null) $control['disabled'] = $disabled;
  67. if($multiple !== null) $control['multiple'] = $multiple;
  68. if($items !== null) $control['items'] = $items;
  69. if($placeholder !== null) $control['placeholder'] = $placeholder;
  70. if($readonly !== null) $control['readonly'] = $readonly;
  71. }
  72. $asIndex = $control['control'] === 'index';
  73. if($asIndex) $control['control'] = 'static';
  74. if($control['control'] == 'static') $name .= '_static';
  75. if($control['control'] === 'priPicker' || $control == 'severitypicker') $control['required'] = true;
  76. if($control['control'] === 'colorInput' && !isset($control['syncColor'])) $control['syncColor'] = '#' . $name . '_{GID}';
  77. return array(
  78. h::th
  79. (
  80. setClass('form-batch-head'),
  81. $hidden ? setClass('hidden') : null,
  82. zui::width($width),
  83. set('data-required', $required),
  84. set('data-ditto', $ditto),
  85. set('data-name', $name),
  86. $ditto ? set('data-default-ditto', $defaultDitto) : null,
  87. $asIndex ? set('data-index', $asIndex) : null,
  88. set($this->getRestProps()),
  89. span
  90. (
  91. set::className('form-label form-batch-label', $labelClass, $strong ? 'font-bold' : null, $required ? 'required' : null),
  92. set($labelProps),
  93. $label
  94. ),
  95. empty($tip) ? null : new btn
  96. (
  97. set::className('form-batch-tip state text-gray', $tipClass),
  98. set::size('sm'),
  99. set::type('ghost'),
  100. toggle('tooltip', array('title' => $tip)),
  101. set($tipProps),
  102. set::icon($tipIcon)
  103. ),
  104. empty($checkboxName) ? null : new checkbox
  105. (
  106. set::rootClass('inline-flex ml-4'),
  107. set::name($checkboxName),
  108. set::value($checkboxValue),
  109. set::text($checkboxText),
  110. set::checked($checkboxChecked)
  111. )
  112. ),
  113. h::td
  114. (
  115. setClass('form-batch-control', $hidden ? 'hidden' : null),
  116. set('data-name', $name),
  117. empty($control) ? null : new control(set($control)),
  118. $this->children()
  119. )
  120. );
  121. }
  122. }