From 5d88bce00fade548f13d7b451d1ecd2ed75e9a13 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 16 Apr 2013 18:20:23 -0700 Subject: [PATCH] Fix Loading --- js/id/connection.js | 9 +++++--- js/id/ui/loading.js | 52 +++++++++++++++++++++++++++++++++------------ js/id/ui/save.js | 9 ++++++-- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/js/id/connection.js b/js/id/connection.js index c4312a932..0a649558b 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -33,12 +33,15 @@ iD.Connection = function(context) { }; function authLoading() { - loadingModal = iD.ui.loading(context.container(), - t('loading_auth')); + loadingModal = iD.ui.Loading(context) + .message(t('loading_auth')); + + context.container() + .call(loadingModal); } function authDone() { - if (loadingModal) loadingModal.remove(); + if (loadingModal) loadingModal.close(); } function getNodes(obj) { diff --git a/js/id/ui/loading.js b/js/id/ui/loading.js index 634f82aca..c4ad1d55c 100644 --- a/js/id/ui/loading.js +++ b/js/id/ui/loading.js @@ -1,20 +1,44 @@ -iD.ui.loading = function(selection, message, blocking) { - var modal = iD.ui.modal(selection, blocking); +iD.ui.Loading = function(context) { + var message = '', + blocking = false, + modal; - var loadertext = modal.select('.content') - .classed('loading-modal', true) - .append('div') - .attr('class', 'modal-section fillL'); + var loading = function(selection) { + modal = iD.ui.modal(selection, blocking); - loadertext.append('img') - .attr('class', 'loader') - .attr('src', context.imagePath('loader-white.gif')); + var loadertext = modal.select('.content') + .classed('loading-modal', true) + .append('div') + .attr('class', 'modal-section fillL'); - loadertext.append('h3') - .text(message || ''); + loadertext.append('img') + .attr('class', 'loader') + .attr('src', context.imagePath('loader-white.gif')); - modal.select('button.close') - .attr('class', 'hide'); + loadertext.append('h3') + .text(message); - return modal; + modal.select('button.close') + .attr('class', 'hide'); + + return loading; + }; + + loading.message = function(_) { + if (!arguments.length) return message; + message = _; + return loading; + }; + + loading.blocking = function(_) { + if (!arguments.length) return blocking; + blocking = _; + return loading; + }; + + loading.close = function() { + modal.remove(); + }; + + return loading; }; diff --git a/js/id/ui/save.js b/js/id/ui/save.js index 26c6d22a7..369982008 100644 --- a/js/id/ui/save.js +++ b/js/id/ui/save.js @@ -30,14 +30,19 @@ iD.ui.Save = function(context) { context.container().select('.shaded') .remove(); - var loading = iD.ui.loading(context.container(), t('save.uploading'), true); + var loading = iD.ui.Loading(context) + .message(t('save.uploading')) + .blocking(true); + + context.container() + .call(loading); connection.putChangeset( history.changes(), e.comment, history.imagery_used(), function(err, changeset_id) { - loading.remove(); + loading.close(); if (err) { var confirm = iD.ui.confirm(context.container()); confirm