2013-11-21 21:35:36 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-passphrase-credential-control
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-workflow
|
|
|
|
* javelin-util
|
2013-11-22 23:35:35 +01:00
|
|
|
* javelin-uri
|
|
|
|
* @javelin
|
2013-11-21 21:35:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2013-11-22 23:35:35 +01:00
|
|
|
var uri = JX.$U('/passphrase/edit/');
|
|
|
|
uri.setQueryParam('type', data.type);
|
|
|
|
uri.setQueryParam('username', data.username);
|
|
|
|
|
|
|
|
new JX.Workflow(uri)
|
2013-11-21 21:35:36 +01:00
|
|
|
.setHandler(JX.bind(null, onadd, control))
|
|
|
|
.start();
|
|
|
|
|
|
|
|
e.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
function onadd(control, response) {
|
|
|
|
var select = JX.DOM.find(control, 'select', 'passphrase-credential-select');
|
|
|
|
|
2013-11-22 23:35:35 +01:00
|
|
|
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;
|
2013-11-21 21:35:36 +01:00
|
|
|
for (var ii = 0; ii < select.options.length; ii++) {
|
|
|
|
if (!select.options[ii].value) {
|
2013-11-22 23:35:35 +01:00
|
|
|
if (!data.allowNull) {
|
|
|
|
select.remove(ii);
|
|
|
|
} else {
|
|
|
|
target = ii + 1;
|
|
|
|
}
|
2013-11-21 21:35:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
select.add(
|
|
|
|
JX.$N('option', {value: response.phid}, response.name),
|
2013-11-22 23:35:35 +01:00
|
|
|
select.options[target] || null);
|
2013-11-21 21:35:36 +01:00
|
|
|
|
|
|
|
select.value = response.phid;
|
|
|
|
select.disabled = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|