v1.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * The formBatchPanel 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. class formSettingBtn extends wg
  13. {
  14. /**
  15. * @var mixed[]
  16. */
  17. protected static $defaultProps = array(
  18. 'customFields' => array(),
  19. 'urlParams' => '',
  20. 'canGlobal' => false,
  21. 'submitCallBack' => '',
  22. 'restoreCallBack' => '',
  23. 'noCancel' => false,
  24. 'text' => ''
  25. );
  26. public static function getPageCSS()
  27. {
  28. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  29. }
  30. public static function getPageJS()
  31. {
  32. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  33. }
  34. /**
  35. * @param mixed[] $customFields
  36. */
  37. private function buildCustomFields($customFields)
  38. {
  39. $listFields = zget($customFields, 'list', array());
  40. $showFields = zget($customFields, 'show', array());
  41. if(!$listFields) return array();
  42. $items = array();
  43. foreach($listFields as $field => $text)
  44. {
  45. $items[] = checkbox
  46. (
  47. set::name('fields[]'),
  48. set::value($field),
  49. set::text($text),
  50. set::checked($showFields ? in_array($field, $showFields) : true),
  51. empty($text) ? set::rootClass('hidden') : null
  52. );
  53. }
  54. return $items;
  55. }
  56. protected function build()
  57. {
  58. list($urlParams, $text, $submitCallback, $restoreCallback, $canGlobal, $noCancel) = $this->prop(array('urlParams', 'text', 'submitCallback', 'restoreCallback', 'canGlobal', 'noCancel'));
  59. $customFields = $this->prop('customFields', array());
  60. $urlParams = $this->prop('urlParams', '');
  61. global $lang;
  62. if($canGlobal)
  63. {
  64. global $app;
  65. $app->loadLang('datatable'); // Use lang->datatable->setGlobal variable.
  66. }
  67. $customLink = createLink('custom', 'ajaxSaveCustomFields', $urlParams);
  68. $cancelLink = createLink('custom', 'ajaxGetCustomFields', $urlParams);
  69. return dropdown
  70. (
  71. set::arrow('false'),
  72. set::placement('bottom-end'),
  73. set::id('formSettingBtn'),
  74. to::trigger(btn(set::icon('cog-outline'), $text, setClass('ghost'), set::caret(false))),
  75. to::menu(menu
  76. (
  77. setClass('dropdown-menu'),
  78. on::click('e.stopPropagation();'),
  79. formpanel
  80. (
  81. setClass('form-setting-btn'),
  82. set::title($lang->customField),
  83. set::url($customLink),
  84. set::showExtra(false),
  85. set::actions(array
  86. (
  87. $canGlobal ? checkList(set::name('global'), setClass('whitespace-nowrap'), set::style(array('padding' => 0)), set::inline(true), set::items(array(array('text' => $lang->datatable->setGlobal, 'value' => '1')))) : null,
  88. btn(set::text($lang->save), setClass('primary'), on::click('onSubmitFormtSetting'), $submitCallback ? on::click($submitCallback) : null),
  89. $noCancel ? null : btn(set::text($lang->cancel), set::btnType('button'), on::click('cancelFormSetting'), set('data-url', $cancelLink)),
  90. btn(set::text($lang->restore), setClass('text-primary ghost'), set('data-url', $customLink), on::click('revertDefaultFields'), $restoreCallback ? on::click($restoreCallback) : null)
  91. )),
  92. to::headingActions(array
  93. (
  94. btn(set::icon('close'), setClass('ghost'), set::size('sm'), on::click('closeCustomPopupMenu'))
  95. )),
  96. $this->buildCustomFields($customFields)
  97. )
  98. ))
  99. );
  100. }
  101. }