launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04941
[Merge] lp:~rvb/launchpad/confirmationoverlay-fn into lp:launchpad
Raphaël Victor Badin has proposed merging lp:~rvb/launchpad/confirmationoverlay-fn into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/launchpad/confirmationoverlay-fn/+merge/74997
This branch improves the functionality of the ConfirmationOverlay object: it now takes an optional callback function which will be called when the confirmation is passed (i.e. 'ok' is clicked on the confirmation overlay) instead of submitting the form.
= Tests =
lib/lp/app/javascript/confirmationoverlay/tests/test_confirmationoverlay.html
= Q/A =
None.
--
https://code.launchpad.net/~rvb/launchpad/confirmationoverlay-fn/+merge/74997
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/launchpad/confirmationoverlay-fn into lp:launchpad.
=== modified file 'lib/lp/app/javascript/confirmationoverlay/confirmationoverlay.js'
--- lib/lp/app/javascript/confirmationoverlay/confirmationoverlay.js 2011-08-30 17:32:03 +0000
+++ lib/lp/app/javascript/confirmationoverlay/confirmationoverlay.js 2011-09-12 13:37:39 +0000
@@ -59,6 +59,18 @@
},
/**
+ * Ann (optional) callback function that should be called (instead
+ * of submitting the form ) when the confirmation has been passed.
+ *
+ * @attribute submit_fn
+ * @type Function
+ * @default null
+ */
+ submit_fn: {
+ value: null
+ },
+
+ /**
* An optional function (must return a string or a Node) that will be run
* to populate the form_content of the confirmation overlay when it's
* displayed. This is useful if the confirmation overlay must displayed
@@ -117,13 +129,24 @@
this.set('submit_form', this.get('button').ancestor('form'));
- // When ok is clicked, submit the form.
var self = this;
- var submit_form = function() {
- self._createHiddenDispatcher();
- self._submitForm();
- };
- this.set('form_submit_callback', submit_form);
+ var submit_fn = this.get('submit_fn');
+ if (submit_fn === null) {
+ // When ok is clicked, submit the form.
+ var submit_form = function() {
+ self._createHiddenDispatcher();
+ self._submitForm();
+ };
+ this.set('form_submit_callback', submit_form);
+ }
+ else {
+ // When ok is clicked, call submit_fn.
+ var submit_form_fn = function() {
+ self.hide();
+ submit_fn();
+ };
+ this.set('form_submit_callback', submit_form_fn);
+ }
// Enable the button if it's disabled.
this.get('button').set('disabled', false);
=== modified file 'lib/lp/app/javascript/confirmationoverlay/tests/test_confirmationoverlay.js'
--- lib/lp/app/javascript/confirmationoverlay/tests/test_confirmationoverlay.js 2011-08-30 17:01:22 +0000
+++ lib/lp/app/javascript/confirmationoverlay/tests/test_confirmationoverlay.js 2011-09-12 13:37:39 +0000
@@ -157,6 +157,24 @@
// The Overlay was not displayed.
Y.Assert.isFalse(this.overlay.get('visible'));
+ },
+
+ test_callback_called: function() {
+ // If submit_fn is passed to the constructor, call this function
+ // when the 'ok' is clicked instead of submitting the form.
+ var called = false;
+ var callback = function() {
+ called = true;
+ };
+ this.overlay = new Y.lp.app.confirmationoverlay.ConfirmationOverlay({
+ button: this.button,
+ submit_fn: callback
+ });
+ this.button.simulate('click');
+ Y.Assert.isTrue(this.overlay.get('visible'));
+ this.overlay.form_node.one('.ok-btn').simulate('click');
+ Y.Assert.isFalse(this.overlay.get('visible'));
+ Y.Assert.isTrue(called);
}
}));