Path: blob/master/src/view/phui/PHUIRemarkupPreviewPanel.php
12249 views
<?php12/**3* Render a simple preview panel for a bound Remarkup text control.4*/5final class PHUIRemarkupPreviewPanel extends AphrontTagView {67private $header;8private $loadingText;9private $controlID;10private $previewURI;11private $previewType;1213const DOCUMENT = 'document';1415protected function canAppendChild() {16return false;17}1819public function setPreviewURI($preview_uri) {20$this->previewURI = $preview_uri;21return $this;22}2324public function setControlID($control_id) {25$this->controlID = $control_id;26return $this;27}2829public function setHeader($header) {30$this->header = $header;31return $this;32}3334public function setLoadingText($loading_text) {35$this->loadingText = $loading_text;36return $this;37}3839public function setPreviewType($type) {40$this->previewType = $type;41return $this;42}4344protected function getTagName() {45return 'div';46}4748protected function getTagAttributes() {49$classes = array();50$classes[] = 'phui-remarkup-preview';5152return array(53'class' => $classes,54);55}5657protected function getTagContent() {58if ($this->previewURI === null) {59throw new PhutilInvalidStateException('setPreviewURI');60}61if ($this->controlID === null) {62throw new PhutilInvalidStateException('setControlID');63}6465$preview_id = celerity_generate_unique_node_id();6667require_celerity_resource('phui-remarkup-preview-css');68Javelin::initBehavior(69'remarkup-preview',70array(71'previewID' => $preview_id,72'controlID' => $this->controlID,73'uri' => $this->previewURI,74));7576$loading = phutil_tag(77'div',78array(79'class' => 'phui-preview-loading-text',80),81nonempty($this->loadingText, pht('Loading preview...')));8283$preview = phutil_tag(84'div',85array(86'id' => $preview_id,87'class' => 'phabricator-remarkup phui-preview-body',88),89$loading);9091if (!$this->previewType) {92$header = null;93if ($this->header) {94$header = phutil_tag(95'div',96array(97'class' => 'phui-preview-header',98),99$this->header);100}101$content = array($header, $preview);102103} else if ($this->previewType == self::DOCUMENT) {104$header = id(new PHUIHeaderView())105->setHeader(pht('%s (Preview)', $this->header));106107$content = id(new PHUIDocumentView())108->setHeader($header)109->appendChild($preview);110}111112return id(new PHUIObjectBoxView())113->appendChild($content)114->setCollapsed(true);115}116117}118119120