refactor UI.js, fixes a bug where list deselection wouldn't work after loading an item of that list and going back

This commit is contained in:
rolux 2011-11-05 13:09:51 +00:00
parent a4085880b4
commit d67a1cdfba
2 changed files with 56 additions and 44 deletions

View file

@ -25,12 +25,16 @@ pandora.UI = (function() {
// key foo.bar.baz sets pandora.user.ui.foo.bar.baz
// val null removes a key
that.set = function(/* {key: val}[, flag] or key, val[, flag] */) {
var add = {},
args,
doNotTriggerEvents,
item,
list,
listSettings = pandora.site.listSettings,
set = {},
trigger = {};
if (Ox.isObject(arguments[0])) {
args = arguments[0];
triggerEvents = Ox.isUndefined(arguments[1]) ? true : arguments[1];
@ -38,15 +42,18 @@ pandora.UI = (function() {
args = Ox.makeObject([arguments[0], arguments[1]]);
triggerEvents = Ox.isUndefined(arguments[2]) ? true : arguments[1];
}
Ox.Log('', 'UI SET', args)
Ox.Log('UI SET', args)
self.previousUI = Ox.clone(pandora.user.ui, true);
self.previousUI._list = pandora.getListsState(self.previousUI.find);
if ('find' in args) {
// the challenge here is that find may change list,
// and list may then change listSort and listView,
// which we don't want to trigger, since find triggers
// (values we put in add will be changed, but won't trigger)
var list = pandora.getListsState(args.find);
list = pandora.getListsState(args.find);
pandora.user.ui._list = list;
pandora.user.ui._groupsState = pandora.getGroupsState(args.find);
pandora.user.ui._findState = pandora.getFindState(args.find);
@ -56,23 +63,16 @@ pandora.UI = (function() {
args['item'] = '';
}
add['itemFind'] = pandora.site.user.ui.itemFind;
if (!pandora.user.ui.lists[list]) {
add['lists.' + that.encode(list)] = {};
}
if (list != self.previousUI._list) {
Ox.Log('', 'FIND HAS CHANGED LIST')
if (!pandora.user.ui.lists[list]) {
add['lists.' + that.encode(list)] = {};
}
// if find has changed list
Ox.forEach(listSettings, function(listSetting, setting) {
// then for each setting that corresponds to a list setting
if (!pandora.user.ui.lists[list]) {
// add default list setting and copy to settings
add[
'lists.' + that.encode(list) + '.' + listSetting
] = pandora.site.user.ui[setting];
// either add the default setting
add[setting] = pandora.site.user.ui[setting];
} else {
// copy lists setting to settings
// or the existing list setting
add[setting] = pandora.user.ui.lists[list][listSetting]
}
});
@ -80,43 +80,55 @@ pandora.UI = (function() {
add.itemFind = pandora.isItemFind(args.find)
? args.find : pandora.site.user.ui.itemFind;
}
// it is important to check for find first, so that if find
// changes list, pandora.user.ui._list is correct here
var item = args['item'] || pandora.user.ui.item,
list = pandora.user.ui._list || '';
item = args['item'] || pandora.user.ui.item,
list = pandora.user.ui._list || self.previousUI._list;
if (!pandora.user.ui.lists[list]) {
add['lists.' + that.encode(list)] = {};
}
Ox.forEach(args, function(val, key) {
if (Object.keys(listSettings).indexOf(key) > -1) {
// if applicable, copy setting to list setting
add['lists.' + that.encode(list) + '.' + listSettings[key]] = val;
}
if (key == 'item' && val) {
// when switching to an item, update list selection
add['listSelection'] = [val];
if (!pandora.user.ui.lists[list]) {
add['lists.' + that.encode(list)] = {};
}
add['lists.' + that.encode(list) + '.selection'] = [val];
}
if (!args['videoPoints.' + item] && ((
key == 'item'
&& ['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1
&& !pandora.user.ui.videoPoints[val]
) || (
key == 'itemView'
&& ['video', 'timeline'].indexOf(val) > -1
&& !pandora.user.ui.videoPoints[item]
))) {
// when switching to a video view, add default videoPoints
add['videoPoints.' + item] = {'in': 0, out: 0, position: 0};
}
if (key == 'itemView' && ['video', 'timeline'].indexOf(val) > -1) {
// when switching to a video view, add it as default video view
add.videoView = val;
Ox.forEach(listSettings, function(listSetting, setting) {
// for each setting that corresponds to a list setting
// set that list setting to
var key = 'lists.' + that.encode(list) + '.' + listSetting;
if (setting in args) {
// the setting passed to UI.set
add[key] = args[setting];
} else if (setting in add) {
// or the setting changed via find
add[key] = add[setting];
} else if (!pandora.user.ui.lists[list]) {
// or the default setting
add[key] = pandora.site.user.ui[setting];
}
});
if (args.item) {
// when switching to an item, update list selection
add['listSelection'] = [args.item];
add['lists.' + that.encode(list) + '.selection'] = [args.item];
if (
!args.itemView
&& ['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1
&& !pandora.user.ui.videoPoints[item]
) {
// if the item view won't be changed, remains a video view,
// and there are no video points yet, add default video points
add['videoPoints.' + item] = {'in': 0, out: 0, position: 0};
}
}
if (['video', 'timeline'].indexOf(args.itemView) > -1) {
// when switching to a video view, add it as default video view
args.videoView = args.itemView;
if (!pandora.user.ui.videoPoints[item]) {
// if there are no video points yet, add default video points
add['videoPoints.' + item] = {'in': 0, out: 0, position: 0};
}
}
[args, add].forEach(function(obj, isAdd) {
Ox.forEach(obj, function(val, key) {
Ox.Log('', 'key/val', key, val)

View file

@ -174,7 +174,7 @@ pandora.enableDragAndDrop = function($list, canMove) {
drag.source = pandora.getListData(),
drag.targets = {};
Ox.forEach(pandora.$ui.folderList, function($list) {
$list.addClass('OxDroppable').find('.OxItem').each(function() {
$list.addClass('OxDroppable').$element.find('.OxItem').each(function() {
var $item = $(this),
id = $item.data('id'),
data = $list.value(id);