From 89873f0c4d01226e9928cf80ea7ef8244054fb3a Mon Sep 17 00:00:00 2001 From: rlx Date: Sat, 16 Jan 2016 14:59:34 +0530 Subject: [PATCH] improved handling of booking falling out of context after edit/delete --- static/js/browser.js | 58 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/static/js/browser.js b/static/js/browser.js index 925bc18..04165d0 100644 --- a/static/js/browser.js +++ b/static/js/browser.js @@ -92,32 +92,12 @@ oml.ui.browser = function() { } }, select: function(data) { - if (ui.item) { - if (data.ids.length) { - oml.UI.set({ - item: data.ids[0], - itemView: 'info', - listSelection: data.ids - }); - } else { - // no longer in context after edit - oml.api.find({ - query: {conditions: [], operator: '&'}, - positions: [ui.item] - }, function(result) { - if (result.data.positions[ui.item] === void 0) { - // no longer in libraries after delete - oml.UI.set({item: ''}); - } else { - oml.stayInItemView = true; - oml.UI.set({ - find: {conditions: [], operator: '&'}, - listSelection: [ui.item] - }); - oml.stayInItemView = false; - } - }); - } + if (ui.item && data.ids.length) { + oml.UI.set({ + item: data.ids[0], + itemView: 'info', + listSelection: data.ids + }); } }, toggle: function(data) { @@ -144,6 +124,32 @@ oml.ui.browser = function() { if (data.value.length) { that.options({selected: [data.value[0]]}); } + else { + // no longer in context after edit + Ox.print('OUT OF CONTEXT') + oml.api.find({ + query: {conditions: [], operator: '&'}, + positions: [ui.item] + }, function(result) { + if (result.data.positions[ui.item] === void 0) { + // no longer in libraries after delete + oml.UI.set({ + find: {conditions: [], operator: '&'}, + item: '', + listSelection: [] + }); + } else { + Ox.Request.clearCache('find'); + oml.stayInItemView = true; + oml.UI.set({ + find: {conditions: [], operator: '&'}, + item: ui.item, + listSelection: [ui.item] + }); + oml.stayInItemView = false; + } + }); + } }, oml_listsort: function(data) { that.options({sort: data.value});