コード例 #1
0
 public function render()
 {
     require_celerity_resource('ponder-core-view-css');
     $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
     $question = $this->question;
     $header = id(new PhabricatorHeaderView())->setHeader('Add Answer');
     $form = new AphrontFormView();
     $form->setFlexible(true)->setUser($this->user)->setAction($this->actionURI)->setWorkflow(true)->addHiddenInput('question_id', $question->getID())->appendChild(id(new PhabricatorRemarkupControl())->setName('answer')->setLabel('Answer')->setError(true)->setID('answer-content'))->appendChild(id(new AphrontFormSubmitControl())->setValue($is_serious ? 'Submit' : 'Make it so.'));
     $preview = '<div class="aphront-panel-flush">' . '<div id="answer-preview">' . '<span class="aphront-panel-preview-loading-text">' . 'Loading answer preview...' . '</span>' . '</div>' . '</div>';
     Javelin::initBehavior('ponder-feedback-preview', array('uri' => '/ponder/answer/preview/', 'content' => 'answer-content', 'preview' => 'answer-preview', 'question_id' => $question->getID()));
     return id(new AphrontNullView())->appendChild(array($header, $form, $preview))->render();
 }
コード例 #2
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $parent = null;
     $parent_id = null;
     if (!$this->id) {
         $is_create = true;
         $paste = new PhabricatorPaste();
         $parent_id = $request->getStr('parent');
         if ($parent_id) {
             // NOTE: If the Paste is forked from a paste which the user no longer
             // has permission to see, we still let them edit it.
             $parent = id(new PhabricatorPasteQuery())->setViewer($user)->withIDs(array($parent_id))->needContent(true)->execute();
             $parent = head($parent);
             if ($parent) {
                 $paste->setParentPHID($parent->getPHID());
             }
         }
         $paste->setAuthorPHID($user->getPHID());
     } else {
         $is_create = false;
         $paste = id(new PhabricatorPasteQuery())->setViewer($user)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($this->id))->executeOne();
         if (!$paste) {
             return new Aphront404Response();
         }
     }
     $text = null;
     $e_text = true;
     $errors = array();
     if ($request->isFormPost()) {
         if ($is_create) {
             $text = $request->getStr('text');
             if (!strlen($text)) {
                 $e_text = 'Required';
                 $errors[] = 'The paste may not be blank.';
             } else {
                 $e_text = null;
             }
         }
         $paste->setTitle($request->getStr('title'));
         $paste->setLanguage($request->getStr('language'));
         if (!$errors) {
             if ($is_create) {
                 $paste_file = PhabricatorFile::newFromFileData($text, array('name' => $paste->getTitle(), 'mime-type' => 'text/plain; charset=utf-8', 'authorPHID' => $user->getPHID()));
                 $paste->setFilePHID($paste_file->getPHID());
             }
             $paste->save();
             return id(new AphrontRedirectResponse())->setURI($paste->getURI());
         }
     } else {
         if ($is_create && $parent) {
             $paste->setTitle('Fork of ' . $parent->getFullName());
             $paste->setLanguage($parent->getLanguage());
             $text = $parent->getContent();
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('A fatal omission!')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setFlexible(true);
     $langs = array('' => '(Detect With Wizardly Powers)') + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
     $form->setUser($user)->addHiddenInput('parent', $parent_id)->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setValue($paste->getTitle())->setName('title'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Language')->setName('language')->setValue($paste->getLanguage())->setOptions($langs));
     if ($is_create) {
         $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Text')->setError($e_text)->setValue($text)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setCustomClass('PhabricatorMonospaced')->setName('text'));
     }
     /* TODO: Doesn't have any useful options yet.
          ->appendChild(
            id(new AphrontFormPolicyControl())
              ->setLabel('Visible To')
              ->setUser($user)
              ->setValue(
                $new_paste->getPolicy(PhabricatorPolicyCapability::CAN_VIEW))
              ->setName('policy'))
        */
     $submit = new AphrontFormSubmitControl();
     if (!$is_create) {
         $submit->addCancelButton($paste->getURI());
         $submit->setValue('Save Paste');
         $title = 'Edit ' . $paste->getFullName();
     } else {
         $submit->setValue('Create Paste');
         $title = 'Create Paste';
     }
     $form->appendChild($submit);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('edit');
     $nav->appendChild(array(id(new PhabricatorHeaderView())->setHeader($title), $error_view, $form));
     return $this->buildApplicationPage($nav, array('title' => $title, 'device' => true));
 }
コード例 #3
0
 private function renderCreatePaste()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $new_paste = $this->getPaste();
     $form = new AphrontFormView();
     $form->setFlexible(true);
     $available_languages = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
     asort($available_languages);
     $language_select = id(new AphrontFormSelectControl())->setLabel('Language')->setName('language')->setValue($new_paste->getLanguage())->setOptions($available_languages);
     $form->setUser($user)->setAction($request->getRequestURI()->getPath())->addHiddenInput('parent', $new_paste->getParentPHID())->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setValue($new_paste->getTitle())->setName('title'))->appendChild($language_select)->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Text')->setError($this->getErrorText())->setValue($this->getPasteText())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setName('text'))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/paste/')->setValue('Create Paste'));
     return array(id(new PhabricatorHeaderView())->setHeader('Create Paste'), $form);
 }