From 96d831491c2f4f057ac708132a098214ecf0f7e2 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 8 Jul 2013 17:05:33 -0700 Subject: [PATCH] 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 --- src/__celerity_resource_map__.php | 13 ++++++++ src/__phutil_library_map__.php | 2 ++ .../PhabricatorApplicationLegalpad.php | 2 ++ .../LegalpadDocumentEditController.php | 25 ++++++++++++++ .../LegalpadDocumentPreviewController.php | 26 +++++++++++++++ .../legalpad/legalpad-document-preview.js | 33 +++++++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 src/applications/legalpad/controller/LegalpadDocumentPreviewController.php create mode 100644 webroot/rsrc/js/application/legalpad/legalpad-document-preview.js diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 244f863f43..e56d3f55c7 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -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', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 46188d9c83..dee3337316 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php b/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php index c10ebddbb3..10044127e4 100644 --- a/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php +++ b/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php @@ -48,6 +48,8 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication { 'edit/(?P\d+)/' => 'LegalpadDocumentEditController', 'comment/(?P\d+)/' => 'LegalpadDocumentCommentController', 'view/(?P\d+)/' => 'LegalpadDocumentViewController', + 'document/' => array( + 'preview/' => 'LegalpadDocumentPreviewController'), )); } diff --git a/src/applications/legalpad/controller/LegalpadDocumentEditController.php b/src/applications/legalpad/controller/LegalpadDocumentEditController.php index 6745684f73..99307fa3b0 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentEditController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentEditController.php @@ -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, diff --git a/src/applications/legalpad/controller/LegalpadDocumentPreviewController.php b/src/applications/legalpad/controller/LegalpadDocumentPreviewController.php new file mode 100644 index 0000000000..5aac38e9f9 --- /dev/null +++ b/src/applications/legalpad/controller/LegalpadDocumentPreviewController.php @@ -0,0 +1,26 @@ +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('
%s
', $content); + + return id(new AphrontAjaxResponse())->setContent($content); + } +} diff --git a/webroot/rsrc/js/application/legalpad/legalpad-document-preview.js b/webroot/rsrc/js/application/legalpad/legalpad-document-preview.js new file mode 100644 index 0000000000..9826bdc593 --- /dev/null +++ b/webroot/rsrc/js/application/legalpad/legalpad-document-preview.js @@ -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(); + +});