1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-29 08:50:58 +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:
Bob Trahan 2013-07-08 17:05:33 -07:00
parent 984bc8ea63
commit 96d831491c
6 changed files with 101 additions and 0 deletions

View file

@ -1765,6 +1765,19 @@ celerity_register_resource_map(array(
),
'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' =>
array(
'uri' => '/res/72b4d3a8/rsrc/js/core/behavior-lightbox-attachments.js',

View file

@ -640,6 +640,7 @@ phutil_register_library_map(array(
'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php',
'LegalpadDocumentEditor' => 'applications/legalpad/editor/LegalpadDocumentEditor.php',
'LegalpadDocumentListController' => 'applications/legalpad/controller/LegalpadDocumentListController.php',
'LegalpadDocumentPreviewController' => 'applications/legalpad/controller/LegalpadDocumentPreviewController.php',
'LegalpadDocumentQuery' => 'applications/legalpad/query/LegalpadDocumentQuery.php',
'LegalpadDocumentSearchEngine' => 'applications/legalpad/query/LegalpadDocumentSearchEngine.php',
'LegalpadDocumentSignature' => 'applications/legalpad/storage/LegalpadDocumentSignature.php',
@ -2572,6 +2573,7 @@ phutil_register_library_map(array(
0 => 'LegalpadController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'LegalpadDocumentPreviewController' => 'LegalpadController',
'LegalpadDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'LegalpadDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
'LegalpadDocumentSignature' => 'LegalpadDAO',

View file

@ -48,6 +48,8 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication {
'edit/(?P<id>\d+)/' => 'LegalpadDocumentEditController',
'comment/(?P<id>\d+)/' => 'LegalpadDocumentCommentController',
'view/(?P<id>\d+)/' => 'LegalpadDocumentViewController',
'document/' => array(
'preview/' => 'LegalpadDocumentPreviewController'),
));
}

View file

@ -115,12 +115,14 @@ final class LegalpadDocumentEditController extends LegalpadController {
->setUser($user)
->appendChild(
id(new AphrontFormTextControl())
->setID('document-title')
->setLabel(pht('Title'))
->setError($e_title)
->setValue($title)
->setName('title'))
->appendChild(
id(new PhabricatorRemarkupControl())
->setID('document-text')
->setLabel(pht('Text'))
->setError($e_text)
->setValue($text)
@ -168,11 +170,34 @@ final class LegalpadDocumentEditController extends LegalpadController {
$crumbs->addCrumb(
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(
array(
$crumbs,
$error_view,
$form,
$preview_panel
),
array(
'title' => $title,

View file

@ -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);
}
}

View file

@ -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();
});