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
'use strict';
pandora.ui.filterDialog = function(list) {
var that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
title: 'Done'
})
.bindEvent({
click: function() {
var list = pandora.$ui.filterForm.$filter.getList();
that.close();
if (list.save) {
pandora.api.addList({
name: list.name,
query: list.query,
status: 'private',
type: 'smart'
}, function(result) {
var $list = pandora.$ui.folderList.personal,
id = result.data.id;
pandora.UI.set({
find: {
conditions: [{key: 'list', value: id, operator: '=='}],
operator: '&'
}
buttons: [
Ox.Button({
id: 'done',
title: 'Done'
})
.bindEvent({
click: function() {
var list = pandora.$ui.filterForm.getList();
if (list.save) {
pandora.api.addList({
name: list.name,
query: list.query,
status: 'private',
type: 'smart'
}, function(result) {
var $list = pandora.$ui.folderList.personal,
id = result.data.id;
pandora.UI.set({
find: {
conditions: [{key: 'list', value: id, operator: '=='}],
operator: '&'
}
});
Ox.Request.clearCache(); // fixme: remove
$list.bindEventOnce({
load: function(data) {
$list.gainFocus()
.options({selected: [id]});
}
})
.reloadList();
});
Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEventOnce({
load: function(data) {
$list.gainFocus()
.options({selected: [id]});
}
});
});
} else if (!pandora.user.ui.updateAdvancedFind) {
pandora.$ui.filterForm.updateResults();
}
that.close();
}
}
})
],
content: pandora.$ui.filterForm = pandora.ui.filterForm(list),
maxWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
minHeight: 264,
minWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
height: 264,
// keys: {enter: 'save', escape: 'cancel'},
removeOnClose: true,
title: list ? 'Smart List - ' + list.name : 'Advanced Find',
width: 648 + Ox.UI.SCROLLBAR_SIZE
});
})
],
content: pandora.$ui.filterForm = pandora.ui.filterForm(list),
maxWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
minHeight: 264,
minWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
height: 264,
// keys: {enter: 'save', escape: 'cancel'},
removeOnClose: true,
title: list ? 'Smart List - ' + list.name : 'Advanced Find',
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;
};

View file

@ -45,29 +45,39 @@ pandora.ui.filterForm = function(list) {
id: list.id,
query: data.query
}, function(result) {
Ox.Request.clearCache(list.id);
pandora.$ui.list
.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();
});
if (pandora.user.ui.updateAdvancedFind) {
that.updateResults(data.query);
}
});
} else {
Ox.Log('FIND', 'change form', data.query, pandora.user.ui.find)
pandora.UI.set({find: Ox.clone(data.query, true)});
pandora.$ui.findElement.updateElement();
} 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);
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;
};

View file

@ -5,7 +5,6 @@
pandora.ui.listDialog = function(section) {
section = section || 'general';
var width = getWidth(section);
var listData = pandora.getListData(),
tabs = [].concat([
{id: 'general', title: 'General'},
@ -15,6 +14,7 @@ pandora.ui.listDialog = function(section) {
: []
),
ui = pandora.user.ui,
width = getWidth(section),
folderItems = ui.section == 'items' ? 'Lists' : Ox.toTitleCase(ui.section),
folderItem = folderItems.slice(0, -1);
Ox.getObjectById(tabs, section).selected = true;
@ -26,7 +26,12 @@ pandora.ui.listDialog = function(section) {
} else if (id == 'icon') {
return pandora.$ui.listIconPanel = pandora.ui.listIconPanel(listData);
} 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
@ -40,6 +45,14 @@ pandora.ui.listDialog = function(section) {
});
$dialog.setSize(width, 312);
$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'});
@ -80,35 +93,55 @@ pandora.ui.listDialog = function(section) {
})
],
})
.css({float: 'right', margin: '4px', align: 'right'});
if (section != 'icon') {
$findElement.hide();
}
$findElement.appendTo(pandora.$ui.listDialogTabPanel.children('.OxBar'));
.css({float: 'right', margin: '4px', align: 'right'})
[section == 'icon' ? 'show' : 'hide']()
.appendTo(pandora.$ui.listDialogTabPanel.children('.OxBar')),
var $dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
title: 'Done'
})
.bindEvent({
click: function() {
$dialog.close();
}
})
],
closeButton: true,
content: pandora.$ui.listDialogTabPanel,
maxWidth: width,
minHeight: 312,
minWidth: width,
height: 312,
// keys: {enter: 'save', escape: 'cancel'},
removeOnClose: true,
title: folderItem + ' — ' + Ox.encodeHTMLEntities(listData.name),
width: width
});
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
title: 'Done'
})
.bindEvent({
click: function() {
if (
pandora.$ui.listDialogTabPanel.selected() == 'query'
&& !pandora.user.ui.updateAdvancedFind
) {
pandora.$ui.filterForm.updateResults();
}
$dialog.close();
}
})
],
closeButton: true,
content: pandora.$ui.listDialogTabPanel,
maxWidth: 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) {
return section == 'general' ? 496