1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

Multiple comment submissions for a diff is prevented now.

Summary:
It was possible to submit a comment multiple times if the submit
button was pressed more than once quickly. Added javascript code
that disables the button when it is clicked.

Test Plan:
Tried to click the button multiple times very quickly, but the
button was disabled after the first click.

Reviewed By: epriestley
Reviewers: epriestley, jungejason
Commenters: aran
CC: aran, epriestley, tuomaspelkonen
Differential Revision: 337
This commit is contained in:
tuomaspelkonen 2011-05-23 14:33:54 -07:00
parent 3dd12e7cc6
commit d21a056f1c
4 changed files with 66 additions and 0 deletions

View file

@ -284,6 +284,18 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/core/behavior-tokenizer.js',
),
'javelin-behavior-aphront-form-disable-on-submit' =>
array(
'uri' => '/res/6c659ede/rsrc/js/application/core/behavior-form.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-stratcom',
2 => 'javelin-dom',
),
'disk' => '/rsrc/js/application/core/behavior-form.js',
),
'javelin-behavior-dark-console' =>
array(
'uri' => '/res/044c171f/rsrc/js/application/core/behavior-dark-console.js',

View file

@ -64,6 +64,11 @@ final class AphrontFormView extends AphrontView {
public function render() {
require_celerity_resource('aphront-form-view-css');
Javelin::initBehavior(
'aphront-form-disable-on-submit',
array());
return javelin_render_tag(
'form',
array(

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'view/base');

View file

@ -0,0 +1,48 @@
/**
* @requires javelin-behavior javelin-stratcom javelin-dom
* @provides javelin-behavior-aphront-form-disable-on-submit
*/
JX.behavior('aphront-form-disable-on-submit', function(config) {
var restore = [];
var root = null;
JX.Stratcom.listen('submit', 'tag:form', function(e) {
if (e.getNode('workflow')) {
// Don't activate for forms with workflow, the workflow behavior will
// handle it.
return;
}
root = e.getNode('tag:form');
if (root._disabled) {
e.kill();
}
root._disabled = true;
var buttons = JX.DOM.scry(root, 'button');
for (var ii = 0; ii < buttons.length; ii++) {
if (!buttons[ii].disabled) {
buttons[ii].disabled = 'disabled';
JX.DOM.alterClass(buttons[ii], 'disabled', true);
restore.push(buttons[ii]);
}
}
});
JX.Stratcom.listen('unload', null, function(e) {
// Reenable everything on page unload so we don't bfcache back to a page
// that has disabled forms.
for (var ii = 0; ii < restore.length; ii++) {
restore[ii].disabled = '';
JX.DOM.alterClass(restore[ii], 'disabled', false);
root._disabled = false;
}
if (root) {
delete root._disabled;
}
restore = [];
root = null;
});
});