v1.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'section' . DS . 'v1.php';
  4. class fileList extends wg
  5. {
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array(
  10. 'files?:array',
  11. 'fieldset?:bool=true',
  12. 'method?:string="view"',
  13. 'showDelete?:bool=false',
  14. 'showEdit?:bool=false',
  15. 'extra?:string=""',
  16. 'fileTitle?:string=""',
  17. 'object?:object',
  18. 'padding?:bool=true',
  19. 'objectType?:string=""',
  20. 'objectID?: int'
  21. );
  22. public static function getPageCSS()
  23. {
  24. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  25. }
  26. public static function getPageJS()
  27. {
  28. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  29. }
  30. private function fileList()
  31. {
  32. global $app;
  33. $files = $this->prop('files');
  34. $method = $this->prop('method');
  35. $showDelete = $this->prop('showDelete');
  36. $showEdit = $this->prop('showEdit');
  37. $extra = $this->prop('extra');
  38. $object = (object)$this->prop('object');
  39. $fileListView = h::ul(setClass('files-list col relative'));
  40. foreach($files as $file)
  41. {
  42. if($extra && $file->extra != $extra) continue;
  43. $fileItemView = html($app->loadTarget('file')->printFile($file, $method, $showDelete, $showEdit, $object));
  44. $fileListView->add($fileItemView);
  45. }
  46. return $fileListView;
  47. }
  48. protected function build()
  49. {
  50. global $lang;
  51. $fieldset = $this->prop('fieldset');
  52. $isInModal = isAjaxRequest('modal');
  53. $px = $isInModal ? 'px-3' : 'px-6';
  54. $pb = $isInModal ? 'pb-3' : 'pb-6';
  55. $method = $this->prop('method');
  56. $showDelete = $this->prop('showDelete');
  57. $objectType = $this->prop('objectType');
  58. $objectID = $this->prop('objectID');
  59. $fileDiv = div
  60. (
  61. set
  62. (
  63. array(
  64. 'data-method' => $method,
  65. 'data-showDelete' => $showDelete,
  66. 'data-session' => session_name() . '=' . session_id(),
  67. 'data-objectType' => $objectType,
  68. 'data-objectID' => $objectID
  69. )
  70. ),
  71. $this->fileList()
  72. );
  73. $fileTitle = $this->prop('fileTitle') ? $this->prop('fileTitle') : $lang->files;
  74. return $fieldset ? new section
  75. (
  76. setClass('files', 'pt-4', 'canvas'),
  77. $this->prop('padding') ? setClass($px, $pb) : null,
  78. set::title($fileTitle),
  79. set($this->getRestProps()),
  80. to::actions
  81. (
  82. icon('paper-clip ml-1')
  83. ),
  84. $fileDiv
  85. ) : $fileDiv;
  86. }
  87. }