v1.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * The userPicker 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 Gang Liu <liugang@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. class userPicker extends wg
  13. {
  14. /**
  15. * @var mixed[]
  16. */
  17. protected static $defineProps = array(
  18. 'label?: string', // 控件标签。
  19. 'id?: string', // 控件 ID。
  20. 'name?: string="users[]"', // 控件名称。
  21. 'value?: string', // 控件默认值。
  22. 'items?: array', // picker 列表项或表项获取方法。
  23. 'menu?: array', // picker 附加的菜单选项。
  24. 'toolbar?: boolean|array', // picker 列表工具栏。
  25. 'multiple?: boolean|number=false', // picker 是否允许选择多个值,如果指定为数字,则限制多选的数目,默认 `false`。
  26. 'contactList?: boolean=true', // 是否显示联系人列表。
  27. 'inputGroupClass?: string=""' // inputGroup 的 class 属性。
  28. );
  29. /**
  30. * @var mixed[]
  31. */
  32. protected static $defaultProps = array(
  33. 'menu' => array('checkbox' => true),
  34. 'toolbar' => true,
  35. 'multiple' => true
  36. );
  37. protected function created()
  38. {
  39. $items = $this->prop('items');
  40. if(!$items)
  41. {
  42. global $app;
  43. $users = $app->control->loadModel('user')->getPairs('noclosed|nodeleted');
  44. $items = array_map(function($account, $name){return array('text' => $name, 'value' => $account);}, array_keys($users), $users);
  45. $this->setProp('items', $items);
  46. }
  47. }
  48. protected function build()
  49. {
  50. return inputGroup
  51. (
  52. $this->prop('inputGroupClass') ? setClass($this->prop('inputGroupClass')) : null,
  53. $this->prop('label', null),
  54. picker(set($this->props->pick(array('id', 'name', 'value', 'items', 'toolbar', 'menu', 'multiple')))),
  55. $this->prop('contactList') ? contactList() : null
  56. );
  57. }
  58. }