From cbcd96dfbe8f4f083857e297102dd78ff309dd65 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Wed, 2 Dec 2015 06:28:51 +1030 Subject: [PATCH 1/2] MA-204 Added self to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 8026729689..e4bf2dbed6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -257,3 +257,4 @@ Muhammad Rehan Shawn Milochik Afeef Janjua Jacek Bzdak +Jillian Vogel From 6fd5ba5a69123e580f7fb4690748be0902169dfa Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Sun, 29 Nov 2015 10:13:50 +1030 Subject: [PATCH 2/2] MA-240 Added window beforeunload handler to the ActiveVideoUploadList view, which shows a notification if there are any "Queued" or "Uploading" videos still in progress. --- .../views/active_video_upload_list_spec.js | 28 +++++++++++++++++++ .../js/views/active_video_upload_list.js | 15 ++++++++++ 2 files changed, 43 insertions(+) diff --git a/cms/static/js/spec/views/active_video_upload_list_spec.js b/cms/static/js/spec/views/active_video_upload_list_spec.js index 7c016507c5..bd1b7fd623 100644 --- a/cms/static/js/spec/views/active_video_upload_list_spec.js +++ b/cms/static/js/spec/views/active_video_upload_list_spec.js @@ -22,6 +22,11 @@ define( $(document).ajaxError(this.globalAjaxError); }); + // Remove window unload handler triggered by the upload requests + afterEach(function() { + $(window).off("beforeunload"); + }); + it("should trigger file selection when either the upload button or the drop zone is clicked", function() { var clickSpy = jasmine.createSpy(); clickSpy.andCallFake(function(event) { event.preventDefault(); }); @@ -33,6 +38,10 @@ define( expect(clickSpy).toHaveBeenCalled(); }); + it('should not show a notification message if there are no active video uploads', function () { + expect(this.view.onBeforeUnload()).toBeUndefined(); + }); + var makeUploadUrl = function(fileName) { return "http://www.example.com/test_url/" + fileName; }; @@ -152,6 +161,10 @@ define( }); }); + it('should show a notification message when there are active video uploads', function () { + expect(this.view.onBeforeUnload()).toBe("Your video uploads are not complete."); + }); + // TODO: test progress update; the libraries we are using to mock ajax // do not currently support progress events. If we upgrade to Jasmine // 2.0, the latest version of jasmine-ajax (mock-ajax.js) does have the @@ -211,6 +224,21 @@ define( expect($uploadElem).not.toHaveClass("queued"); }); } + + // If we're uploading more files than the one we've closed above, + // the unload warning should still be shown + if (caseInfo.numFiles > 1) { + it('should show notification when videos are still uploading', + function () { + expect(this.view.onBeforeUnload()).toBe( + "Your video uploads are not complete."); + }); + } else { + it('should not show notification once video uploads are complete', + function () { + expect(this.view.onBeforeUnload()).toBeUndefined(); + }); + } }); } ); diff --git a/cms/static/js/views/active_video_upload_list.js b/cms/static/js/views/active_video_upload_list.js index 46d9fd7f05..92a1d752e0 100644 --- a/cms/static/js/views/active_video_upload_list.js +++ b/cms/static/js/views/active_video_upload_list.js @@ -48,10 +48,25 @@ define( }; $(window).on("dragover", preventDefault); $(window).on("drop", preventDefault); + $(window).on("beforeunload", this.onBeforeUnload.bind(this)); return this; }, + onBeforeUnload: function () { + // Are there are uploads queued or in progress? + var uploading = this.collection.filter(function(model) { + var stat = model.get("status"); + return (model.get("progress") < 1) && + ((stat === ActiveVideoUpload.STATUS_QUEUED || + (stat === ActiveVideoUpload.STATUS_UPLOADING))); + }); + // If so, show a warning message. + if (uploading.length) { + return gettext("Your video uploads are not complete."); + } + }, + addUpload: function(model) { var itemView = new ActiveVideoUploadView({model: model}); this.itemViews.push(itemView);