v1.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * The contactList 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 contactList extends wg
  13. {
  14. /**
  15. * @var mixed[]
  16. */
  17. protected static $defineProps = array(
  18. 'name?: string="contactList"', // 控件名称。
  19. 'target?: string', // 选中项改变时更新的目标
  20. 'items?: array', // picker 列表项或表项获取方法。
  21. 'placeholder?: string', // picker 占位符。
  22. );
  23. public static function getPageJS()
  24. {
  25. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  26. }
  27. protected function created()
  28. {
  29. $items = $this->prop('items');
  30. if(!$items)
  31. {
  32. global $app;
  33. $lists = $app->control->loadModel('user')->getContactLists();
  34. $items = array_map(function($id, $name){return array('text' => $name, 'value' => $id);}, array_keys($lists), $lists);
  35. $this->setProp('items', $items);
  36. }
  37. $placeholder = $this->prop('placeholder');
  38. if(!$placeholder)
  39. {
  40. global $lang;
  41. $placeholder = $lang->contact->common;
  42. $this->setProp('placeholder', $placeholder);
  43. }
  44. }
  45. protected function build()
  46. {
  47. global $app, $lang;
  48. $app->loadLang('user');
  49. $items = $this->prop('items');
  50. $target = $this->prop('target');
  51. return span
  52. (
  53. setID('contactList'),
  54. setClass('contactBox w-auto input-group-' . ($items ? 'addon p-0 w-24' : 'btn')),
  55. picker
  56. (
  57. $items ? null : setClass('hidden'),
  58. set::name($this->prop('name')),
  59. set::items($items),
  60. set::placeholder($this->prop('placeholder')),
  61. on::change()->call('loadContactUsers', "{$target}")
  62. ),
  63. a
  64. (
  65. $items ? setClass('hidden') : null,
  66. setID('manageContact'),
  67. setClass('btn'),
  68. setData(array('toggle' => 'modal')),
  69. set('href', createLink('my', 'managecontacts')),
  70. set('title', $lang->user->contacts->manage),
  71. icon('groups')
  72. )
  73. );
  74. }
  75. }