Path: blob/master/src/applications/conpherence/view/ConpherenceDurableColumnView.php
12256 views
<?php12final class ConpherenceDurableColumnView extends AphrontTagView {34private $conpherences = array();5private $draft;6private $selectedConpherence;7private $transactions;8private $visible;9private $minimize;10private $initialLoad = false;11private $policyObjects;12private $quicksandConfig = array();1314public function setConpherences(array $conpherences) {15assert_instances_of($conpherences, 'ConpherenceThread');16$this->conpherences = $conpherences;17return $this;18}1920public function getConpherences() {21return $this->conpherences;22}2324public function setDraft(PhabricatorDraft $draft) {25$this->draft = $draft;26return $this;27}2829public function getDraft() {30return $this->draft;31}3233public function setSelectedConpherence(34ConpherenceThread $conpherence = null) {35$this->selectedConpherence = $conpherence;36return $this;37}3839public function getSelectedConpherence() {40return $this->selectedConpherence;41}4243public function setTransactions(array $transactions) {44assert_instances_of($transactions, 'ConpherenceTransaction');45$this->transactions = $transactions;46return $this;47}4849public function getTransactions() {50return $this->transactions;51}5253public function setVisible($visible) {54$this->visible = $visible;55return $this;56}5758public function getVisible() {59return $this->visible;60}6162public function setMinimize($minimize) {63$this->minimize = $minimize;64return $this;65}6667public function getMinimize() {68return $this->minimize;69}7071public function setInitialLoad($bool) {72$this->initialLoad = $bool;73return $this;74}7576public function getInitialLoad() {77return $this->initialLoad;78}7980public function setPolicyObjects(array $objects) {81assert_instances_of($objects, 'PhabricatorPolicy');8283$this->policyObjects = $objects;84return $this;85}8687public function getPolicyObjects() {88return $this->policyObjects;89}9091public function setQuicksandConfig(array $config) {92$this->quicksandConfig = $config;93return $this;94}9596public function getQuicksandConfig() {97return $this->quicksandConfig;98}99100protected function getTagAttributes() {101if ($this->getVisible()) {102$style = null;103} else {104$style = 'display: none;';105}106$classes = array('conpherence-durable-column');107if ($this->getInitialLoad()) {108$classes[] = 'loading';109}110111return array(112'id' => 'conpherence-durable-column',113'class' => implode(' ', $classes),114'style' => $style,115'sigil' => 'conpherence-durable-column',116);117}118119protected function getTagContent() {120$column_key = PhabricatorConpherenceColumnVisibleSetting::SETTINGKEY;121$minimize_key = PhabricatorConpherenceColumnMinimizeSetting::SETTINGKEY;122123Javelin::initBehavior(124'durable-column',125array(126'visible' => $this->getVisible(),127'minimize' => $this->getMinimize(),128'visibleURI' => '/settings/adjust/?key='.$column_key,129'minimizeURI' => '/settings/adjust/?key='.$minimize_key,130'quicksandConfig' => $this->getQuicksandConfig(),131));132133$policy_objects = ConpherenceThread::loadViewPolicyObjects(134$this->getUser(),135$this->getConpherences());136$this->setPolicyObjects($policy_objects);137138$classes = array();139$classes[] = 'conpherence-durable-column-header';140$classes[] = 'grouped';141142$header = phutil_tag(143'div',144array(145'class' => implode(' ', $classes),146'data-sigil' => 'conpherence-minimize-window',147),148$this->buildHeader());149150$icon_bar = null;151if ($this->conpherences) {152$icon_bar = $this->buildIconBar();153}154$icon_bar = phutil_tag(155'div',156array(157'class' => 'conpherence-durable-column-icon-bar',158),159$icon_bar);160161$transactions = $this->buildTransactions();162163$content = javelin_tag(164'div',165array(166'class' => 'conpherence-durable-column-main',167'sigil' => 'conpherence-durable-column-main',168),169phutil_tag(170'div',171array(172'id' => 'conpherence-durable-column-content',173'class' => 'conpherence-durable-column-frame',174),175javelin_tag(176'div',177array(178'class' => 'conpherence-durable-column-transactions',179'sigil' => 'conpherence-durable-column-transactions',180),181$transactions)));182183$input = $this->buildTextInput();184185return array(186$header,187javelin_tag(188'div',189array(190'class' => 'conpherence-durable-column-body',191'sigil' => 'conpherence-durable-column-body',192),193array(194$icon_bar,195$content,196$input,197)),198);199}200201private function buildIconBar() {202$icons = array();203$selected_conpherence = $this->getSelectedConpherence();204$conpherences = $this->getConpherences();205206foreach ($conpherences as $conpherence) {207$classes = array('conpherence-durable-column-thread-icon');208if ($selected_conpherence->getID() == $conpherence->getID()) {209$classes[] = 'selected';210}211$data = $conpherence->getDisplayData($this->getUser());212$thread_title = phutil_tag(213'span',214array(),215array(216$data['title'],217));218$image = $data['image'];219Javelin::initBehavior('phabricator-tooltips');220$icons[] =221javelin_tag(222'a',223array(224'href' => '/conpherence/columnview/',225'class' => implode(' ', $classes),226'sigil' => 'conpherence-durable-column-thread-icon has-tooltip',227'meta' => array(228'threadID' => $conpherence->getID(),229'threadTitle' => hsprintf('%s', $thread_title),230'tip' => $data['title'],231'align' => 'W',232),233),234phutil_tag(235'span',236array(237'style' => 'background-image: url('.$image.')',238),239''));240}241242return $icons;243}244245private function buildHeader() {246$conpherence = $this->getSelectedConpherence();247248$bubble_id = celerity_generate_unique_node_id();249$dropdown_id = celerity_generate_unique_node_id();250251$settings_list = new PHUIListView();252$header_actions = $this->getHeaderActionsConfig($conpherence);253foreach ($header_actions as $action) {254$settings_list->addMenuItem(255id(new PHUIListItemView())256->setHref($action['href'])257->setName($action['name'])258->setIcon($action['icon'])259->setDisabled($action['disabled'])260->addSigil('conpherence-durable-column-header-action')261->setMetadata(array(262'action' => $action['key'],263)));264}265266$settings_menu = phutil_tag(267'div',268array(269'id' => $dropdown_id,270'class' => 'phabricator-main-menu-dropdown phui-list-sidenav '.271'conpherence-settings-dropdown',272'sigil' => 'phabricator-notification-menu',273'style' => 'display: none',274),275$settings_list);276277Javelin::initBehavior(278'aphlict-dropdown',279array(280'bubbleID' => $bubble_id,281'dropdownID' => $dropdown_id,282'local' => true,283'containerDivID' => 'conpherence-durable-column',284));285286$bars = id(new PHUIListItemView())287->setName(pht('Room Actions'))288->setIcon('fa-gear')289->addClass('core-menu-item')290->addClass('conpherence-settings-icon')291->addSigil('conpherence-settings-menu')292->setID($bubble_id)293->setHref('#')294->setAural(pht('Room Actions'))295->setOrder(400);296297$minimize = id(new PHUIListItemView())298->setName(pht('Minimize Window'))299->setIcon('fa-toggle-down')300->addClass('core-menu-item')301->addClass('conpherence-minimize-icon')302->addSigil('conpherence-minimize-window')303->setHref('#')304->setAural(pht('Minimize Window'))305->setOrder(300);306307$settings_button = id(new PHUIListView())308->addMenuItem($bars)309->addMenuItem($minimize)310->addClass('phabricator-application-menu');311312if ($conpherence) {313$data = $conpherence->getDisplayData($this->getUser());314$header = phutil_tag(315'span',316array(),317$data['title']);318} else {319$header = phutil_tag(320'span',321array(),322pht('Conpherence'));323}324325$status = new PhabricatorNotificationStatusView();326327return328phutil_tag(329'div',330array(331'class' => 'conpherence-durable-column-header-inner',332),333array(334$status,335javelin_tag(336'div',337array(338'sigil' => 'conpherence-durable-column-header-text',339'class' => 'conpherence-durable-column-header-text',340),341$header),342$settings_button,343$settings_menu,344));345}346347private function getHeaderActionsConfig($conpherence) {348349$actions = array();350if ($conpherence) {351$can_edit = PhabricatorPolicyFilter::hasCapability(352$this->getUser(),353$conpherence,354PhabricatorPolicyCapability::CAN_EDIT);355$actions[] = array(356'name' => pht('Add Participants'),357'disabled' => !$can_edit,358'href' => '/conpherence/update/'.$conpherence->getID().'/',359'icon' => 'fa-plus',360'key' => ConpherenceUpdateActions::ADD_PERSON,361);362$actions[] = array(363'name' => pht('Edit Room'),364'disabled' => !$can_edit,365'href' => '/conpherence/edit/'.$conpherence->getID().'/',366'icon' => 'fa-pencil',367'key' => 'go_edit',368);369$actions[] = array(370'name' => pht('View in Conpherence'),371'disabled' => false,372'href' => '/'.$conpherence->getMonogram(),373'icon' => 'fa-comments',374'key' => 'go_conpherence',375);376}377378$actions[] = array(379'name' => pht('Hide Window'),380'disabled' => false,381'href' => '#',382'icon' => 'fa-times',383'key' => 'hide_column',384);385386return $actions;387}388389private function buildTransactions() {390$conpherence = $this->getSelectedConpherence();391if (!$conpherence) {392if (!$this->getVisible() || $this->getInitialLoad()) {393return pht('Loading...');394}395$view = array(396phutil_tag(397'div',398array(399'class' => 'column-no-rooms-text',400),401pht('You have not joined any rooms yet.')),402javelin_tag(403'a',404array(405'href' => '/conpherence/search/',406'class' => 'button button-grey',407),408pht('Find Rooms')),409);410return phutil_tag_div('column-no-rooms', $view);411}412413$data = ConpherenceTransactionRenderer::renderTransactions(414$this->getUser(),415$conpherence);416$messages = ConpherenceTransactionRenderer::renderMessagePaneContent(417$data['transactions'],418$data['oldest_transaction_id'],419$data['newest_transaction_id']);420421return $messages;422}423424private function buildTextInput() {425$conpherence = $this->getSelectedConpherence();426if (!$conpherence) {427return null;428}429430$draft = $this->getDraft();431$draft_value = null;432if ($draft) {433$draft_value = $draft->getDraft();434}435436$textarea_id = celerity_generate_unique_node_id();437$textarea = javelin_tag(438'textarea',439array(440'id' => $textarea_id,441'name' => 'text',442'class' => 'conpherence-durable-column-textarea',443'sigil' => 'conpherence-durable-column-textarea',444'placeholder' => pht('Send a message...'),445),446$draft_value);447Javelin::initBehavior(448'aphront-drag-and-drop-textarea',449array(450'target' => $textarea_id,451'activatedClass' => 'aphront-textarea-drag-and-drop',452'uri' => '/file/dropupload/',453));454$id = $conpherence->getID();455return phabricator_form(456$this->getUser(),457array(458'method' => 'POST',459'action' => '/conpherence/update/'.$id.'/',460'sigil' => 'conpherence-message-form',461),462array(463$textarea,464phutil_tag(465'input',466array(467'type' => 'hidden',468'name' => 'action',469'value' => ConpherenceUpdateActions::MESSAGE,470)),471));472}473474private function buildStatusText() {475return null;476}477478private function buildSendButton() {479$conpherence = $this->getSelectedConpherence();480if (!$conpherence) {481return null;482}483484return javelin_tag(485'button',486array(487'class' => 'grey',488'sigil' => 'conpherence-send-message',489),490pht('Send'));491}492493}494495496