1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Stop using forms to download files in file embed and lightbox elements

Summary: Depends on D19156. Ref T13094. This replaces the remaining forms in the file embed view and lightbox with normal download links.

Test Plan: Clicked "Download" and lightbox -> download for embedded files.

Maniphest Tasks: T13094

Differential Revision: https://secure.phabricator.com/D19157
This commit is contained in:
epriestley 2018-02-28 17:04:40 -08:00
parent ab579f2511
commit a2fdf14275
4 changed files with 47 additions and 86 deletions

View file

@ -10,7 +10,7 @@ return array(
'conpherence.pkg.css' => 'e68cf1fa', 'conpherence.pkg.css' => 'e68cf1fa',
'conpherence.pkg.js' => '15191c65', 'conpherence.pkg.js' => '15191c65',
'core.pkg.css' => '2fa91e14', 'core.pkg.css' => '2fa91e14',
'core.pkg.js' => 'e7ce7bba', 'core.pkg.js' => 'a3ceffdb',
'darkconsole.pkg.js' => '1f9a31bc', 'darkconsole.pkg.js' => '1f9a31bc',
'differential.pkg.css' => '113e692c', 'differential.pkg.css' => '113e692c',
'differential.pkg.js' => 'f6d809c0', 'differential.pkg.js' => 'f6d809c0',
@ -494,7 +494,7 @@ return array(
'rsrc/js/core/behavior-hovercard.js' => 'bcaccd64', 'rsrc/js/core/behavior-hovercard.js' => 'bcaccd64',
'rsrc/js/core/behavior-keyboard-pager.js' => 'a8da01f0', 'rsrc/js/core/behavior-keyboard-pager.js' => 'a8da01f0',
'rsrc/js/core/behavior-keyboard-shortcuts.js' => '01fca1f0', 'rsrc/js/core/behavior-keyboard-shortcuts.js' => '01fca1f0',
'rsrc/js/core/behavior-lightbox-attachments.js' => '560f41da', 'rsrc/js/core/behavior-lightbox-attachments.js' => 'e31fad01',
'rsrc/js/core/behavior-line-linker.js' => '1499a8cb', 'rsrc/js/core/behavior-line-linker.js' => '1499a8cb',
'rsrc/js/core/behavior-more.js' => 'a80d0378', 'rsrc/js/core/behavior-more.js' => 'a80d0378',
'rsrc/js/core/behavior-object-selector.js' => '77c1f0b0', 'rsrc/js/core/behavior-object-selector.js' => '77c1f0b0',
@ -642,7 +642,7 @@ return array(
'javelin-behavior-history-install' => '7ee2b591', 'javelin-behavior-history-install' => '7ee2b591',
'javelin-behavior-icon-composer' => '8499b6ab', 'javelin-behavior-icon-composer' => '8499b6ab',
'javelin-behavior-launch-icon-composer' => '48086888', 'javelin-behavior-launch-icon-composer' => '48086888',
'javelin-behavior-lightbox-attachments' => '560f41da', 'javelin-behavior-lightbox-attachments' => 'e31fad01',
'javelin-behavior-line-chart' => 'e4232876', 'javelin-behavior-line-chart' => 'e4232876',
'javelin-behavior-load-blame' => '42126667', 'javelin-behavior-load-blame' => '42126667',
'javelin-behavior-maniphest-batch-selector' => 'ad54037e', 'javelin-behavior-maniphest-batch-selector' => 'ad54037e',
@ -1359,15 +1359,6 @@ return array(
'javelin-vector', 'javelin-vector',
'javelin-dom', 'javelin-dom',
), ),
'560f41da' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-dom',
'javelin-mask',
'javelin-util',
'phuix-icon-view',
'phabricator-busy',
),
'58dea2fa' => array( '58dea2fa' => array(
'javelin-install', 'javelin-install',
'javelin-util', 'javelin-util',
@ -2070,6 +2061,15 @@ return array(
'javelin-dom', 'javelin-dom',
'phabricator-draggable-list', 'phabricator-draggable-list',
), ),
'e31fad01' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-dom',
'javelin-mask',
'javelin-util',
'phuix-icon-view',
'phabricator-busy',
),
'e379b58e' => array( 'e379b58e' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-stratcom', 'javelin-stratcom',

View file

@ -134,21 +134,13 @@ final class PhabricatorFileLinkView extends AphrontTagView {
$dl_icon = id(new PHUIIconView()) $dl_icon = id(new PHUIIconView())
->setIcon('fa-download'); ->setIcon('fa-download');
$download_form = phabricator_form( $download_link = phutil_tag(
$this->getViewer(), 'a',
array(
'action' => $this->getFileDownloadURI(),
'method' => 'POST',
'class' => 'embed-download-form',
'sigil' => 'embed-download-form download',
),
phutil_tag(
'button',
array( array(
'class' => 'phabricator-remarkup-embed-layout-download', 'class' => 'phabricator-remarkup-embed-layout-download',
'type' => 'submit', 'href' => $this->getFileDownloadURI(),
), ),
pht('Download'))); pht('Download'));
$info = phutil_tag( $info = phutil_tag(
'span', 'span',
@ -177,7 +169,7 @@ final class PhabricatorFileLinkView extends AphrontTagView {
return array( return array(
$icon, $icon,
$inner, $inner,
$download_form, $download_link,
); );
} }
} }

View file

@ -279,35 +279,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
} }
} }
$icon = id(new PHUIIconView()) Javelin::initBehavior('lightbox-attachments');
->setIcon('fa-download')
->addClass('phui-icon-circle-icon');
$lightbox_id = celerity_generate_unique_node_id();
$download_form = phabricator_form(
$user,
array(
'action' => '#',
'method' => 'POST',
'class' => 'lightbox-download-form',
'sigil' => 'download lightbox-download-submit',
'id' => 'lightbox-download-form',
),
phutil_tag(
'a',
array(
'class' => 'lightbox-download phui-icon-circle hover-green',
'href' => '#',
),
array(
$icon,
)));
Javelin::initBehavior(
'lightbox-attachments',
array(
'lightbox_id' => $lightbox_id,
'downloadForm' => $download_form,
));
} }
Javelin::initBehavior('aphront-form-disable-on-submit'); Javelin::initBehavior('aphront-form-disable-on-submit');

View file

@ -9,19 +9,18 @@
* phabricator-busy * phabricator-busy
*/ */
JX.behavior('lightbox-attachments', function (config) { JX.behavior('lightbox-attachments', function() {
var lightbox = null; var lightbox = null;
var prev = null; var prev = null;
var next = null; var next = null;
var shown = false; var shown = false;
var downloadForm = JX.$H(config.downloadForm).getFragment().firstChild;
var lightbox_id = config.lightbox_id;
function _toggleComment(e) { function _toggleComment(e) {
e.kill(); e.kill();
shown = !shown; shown = !shown;
JX.DOM.alterClass(JX.$(lightbox_id), 'comment-panel-open', shown); JX.DOM.alterClass(lightbox, 'comment-panel-open', shown);
} }
function markCommentsLoading(loading) { function markCommentsLoading(loading) {
@ -48,6 +47,12 @@ JX.behavior('lightbox-attachments', function (config) {
return; return;
} }
// If you click the "Download" link inside an embedded file element,
// don't lightbox the file.
if (e.getNode('tag:a')) {
return;
}
e.kill(); e.kill();
var mainFrame = JX.$('main-page-frame'); var mainFrame = JX.$('main-page-frame');
@ -82,8 +87,7 @@ JX.behavior('lightbox-attachments', function (config) {
var img_uri = ''; var img_uri = '';
var img = ''; var img = '';
var extra_status = ''; var extra_status = '';
// for now, this conditional is always true
// revisit if / when we decide to add non-images to lightbox view
if (target_data.viewable) { if (target_data.viewable) {
img_uri = target_data.uri; img_uri = target_data.uri;
var alt_name = ''; var alt_name = '';
@ -114,7 +118,7 @@ JX.behavior('lightbox-attachments', function (config) {
{ {
className : 'lightbox-icon-frame', className : 'lightbox-icon-frame',
sigil : 'lightbox-download-submit', sigil : 'lightbox-download-submit',
href : '#', href : target_data.dUri,
}, },
[ imgIcon, nameElement ] [ imgIcon, nameElement ]
); );
@ -138,12 +142,12 @@ JX.behavior('lightbox-attachments', function (config) {
); );
var commentClass = (shown) ? 'comment-panel-open' : ''; var commentClass = (shown) ? 'comment-panel-open' : '';
lightbox = lightbox =
JX.$N('div', JX.$N('div',
{ {
className : 'lightbox-attachment ' + commentClass, className : 'lightbox-attachment ' + commentClass,
sigil : 'lightbox-attachment', sigil : 'lightbox-attachment'
id : lightbox_id
}, },
[imgFrame, commentFrame] [imgFrame, commentFrame]
); );
@ -161,12 +165,17 @@ JX.behavior('lightbox-attachments', function (config) {
] ]
); );
var downloadSpan = var download_icon = new JX.PHUIXIconView()
JX.$N('span', .setIcon('fa-download phui-icon-circle-icon')
.getNode();
var download_button = JX.$N(
'a',
{ {
className : 'lightbox-download' className: 'lightbox-download phui-icon-circle hover-sky',
} href: target_data.dUri
); },
download_icon);
var commentIcon = new JX.PHUIXIconView() var commentIcon = new JX.PHUIXIconView()
.setIcon('fa-comments phui-icon-circle-icon') .setIcon('fa-comments phui-icon-circle-icon')
@ -180,6 +189,7 @@ JX.behavior('lightbox-attachments', function (config) {
}, },
commentIcon commentIcon
); );
var closeIcon = new JX.PHUIXIconView() var closeIcon = new JX.PHUIXIconView()
.setIcon('fa-times phui-icon-circle-icon') .setIcon('fa-times phui-icon-circle-icon')
.getNode(); .getNode();
@ -190,12 +200,13 @@ JX.behavior('lightbox-attachments', function (config) {
href : '#' href : '#'
}, },
closeIcon); closeIcon);
var statusHTML = var statusHTML =
JX.$N('div', JX.$N('div',
{ {
className : 'lightbox-status' className : 'lightbox-status'
}, },
[statusSpan, closeButton, commentButton, downloadSpan] [statusSpan, closeButton, commentButton, download_button]
); );
JX.DOM.appendContent(lightbox, statusHTML); JX.DOM.appendContent(lightbox, statusHTML);
JX.DOM.listen(closeButton, 'click', null, closeLightBox); JX.DOM.listen(closeButton, 'click', null, closeLightBox);
@ -246,9 +257,6 @@ JX.behavior('lightbox-attachments', function (config) {
JX.DOM.alterClass(document.body, 'lightbox-attached', true); JX.DOM.alterClass(document.body, 'lightbox-attached', true);
JX.Mask.show('jx-dark-mask'); JX.Mask.show('jx-dark-mask');
downloadForm.action = target_data.dUri;
downloadSpan.appendChild(downloadForm);
document.body.appendChild(lightbox); document.body.appendChild(lightbox);
if (img_uri) { if (img_uri) {
@ -365,23 +373,12 @@ JX.behavior('lightbox-attachments', function (config) {
'lightbox-comment-form', 'lightbox-comment-form',
_sendMessage); _sendMessage);
var _startDownload = function(e) {
e.kill();
var form = JX.$('lightbox-download-form');
form.submit();
};
var _startPageDownload = function(e) { var _startPageDownload = function(e) {
e.kill(); e.kill();
var form = e.getNode('tag:form'); var form = e.getNode('tag:form');
form.submit(); form.submit();
}; };
JX.Stratcom.listen(
'click',
'lightbox-download-submit',
_startDownload);
JX.Stratcom.listen( JX.Stratcom.listen(
'click', 'click',
'embed-download-form', 'embed-download-form',