3 final class PholioInlineController
extends PholioController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
10 $inline = id(new PholioTransactionComment())->load($id);
13 return new Aphront404Response();
16 if ($inline->getTransactionPHID()) {
19 if ($inline->getAuthorPHID() == $viewer->getPHID()) {
22 return new Aphront404Response();
26 $mock = id(new PholioMockQuery())
28 ->withIDs(array($request->getInt('mockID')))
32 return new Aphront404Response();
35 $inline = id(new PholioTransactionComment())
36 ->setImageID($request->getInt('imageID'))
37 ->setX($request->getInt('startX'))
38 ->setY($request->getInt('startY'))
39 ->setCommentVersion(1)
40 ->setAuthorPHID($viewer->getPHID())
41 ->setEditPolicy($viewer->getPHID())
42 ->setViewPolicy(PhabricatorPolicies
::POLICY_PUBLIC
)
43 ->setContentSourceFromRequest($request)
44 ->setWidth($request->getInt('endX') - $request->getInt('startX'))
45 ->setHeight($request->getInt('endY') - $request->getInt('startY'));
50 $v_content = $inline->getContent();
52 // TODO: Not correct, but we don't always have a mock right now.
55 if ($mode == 'view') {
56 require_celerity_resource('pholio-inline-comments-css');
57 $image = id(new PholioImageQuery())
59 ->withIDs(array($inline->getImageID()))
62 $handles = $this->loadViewerHandles(array($inline->getAuthorPHID()));
63 $author_handle = $handles[$inline->getAuthorPHID()];
65 $file = $image->getFile();
66 if (!$file->isViewableImage()) {
67 throw new Exception(pht('File is not viewable.'));
70 $image_uri = $file->getBestURI();
72 $thumb = id(new PHUIImageMaskView())
74 ->setImage($image_uri)
75 ->setDisplayHeight(200)
76 ->setDisplayWidth(498)
79 $inline->getX(), $inline->getY(),
80 $inline->getHeight(), $inline->getWidth());
82 $comment_head = phutil_tag(
85 'class' => 'pholio-inline-comment-head',
87 $author_handle->renderLink());
89 $inline_content = new PHUIRemarkupView($viewer, $inline->getContent());
90 $comment_body = phutil_tag(
93 'class' => 'pholio-inline-comment-body',
97 return $this->newDialog()
98 ->setTitle(pht('Inline Comment'))
100 ->appendChild($comment_head)
101 ->appendChild($comment_body)
102 ->addCancelButton($mock_uri, pht('Close'));
105 if ($request->isFormPost()) {
106 $v_content = $request->getStr('content');
108 if (strlen($v_content)) {
109 $inline->setContent($v_content);
111 $dictionary = $inline->toDictionary();
112 } else if ($inline->getID()) {
114 $dictionary = array();
117 return id(new AphrontAjaxResponse())->setContent($dictionary);
122 $title = pht('Edit Inline Comment');
123 $submit_text = pht('Save Draft');
126 $title = pht('New Inline Comment');
127 $submit_text = pht('Save Draft');
131 $form = id(new AphrontFormView())
134 if ($mode == 'new') {
136 'mockID' => $request->getInt('mockID'),
137 'imageID' => $request->getInt('imageID'),
138 'startX' => $request->getInt('startX'),
139 'startY' => $request->getInt('startY'),
140 'endX' => $request->getInt('endX'),
141 'endY' => $request->getInt('endY'),
143 foreach ($params as $key => $value) {
144 $form->addHiddenInput($key, $value);
150 id(new PhabricatorRemarkupControl())
153 ->setLabel(pht('Comment'))
154 ->setValue($v_content));
156 return $this->newDialog()
158 ->setWidth(AphrontDialogView
::WIDTH_FORM
)
159 ->appendChild($form->buildLayoutView())
160 ->addCancelButton($mock_uri)
161 ->addSubmitButton($submit_text);