1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 08:20:57 +01:00
phorge-phorge/webroot/rsrc/js/phui/behavior-phui-timer-control.js
epriestley 2ca316d652 When users confirm Duo MFA in the mobile app, live-update the UI
Summary: Ref T13249. Poll for Duo updates in the background so we can automatically update the UI when the user clicks the mobile phone app button.

Test Plan: Hit a Duo gate, clicked "Approve" in the mobile app, saw the UI update immediately.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13249

Differential Revision: https://secure.phabricator.com/D20169
2019-02-15 14:38:15 -08:00

41 lines
986 B
JavaScript

/**
* @provides javelin-behavior-phui-timer-control
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
*/
JX.behavior('phui-timer-control', function(config) {
var node = JX.$(config.nodeID);
var uri = config.uri;
var state = null;
function onupdate(result) {
var markup = result.markup;
if (markup) {
var new_node = JX.$H(markup).getFragment().firstChild;
JX.DOM.replace(node, new_node);
node = new_node;
// If the overall state has changed from the previous display state,
// animate the control to draw the user's attention to the state change.
if (result.state !== state) {
state = result.state;
JX.DOM.alterClass(node, 'phui-form-timer-updated', true);
}
}
var retry = result.retry;
if (retry) {
setTimeout(update, 1000);
}
}
function update() {
new JX.Request(uri, onupdate)
.setTimeout(10000)
.send();
}
update();
});