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,53 +1,74 @@
// 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({
id: 'done', id: 'done',
title: 'Done' title: 'Done'
}) })
.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, query: list.query,
query: list.query, status: 'private',
status: 'private', type: 'smart'
type: 'smart' }, function(result) {
}, function(result) { var $list = pandora.$ui.folderList.personal,
var $list = pandora.$ui.folderList.personal, id = result.data.id;
id = result.data.id; pandora.UI.set({
pandora.UI.set({ find: {
find: { conditions: [{key: 'list', value: id, operator: '=='}],
conditions: [{key: 'list', value: id, operator: '=='}], operator: '&'
operator: '&' }
} });
Ox.Request.clearCache(); // fixme: remove
$list.bindEventOnce({
load: function(data) {
$list.gainFocus()
.options({selected: [id]});
}
})
.reloadList();
}); });
Ox.Request.clearCache(); // fixme: remove } else if (!pandora.user.ui.updateAdvancedFind) {
$list.reloadList().bindEventOnce({ pandora.$ui.filterForm.updateResults();
load: function(data) { }
$list.gainFocus() that.close();
.options({selected: [id]});
}
});
});
} }
} })
}) ],
], content: pandora.$ui.filterForm = pandora.ui.filterForm(list),
content: pandora.$ui.filterForm = pandora.ui.filterForm(list), maxWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
maxWidth: 648 + Ox.UI.SCROLLBAR_SIZE, minHeight: 264,
minHeight: 264, minWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
minWidth: 648 + Ox.UI.SCROLLBAR_SIZE, height: 264,
height: 264, // keys: {enter: 'save', escape: 'cancel'},
// keys: {enter: 'save', escape: 'cancel'}, 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) {
Ox.Request.clearCache(list.id); if (pandora.user.ui.updateAdvancedFind) {
pandora.$ui.list that.updateResults(data.query);
.bindEventOnce({ }
init: function(data) {
pandora.$ui.folderList[
pandora.getListData().folder
].value(list.id, 'items', data.items);
}
})
.reloadList();
pandora.$ui.filters.forEach(function($filter) {
$filter.reloadList();
});
}); });
} else { } else if (pandora.user.ui.updateAdvancedFind) {
Ox.Log('FIND', 'change form', data.query, pandora.user.ui.find) that.updateResults();
pandora.UI.set({find: Ox.clone(data.query, true)});
pandora.$ui.findElement.updateElement();
} }
that.triggerEvent('change', data);
} }
}) })
); );
that.getList = that.$filter.getList;
}); });
that.updateResults = function(query) {
if (list) {
Ox.Request.clearCache(list.id);
pandora.$ui.list
.bindEventOnce({
init: function(data) {
pandora.$ui.folderList[
pandora.getListData().folder
].value(list.id, 'query', query);
}
})
.reloadList();
pandora.$ui.filters.forEach(function($filter) {
$filter.reloadList();
});
} else {
pandora.UI.set({find: Ox.clone(that.$filter.options('query'), true)});
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,35 +93,55 @@ 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',
title: 'Done' title: 'Done'
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
$dialog.close(); if (
} pandora.$ui.listDialogTabPanel.selected() == 'query'
}) && !pandora.user.ui.updateAdvancedFind
], ) {
closeButton: true, pandora.$ui.filterForm.updateResults();
content: pandora.$ui.listDialogTabPanel, }
maxWidth: width, $dialog.close();
minHeight: 312, }
minWidth: width, })
height: 312, ],
// keys: {enter: 'save', escape: 'cancel'}, closeButton: true,
removeOnClose: true, content: pandora.$ui.listDialogTabPanel,
title: folderItem + ' — ' + Ox.encodeHTMLEntities(listData.name), maxWidth: width,
width: width minHeight: 312,
}); minWidth: width,
height: 312,
// keys: {enter: 'save', escape: 'cancel'},
removeOnClose: true,
title: folderItem + ' — ' + Ox.encodeHTMLEntities(listData.name),
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