Page MenuHomePhabricator

D7624.diff

diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php
--- a/src/__celerity_resource_map__.php
+++ b/src/__celerity_resource_map__.php
@@ -1982,15 +1982,16 @@
),
'javelin-behavior-passphrase-credential-control' =>
array(
- 'uri' => '/res/e606ad52/rsrc/js/application/passphrase/phame-credential-control.js',
+ 'uri' => '/res/70823662/rsrc/js/application/passphrase/phame-credential-control.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-dom',
2 => 'javelin-stratcom',
3 => 'javelin-workflow',
4 => 'javelin-util',
+ 5 => 'javelin-uri',
),
'disk' => '/rsrc/js/application/passphrase/phame-credential-control.js',
),
diff --git a/src/applications/passphrase/controller/PassphraseCredentialEditController.php b/src/applications/passphrase/controller/PassphraseCredentialEditController.php
--- a/src/applications/passphrase/controller/PassphraseCredentialEditController.php
+++ b/src/applications/passphrase/controller/PassphraseCredentialEditController.php
@@ -45,6 +45,9 @@
->setProvidesType($type->getProvidesType());
$is_new = true;
+
+ // Prefill username if provided.
+ $credential->setUsername($request->getStr('username'));
}
$errors = array();
diff --git a/src/applications/passphrase/view/PassphraseCredentialControl.php b/src/applications/passphrase/view/PassphraseCredentialControl.php
--- a/src/applications/passphrase/view/PassphraseCredentialControl.php
+++ b/src/applications/passphrase/view/PassphraseCredentialControl.php
@@ -4,6 +4,18 @@
private $options;
private $credentialType;
+ 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;
+ }
public function setCredentialType($credential_type) {
$this->credentialType = $credential_type;
@@ -35,9 +47,13 @@
}
$disabled = $this->getDisabled();
- if (!$options_map) {
- $options_map[''] = pht('(No Existing Credentials)');
- $disabled = true;
+ if ($this->allowNull) {
+ $options_map = array('' => pht('(No Credentials)')) + $options_map;
+ } else {
+ if (!$options_map) {
+ $options_map[''] = pht('(No Existing Credentials)');
+ $disabled = true;
+ }
}
Javelin::initBehavior('passphrase-credential-control');
@@ -68,6 +84,8 @@
'sigil' => 'passphrase-credential-control',
'meta' => array(
'type' => $this->getCredentialType(),
+ 'username' => $this->defaultUsername,
+ 'allowNull' => $this->allowNull,
),
),
array(
diff --git a/webroot/rsrc/js/application/passphrase/phame-credential-control.js b/webroot/rsrc/js/application/passphrase/phame-credential-control.js
--- a/webroot/rsrc/js/application/passphrase/phame-credential-control.js
+++ b/webroot/rsrc/js/application/passphrase/phame-credential-control.js
@@ -5,6 +5,8 @@
* javelin-stratcom
* javelin-workflow
* javelin-util
+ * javelin-uri
+ * @javelin
*/
JX.behavior('passphrase-credential-control', function(config) {
@@ -16,7 +18,11 @@
var control = e.getNode('passphrase-credential-control');
var data = e.getNodeData('passphrase-credential-control');
- new JX.Workflow('/passphrase/edit/?type=' + data.type)
+ var uri = JX.$U('/passphrase/edit/');
+ uri.setQueryParam('type', data.type);
+ uri.setQueryParam('username', data.username);
+
+ new JX.Workflow(uri)
.setHandler(JX.bind(null, onadd, control))
.start();
@@ -26,16 +32,29 @@
function onadd(control, response) {
var select = JX.DOM.find(control, 'select', 'passphrase-credential-select');
+ var data = JX.Stratcom.getData(control);
+
+ // If this allows the user to select "No Credential" (`allowNull`),
+ // put the new credential in the menu below the "No Credential" option.
+
+ // Otherwise, remove the "(No Existing Credentials)" if it exists and
+ // put the new credential at the top.
+
+ var target = 0;
for (var ii = 0; ii < select.options.length; ii++) {
if (!select.options[ii].value) {
- select.remove(ii);
+ if (!data.allowNull) {
+ select.remove(ii);
+ } else {
+ target = ii + 1;
+ }
break;
}
}
select.add(
JX.$N('option', {value: response.phid}, response.name),
- select.options[0] || null);
+ select.options[target] || null);
select.value = response.phid;
select.disabled = null;

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/ve/xc/gx6o4jqwlarxgkb2
Default Alt Text
D7624.diff (4 KB)

Event Timeline