Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/view/PhabricatorGlobalUploadTargetView.php
12242 views
1
<?php
2
3
/**
4
* IMPORTANT: If you use this, make sure to implement
5
*
6
* public function isGlobalDragAndDropUploadEnabled() {
7
* return true;
8
* }
9
*
10
* on the controller(s) that render this class...! This is necessary
11
* to make sure Quicksand works properly with the javascript in this
12
* UI.
13
*/
14
final class PhabricatorGlobalUploadTargetView extends AphrontView {
15
16
private $showIfSupportedID;
17
private $hintText;
18
private $viewPolicy;
19
private $submitURI;
20
21
public function setShowIfSupportedID($show_if_supported_id) {
22
$this->showIfSupportedID = $show_if_supported_id;
23
return $this;
24
}
25
26
public function getShowIfSupportedID() {
27
return $this->showIfSupportedID;
28
}
29
30
public function setHintText($hint_text) {
31
$this->hintText = $hint_text;
32
return $this;
33
}
34
35
public function getHintText() {
36
return $this->hintText;
37
}
38
39
public function setViewPolicy($view_policy) {
40
$this->viewPolicy = $view_policy;
41
return $this;
42
}
43
44
public function getViewPolicy() {
45
return $this->viewPolicy;
46
}
47
48
public function setSubmitURI($submit_uri) {
49
$this->submitURI = $submit_uri;
50
return $this;
51
}
52
53
public function getSubmitURI() {
54
return $this->submitURI;
55
}
56
57
58
59
public function render() {
60
$viewer = $this->getViewer();
61
if (!$viewer->isLoggedIn()) {
62
return null;
63
}
64
65
$instructions_id = 'phabricator-global-drag-and-drop-upload-instructions';
66
67
require_celerity_resource('global-drag-and-drop-css');
68
69
$hint_text = $this->getHintText();
70
if ($hint_text === null || !strlen($hint_text)) {
71
$hint_text = "\xE2\x87\xAA ".pht('Drop Files to Upload');
72
}
73
74
// Use the configured default view policy. Drag and drop uploads use
75
// a more restrictive view policy if we don't specify a policy explicitly,
76
// as the more restrictive policy is correct for most drop targets (like
77
// Pholio uploads and Remarkup text areas).
78
79
$view_policy = $this->getViewPolicy();
80
if ($view_policy === null) {
81
$view_policy = PhabricatorFile::initializeNewFile()->getViewPolicy();
82
}
83
84
$submit_uri = $this->getSubmitURI();
85
$done_uri = '/file/query/authored/';
86
87
Javelin::initBehavior('global-drag-and-drop', array(
88
'ifSupported' => $this->showIfSupportedID,
89
'instructions' => $instructions_id,
90
'uploadURI' => '/file/dropupload/',
91
'submitURI' => $submit_uri,
92
'browseURI' => $done_uri,
93
'viewPolicy' => $view_policy,
94
'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(),
95
));
96
97
return phutil_tag(
98
'div',
99
array(
100
'id' => $instructions_id,
101
'class' => 'phabricator-global-upload-instructions',
102
'style' => 'display: none;',
103
),
104
$hint_text);
105
}
106
}
107
108