v1.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. require_once dirname(__DIR__) . DS . 'formpanel' . DS . 'v1.php';
  13. require_once dirname(__DIR__) . DS . 'pastedialog' . DS . 'v1.php';
  14. /**
  15. * 批量编辑表单面板(formBatchPanel)部件类。
  16. * The batch operate form panel widget class.
  17. *
  18. * @author Hao Sun
  19. */
  20. class formBatchPanel extends formPanel
  21. {
  22. /**
  23. * Define widget properties.
  24. *
  25. * @var array
  26. * @access protected
  27. */
  28. protected static $defineProps = array(
  29. 'uploadParams?: string|false', // 多图上传的参数,如果设置为 `false` 则不显示按钮
  30. 'pasteField?: string|false', // 多行录入的字段名,如果设置为 `false` 则不显示按钮
  31. 'items?: array[]', // 使用一个列定义对象数组来定义批量表单项。
  32. 'minRows?: int', // 最小显示的行数目。
  33. 'maxRows?: int', // 最多显示的行数目。
  34. 'data?: array[]', // 初始化行数据。
  35. 'mode?: string', // 批量操作模式,可以为 `'add'`(批量添加) 或 `'edit'`(批量编辑)。
  36. 'actionsText?: string', // 操作列头部文本,如果不指定则使用 `$lang->actions` 的值。
  37. 'addRowIcon?: string|false', // 添加行的图标,如果设置为 `false` 则不显示图标
  38. 'deleteRowIcon?: string|false', // 删除行的图标,如果设置为 `false` 则不显示图标
  39. 'sortRowIcon?: string|false', // 排序行的图标,如果设置为 `false` 则不显示图标
  40. 'sortable?: boo|array', // 排序配置,设置为 false 不启用排序,设置为 true 使用默认排序
  41. 'onRenderRow?: function', // 渲染行时的回调函数。
  42. 'onRenderRowCol?: function', // 渲染列时的回调函数。
  43. 'batchFormOptions?: array' // 批量表单选项。
  44. );
  45. public static function getPageCSS()
  46. {
  47. return <<<'CSS'
  48. .panel-form-batch {margin: 0 auto; padding-bottom: 0}
  49. .panel-form-batch > .panel-heading {padding-left: 0; padding-right: 0}
  50. .panel-form-batch > .panel-body {position: relative; padding: 0; margin: 0 -16px}
  51. .panel-form-batch .form {gap: 0}
  52. .panel-form-batch .form-batch-container {max-height: calc(100vh - 214px); padding: 0 16px 16px; flex: auto; min-height: 0; overflow: auto}
  53. .panel-form-batch .page-has-mainNavbar .form-batch-container {max-height: calc(100vh - 258px)}
  54. .panel-form-batch .form-actions {left: 0; position: static; flex: none; padding: 24px 0; border-top: 1px solid var(--color-border)}
  55. .modal-body .panel-form-batch .form-batch-container {max-height: calc(100vh - 208px);}
  56. .modal-body > .panel-form-batch {box-shadow: none; margin-top: -12px; margin-bottom: -24px}
  57. .modal-actions + .modal-body > .panel-form-batch > .panel-heading {padding-right: 20px; background: var(--color-canvas); position: sticky; top: -12px; z-index: 12}
  58. CSS;
  59. }
  60. /**
  61. * Define default properties.
  62. *
  63. * @var array
  64. * @access protected
  65. */
  66. protected static $defaultProps = array(
  67. 'class' => 'panel-form panel-form-batch',
  68. 'uploadParams' => false,
  69. 'pasteField' => false,
  70. 'customFields' => array(),
  71. 'batch' => true,
  72. 'shadow' => true
  73. );
  74. protected function getHeadingActions()
  75. {
  76. global $lang;
  77. $actions = parent::getHeadingActions();
  78. $uploadImage = $this->prop('uploadParams') && hasPriv('file', 'uploadImages');
  79. $pasteField = $this->prop('pasteField');
  80. /* Multi-input. */
  81. if($pasteField)
  82. {
  83. array_unshift($actions, array('class' => 'btn primary-pale mr-2', 'data-toggle' => 'modal', 'data-target' => '#paste-dialog', 'text' => $lang->pasteText, 'data-backdrop' => 'static'));
  84. $headingActionsBlock = $this->block('headingActions');
  85. if(empty($headingActionsBlock) || array_every($headingActionsBlock, function($item){return !($item instanceof pasteDialog);}))
  86. {
  87. $this->addToBlock('headingActions', new pasteDialog(set::field($pasteField)));
  88. }
  89. }
  90. /* Upload images. */
  91. if($uploadImage) array_unshift($actions, array('url' => createLink('file', 'uploadImages', $this->prop('uploadParams')), 'class' => 'btn primary-pale mr-4', 'data-toggle' => 'modal', 'data-width' => '0.7', 'text' => $lang->uploadImages));
  92. return $actions;
  93. }
  94. public function children()
  95. {
  96. $children = parent::children();
  97. $children[] = on::init()->do('$element.toggleClass("page-has-mainNavbar", !!$("#mainNavbar").length && !$element.closest(".modal-body").length)');
  98. return $children;
  99. }
  100. }