2013-02-06 20:28:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group pholio
|
|
|
|
*/
|
|
|
|
final class PholioInlineSaveController extends PholioController {
|
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
private $operation;
|
|
|
|
|
|
|
|
public function getOperation() {
|
|
|
|
return $this->operation;
|
|
|
|
}
|
|
|
|
|
2013-02-06 20:28:03 +01:00
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$mock = id(new PholioMockQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($request->getInt('mockID')))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$mock) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
$this->operation = $request->getBool('op');
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
if ($this->getOperation() == 'save') {
|
|
|
|
$new_content = $request->getStr('comment');
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
if (strlen(trim($new_content)) == 0) {
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(array('success' => false));
|
|
|
|
}
|
|
|
|
|
|
|
|
$draft = id(new PholioTransactionComment());
|
|
|
|
$draft->setImageID($request->getInt('imageID'));
|
|
|
|
$draft->setX($request->getInt('startX'));
|
|
|
|
$draft->setY($request->getInt('startY'));
|
|
|
|
|
|
|
|
$draft->setCommentVersion(1);
|
|
|
|
$draft->setAuthorPHID($user->getPHID());
|
|
|
|
$draft->setEditPolicy($user->getPHID());
|
|
|
|
$draft->setViewPolicy(PhabricatorPolicies::POLICY_PUBLIC);
|
|
|
|
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr(),
|
|
|
|
));
|
|
|
|
|
|
|
|
$draft->setContentSource($content_source);
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
$draft->setWidth($request->getInt('endX') - $request->getInt('startX'));
|
|
|
|
$draft->setHeight($request->getInt('endY') - $request->getInt('startY'));
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
$draft->setContent($new_content);
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
$draft->save();
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
$inline_view = id(new PholioInlineCommentView())
|
|
|
|
->setInlineComment($draft)
|
|
|
|
->setEditable(true)
|
|
|
|
->setHandle(
|
|
|
|
PhabricatorObjectHandleData::loadOneHandle($user->getPHID()));
|
2013-02-19 23:12:33 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(array(
|
|
|
|
'success' => true,
|
|
|
|
'phid' => $draft->getPHID(),
|
|
|
|
'contentHTML' => $inline_view->render()
|
|
|
|
));
|
2013-02-19 23:12:33 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
} else {
|
|
|
|
return id(new AphrontRedirectResponse())->setUri('/M'.$mock->getID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dialog = new PholioInlineCommentSaveView();
|
|
|
|
|
|
|
|
$dialog->setUser($user);
|
|
|
|
$dialog->setSubmitURI($request->getRequestURI());
|
|
|
|
|
|
|
|
$dialog->setTitle(pht('Make inline comment'));
|
|
|
|
|
|
|
|
$dialog->addHiddenInput('op', 'save');
|
2013-02-19 23:12:33 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
$dialog->appendChild($this->renderTextArea(''));
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($dialog->render());
|
2013-02-19 23:12:33 +01:00
|
|
|
}
|
2013-02-06 20:28:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
private function renderTextArea($text) {
|
|
|
|
return javelin_tag(
|
|
|
|
'textarea',
|
|
|
|
array(
|
|
|
|
'class' => 'pholio-inline-comment-dialog-textarea',
|
|
|
|
'name' => 'text',
|
|
|
|
),
|
|
|
|
$text);
|
|
|
|
}
|
|
|
|
|
2013-02-06 20:28:03 +01:00
|
|
|
}
|