Commit 6506e8fd authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge remote-tracking branch 'origin/raos_work' into crose_work

parents 092e6deb 3b77b79f
......@@ -66,9 +66,6 @@ var QfqNS = QfqNS || {};
this.eventEmitter = new EventEmitter();
this.userOkButtonHandlers = new n.Helper.FunctionList();
this.userCancelButtonHandlers = new n.Helper.FunctionList();
this.userSaveButtonHandlers = new n.Helper.FunctionList();
};
n.Alert.prototype.on = n.EventEmitter.onMixin;
......
......@@ -179,8 +179,23 @@ var QfqNS = QfqNS || {};
/**
* @private
*/
n.QfqForm.prototype.handleNewClick = function () {
n.QfqForm.prototype.handleNewClick = function (event) {
event.preventDefault();
var anchorTarget = event.target.getAttribute("href");
this.lastButtonPress = "new";
if (this.form.getFormChanged()) {
var alert = new n.Alert("You have unsaved changes. Do you want to close?", "warning", "yesnosave");
var that = this;
alert.on('alert.save', function () {
that.form.submitTo(that.submitTo);
window.location = anchorTarget;
});
alert.on('alert.ok', function () {
window.location = anchorTarget;
});
alert.show();
}
n.Log.debug("new click");
};
......@@ -330,7 +345,7 @@ var QfqNS = QfqNS || {};
* @private
*/
n.QfqForm.prototype.getNewButton = function () {
return $("#new-button");
return $("#form-new-button");
};
......
......@@ -6,8 +6,8 @@
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.4.1/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.4.1/jasmine.css">
<link rel="stylesheet" href="../../packages/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../../packages/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/bootstrap-theme.min.css">
<script src="lib/jasmine-2.4.1/jasmine.js"></script>
<script src="lib/jasmine-2.4.1/jasmine-html.js"></script>
......
......@@ -61,7 +61,7 @@ describe("Bootstrap Tabs", function () {
it("should call user 'show tab' handlers", function () {
var showHandlerSpy = jasmine.createSpy('showhandler');
bsTabs.addTabShowHandler(showHandlerSpy);
bsTabs.on('bootstrap.tab.shown', showHandlerSpy);
bsTabs.activateTab('tab1');
expect(showHandlerSpy).toHaveBeenCalled();
......
......@@ -45,23 +45,28 @@ describe("Form", function () {
it("should notify upon form change", function () {
var changeHandler = jasmine.createSpy('ChangeHandler');
form.addChangeHandler(changeHandler);
form.on('form.changed', changeHandler);
$("#name").change();
expect(changeHandler).toHaveBeenCalledTimes(1);
expect(changeHandler).toHaveBeenCalledWith(form);
var callArgs = changeHandler.calls.argsFor(0)[0];
expect(callArgs.target).toBeDefined();
expect(callArgs.target).toBe(form);
});
it("should notify upon state reset", function () {
var resetHandler = jasmine.createSpy('StateResetHandler');
form.addResetHandler(resetHandler);
form.on('form.reset', resetHandler);
form.resetFormChanged();
expect(resetHandler).toHaveBeenCalledTimes(1);
expect(resetHandler).toHaveBeenCalledWith(form);
var callArgs = resetHandler.calls.argsFor(0)[0];
expect(callArgs.target).toBeDefined();
expect(callArgs.target).toBe(form);
});
it("should reset state upon resetFormChanged()", function () {
......@@ -79,8 +84,8 @@ describe("Form", function () {
var successHandler = jasmine.createSpy("success");
var failureHandler = jasmine.createSpy("failure");
form.addSubmitSuccessHandler(successHandler);
form.addSubmitFailureHandler(failureHandler);
form.on('form.submit.successful', successHandler);
form.on('form.submit.failed', failureHandler);
form.submitTo("/test/url");
jasmine.Ajax.requests.mostRecent().respondWith({
......@@ -89,7 +94,7 @@ describe("Form", function () {
"responseText": "{ \"status\": \"success\" }"
});
expect(successHandler).toHaveBeenCalledWith(form, {status: "success"}, "success");
expect(successHandler).toHaveBeenCalledTimes(1);
expect(failureHandler).not.toHaveBeenCalled();
jasmine.Ajax.uninstall();
......@@ -101,8 +106,8 @@ describe("Form", function () {
var successHandler = jasmine.createSpy("success");
var failureHandler = jasmine.createSpy("failure");
form.addSubmitSuccessHandler(successHandler);
form.addSubmitFailureHandler(failureHandler);
form.on('form.submit.successful', successHandler);
form.on('form.submit.failed', failureHandler);
form.submitTo("/test/url");
jasmine.Ajax.requests.mostRecent().respondWith({
......@@ -114,10 +119,12 @@ describe("Form", function () {
expect(successHandler).not.toHaveBeenCalled();
expect(failureHandler).toHaveBeenCalled();
expect(failureHandler.calls.argsFor(0)[0]).toBe(form);
expect(failureHandler.calls.argsFor(0)[1]).toBe("error");
// arg 2 is jqXHR, which I don't want to test for, and therefore continue with 3
expect(failureHandler.calls.argsFor(0)[3]).toBe("not found");
var callArgs = failureHandler.calls.argsFor(0)[0];
expect(callArgs.target).toBe(form);
expect(callArgs.textStatus).toBe("error");
expect(callArgs.errorThrown).toBe("not found");
jasmine.Ajax.uninstall();
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment