Changeset View
Changeset View
Standalone View
Standalone View
src/view/form/control/PhabricatorRemarkupControl.php
<?php | <?php | ||||
final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { | final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { | ||||
private $disableMacro = false; | private $disableMacro = false; | ||||
private $disableFullScreen = false; | private $disableFullScreen = false; | ||||
private $canPin; | private $canPin; | ||||
private $sendOnEnter = false; | private $sendOnEnter = false; | ||||
private $remarkupMetadata = array(); | |||||
public function setDisableMacros($disable) { | public function setDisableMacros($disable) { | ||||
$this->disableMacro = $disable; | $this->disableMacro = $disable; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setDisableFullScreen($disable) { | public function setDisableFullScreen($disable) { | ||||
$this->disableFullScreen = $disable; | $this->disableFullScreen = $disable; | ||||
Show All 13 Lines | public function setSendOnEnter($soe) { | ||||
$this->sendOnEnter = $soe; | $this->sendOnEnter = $soe; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getSendOnEnter() { | public function getSendOnEnter() { | ||||
return $this->sendOnEnter; | return $this->sendOnEnter; | ||||
} | } | ||||
public function getRemarkupCorpusControlName() { | |||||
return $this->getName(); | |||||
} | |||||
public function getRemarkupMetadataControlName() { | |||||
return $this->getRemarkupCorpusControlName().'__metadata'; | |||||
} | |||||
public function setRemarkupMetadata(array $value) { | |||||
$this->remarkupMetadata = $value; | |||||
return $this; | |||||
} | |||||
public function getRemarkupMetadata() { | |||||
return $this->remarkupMetadata; | |||||
} | |||||
protected function renderInput() { | protected function renderInput() { | ||||
$id = $this->getID(); | $id = $this->getID(); | ||||
if (!$id) { | if (!$id) { | ||||
$id = celerity_generate_unique_node_id(); | $id = celerity_generate_unique_node_id(); | ||||
$this->setID($id); | $this->setID($id); | ||||
} | } | ||||
$viewer = $this->getUser(); | $viewer = $this->getUser(); | ||||
if (!$viewer) { | if (!$viewer) { | ||||
throw new PhutilInvalidStateException('setUser'); | throw new PhutilInvalidStateException('setUser'); | ||||
} | } | ||||
// NOTE: Metadata is passed to Javascript in a structured way, and also | |||||
// dumped directly into the form as an encoded string. This makes it less | |||||
// likely that we'll lose server-provided metadata (for example, from a | |||||
// saved draft) if there is a client-side error. | |||||
$metadata_value = (object)$this->getRemarkupMetadata(); | |||||
$metadata_string = phutil_json_encode($metadata_value); | |||||
$metadata_id = celerity_generate_unique_node_id(); | |||||
$metadata_input = phutil_tag( | |||||
'input', | |||||
array( | |||||
'type' => 'hidden', | |||||
'id' => $metadata_id, | |||||
'name' => $this->getRemarkupMetadataControlName(), | |||||
'value' => $metadata_string, | |||||
)); | |||||
// We need to have this if previews render images, since Ajax can not | // We need to have this if previews render images, since Ajax can not | ||||
// currently ship JS or CSS. | // currently ship JS or CSS. | ||||
require_celerity_resource('phui-lightbox-css'); | require_celerity_resource('phui-lightbox-css'); | ||||
if (!$this->getDisabled()) { | if (!$this->getDisabled()) { | ||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'aphront-drag-and-drop-textarea', | 'aphront-drag-and-drop-textarea', | ||||
array( | array( | ||||
'target' => $id, | 'target' => $id, | ||||
'remarkupMetadataID' => $metadata_id, | |||||
'remarkupMetadataValue' => $metadata_value, | |||||
'activatedClass' => 'aphront-textarea-drag-and-drop', | 'activatedClass' => 'aphront-textarea-drag-and-drop', | ||||
'uri' => '/file/dropupload/', | 'uri' => '/file/dropupload/', | ||||
'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(), | 'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(), | ||||
)); | )); | ||||
} | } | ||||
$root_id = celerity_generate_unique_node_id(); | $root_id = celerity_generate_unique_node_id(); | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | return javelin_tag( | ||||
array( | array( | ||||
'sigil' => 'remarkup-assist-control', | 'sigil' => 'remarkup-assist-control', | ||||
'class' => $this->getDisabled() ? 'disabled-control' : null, | 'class' => $this->getDisabled() ? 'disabled-control' : null, | ||||
'id' => $root_id, | 'id' => $root_id, | ||||
), | ), | ||||
array( | array( | ||||
$buttons, | $buttons, | ||||
parent::renderInput(), | parent::renderInput(), | ||||
$metadata_input, | |||||
)); | )); | ||||
} | } | ||||
} | } |