1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 13:30:55 +01:00

Give "RemarkupControl" support for tracking metadata

Summary: Ref T13603. This will support explicit handling of attached files.

Test Plan: Adjusted new input to have "text" input type, used it alongside additional upcoming changes, saw sensible metadata behavior.

Maniphest Tasks: T13603

Differential Revision: https://secure.phabricator.com/D21827
This commit is contained in:
epriestley 2022-05-19 11:18:52 -07:00
parent 147b48b934
commit 33a0731619
3 changed files with 58 additions and 9 deletions

View file

@ -13,7 +13,7 @@ return array(
'core.pkg.js' => 'd2de90d9',
'dark-console.pkg.js' => '187792c2',
'differential.pkg.css' => 'ffb69e3d',
'differential.pkg.js' => '8deec4cd',
'differential.pkg.js' => 'e31329dc',
'diffusion.pkg.css' => '42c75c37',
'diffusion.pkg.js' => '78c9885d',
'maniphest.pkg.css' => '35995d6d',
@ -473,7 +473,7 @@ return array(
'rsrc/js/core/behavior-copy.js' => 'cf32921f',
'rsrc/js/core/behavior-detect-timezone.js' => '78bc5d94',
'rsrc/js/core/behavior-device.js' => 'ac2b1e01',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '7ad020a5',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '7df68a45',
'rsrc/js/core/behavior-fancy-datepicker.js' => '36821f8d',
'rsrc/js/core/behavior-form.js' => '55d7b788',
'rsrc/js/core/behavior-gesture.js' => 'b58d1a2a',
@ -589,7 +589,7 @@ return array(
'javelin-behavior-aphlict-listen' => '4e61fa88',
'javelin-behavior-aphlict-status' => 'c3703a16',
'javelin-behavior-aphront-basic-tokenizer' => '3b4899b0',
'javelin-behavior-aphront-drag-and-drop-textarea' => '7ad020a5',
'javelin-behavior-aphront-drag-and-drop-textarea' => '7df68a45',
'javelin-behavior-aphront-form-disable-on-submit' => '55d7b788',
'javelin-behavior-aphront-more' => '506aa3f4',
'javelin-behavior-audio-source' => '3dc5ad43',
@ -1604,12 +1604,6 @@ return array(
'javelin-install',
'javelin-dom',
),
'7ad020a5' => array(
'javelin-behavior',
'javelin-dom',
'phabricator-drag-and-drop-file-upload',
'phabricator-textareautils',
),
'7b139193' => array(
'javelin-behavior',
'javelin-stratcom',
@ -1620,6 +1614,13 @@ return array(
'javelin-install',
'javelin-dom',
),
'7df68a45' => array(
'javelin-behavior',
'javelin-dom',
'javelin-json',
'phabricator-drag-and-drop-file-upload',
'phabricator-textareautils',
),
'80bff3af' => array(
'javelin-install',
'javelin-typeahead-source',

View file

@ -6,6 +6,7 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
private $disableFullScreen = false;
private $canPin;
private $sendOnEnter = false;
private $remarkupMetadata = array();
public function setDisableMacros($disable) {
$this->disableMacro = $disable;
@ -35,6 +36,15 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
return $this->sendOnEnter;
}
public function setRemarkupMetadata(array $value) {
$this->remarkupMetadata = $value;
return $this;
}
public function getRemarkupMetadata() {
return $this->remarkupMetadata;
}
protected function renderInput() {
$id = $this->getID();
if (!$id) {
@ -47,6 +57,25 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
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_name = $this->getName().'_metadata';
$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' => $metadata_name,
'value' => $metadata_string,
));
// We need to have this if previews render images, since Ajax can not
// currently ship JS or CSS.
require_celerity_resource('phui-lightbox-css');
@ -56,6 +85,8 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
'aphront-drag-and-drop-textarea',
array(
'target' => $id,
'remarkupMetadataID' => $metadata_id,
'remarkupMetadataValue' => $metadata_value,
'activatedClass' => 'aphront-textarea-drag-and-drop',
'uri' => '/file/dropupload/',
'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(),
@ -353,6 +384,7 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
array(
$buttons,
parent::renderInput(),
$metadata_input,
));
}

View file

@ -2,6 +2,7 @@
* @provides javelin-behavior-aphront-drag-and-drop-textarea
* @requires javelin-behavior
* javelin-dom
* javelin-json
* phabricator-drag-and-drop-file-upload
* phabricator-textareautils
*/
@ -10,6 +11,21 @@ JX.behavior('aphront-drag-and-drop-textarea', function(config) {
var target = JX.$(config.target);
var metadata_node = JX.$(config.remarkupMetadataID);
var metadata_value = config.remarkupMetadataValue;
function set_metadata(key, value) {
metadata_value[key] = value;
metadata_node.value = JX.JSON.stringify(metadata_value);
}
function get_metadata(key, default_value) {
if (metadata_value.hasOwnProperty(key)) {
return metadata_value[key];
}
return default_value;
}
if (JX.PhabricatorDragAndDropFileUpload.isSupported()) {
var drop = new JX.PhabricatorDragAndDropFileUpload(target)
.setURI(config.uri)