mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-01 02:10:59 +01:00
Legalpad - add a preview to document create / edit
Summary: 'cuz legal documents be long! Fixes T4382. Test Plan: created / edited a document and got working preview Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T3482 Differential Revision: https://secure.phabricator.com/D6386
This commit is contained in:
parent
984bc8ea63
commit
96d831491c
6 changed files with 101 additions and 0 deletions
|
@ -1765,6 +1765,19 @@ celerity_register_resource_map(array(
|
||||||
),
|
),
|
||||||
'disk' => '/rsrc/js/core/behavior-konami.js',
|
'disk' => '/rsrc/js/core/behavior-konami.js',
|
||||||
),
|
),
|
||||||
|
'javelin-behavior-legalpad-document-preview' =>
|
||||||
|
array(
|
||||||
|
'uri' => '/res/d0ce5a8c/rsrc/js/application/legalpad/legalpad-document-preview.js',
|
||||||
|
'type' => 'js',
|
||||||
|
'requires' =>
|
||||||
|
array(
|
||||||
|
0 => 'javelin-behavior',
|
||||||
|
1 => 'javelin-dom',
|
||||||
|
2 => 'javelin-util',
|
||||||
|
3 => 'phabricator-shaped-request',
|
||||||
|
),
|
||||||
|
'disk' => '/rsrc/js/application/legalpad/legalpad-document-preview.js',
|
||||||
|
),
|
||||||
'javelin-behavior-lightbox-attachments' =>
|
'javelin-behavior-lightbox-attachments' =>
|
||||||
array(
|
array(
|
||||||
'uri' => '/res/72b4d3a8/rsrc/js/core/behavior-lightbox-attachments.js',
|
'uri' => '/res/72b4d3a8/rsrc/js/core/behavior-lightbox-attachments.js',
|
||||||
|
|
|
@ -640,6 +640,7 @@ phutil_register_library_map(array(
|
||||||
'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php',
|
'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php',
|
||||||
'LegalpadDocumentEditor' => 'applications/legalpad/editor/LegalpadDocumentEditor.php',
|
'LegalpadDocumentEditor' => 'applications/legalpad/editor/LegalpadDocumentEditor.php',
|
||||||
'LegalpadDocumentListController' => 'applications/legalpad/controller/LegalpadDocumentListController.php',
|
'LegalpadDocumentListController' => 'applications/legalpad/controller/LegalpadDocumentListController.php',
|
||||||
|
'LegalpadDocumentPreviewController' => 'applications/legalpad/controller/LegalpadDocumentPreviewController.php',
|
||||||
'LegalpadDocumentQuery' => 'applications/legalpad/query/LegalpadDocumentQuery.php',
|
'LegalpadDocumentQuery' => 'applications/legalpad/query/LegalpadDocumentQuery.php',
|
||||||
'LegalpadDocumentSearchEngine' => 'applications/legalpad/query/LegalpadDocumentSearchEngine.php',
|
'LegalpadDocumentSearchEngine' => 'applications/legalpad/query/LegalpadDocumentSearchEngine.php',
|
||||||
'LegalpadDocumentSignature' => 'applications/legalpad/storage/LegalpadDocumentSignature.php',
|
'LegalpadDocumentSignature' => 'applications/legalpad/storage/LegalpadDocumentSignature.php',
|
||||||
|
@ -2572,6 +2573,7 @@ phutil_register_library_map(array(
|
||||||
0 => 'LegalpadController',
|
0 => 'LegalpadController',
|
||||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||||
),
|
),
|
||||||
|
'LegalpadDocumentPreviewController' => 'LegalpadController',
|
||||||
'LegalpadDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'LegalpadDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'LegalpadDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'LegalpadDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'LegalpadDocumentSignature' => 'LegalpadDAO',
|
'LegalpadDocumentSignature' => 'LegalpadDAO',
|
||||||
|
|
|
@ -48,6 +48,8 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication {
|
||||||
'edit/(?P<id>\d+)/' => 'LegalpadDocumentEditController',
|
'edit/(?P<id>\d+)/' => 'LegalpadDocumentEditController',
|
||||||
'comment/(?P<id>\d+)/' => 'LegalpadDocumentCommentController',
|
'comment/(?P<id>\d+)/' => 'LegalpadDocumentCommentController',
|
||||||
'view/(?P<id>\d+)/' => 'LegalpadDocumentViewController',
|
'view/(?P<id>\d+)/' => 'LegalpadDocumentViewController',
|
||||||
|
'document/' => array(
|
||||||
|
'preview/' => 'LegalpadDocumentPreviewController'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,12 +115,14 @@ final class LegalpadDocumentEditController extends LegalpadController {
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
|
->setID('document-title')
|
||||||
->setLabel(pht('Title'))
|
->setLabel(pht('Title'))
|
||||||
->setError($e_title)
|
->setError($e_title)
|
||||||
->setValue($title)
|
->setValue($title)
|
||||||
->setName('title'))
|
->setName('title'))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new PhabricatorRemarkupControl())
|
id(new PhabricatorRemarkupControl())
|
||||||
|
->setID('document-text')
|
||||||
->setLabel(pht('Text'))
|
->setLabel(pht('Text'))
|
||||||
->setError($e_text)
|
->setError($e_text)
|
||||||
->setValue($text)
|
->setValue($text)
|
||||||
|
@ -168,11 +170,34 @@ final class LegalpadDocumentEditController extends LegalpadController {
|
||||||
$crumbs->addCrumb(
|
$crumbs->addCrumb(
|
||||||
id(new PhabricatorCrumbView())->setName($short));
|
id(new PhabricatorCrumbView())->setName($short));
|
||||||
|
|
||||||
|
$preview_header = id(new PhabricatorHeaderView())
|
||||||
|
->setHeader(pht('Document Preview'));
|
||||||
|
$preview_view = phutil_tag(
|
||||||
|
'div',
|
||||||
|
array(
|
||||||
|
'id' => 'document-preview'),
|
||||||
|
phutil_tag(
|
||||||
|
'div',
|
||||||
|
array(
|
||||||
|
'class' => 'aphront-panel-preview-loading-text'),
|
||||||
|
pht('Loading preview...')));
|
||||||
|
$preview_panel = id(new PHUIDocumentView())
|
||||||
|
->appendChild($preview_header)
|
||||||
|
->appendChild($preview_view);
|
||||||
|
Javelin::initBehavior(
|
||||||
|
'legalpad-document-preview',
|
||||||
|
array(
|
||||||
|
'preview' => 'document-preview',
|
||||||
|
'title' => 'document-title',
|
||||||
|
'text' => 'document-text',
|
||||||
|
'uri' => $this->getApplicationURI('document/preview/')));
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
array(
|
array(
|
||||||
$crumbs,
|
$crumbs,
|
||||||
$error_view,
|
$error_view,
|
||||||
$form,
|
$form,
|
||||||
|
$preview_panel
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legalpad
|
||||||
|
*/
|
||||||
|
final class LegalpadDocumentPreviewController
|
||||||
|
extends LegalpadController {
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$user = $request->getUser();
|
||||||
|
$text = $request->getStr('text');
|
||||||
|
|
||||||
|
$body = id(new LegalpadDocumentBody())
|
||||||
|
->setText($text);
|
||||||
|
|
||||||
|
$content = PhabricatorMarkupEngine::renderOneObject(
|
||||||
|
$body,
|
||||||
|
LegalpadDocumentBody::MARKUP_FIELD_TEXT,
|
||||||
|
$user);
|
||||||
|
|
||||||
|
$content = hsprintf('<div class="phabricator-remarkup">%s</div>', $content);
|
||||||
|
|
||||||
|
return id(new AphrontAjaxResponse())->setContent($content);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* @provides javelin-behavior-legalpad-document-preview
|
||||||
|
* @requires javelin-behavior
|
||||||
|
* javelin-dom
|
||||||
|
* javelin-util
|
||||||
|
* phabricator-shaped-request
|
||||||
|
*/
|
||||||
|
|
||||||
|
JX.behavior('legalpad-document-preview', function(config) {
|
||||||
|
|
||||||
|
var preview = JX.$(config.preview);
|
||||||
|
var title = JX.$(config.title);
|
||||||
|
var text = JX.$(config.text);
|
||||||
|
|
||||||
|
var callback = function(r) {
|
||||||
|
JX.DOM.setContent(JX.$(config.preview), JX.$H(r));
|
||||||
|
};
|
||||||
|
|
||||||
|
var getdata = function() {
|
||||||
|
return {
|
||||||
|
title : title.value,
|
||||||
|
text : text.value
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
|
||||||
|
var trigger = JX.bind(request, request.trigger);
|
||||||
|
|
||||||
|
JX.DOM.listen(title, 'keydown', null, trigger);
|
||||||
|
JX.DOM.listen(text, 'keydown', null, trigger);
|
||||||
|
request.start();
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in a new issue