v1.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace zin;
  3. class deliverable extends wg
  4. {
  5. /**
  6. * 默认的组件属性。
  7. * Define widget properties.
  8. *
  9. * @var array
  10. * @access protected
  11. */
  12. protected static $defineProps = array
  13. (
  14. 'items: array', // 交付物条目。
  15. 'formName: string', // 表单名称。
  16. 'maxFileSize: string' // 最大文件大小。
  17. );
  18. /**
  19. * 获取JS。
  20. * Get page JS.
  21. *
  22. * @static
  23. * @access public
  24. * @return string
  25. */
  26. public static function getPageJS()
  27. {
  28. global $lang, $app;
  29. $app->loadLang('doc');
  30. $app->loadLang('deliverable');
  31. jsVar('createByTemplate', $lang->deliverable->createByTemplate);
  32. jsVar('createDoc', $lang->doc->create);
  33. jsVar('uploadFile', $lang->doc->uploadFile);
  34. jsVar('deleteItem', $lang->delete);
  35. jsVar('otherLang', $lang->other);
  36. jsVar('canDownload', hasPriv('file', 'download'));
  37. jsVar('canCreateDoc', hasPriv('doc', 'create'));
  38. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  39. }
  40. /**
  41. * 获取CSS。
  42. * Get page CSS.
  43. *
  44. * @static
  45. * @access public
  46. * @return string
  47. */
  48. public static function getPageCss()
  49. {
  50. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  51. }
  52. /**
  53. * 构建组件。
  54. * Build.
  55. *
  56. * @access protected
  57. * @return zui
  58. */
  59. protected function build()
  60. {
  61. global $lang, $app;
  62. $app->loadLang('doc');
  63. $app->loadLang('file');
  64. $app->loadLang('deliverable');
  65. $formName = $this->prop('formName') ? $this->prop('formName') : 'deliverable';
  66. $isTemplate = $this->prop('isTemplate') ? $this->prop('isTemplate') : false;
  67. $onlyShow = $this->prop('onlyShow') ? $this->prop('onlyShow') : false;
  68. $extraCategory = $this->prop('extraCategory') ? $this->prop('extraCategory') : array_column($this->prop('items'), 'category');
  69. $categories = $this->prop('categories');
  70. $projectID = $this->prop('projectID');
  71. $createDocUrl = $this->prop('createDocUrl');
  72. $uploadDocUrl = $this->prop('uploadDocUrl');
  73. jsVar('addFile', $isTemplate ? $lang->deliverable->files : $lang->doc->addFile);
  74. jsVar('createDocUrl', $createDocUrl);
  75. jsVar('uploadDocUrl', $uploadDocUrl);
  76. jsVar('isTemplate', $isTemplate);
  77. jsVar('onlyShow', $onlyShow);
  78. if(!$this->hasProp('maxFileSize'))
  79. {
  80. $maxFileSize = ini_get('upload_max_filesize');
  81. $lastChar = substr($maxFileSize, -1);
  82. $fileSizeUnit = array('K', 'M', 'G', 'T');
  83. if(in_array($lastChar, $fileSizeUnit)) $maxFileSize .= 'B';
  84. $this->setProp('maxFileSize', $maxFileSize);
  85. }
  86. $selectDocTips = $isTemplate ? $lang->deliverable->selectDoc : $lang->deliverable->selectDocInProject;
  87. $docLink = $isTemplate ? helper::createLink('doc', 'ajaxGetTemplateDocs', "keyword={search}") : helper::createLink('doc', 'ajaxGetDeliverableDocs', "keyword={search}&projectID={$projectID}");
  88. return zui::deliverableList
  89. (
  90. set::formName($formName),
  91. set::items($this->prop('items')),
  92. set::docPicker(array('placeholder' => $selectDocTips, 'items' => $docLink, 'cache' => false)),
  93. set::getFileActions(jsRaw('window.getDeliverableFileActions')),
  94. set::getDocActions(jsRaw('window.getDocActions')),
  95. set::getEmptyActions(jsRaw('window.getDeliverableActions')),
  96. set::maxFileSize($this->prop('maxFileSize')),
  97. set::isTemplate($isTemplate),
  98. set::extraCategory($extraCategory),
  99. set::categories($categories)
  100. );
  101. }
  102. }