From e674840630e058c0e2994f909e75a60fde4dd94d Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 10 Mar 2015 16:52:44 +1100 Subject: [PATCH] Fixed bug where uploading an attachment would discard your changes --- src/main/webapp/modules/feature-test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/webapp/modules/feature-test.js b/src/main/webapp/modules/feature-test.js index 228c0f3d..dbed856c 100644 --- a/src/main/webapp/modules/feature-test.js +++ b/src/main/webapp/modules/feature-test.js @@ -228,6 +228,25 @@ YUI.add('feature-test', function (Y) { }, _addClickListeners: function () { Y.all('.upload-attachment').each(Y.bind(function (item) { + item.ancestor().on('click', Y.bind(function(e) { + var editInProgress = function(model) { + var i = 0; + for (var property in model.changed) { + if (model.changed.hasOwnProperty(property)) { + i++; + } + } + return i>0; + }, + model = this.get('model'); + + if (editInProgress(model)) { + alert('Please save or discard your changes before uploading attachments'); + e.preventDefault(); + e.stopPropagation(); + return false; + } + }, this)); item.on('change', Y.bind(function () { var model = this.get('model'), formgroup = item.ancestor(".image-form"),