private function renderSettingsWidgetPaneContent() { $user = $this->getRequest()->getUser(); $conpherence = $this->getConpherence(); $participants = $conpherence->getParticipants(); $participant = $participants[$user->getPHID()]; $default = ConpherenceSettings::EMAIL_ALWAYS; $preference = $this->getUserPreferences(); if ($preference) { $default = $preference->getPreference(PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS, ConpherenceSettings::EMAIL_ALWAYS); } $settings = $participant->getSettings(); $notifications = idx($settings, 'notifications', $default); $options = id(new AphrontFormRadioButtonControl())->addButton(ConpherenceSettings::EMAIL_ALWAYS, ConpherenceSettings::getHumanString(ConpherenceSettings::EMAIL_ALWAYS), '')->addButton(ConpherenceSettings::NOTIFICATIONS_ONLY, ConpherenceSettings::getHumanString(ConpherenceSettings::NOTIFICATIONS_ONLY), '')->setName('notifications')->setValue($notifications); $layout = array($options, phutil_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'notifications')), phutil_tag('button', array('type' => 'submit', 'class' => 'notifications-update'), pht('Save'))); return phabricator_form($user, array('method' => 'POST', 'action' => $this->getWidgetURI(), 'sigil' => 'notifications-update'), $layout); }
private function renderSettingsWidgetPaneContent() { $viewer = $this->getViewer(); $conpherence = $this->getConpherence(); $participant = $conpherence->getParticipantIfExists($viewer->getPHID()); if (!$participant) { $can_join = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_JOIN); if ($can_join) { $text = pht('Notification settings are available after joining the room.'); } else { if ($viewer->isLoggedIn()) { $text = pht('Notification settings not applicable to rooms you can not join.'); } else { $text = pht('Notification settings are available after logging in and joining ' . 'the room.'); } } return phutil_tag('div', array('class' => 'no-settings'), $text); } $default = ConpherenceSettings::EMAIL_ALWAYS; $preference = $this->getUserPreferences(); if ($preference) { $default = $preference->getPreference(PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS, ConpherenceSettings::EMAIL_ALWAYS); } $settings = $participant->getSettings(); $notifications = idx($settings, 'notifications', $default); $options = id(new AphrontFormRadioButtonControl())->addButton(ConpherenceSettings::EMAIL_ALWAYS, ConpherenceSettings::getHumanString(ConpherenceSettings::EMAIL_ALWAYS), '')->addButton(ConpherenceSettings::NOTIFICATIONS_ONLY, ConpherenceSettings::getHumanString(ConpherenceSettings::NOTIFICATIONS_ONLY), '')->setName('notifications')->setValue($notifications); $layout = array($options, phutil_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'notifications')), phutil_tag('button', array('type' => 'submit', 'class' => 'notifications-update'), pht('Save'))); return phabricator_form($viewer, array('method' => 'POST', 'action' => $this->getWidgetURI(), 'sigil' => 'notifications-update'), $layout); }
public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); $conpherence_id = $request->getURIData('id'); if (!$conpherence_id) { return new Aphront404Response(); } $need_participants = false; $needed_capabilities = array(PhabricatorPolicyCapability::CAN_VIEW); $action = $request->getStr('action', ConpherenceUpdateActions::METADATA); switch ($action) { case ConpherenceUpdateActions::REMOVE_PERSON: $person_phid = $request->getStr('remove_person'); if ($person_phid != $user->getPHID()) { $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; } break; case ConpherenceUpdateActions::ADD_PERSON: case ConpherenceUpdateActions::METADATA: $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; break; case ConpherenceUpdateActions::JOIN_ROOM: $needed_capabilities[] = PhabricatorPolicyCapability::CAN_JOIN; break; case ConpherenceUpdateActions::NOTIFICATIONS: $need_participants = true; break; case ConpherenceUpdateActions::LOAD: break; } $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->needFilePHIDs(true)->needOrigPics(true)->needCropPics(true)->needParticipants($need_participants)->requireCapabilities($needed_capabilities)->executeOne(); $latest_transaction_id = null; $response_mode = $request->isAjax() ? 'ajax' : 'redirect'; $error_view = null; $e_file = array(); $errors = array(); $delete_draft = false; $xactions = array(); if ($request->isFormPost() || $action == ConpherenceUpdateActions::LOAD) { $editor = id(new ConpherenceEditor())->setContinueOnNoEffect($request->isContinueRequest())->setContentSourceFromRequest($request)->setActor($user); switch ($action) { case ConpherenceUpdateActions::DRAFT: $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID()); $draft->setDraft($request->getStr('text')); $draft->replaceOrDelete(); return new AphrontAjaxResponse(); case ConpherenceUpdateActions::JOIN_ROOM: $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => array($user->getPHID()))); $delete_draft = true; $message = $request->getStr('text'); if ($message) { $message_xactions = $editor->generateTransactionsFromText($user, $conpherence, $message); $xactions = array_merge($xactions, $message_xactions); } // for now, just redirect back to the conpherence so everything // will work okay...! $response_mode = 'redirect'; break; case ConpherenceUpdateActions::MESSAGE: $message = $request->getStr('text'); if (strlen($message)) { $xactions = $editor->generateTransactionsFromText($user, $conpherence, $message); $delete_draft = true; } else { $action = ConpherenceUpdateActions::LOAD; $updated = false; $response_mode = 'ajax'; } break; case ConpherenceUpdateActions::ADD_PERSON: $person_phids = $request->getArr('add_person'); if (!empty($person_phids)) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $person_phids)); } break; case ConpherenceUpdateActions::REMOVE_PERSON: if (!$request->isContinueRequest()) { // do nothing; we'll display a confirmation dialogue instead break; } $person_phid = $request->getStr('remove_person'); if ($person_phid && $person_phid == $user->getPHID()) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('-' => array($person_phid))); $response_mode = 'go-home'; } break; case ConpherenceUpdateActions::NOTIFICATIONS: $notifications = $request->getStr('notifications'); $participant = $conpherence->getParticipantIfExists($user->getPHID()); if (!$participant) { return id(new Aphront404Response()); } $participant->setSettings(array('notifications' => $notifications)); $participant->save(); $result = pht('Updated notification settings to "%s".', ConpherenceSettings::getHumanString($notifications)); return id(new AphrontAjaxResponse())->setContent($result); break; case ConpherenceUpdateActions::METADATA: $top = $request->getInt('image_y'); $left = $request->getInt('image_x'); $file_id = $request->getInt('file_id'); $title = $request->getStr('title'); if ($file_id) { $orig_file = id(new PhabricatorFileQuery())->setViewer($user)->withIDs(array($file_id))->executeOne(); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE)->setNewValue($orig_file); $okay = $orig_file->isTransformableImage(); if ($okay) { $xformer = new PhabricatorImageTransformer(); $crop_file = $xformer->executeConpherenceTransform($orig_file, 0, 0, ConpherenceImageData::CROP_WIDTH, ConpherenceImageData::CROP_HEIGHT); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE_CROP)->setNewValue($crop_file->getPHID()); } $response_mode = 'redirect'; } // all other metadata updates are continue requests if (!$request->isContinueRequest()) { break; } if ($top !== null || $left !== null) { $file = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG); $xformer = new PhabricatorImageTransformer(); $xformed = $xformer->executeConpherenceTransform($file, $top, $left, ConpherenceImageData::CROP_WIDTH, ConpherenceImageData::CROP_HEIGHT); $image_phid = $xformed->getPHID(); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE_CROP)->setNewValue($image_phid); } $title = $request->getStr('title'); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($title); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getStr('viewPolicy')); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($request->getStr('editPolicy')); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)->setNewValue($request->getStr('joinPolicy')); if (!$request->getExists('force_ajax')) { $response_mode = 'redirect'; } break; case ConpherenceUpdateActions::LOAD: $updated = false; $response_mode = 'ajax'; break; default: throw new Exception(pht('Unknown action: %s', $action)); break; } if ($xactions) { try { $xactions = $editor->applyTransactions($conpherence, $xactions); if ($delete_draft) { $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID()); $draft->delete(); } } catch (PhabricatorApplicationTransactionNoEffectException $ex) { return id(new PhabricatorApplicationTransactionNoEffectResponse())->setCancelURI($this->getApplicationURI($conpherence_id . '/'))->setException($ex); } // xactions had no effect...! if (empty($xactions)) { $errors[] = pht('That was a non-update. Try cancel.'); } } if ($xactions || $action == ConpherenceUpdateActions::LOAD) { switch ($response_mode) { case 'ajax': $latest_transaction_id = $request->getInt('latest_transaction_id'); $content = $this->loadAndRenderUpdates($action, $conpherence_id, $latest_transaction_id); return id(new AphrontAjaxResponse())->setContent($content); break; case 'go-home': $content = array('href' => $this->getApplicationURI()); return id(new AphrontAjaxResponse())->setContent($content); break; case 'redirect': default: return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram()); break; } } } if ($errors) { $error_view = id(new PHUIInfoView())->setErrors($errors); } switch ($action) { case ConpherenceUpdateActions::ADD_PERSON: $dialogue = $this->renderAddPersonDialogue($conpherence); break; case ConpherenceUpdateActions::REMOVE_PERSON: $dialogue = $this->renderRemovePersonDialogue($conpherence); break; case ConpherenceUpdateActions::METADATA: default: $dialogue = $this->renderMetadataDialogue($conpherence, $error_view); break; } return id(new AphrontDialogResponse())->setDialog($dialogue->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setSubmitURI($this->getApplicationURI('update/' . $conpherence_id . '/'))->addSubmitButton()->addCancelButton($this->getApplicationURI($conpherence->getID() . '/'))); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $conpherence_id = $this->getConpherenceID(); if (!$conpherence_id) { return new Aphront404Response(); } $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->needFilePHIDs(true)->executeOne(); $action = $request->getStr('action', ConpherenceUpdateActions::METADATA); $latest_transaction_id = null; $response_mode = $request->isAjax() ? 'ajax' : 'redirect'; $error_view = null; $e_file = array(); $errors = array(); $delete_draft = false; $xactions = array(); if ($request->isFormPost() || $action == ConpherenceUpdateActions::LOAD) { $editor = id(new ConpherenceEditor())->setContinueOnNoEffect($request->isContinueRequest())->setContentSourceFromRequest($request)->setActor($user); switch ($action) { case ConpherenceUpdateActions::DRAFT: $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID()); $draft->setDraft($request->getStr('text')); $draft->replaceOrDelete(); return new AphrontAjaxResponse(); case ConpherenceUpdateActions::MESSAGE: $message = $request->getStr('text'); $xactions = $editor->generateTransactionsFromText($user, $conpherence, $message); $delete_draft = true; break; case ConpherenceUpdateActions::ADD_PERSON: $person_phids = $request->getArr('add_person'); if (!empty($person_phids)) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS)->setNewValue(array('+' => $person_phids)); } break; case ConpherenceUpdateActions::REMOVE_PERSON: if (!$request->isContinueRequest()) { // do nothing; we'll display a confirmation dialogue instead break; } $person_phid = $request->getStr('remove_person'); if ($person_phid && $person_phid == $user->getPHID()) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS)->setNewValue(array('-' => array($person_phid))); $response_mode = 'go-home'; } break; case ConpherenceUpdateActions::NOTIFICATIONS: $notifications = $request->getStr('notifications'); $participant = $conpherence->getParticipant($user->getPHID()); $participant->setSettings(array('notifications' => $notifications)); $participant->save(); $result = pht('Updated notification settings to "%s".', ConpherenceSettings::getHumanString($notifications)); return id(new AphrontAjaxResponse())->setContent($result); break; case ConpherenceUpdateActions::METADATA: $updated = false; // all metadata updates are continue requests if (!$request->isContinueRequest()) { break; } $title = $request->getStr('title'); if ($title != $conpherence->getTitle()) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)->setNewValue($title); $updated = true; $response_mode = 'redirect'; } if (!$updated) { $errors[] = pht('That was a non-update. Try cancel.'); } break; case ConpherenceUpdateActions::LOAD: $updated = false; $response_mode = 'ajax'; break; default: throw new Exception('Unknown action: ' . $action); break; } if ($xactions || $action == ConpherenceUpdateActions::LOAD) { if ($xactions) { try { $xactions = $editor->applyTransactions($conpherence, $xactions); if ($delete_draft) { $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID()); $draft->delete(); } } catch (PhabricatorApplicationTransactionNoEffectException $ex) { return id(new PhabricatorApplicationTransactionNoEffectResponse())->setCancelURI($this->getApplicationURI($conpherence_id . '/'))->setException($ex); } } switch ($response_mode) { case 'ajax': $latest_transaction_id = $request->getInt('latest_transaction_id'); $content = $this->loadAndRenderUpdates($action, $conpherence_id, $latest_transaction_id); return id(new AphrontAjaxResponse())->setContent($content); break; case 'go-home': return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI()); break; case 'redirect': default: return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI($conpherence->getID() . '/')); break; } } } if ($errors) { $error_view = id(new AphrontErrorView())->setErrors($errors); } switch ($action) { case ConpherenceUpdateActions::ADD_PERSON: $dialogue = $this->renderAddPersonDialogue($conpherence); break; case ConpherenceUpdateActions::REMOVE_PERSON: $dialogue = $this->renderRemovePersonDialogue($conpherence); break; case ConpherenceUpdateActions::METADATA: default: $dialogue = $this->renderMetadataDialogue($conpherence, $error_view); break; } return id(new AphrontDialogResponse())->setDialog($dialogue->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setSubmitURI($this->getApplicationURI('update/' . $conpherence_id . '/'))->addSubmitButton()->addCancelButton($this->getApplicationURI($conpherence->getID() . '/'))); }