Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15283954
D7617.id17197.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D7617.id17197.diff
View Options
Index: src/__celerity_resource_map__.php
===================================================================
--- src/__celerity_resource_map__.php
+++ src/__celerity_resource_map__.php
@@ -1980,6 +1980,20 @@
),
'disk' => '/rsrc/js/application/owners/owners-path-editor.js',
),
+ 'javelin-behavior-passphrase-credential-control' =>
+ array(
+ 'uri' => '/res/b599c028/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',
+ ),
+ 'disk' => '/rsrc/js/application/passphrase/phame-credential-control.js',
+ ),
'javelin-behavior-persona-login' =>
array(
'uri' => '/res/128fdf56/rsrc/js/application/auth/behavior-persona-login.js',
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -946,6 +946,7 @@
'PackageModifyMail' => 'applications/owners/mail/PackageModifyMail.php',
'PassphraseController' => 'applications/passphrase/controller/PassphraseController.php',
'PassphraseCredential' => 'applications/passphrase/storage/PassphraseCredential.php',
+ 'PassphraseCredentialControl' => 'applications/passphrase/view/PassphraseCredentialControl.php',
'PassphraseCredentialCreateController' => 'applications/passphrase/controller/PassphraseCredentialCreateController.php',
'PassphraseCredentialDestroyController' => 'applications/passphrase/controller/PassphraseCredentialDestroyController.php',
'PassphraseCredentialEditController' => 'applications/passphrase/controller/PassphraseCredentialEditController.php',
@@ -3329,6 +3330,7 @@
0 => 'PassphraseDAO',
1 => 'PhabricatorPolicyInterface',
),
+ 'PassphraseCredentialControl' => 'AphrontFormControl',
'PassphraseCredentialCreateController' => 'PassphraseController',
'PassphraseCredentialDestroyController' => 'PassphraseController',
'PassphraseCredentialEditController' => 'PassphraseController',
Index: src/applications/passphrase/controller/PassphraseCredentialEditController.php
===================================================================
--- src/applications/passphrase/controller/PassphraseCredentialEditController.php
+++ src/applications/passphrase/controller/PassphraseCredentialEditController.php
@@ -129,8 +129,16 @@
$credential->saveTransaction();
- return id(new AphrontRedirectResponse())
- ->setURI('/K'.$credential->getID());
+ if ($request->isAjax()) {
+ return id(new AphrontAjaxResponse())->setContent(
+ array(
+ 'phid' => $credential->getPHID(),
+ 'name' => 'K'.$credential->getID().' '.$credential->getName(),
+ ));
+ } else {
+ return id(new AphrontRedirectResponse())
+ ->setURI('/K'.$credential->getID());
+ }
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$credential->killTransaction();
@@ -151,8 +159,14 @@
$secret_control = $type->newSecretControl();
- $form = id(new AphrontFormView())
- ->setUser($viewer)
+ if ($request->isAjax()) {
+ $form = new PHUIFormLayoutView();
+ } else {
+ $form = id(new AphrontFormView())
+ ->setUser($viewer);
+ }
+
+ $form
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
@@ -197,11 +211,6 @@
->setLabel($type->getSecretLabel())
->setValue($v_secret));
- $form->appendChild(
- id(new AphrontFormSubmitControl())
- ->setValue(pht('Save'))
- ->addCancelButton($this->getApplicationURI()));
-
$crumbs = $this->buildApplicationCrumbs();
if ($is_new) {
@@ -222,6 +231,23 @@
->setName(pht('Edit')));
}
+ if ($request->isAjax()) {
+ $dialog = id(new AphrontDialogView())
+ ->setUser($viewer)
+ ->setWidth(AphrontDialogView::WIDTH_FORM)
+ ->setTitle($title)
+ ->appendChild($form)
+ ->addSubmitButton(pht('Create Credential'))
+ ->addCancelButton($this->getApplicationURI());
+
+ return id(new AphrontDialogResponse())->setDialog($dialog);
+ }
+
+ $form->appendChild(
+ id(new AphrontFormSubmitControl())
+ ->setValue(pht('Save'))
+ ->addCancelButton($this->getApplicationURI()));
+
$box = id(new PHUIObjectBoxView())
->setHeaderText($header)
->setValidationException($validation_exception)
Index: src/applications/passphrase/view/PassphraseCredentialControl.php
===================================================================
--- /dev/null
+++ src/applications/passphrase/view/PassphraseCredentialControl.php
@@ -0,0 +1,79 @@
+<?php
+
+final class PassphraseCredentialControl extends AphrontFormControl {
+
+ private $options;
+ private $credentialType;
+
+ 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();
+ if (!$options_map) {
+ $options_map[''] = pht('(No Existing Credentials)');
+ $disabled = true;
+ }
+
+ 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(),
+ ),
+ ),
+ array(
+ $options,
+ $button,
+ ));
+ }
+
+}
Index: src/applications/uiexample/examples/PhabricatorFormExample.php
===================================================================
--- src/applications/uiexample/examples/PhabricatorFormExample.php
+++ src/applications/uiexample/examples/PhabricatorFormExample.php
@@ -38,11 +38,22 @@
$null_value = $null_time->readValueFromRequest($request);
}
+ $divider_control = new AphrontFormDividerControl();
+
+ $credentials = array();
+ $password_control = id(new PassphraseCredentialControl())
+ ->setName('credentialPHID')
+ ->setLabel(pht('Password'))
+ ->setCredentialType('password')
+ ->setOptions($credentials);
+
$form = id(new AphrontFormView())
->setUser($user)
->appendChild($start_time)
->appendChild($end_time)
->appendChild($null_time)
+ ->appendChild($divider_control)
+ ->appendChild($password_control)
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Submit'));
Index: webroot/rsrc/js/application/passphrase/phame-credential-control.js
===================================================================
--- /dev/null
+++ webroot/rsrc/js/application/passphrase/phame-credential-control.js
@@ -0,0 +1,44 @@
+/**
+ * @provides javelin-behavior-passphrase-credential-control
+ * @requires javelin-behavior
+ * javelin-dom
+ * javelin-stratcom
+ * javelin-workflow
+ * javelin-util
+ */
+
+JX.behavior('passphrase-credential-control', function(config) {
+
+ JX.Stratcom.listen(
+ 'click',
+ 'passphrase-credential-add',
+ function(e) {
+ var control = e.getNode('passphrase-credential-control');
+ var data = e.getNodeData('passphrase-credential-control');
+
+ new JX.Workflow('/passphrase/edit/?type=' + data.type)
+ .setHandler(JX.bind(null, onadd, control))
+ .start();
+
+ e.kill();
+ });
+
+ function onadd(control, response) {
+ var select = JX.DOM.find(control, 'select', 'passphrase-credential-select');
+
+ for (var ii = 0; ii < select.options.length; ii++) {
+ if (!select.options[ii].value) {
+ select.remove(ii);
+ break;
+ }
+ }
+
+ select.add(
+ JX.$N('option', {value: response.phid}, response.name),
+ select.options[0] || null);
+
+ select.value = response.phid;
+ select.disabled = null;
+ }
+
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 5, 8:59 AM (23 h, 41 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7224382
Default Alt Text
D7617.id17197.diff (8 KB)
Attached To
Mode
D7617: Add a credential selection control to Passphrase
Attached
Detach File
Event Timeline
Log In to Comment