add 'Update Results in the Background' checkbox to advanced find and list query dialogs; fix a bug where the list query wouldn't update when navigating away from and back to the list query tab

This commit is contained in:
rolux 2013-03-03 10:15:38 +00:00
parent 74511f85d6
commit d0e50719b8
3 changed files with 155 additions and 91 deletions

View file

@ -1,6 +1,7 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript // vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict'; 'use strict';
pandora.ui.filterDialog = function(list) { pandora.ui.filterDialog = function(list) {
var that = Ox.Dialog({ var that = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
@ -9,8 +10,7 @@ pandora.ui.filterDialog = function(list) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
var list = pandora.$ui.filterForm.$filter.getList(); var list = pandora.$ui.filterForm.getList();
that.close();
if (list.save) { if (list.save) {
pandora.api.addList({ pandora.api.addList({
name: list.name, name: list.name,
@ -27,14 +27,18 @@ pandora.ui.filterDialog = function(list) {
} }
}); });
Ox.Request.clearCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEventOnce({ $list.bindEventOnce({
load: function(data) { load: function(data) {
$list.gainFocus() $list.gainFocus()
.options({selected: [id]}); .options({selected: [id]});
} }
})
.reloadList();
}); });
}); } else if (!pandora.user.ui.updateAdvancedFind) {
pandora.$ui.filterForm.updateResults();
} }
that.close();
} }
}) })
], ],
@ -47,7 +51,24 @@ pandora.ui.filterDialog = function(list) {
removeOnClose: true, removeOnClose: true,
title: list ? 'Smart List - ' + list.name : 'Advanced Find', title: list ? 'Smart List - ' + list.name : 'Advanced Find',
width: 648 + Ox.UI.SCROLLBAR_SIZE width: 648 + Ox.UI.SCROLLBAR_SIZE
}),
$updateCheckbox = Ox.Checkbox({
title: 'Update Results in the Background',
value: pandora.user.ui.updateAdvancedFind
})
.css({float: 'left', margin: '4px'})
.bindEvent({
change: function(data) {
pandora.UI.set({updateAdvancedFind: data.value});
data.value && pandora.$ui.filterForm.updateResults();
}
}); });
$($updateCheckbox.find('.OxButton')[0]).css({margin: 0});
$(that.find('.OxBar')[1]).append($updateCheckbox);
return that; return that;
}; };

View file

@ -45,29 +45,39 @@ pandora.ui.filterForm = function(list) {
id: list.id, id: list.id,
query: data.query query: data.query
}, function(result) { }, function(result) {
if (pandora.user.ui.updateAdvancedFind) {
that.updateResults(data.query);
}
});
} else if (pandora.user.ui.updateAdvancedFind) {
that.updateResults();
}
that.triggerEvent('change', data);
}
})
);
that.getList = that.$filter.getList;
});
that.updateResults = function(query) {
if (list) {
Ox.Request.clearCache(list.id); Ox.Request.clearCache(list.id);
pandora.$ui.list pandora.$ui.list
.bindEventOnce({ .bindEventOnce({
init: function(data) { init: function(data) {
pandora.$ui.folderList[ pandora.$ui.folderList[
pandora.getListData().folder pandora.getListData().folder
].value(list.id, 'items', data.items); ].value(list.id, 'query', query);
} }
}) })
.reloadList(); .reloadList();
pandora.$ui.filters.forEach(function($filter) { pandora.$ui.filters.forEach(function($filter) {
$filter.reloadList(); $filter.reloadList();
}); });
});
} else { } else {
Ox.Log('FIND', 'change form', data.query, pandora.user.ui.find) pandora.UI.set({find: Ox.clone(that.$filter.options('query'), true)});
pandora.UI.set({find: Ox.clone(data.query, true)});
pandora.$ui.findElement.updateElement(); pandora.$ui.findElement.updateElement();
} }
} };
})
);
});
return that; return that;
}; };

View file

@ -5,7 +5,6 @@
pandora.ui.listDialog = function(section) { pandora.ui.listDialog = function(section) {
section = section || 'general'; section = section || 'general';
var width = getWidth(section);
var listData = pandora.getListData(), var listData = pandora.getListData(),
tabs = [].concat([ tabs = [].concat([
{id: 'general', title: 'General'}, {id: 'general', title: 'General'},
@ -15,6 +14,7 @@ pandora.ui.listDialog = function(section) {
: [] : []
), ),
ui = pandora.user.ui, ui = pandora.user.ui,
width = getWidth(section),
folderItems = ui.section == 'items' ? 'Lists' : Ox.toTitleCase(ui.section), folderItems = ui.section == 'items' ? 'Lists' : Ox.toTitleCase(ui.section),
folderItem = folderItems.slice(0, -1); folderItem = folderItems.slice(0, -1);
Ox.getObjectById(tabs, section).selected = true; Ox.getObjectById(tabs, section).selected = true;
@ -26,7 +26,12 @@ pandora.ui.listDialog = function(section) {
} else if (id == 'icon') { } else if (id == 'icon') {
return pandora.$ui.listIconPanel = pandora.ui.listIconPanel(listData); return pandora.$ui.listIconPanel = pandora.ui.listIconPanel(listData);
} else if (id == 'query') { } else if (id == 'query') {
return pandora.$ui.filterForm = pandora.ui.filterForm(listData); return pandora.$ui.filterForm = pandora.ui.filterForm(listData)
.bindEvent({
change: function(data) {
listData.query = data.query;
}
});
} }
}, },
tabs: tabs tabs: tabs
@ -40,6 +45,14 @@ pandora.ui.listDialog = function(section) {
}); });
$dialog.setSize(width, 312); $dialog.setSize(width, 312);
$findElement[data.selected == 'icon' ? 'show' : 'hide'](); $findElement[data.selected == 'icon' ? 'show' : 'hide']();
$updateCheckbox[data.selected == 'query' ? 'show' : 'hide']();
if (
pandora.user.ui.section == 'items'
&& data.selected != 'query'
&& !pandora.user.ui.updateAdvancedFind
) {
pandora.$ui.filterForm.updateResults();
}
} }
}); });
pandora.$ui.listDialogTabPanel.find('.OxButtonGroup').css({width: '256px'}); pandora.$ui.listDialogTabPanel.find('.OxButtonGroup').css({width: '256px'});
@ -80,13 +93,11 @@ pandora.ui.listDialog = function(section) {
}) })
], ],
}) })
.css({float: 'right', margin: '4px', align: 'right'}); .css({float: 'right', margin: '4px', align: 'right'})
if (section != 'icon') { [section == 'icon' ? 'show' : 'hide']()
$findElement.hide(); .appendTo(pandora.$ui.listDialogTabPanel.children('.OxBar')),
}
$findElement.appendTo(pandora.$ui.listDialogTabPanel.children('.OxBar'));
var $dialog = Ox.Dialog({ $dialog = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
id: 'done', id: 'done',
@ -94,6 +105,12 @@ pandora.ui.listDialog = function(section) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
if (
pandora.$ui.listDialogTabPanel.selected() == 'query'
&& !pandora.user.ui.updateAdvancedFind
) {
pandora.$ui.filterForm.updateResults();
}
$dialog.close(); $dialog.close();
} }
}) })
@ -108,8 +125,24 @@ pandora.ui.listDialog = function(section) {
removeOnClose: true, removeOnClose: true,
title: folderItem + ' — ' + Ox.encodeHTMLEntities(listData.name), title: folderItem + ' — ' + Ox.encodeHTMLEntities(listData.name),
width: width width: width
}),
$updateCheckbox = Ox.Checkbox({
title: 'Update Results in the Background',
value: pandora.user.ui.updateAdvancedFind
})
.css({float: 'left', margin: '4px'})
[section == 'query' ? 'show' : 'hide']()
.bindEvent({
change: function(data) {
pandora.UI.set({updateAdvancedFind: data.value});
data.value && pandora.$ui.filterForm.updateResults();
}
}); });
$($updateCheckbox.find('.OxButton')[0]).css({margin: 0});
$($dialog.$element.find('.OxBar')[2]).append($updateCheckbox);
function getWidth(section) { function getWidth(section) {
return section == 'general' ? 496 return section == 'general' ? 496
: (section == 'icon' ? 696 : 648) + Ox.UI.SCROLLBAR_SIZE; : (section == 'icon' ? 696 : 648) + Ox.UI.SCROLLBAR_SIZE;