@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 119 lines 2.7 kB view raw
1<?php 2 3/** 4 * Render a simple preview panel for a bound Remarkup text control. 5 */ 6final class PHUIRemarkupPreviewPanel extends AphrontTagView { 7 8 private $header; 9 private $loadingText; 10 private $controlID; 11 private $previewURI; 12 private $previewType; 13 14 const DOCUMENT = 'document'; 15 16 protected function canAppendChild() { 17 return false; 18 } 19 20 public function setPreviewURI($preview_uri) { 21 $this->previewURI = $preview_uri; 22 return $this; 23 } 24 25 public function setControlID($control_id) { 26 $this->controlID = $control_id; 27 return $this; 28 } 29 30 public function setHeader($header) { 31 $this->header = $header; 32 return $this; 33 } 34 35 public function setLoadingText($loading_text) { 36 $this->loadingText = $loading_text; 37 return $this; 38 } 39 40 public function setPreviewType($type) { 41 $this->previewType = $type; 42 return $this; 43 } 44 45 protected function getTagName() { 46 return 'div'; 47 } 48 49 protected function getTagAttributes() { 50 $classes = array(); 51 $classes[] = 'phui-remarkup-preview'; 52 53 return array( 54 'class' => $classes, 55 ); 56 } 57 58 protected function getTagContent() { 59 if ($this->previewURI === null) { 60 throw new PhutilInvalidStateException('setPreviewURI'); 61 } 62 if ($this->controlID === null) { 63 throw new PhutilInvalidStateException('setControlID'); 64 } 65 66 $preview_id = celerity_generate_unique_node_id(); 67 68 require_celerity_resource('phui-remarkup-preview-css'); 69 Javelin::initBehavior( 70 'remarkup-preview', 71 array( 72 'previewID' => $preview_id, 73 'controlID' => $this->controlID, 74 'uri' => $this->previewURI, 75 )); 76 77 $loading = phutil_tag( 78 'div', 79 array( 80 'class' => 'phui-preview-loading-text', 81 ), 82 nonempty($this->loadingText, pht('Loading preview...'))); 83 84 $preview = phutil_tag( 85 'div', 86 array( 87 'id' => $preview_id, 88 'class' => 'phabricator-remarkup phui-preview-body', 89 ), 90 $loading); 91 92 $content = null; 93 if (!$this->previewType) { 94 $header = null; 95 if ($this->header) { 96 $header = phutil_tag( 97 'div', 98 array( 99 'class' => 'phui-preview-header', 100 ), 101 $this->header); 102 } 103 $content = array($header, $preview); 104 105 } else if ($this->previewType == self::DOCUMENT) { 106 $header = id(new PHUIHeaderView()) 107 ->setHeader(pht('%s (Preview)', $this->header)); 108 109 $content = id(new PHUIDocumentView()) 110 ->setHeader($header) 111 ->appendChild($preview); 112 } 113 114 return id(new PHUIObjectBoxView()) 115 ->appendChild($content) 116 ->setCollapsed(true); 117 } 118 119}