2013-11-21 12:35:36 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PassphraseCredentialControl extends AphrontFormControl {
|
|
|
|
|
|
|
|
private $options;
|
|
|
|
private $credentialType;
|
2013-11-22 14:35:35 -08:00
|
|
|
private $defaultUsername;
|
|
|
|
private $allowNull;
|
|
|
|
|
|
|
|
public function setAllowNull($allow_null) {
|
|
|
|
$this->allowNull = $allow_null;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDefaultUsername($default_username) {
|
|
|
|
$this->defaultUsername = $default_username;
|
|
|
|
return $this;
|
|
|
|
}
|
2013-11-21 12:35:36 -08:00
|
|
|
|
|
|
|
public function setCredentialType($credential_type) {
|
|
|
|
$this->credentialType = $credential_type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCredentialType() {
|
|
|
|
return $this->credentialType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOptions(array $options) {
|
|
|
|
assert_instances_of($options, 'PassphraseCredential');
|
|
|
|
$this->options = $options;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomControlClass() {
|
|
|
|
return 'passphrase-credential-control';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderInput() {
|
|
|
|
|
|
|
|
$options_map = array();
|
|
|
|
foreach ($this->options as $option) {
|
|
|
|
$options_map[$option->getPHID()] = pht(
|
|
|
|
"%s %s",
|
|
|
|
'K'.$option->getID(),
|
|
|
|
$option->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
$disabled = $this->getDisabled();
|
2013-11-22 14:35:35 -08:00
|
|
|
if ($this->allowNull) {
|
|
|
|
$options_map = array('' => pht('(No Credentials)')) + $options_map;
|
|
|
|
} else {
|
|
|
|
if (!$options_map) {
|
|
|
|
$options_map[''] = pht('(No Existing Credentials)');
|
|
|
|
$disabled = true;
|
|
|
|
}
|
2013-11-21 12:35:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Javelin::initBehavior('passphrase-credential-control');
|
|
|
|
|
|
|
|
$options = AphrontFormSelectControl::renderSelectTag(
|
|
|
|
$this->getValue(),
|
|
|
|
$options_map,
|
|
|
|
array(
|
|
|
|
'id' => $this->getControlID(),
|
|
|
|
'name' => $this->getName(),
|
|
|
|
'disabled' => $disabled ? 'disabled' : null,
|
|
|
|
'sigil' => 'passphrase-credential-select',
|
|
|
|
));
|
|
|
|
|
|
|
|
$button = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'class' => 'button grey',
|
|
|
|
'sigil' => 'passphrase-credential-add',
|
|
|
|
'mustcapture' => true,
|
|
|
|
),
|
|
|
|
pht('Add Credential'));
|
|
|
|
|
|
|
|
return javelin_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'sigil' => 'passphrase-credential-control',
|
|
|
|
'meta' => array(
|
|
|
|
'type' => $this->getCredentialType(),
|
2013-11-22 14:35:35 -08:00
|
|
|
'username' => $this->defaultUsername,
|
|
|
|
'allowNull' => $this->allowNull,
|
2013-11-21 12:35:36 -08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$options,
|
|
|
|
$button,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|