diff --git a/include/staff/orgs.inc.php b/include/staff/orgs.inc.php index fe805eb739bfa500fe9bf97b292e4f66a95ebb5e..3f500a6f1edf5cbe41ed7f3b2a57eb076f5832f0 100644 --- a/include/staff/orgs.inc.php +++ b/include/staff/orgs.inc.php @@ -205,7 +205,8 @@ $(function() { $(document).on('click', 'a.add-org', function(e) { e.preventDefault(); $.orgLookup('ajax.php/orgs/add', function (org) { - window.location.href = 'orgs.php?id='+org.id; + var url = 'orgs.php?id=' + org.id; + $.pjax({url: url, container: '#pjax-container'}) }); return false; diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index 3ac970a0d78a909b9b8d3d4cdff488ca09f0212e..ab21a960653dc950c66ede49df993c4eceaae6e4 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -257,10 +257,11 @@ $(function() { $(document).on('click', 'a.popup-dialog', function(e) { e.preventDefault(); $.userLookup('ajax.php/' + $(this).attr('href').substr(1), function (user) { + var url = window.location.href; if (user && user.id) - window.location.href = 'users.php?id='+user.id; - else - $.pjax({url: window.location.href, container: '#pjax-container'}) + url = 'users.php?id='+user.id; + $.pjax({url: url, container: '#pjax-container'}) + return false; }); return false; @@ -296,11 +297,14 @@ $(function() { $(document).on('dialog:close', function(e, json) { $form = $('form#users-list'); try { - var json = $.parseJSON(json); - $form.find('#org_id').val(json.id); - goBaby('setorg', true); + var json = $.parseJSON(json), + org_id = $form.find('#org_id'); + if (json.id) { + org_id.val(json.id); + goBaby('setorg', true); + } } - catch (e) { console.log(e); } + catch (e) { } }); }); </script> diff --git a/scp/js/scp.js b/scp/js/scp.js index 45186f42991eebc2efcd37fe3d2d562dd3e6c1c3..67bdca721289a744fd2a8de69340afd122579ce4 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -529,11 +529,11 @@ $.toggleOverlay = function (show) { return $.toggleOverlay(!$('#overlay').is(':visible')); } if (show) { - $('#overlay').fadeIn(); + $('#overlay').stop().hide().fadeIn(); $('body').css('overflow', 'hidden'); } else { - $('#overlay').fadeOut(); + $('#overlay').stop().fadeOut(); $('body').css('overflow', 'auto'); } }; @@ -570,13 +570,15 @@ $.dialog = function (url, codes, cb, options) { data: $form.serialize(), cache: false, success: function(resp, status, xhr) { - var done = $.Event('dialog:close'); if (xhr && xhr.status && codes && $.inArray(xhr.status, codes) != -1) { $.toggleOverlay(false); $popup.hide(); $('div.body', $popup).empty(); - if(cb) cb(xhr, resp); + if (cb && (false === cb(xhr, resp))) + // Don't fire event if callback returns false + return; + var done = $.Event('dialog:close'); $popup.trigger(done, [resp, status, xhr]); } else { $('div.body', $popup).html(resp); @@ -612,7 +614,7 @@ $.confirm = function(message, title) { var D = $.Deferred(), $popup = $('.dialog#popup'), hide = function() { - $('#overlay').hide(); + $.toggleOverlay(false); $popup.hide(); }; $('div#popup-loading', $popup).hide(); @@ -635,7 +637,7 @@ $.confirm = function(message, title) { .attr('value', __('OK')) .click(function() { hide(); D.resolve(); }) ))).append($('<div class="clear"></div>')); - $('#overlay').fadeIn(); + $.toggleOverlay(true); $popup.show(); return D.promise(); }; @@ -643,7 +645,7 @@ $.confirm = function(message, title) { $.userLookup = function (url, cb) { $.dialog(url, 201, function (xhr) { var user = $.parseJSON(xhr.responseText); - if (cb) cb(user); + if (cb) return cb(user); }, { onshow: function() { $('#user-search').focus(); } }); @@ -728,6 +730,7 @@ $(document).on('pjax:start', function() { $(window).unbind('beforeunload'); // Close popups $('.dialog .body').empty().parent().hide(); + $.toggleOverlay(false); // Close tooltips $('.tip_box').remove(); }); @@ -743,7 +746,8 @@ $(document).on('pjax:send', function(event) { // right $('#loadingbar').stop(false, true).width((50 + Math.random() * 30) + "%"); - $('#overlay').css('background-color','white').fadeIn(); + $('#overlay').css('background-color','white'); + $.toggleOverlay(true); }); $(document).on('pjax:complete', function() {