cablegates/static/js/pandora/ui/folders.js

200 lines
9.3 KiB
JavaScript
Raw Normal View History

2011-05-25 19:42:45 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=js
pandora.ui.folders = function() {
2011-06-19 17:49:25 +00:00
var that = Ox.Element()
2011-05-25 19:42:45 +00:00
.css({overflowX: 'hidden', overflowY: 'auto'})
.bindEvent({
resize: function(event, data) {
pandora.resizeFolders();
}
});
var counter = 0;
//var $sections = [];
2011-06-06 15:48:11 +00:00
pandora.$ui.folder = [];
pandora.$ui.folderBrowser = {};
pandora.$ui.folderList = {};
if (pandora.user.ui.section == 'site') {
$.each(pandora.site.sectionFolders.site, function(i, folder) {
var height = (Ox.getObjectById(pandora.site.sectionFolders.site, folder.id).items.length * 16);
2011-06-19 17:49:25 +00:00
pandora.$ui.folder[i] = Ox.CollapsePanel({
2011-05-25 19:42:45 +00:00
id: folder.id,
2011-06-06 15:48:11 +00:00
collapsed: !pandora.user.ui.showFolder.site[folder.id],
2011-05-25 19:42:45 +00:00
size: 16,
title: folder.title
})
.bindEvent({
toggle: function(event, data) {
}
});
2011-06-06 15:48:11 +00:00
//alert(JSON.stringify(Ox.getObjectById(pandora.site.sectionFolders.site, folder.id)))
pandora.$ui.folder[i].$content.css({
2011-05-25 19:42:45 +00:00
height: height + 'px'
})
//.appendTo(that);
2011-06-06 15:48:11 +00:00
pandora.$ui.folderList[folder.id] = pandora.ui.folderList(folder.id)
2011-05-25 19:42:45 +00:00
.css({
height: height + 'px'
})
2011-06-06 15:48:11 +00:00
.appendTo(pandora.$ui.folder[i].$content);
pandora.$ui.folder.forEach(function($folder) {
2011-05-25 19:42:45 +00:00
that.append($folder);
});
});
//pandora.resizeFolders();
2011-06-06 15:48:11 +00:00
} else if (pandora.user.ui.section == 'items') {
$.each(pandora.site.sectionFolders.items, function(i, folder) {
2011-05-25 19:42:45 +00:00
var extras = [];
2011-06-06 15:48:11 +00:00
if (folder.id == 'personal' && pandora.user.level != 'guest') {
2011-06-19 17:49:25 +00:00
extras = [Ox.Select({
2011-05-25 19:42:45 +00:00
items: [
{ id: 'new', title: 'New List...' },
{ id: 'newfromselection', title: 'New List from Current Selection...', disabled: true },
{ id: 'newsmart', title: 'New Smart List...' },
{ id: 'newfromresults', title: 'New Smart List from Current Results...', disabled: true },
{},
{ id: 'addselection', title: 'Add Selection to List...' }
],
max: 0,
min: 0,
selectable: false,
type: 'image'
})
.bindEvent({
click: function(event, data) {
2011-06-06 15:48:11 +00:00
var $list = pandora.$ui.folderList[folder.id],
2011-05-25 19:42:45 +00:00
id;
if (data.id == 'new' || data.id == 'newsmart') {
pandora.api.addList({
name: 'Untitled',
status: 'private',
type: data.id == 'new' ? 'static' : 'smart'
}, function(result) {
id = result.data.id;
2011-06-06 15:48:11 +00:00
pandora.UI.set(['lists', id].join('|'), pandora.site.user.ui.lists['']); // fixme: necessary?
2011-05-25 19:42:45 +00:00
pandora.URL.set('?find=list:' + id)
Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEventOnce({
load: function(event, data) {
$list.gainFocus()
.options({selected: [id]})
.editCell(id, 'name');
}
});
});
}
}
})];
2011-06-06 15:48:11 +00:00
} else if (folder.id == 'favorite' && pandora.user.level != 'guest') {
2011-06-19 17:49:25 +00:00
extras = [Ox.Button({
2011-05-25 19:42:45 +00:00
selectable: true,
style: 'symbol',
title: 'Edit',
tooltip: 'Manage Favorite Lists',
type: 'image'
})
.bindEvent({
change: function(event, data) {
Ox.Request.clearCache(); // fixme: remove
2011-06-06 15:48:11 +00:00
pandora.site.sectionFolders.items[i].showBrowser = !pandora.site.sectionFolders.items[i].showBrowser;
if (pandora.site.sectionFolders.items[i].showBrowser) {
pandora.$ui.folderList.favorite.replaceWith(
pandora.$ui.folderBrowser.favorite = pandora.ui.folderBrowser('favorite')
2011-05-25 19:42:45 +00:00
);
} else {
2011-06-06 15:48:11 +00:00
pandora.$ui.folderBrowser.favorite.replaceWith(
pandora.$ui.folderList.favorite = pandora.ui.folderList('favorite')
2011-05-25 19:42:45 +00:00
);
}
pandora.resizeFolders();
}
})];
2011-06-06 15:48:11 +00:00
} else if (folder.id == 'featured' && pandora.user.level == 'admin') {
2011-06-19 17:49:25 +00:00
extras = [Ox.Button({
2011-05-25 19:42:45 +00:00
selectable: true,
style: 'symbol',
title: 'Edit',
tooltip: 'Manage Featured Lists',
type: 'image'
})
.bindEvent({
change: function(event, data) {
Ox.Request.clearCache(); // fixme: remove
2011-06-06 15:48:11 +00:00
pandora.site.sectionFolders.items[i].showBrowser = !pandora.site.sectionFolders.items[i].showBrowser;
if (pandora.site.sectionFolders.items[i].showBrowser) {
pandora.$ui.folderList.featured.replaceWith(
pandora.$ui.folderBrowser.featured = pandora.ui.folderBrowser('featured'));
2011-05-25 19:42:45 +00:00
} else {
2011-06-06 15:48:11 +00:00
pandora.$ui.folderBrowser.featured.replaceWith(
pandora.$ui.folderList.featured = pandora.ui.folderList('featured')
2011-05-25 19:42:45 +00:00
);
}
pandora.resizeFolders();
}
})];
}
2011-06-19 17:49:25 +00:00
pandora.$ui.folder[i] = Ox.CollapsePanel({
2011-05-25 19:42:45 +00:00
id: folder.id,
2011-06-06 15:48:11 +00:00
collapsed: !pandora.user.ui.showFolder.items[folder.id],
2011-05-25 19:42:45 +00:00
extras: extras,
size: 16,
title: folder.title
})
.bindEvent({
// fixme: duplicated
click: function(event, data) {
2011-06-06 15:48:11 +00:00
var $list = pandora.$ui.folderList[i],
2011-05-25 19:42:45 +00:00
hasFocus, id;
if (data.id == 'new' || data.id == 'newsmart') {
pandora.api.addList({
name: 'Untitled',
status: 'private',
type: data.id == 'new' ? 'static' : 'smart'
}, function(result) {
id = result.data.id;
pandora.URL.set('?find=list:' + id)
Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEventOnce({
load: function(event, data) {
$list.gainFocus()
.options({selected: [id]})
.editCell(id, 'name');
}
});
});
} else if (data.id == 'browse') {
alert('??')
/*
2011-06-06 15:48:11 +00:00
pandora.$ui.sectionList[1].replaceWith(pandora.$ui.publicLists = pandora.ui.publicLists());
pandora.site.showAllPublicLists = true;
2011-05-25 19:42:45 +00:00
*/
}
},
toggle: function(event, data) {
2011-06-06 15:48:11 +00:00
data.collapsed && pandora.$ui.folderList[folder.id].loseFocus();
2011-05-25 19:42:45 +00:00
pandora.UI.set('showFolder|items|' + folder.id, !data.collapsed);
pandora.resizeFolders();
}
});
2011-06-06 15:48:11 +00:00
//$sections.push(pandora.$ui.section[i]);
pandora.$ui.folderList[folder.id] = pandora.ui.folderList(folder.id)
2011-05-25 19:42:45 +00:00
.bindEventOnce({
init: function(event, data) {
Ox.print('init', i, counter)
if (++counter == 3) {
2011-06-06 15:48:11 +00:00
pandora.$ui.folder.forEach(function($folder) {
2011-05-25 19:42:45 +00:00
that.append($folder);
});
pandora.resizeFolders();
pandora.selectList(); //fixme: doesn't work
}
}
})
2011-06-06 15:48:11 +00:00
.appendTo(pandora.$ui.folder[i].$content);
2011-05-25 19:42:45 +00:00
});
}
that.toggle = function() {
};
return that;
};