Skip to content

Commit 7eedc9a

Browse files
committed
Merge pull request AtlasOfLivingAustralia#28 from chrisala/master
Dealing with unsaved MERI plan changes.
2 parents f72246b + 0ef0e88 commit 7eedc9a

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

fieldcapture-hubs-plugin/FieldcapturePluginGrailsPlugin.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import grails.util.Holders
22

33
class FieldcapturePluginGrailsPlugin {
44
// the plugin version
5-
def version = "1.0-SNAPSHOT"
5+
def version = "1.0.1-SNAPSHOT"
66
// the version or versions of Grails the plugin is designed for
77
def grailsVersion = "2.4 > *"
88
// resources that are excluded from plugin packaging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div id="timeoutMessage" class="hide">
2+
3+
<span class='label label-important'>Important</span><h4>There was an error while trying to save your changes.</h4>
4+
<p>This could be because your login has timed out or the internet is unavailable.</p>
5+
<p>Your data has been saved on this computer but you may need to login again before the data can be sent to the server.</p>
6+
<a href="${url}">Click here to refresh your login and reload this page.</a>
7+
</div>
8+
9+
<div id="unsavedChangesMessage" class="hide">
10+
11+
<span class='label label-important'>Important</span><h4>You have unsaved changes.</h4>
12+
<p>Press OK to discard your changes.</p>
13+
<p>Press Cancel to continue editing your ${unsavedData}.</p>
14+
15+
</div>

fieldcapture-hubs-plugin/web-app/js/fieldcapture-application.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,20 @@ function blockUIWithMessage(message) {
196196
opacity: .5,
197197
color: '#fff'
198198
} });
199-
}
199+
}
200+
201+
function confirmOnPageExit(e) {
202+
// If we haven't been passed the event get the window.event
203+
e = e || window.event;
204+
205+
var message = 'You have unsaved changes.';
206+
207+
// For IE6-8 and Firefox prior to version 4
208+
if (e)
209+
{
210+
e.returnValue = message;
211+
}
212+
213+
// For Chrome, Safari, IE8+ and Opera 12+
214+
return message;
215+
};

fieldcapture-hubs-plugin/web-app/js/knockout-dates.js

+67
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,49 @@ ko.dirtyFlag = function(root, isInitiallyDirty) {
652652
return result;
653653
};
654654

655+
/**
656+
* A simple dirty flag that will detect the first change to a model, then afterwards always return true (meaning
657+
* dirty). This is to prevent the full model being re-serialized to JSON on every change, which can cause
658+
* performance issues for large models.
659+
* From: http://www.knockmeout.net/2011/05/creating-smart-dirty-flag-in-knockoutjs.html
660+
* @param root the model.
661+
* @returns true if the model has changed since this function was added.
662+
*/
663+
ko.simpleDirtyFlag = function(root) {
664+
var _initialized = ko.observable(false);
665+
666+
// this allows for models that do not have a modelAsJSON method
667+
var getRepresentation = function () {
668+
return (typeof root.modelAsJSON === 'function') ? root.modelAsJSON() : ko.toJSON(root);
669+
};
670+
671+
var result = function() {};
672+
673+
//one-time dirty flag that gives up its dependencies on first change
674+
result.isDirty = ko.computed(function () {
675+
if (!_initialized()) {
676+
677+
//just for subscriptions
678+
getRepresentation();
679+
680+
//next time return true and avoid ko.toJS
681+
_initialized(true);
682+
683+
//on initialization this flag is not dirty
684+
return false;
685+
}
686+
687+
//on subsequent changes, flag is now dirty
688+
return true;
689+
});
690+
result.reset = function() {
691+
_initialized(false);
692+
}
693+
694+
return result;
695+
};
696+
697+
655698

656699
/**
657700
* A vetoableObservable is an observable that provides a mechanism to prevent changes to its value under certain
@@ -963,3 +1006,27 @@ function activityProgressClass(progress) {
9631006
return ACTIVITY_PROGRESS_CLASSES[progress];
9641007
}
9651008

1009+
ko.bindingHandlers.numeric = {
1010+
init: function (element, valueAccessor) {
1011+
$(element).on("keydown", function (event) {
1012+
// Allow: backspace, delete, tab, escape, and enter
1013+
if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
1014+
// Allow: Ctrl+A
1015+
(event.keyCode == 65 && event.ctrlKey === true) ||
1016+
// Allow: . ,
1017+
(event.keyCode == 190 || event.keyCode == 110) ||
1018+
// Allow: home, end, left, right
1019+
(event.keyCode >= 35 && event.keyCode <= 39)) {
1020+
// let it happen, don't do anything
1021+
return;
1022+
}
1023+
else {
1024+
// Ensure that it is a number and stop the keypress
1025+
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
1026+
event.preventDefault();
1027+
}
1028+
}
1029+
});
1030+
}
1031+
};
1032+

0 commit comments

Comments
 (0)