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
'use strict';
pandora.ui.filterDialog = function(list) {
var that = Ox.Dialog({
buttons: [
Ox.Button({
@ -9,8 +10,7 @@ pandora.ui.filterDialog = function(list) {
})
.bindEvent({
click: function() {
var list = pandora.$ui.filterForm.$filter.getList();
that.close();
var list = pandora.$ui.filterForm.getList();
if (list.save) {
pandora.api.addList({
name: list.name,
@ -27,14 +27,18 @@ pandora.ui.filterDialog = function(list) {
}
});
Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEventOnce({
$list.bindEventOnce({
load: function(data) {
$list.gainFocus()
.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,
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) {
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);
pandora.$ui.list
.bindEventOnce({
init: function(data) {
pandora.$ui.folderList[
pandora.getListData().folder
].value(list.id, 'items', data.items);
].value(list.id, 'query', query);
}
})
.reloadList();
pandora.$ui.filters.forEach(function($filter) {
$filter.reloadList();
});
});
} else {
Ox.Log('FIND', 'change form', data.query, pandora.user.ui.find)
pandora.UI.set({find: Ox.clone(data.query, true)});
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,13 +93,11 @@ 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({
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
@ -94,6 +105,12 @@ pandora.ui.listDialog = function(section) {
})
.bindEvent({
click: function() {
if (
pandora.$ui.listDialogTabPanel.selected() == 'query'
&& !pandora.user.ui.updateAdvancedFind
) {
pandora.$ui.filterForm.updateResults();
}
$dialog.close();
}
})
@ -108,8 +125,24 @@ pandora.ui.listDialog = function(section) {
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
: (section == 'icon' ? 696 : 648) + Ox.UI.SCROLLBAR_SIZE;