2012-02-29 23:28:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
final class DifferentialInlineCommentEditView extends AphrontView {
|
|
|
|
|
|
|
|
private $user;
|
|
|
|
private $inputs = array();
|
|
|
|
private $uri;
|
|
|
|
private $title;
|
|
|
|
private $onRight;
|
2012-03-10 01:04:25 +01:00
|
|
|
private $number;
|
|
|
|
private $length;
|
2012-02-29 23:28:48 +01:00
|
|
|
|
|
|
|
public function addHiddenInput($key, $value) {
|
|
|
|
$this->inputs[] = array($key, $value);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSubmitURI($uri) {
|
|
|
|
$this->uri = $uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOnRight($on_right) {
|
|
|
|
$this->onRight = $on_right;
|
|
|
|
$this->addHiddenInput('on_right', $on_right);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-03-10 01:04:25 +01:00
|
|
|
public function setNumber($number) {
|
|
|
|
$this->number = $number;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setLength($length) {
|
|
|
|
$this->length = $length;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-02-29 23:28:48 +01:00
|
|
|
public function render() {
|
|
|
|
if (!$this->uri) {
|
|
|
|
throw new Exception("Call setSubmitURI() before render()!");
|
|
|
|
}
|
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception("Call setUser() before render()!");
|
|
|
|
}
|
|
|
|
|
2012-05-05 02:41:06 +02:00
|
|
|
$content = phabricator_render_form(
|
2012-02-29 23:28:48 +01:00
|
|
|
$this->user,
|
|
|
|
array(
|
|
|
|
'action' => $this->uri,
|
|
|
|
'method' => 'POST',
|
|
|
|
'sigil' => 'inline-edit-form',
|
|
|
|
),
|
|
|
|
$this->renderInputs().
|
2012-05-05 02:41:06 +02:00
|
|
|
$this->renderBody());
|
2012-02-29 23:28:48 +01:00
|
|
|
|
|
|
|
if ($this->onRight) {
|
2012-05-05 02:41:06 +02:00
|
|
|
$core = '<th></th><td></td><th></th><td colspan="2">'.$content.'</td>';
|
2012-02-29 23:28:48 +01:00
|
|
|
} else {
|
2012-05-05 02:41:06 +02:00
|
|
|
$core = '<th></th><td>'.$content.'</td><th></th><td colspan="2"></td>';
|
2012-02-29 23:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return '<table><tr class="inline-comment-splint">'.$core.'</tr></table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderInputs() {
|
|
|
|
$out = array();
|
|
|
|
foreach ($this->inputs as $input) {
|
|
|
|
list($name, $value) = $input;
|
|
|
|
$out[] = phutil_render_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => $name,
|
|
|
|
'value' => $value,
|
|
|
|
),
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
return implode('', $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderBody() {
|
|
|
|
$buttons = array();
|
|
|
|
|
2012-03-06 20:48:01 +01:00
|
|
|
$buttons[] = '<button>Ready</button>';
|
2012-02-29 23:28:48 +01:00
|
|
|
$buttons[] = javelin_render_tag(
|
|
|
|
'button',
|
|
|
|
array(
|
|
|
|
'sigil' => 'inline-edit-cancel',
|
|
|
|
'class' => 'grey',
|
|
|
|
),
|
|
|
|
'Cancel');
|
|
|
|
|
|
|
|
$buttons = implode('', $buttons);
|
2012-07-20 23:04:28 +02:00
|
|
|
|
|
|
|
$formatting = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => PhabricatorEnv::getDoclink(
|
|
|
|
'article/Remarkup_Reference.html'),
|
|
|
|
'tabindex' => '-1',
|
|
|
|
'target' => '_blank',
|
|
|
|
),
|
|
|
|
'Formatting Reference');
|
|
|
|
|
2012-03-10 01:04:25 +01:00
|
|
|
return javelin_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-inline-comment-edit',
|
|
|
|
'sigil' => 'differential-inline-comment',
|
|
|
|
'meta' => array(
|
|
|
|
'on_right' => $this->onRight,
|
|
|
|
'number' => $this->number,
|
|
|
|
'length' => $this->length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'<div class="differential-inline-comment-edit-title">'.
|
|
|
|
phutil_escape_html($this->title).
|
|
|
|
'</div>'.
|
|
|
|
'<div class="differential-inline-comment-edit-body">'.
|
|
|
|
$this->renderChildren().
|
|
|
|
'</div>'.
|
|
|
|
'<div class="differential-inline-comment-edit-buttons">'.
|
2012-07-20 23:04:28 +02:00
|
|
|
$formatting.
|
2012-03-10 01:04:25 +01:00
|
|
|
$buttons.
|
|
|
|
'<div style="clear: both;"></div>'.
|
|
|
|
'</div>');
|
2012-02-29 23:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|