Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Restore submits to Picreel
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Sage committed May 11, 2015
1 parent 6b91a72 commit cceec94
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 25 deletions.
10 changes: 2 additions & 8 deletions build/picreel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
this.action = this.action || "/";
this.carrier = null;

this.unbindDefaultClickEvents();
this.bindNewClickEvents();
}

Expand Down Expand Up @@ -57,10 +56,9 @@
};

APLSubscriber.prototype.handleButtonClick = function(e) {
e.preventDefault();
$(self).trigger('onBeforeSubmit');
this.removeErrorStatus();
this.applyLoadingStatus();

var email = this.$(this.emailSelector).val();

if(this.emailIsValid(email)) {
Expand Down Expand Up @@ -121,14 +119,10 @@
this.carrier = this.$.ajax(carrierOptions);
};

APLSubscriber.prototype.unbindDefaultClickEvents = function() {
this.$(this.submitSelector).off('click');
};

APLSubscriber.prototype.bindNewClickEvents = function() {
var _APL = this;

this.$(_APL.submitSelector).on('click', function(e){
this.$(this.submitSelector).on('onBeforeSubmit', function(e){
_APL.handleButtonClick(e);
});
};
Expand Down
2 changes: 1 addition & 1 deletion build/picreel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/picreel.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions lib/factories/subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
this.action = this.action || "/";
this.carrier = null;

this.unbindDefaultClickEvents();
this.bindNewClickEvents();
}

Expand Down Expand Up @@ -56,10 +55,9 @@
};

APLSubscriber.prototype.handleButtonClick = function(e) {
e.preventDefault();
$(self).trigger('onBeforeSubmit');
this.removeErrorStatus();
this.applyLoadingStatus();

var email = this.$(this.emailSelector).val();

if(this.emailIsValid(email)) {
Expand Down Expand Up @@ -120,14 +118,10 @@
this.carrier = this.$.ajax(carrierOptions);
};

APLSubscriber.prototype.unbindDefaultClickEvents = function() {
this.$(this.submitSelector).off('click');
};

APLSubscriber.prototype.bindNewClickEvents = function() {
var _APL = this;

this.$(_APL.submitSelector).on('click', function(e){
this.$(this.submitSelector).on('onBeforeSubmit', function(e){
_APL.handleButtonClick(e);
});
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picreel",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"author": {
"name": "Brian Sage",
Expand Down
10 changes: 4 additions & 6 deletions test/lib/picreel_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,27 @@ QUnit.test("APL Subscriber", function(assert) {
handleButtonClickSpy.reset();
applyLoadingStatusSpy.reset();
$(subject.emailSelector).val(validEmail);
$(subject.submitSelector).trigger("click");
$(subject.submitSelector).trigger("onBeforeSubmit");
assert.ok(handleButtonClickSpy.called, "When button is clicked, subscriber should submit to custom handler");
assert.ok(applyLoadingStatusSpy.called, "Indicates when loading");

submitSpy.reset();
applyErrorStatusSpy.reset();
$(subject.emailSelector).val(invalidEmail);
$(subject.submitSelector).trigger("click");
$(subject.submitSelector).trigger("onBeforeSubmit");
assert.notOk(submitSpy.called, "Won't submit an invalid Email");
assert.ok(applyErrorStatusSpy.called, "Indicates an error has occured");

submitSpy.reset();
removeErrorStatusSpy.reset();
$(subject.emailSelector).val(validEmail);
$(subject.submitSelector).trigger("click");
$(subject.submitSelector).trigger("onBeforeSubmit");
assert.ok(submitSpy.called, "Will submit a valid Email");
assert.ok(removeErrorStatusSpy.called, "Removes error indicators");

carrierSpy.reset();
$(subject.emailSelector).val(validEmail);
$(subject.submitSelector).trigger("click");
$(subject.submitSelector).trigger("onBeforeSubmit");
assert.deepEqual(subject.formToCarrierParams(), validFormData, "Reads data from the form");
assert.ok(carrierSpy.called, "Sends AJAX carrier");

//"Pass picreel extended form data"
});

0 comments on commit cceec94

Please sign in to comment.