display stats for selected items

This commit is contained in:
rolux 2010-07-06 07:48:42 +02:00
parent 3e11232101
commit ab40deea27

213
pandora/static/js/pandora.js Normal file → Executable file
View file

@ -39,15 +39,16 @@ $(function() {
{ id: "files", title: "Files", admin: true } { id: "files", title: "Files", admin: true }
], ],
listViews: [ listViews: [
{ id: "list", title: "View as List" }, { id: "list", title: "as List" },
{ id: "icons", title: "View as Icons" }, { id: "icons", title: "as Icons" },
{ id: "clips", title: "View with Clips" }, { id: "info", title: "with Info" },
{ id: "timelines", title: "View with Timelines" }, { id: "clips", title: "with Clips" },
{ id: "maps", title: "View with Maps" }, { id: "timelines", title: "with Timelines" },
{ id: "calendars", title: "View with Calendars" }, { id: "maps", title: "with Maps" },
{ id: "clip", title: "View as Clips" }, { id: "calendars", title: "with Calendars" },
{ id: "map", title: "View on Map" }, { id: "clip", title: "as Clips" },
{ id: "calendar", title: "View on Calendar" }, { id: "map", title: "on Map" },
{ id: "calendar", title: "on Calendar" },
], ],
sortKeys: [ sortKeys: [
{ id: "title", title: "Title", operator: "", align: "left", width: 180 }, { id: "title", title: "Title", operator: "", align: "left", width: 180 },
@ -70,7 +71,7 @@ $(function() {
{ id: "profit", title: "Profit", operator: "-", align: "right", width: 90 }, { id: "profit", title: "Profit", operator: "-", align: "right", width: 90 },
{ id: "rating", title: "Rating", operator: "-", align: "right", width: 60 }, { id: "rating", title: "Rating", operator: "-", align: "right", width: 60 },
{ id: "votes", title: "Votes", operator: "-", align: "right", width: 90 }, { id: "votes", title: "Votes", operator: "-", align: "right", width: 90 },
{ id: "id", title: "ID", operator: "", align: "left", width: 90 } { id: "id", title: "ID", operator: "", align: "left", width: 90 },
{ id: "aspectratio", title: "Aspect Ratio", operator: "-", align: "left", width: 90 }, { id: "aspectratio", title: "Aspect Ratio", operator: "-", align: "left", width: 90 },
{ id: "duration", title: "Duration", operator: "-", align: "right", width: 90 }, { id: "duration", title: "Duration", operator: "-", align: "right", width: 90 },
{ id: "color", title: "Color", operator: "", align: "left", width: 90 }, { id: "color", title: "Color", operator: "", align: "left", width: 90 },
@ -91,6 +92,14 @@ $(function() {
{ id: "published", title: "Date Published", operator: "-", align: "left", width: 90 }, { id: "published", title: "Date Published", operator: "-", align: "left", width: 90 },
{ id: "modified", title: "Date Modified", operator: "-", align: "left", width: 90 } { id: "modified", title: "Date Modified", operator: "-", align: "left", width: 90 }
], ],
totals: [
{ id: "items" },
{ id: "runtime" },
{ id: "files", admin: true },
{ id: "duration", admin: true },
{ id: "size", admin: true },
{ id: "pixels" }
],
userSettings: { userSettings: {
group: "guest", group: "guest",
ui: { ui: {
@ -111,7 +120,9 @@ $(function() {
} }
}, },
user = config.userSettings, user = config.userSettings,
$ui = {}; $ui = {
groups: []
};
// App // App
@ -172,7 +183,7 @@ $(function() {
{}, {},
{ id: "newlist", title: "New List..." }, { id: "newlist", title: "New List..." },
{ id: "newlistfromselection", title: "New List from Selection...", disabled: true }, { id: "newlistfromselection", title: "New List from Selection...", disabled: true },
{ id: "newsmartlist", title: "New Smart List..." } { id: "newsmartlist", title: "New Smart List..." },
{}, {},
{ id: "addtolist", title: "Add Selected Movie to List...", disabled: true }, { id: "addtolist", title: "Add Selected Movie to List...", disabled: true },
{}, {},
@ -180,10 +191,10 @@ $(function() {
]}, ]},
{ id: "view", title: "View", items: [ { id: "view", title: "View", items: [
{ id: "movies", title: "View Movies", items: $.map(config.listViews, function(view, i) { { id: "movies", title: "View Movies", items: $.map(config.listViews, function(view, i) {
return $.extend(view, { return $.extend({
checked: user.ui.listView == view.id, checked: user.ui.listView == view.id,
group: "viewmovies" group: "viewmovies"
}); }, view);
}) }, }) },
{ id: "icons", title: "Icons", items: [ { id: "icons", title: "Icons", items: [
{ id: "poster", title: "Poster" }, { id: "poster", title: "Poster" },
@ -195,7 +206,7 @@ $(function() {
{ id: "video", title: "Video" } { id: "video", title: "Video" }
] }, ] },
{}, {},
{ id: "movie", title: "Open Movie", items: $.map(config.listViews, function(view, i) { { id: "movie", title: "Open Movie", items: $.map(config.itemViews, function(view, i) {
return view; return view;
}) }, }) },
{}, {},
@ -206,27 +217,27 @@ $(function() {
]}, ]},
{ id: "sort", title: "Sort", items: [ { id: "sort", title: "Sort", items: [
{ id: "sortmovies", title: "Sort Movies by", items: $.map(config.sortKeys, function(key, i) { { id: "sortmovies", title: "Sort Movies by", items: $.map(config.sortKeys, function(key, i) {
return $.extend(key, { return $.extend({
checked: user.ui.sort[0].key == key, checked: user.ui.sort[0].key == key,
group: "sortmovies" group: "sortmovies"
}); }, key);
}) }, }) },
{ id: "ordermovies", title: "Order Movies", items: [ { id: "ordermovies", title: "Order Movies", items: [
{ id: "ascending", title: "Ascending", group: "ordermovies", checked: user.ui.sort[0].operator == "" }, { id: "ascending", title: "Ascending", group: "ordermovies", checked: user.ui.sort[0].operator == "" },
{ id: "descending", title: "Descending", group: "ordermovies", checked: user.ui.sort[0].operator == "-" } { id: "descending", title: "Descending", group: "ordermovies", checked: user.ui.sort[0].operator == "-" }
]}, ]},
{ id: "advancedsort", title: "Advanced Sort..." } { id: "advancedsort", title: "Advanced Sort..." },
{}, {},
{ id: "groupsstuff", title: "Groups Stuff" } { id: "groupsstuff", title: "Groups Stuff" }
] }, ] },
{ id: "find", title: "Find", items: [ { id: "find", title: "Find", items: [
{ id: "find", title: "Find", items: $.map(config.findKeys, function(key, i) { { id: "find", title: "Find", items: $.map(config.findKeys, function(key, i) {
return $.extend(key, { return $.extend({
checked: user.ui.find.key == key, checked: user.ui.find.key == key,
group: "find" group: "find"
}) }, key)
}) }, }) },
{ id: "advancedfind", "Advanced Find..." } { id: "advancedfind", title: "Advanced Find..." }
] }, ] },
{ id: "code", title: "Code", items: [ { id: "code", title: "Code", items: [
{ id: "download", title: "Download" }, { id: "download", title: "Download" },
@ -262,9 +273,10 @@ $(function() {
$ui.viewSelect = new Ox.Select({ $ui.viewSelect = new Ox.Select({
id: "viewSelect", id: "viewSelect",
items: $.map(config.listViews, function(view, i) { items: $.map(config.listViews, function(view, i) {
return $.extend(view, { view.title = "View " + view.title
checked: user.ui.listView == view.id return $.extend({
}); checked: user.ui.listView == view.id,
}, view);
}) })
}) })
.css({ .css({
@ -318,19 +330,19 @@ $(function() {
}), }),
labelWidth: 85 labelWidth: 85
}) })
css({ .css({
float: "right", float: "right",
margin: "4px" margin: "4px"
}) })
.width(300) .width(300)
); );
// Groups // Groups
var rightPanelWidth = $document.width() - 256, var rightPanelWidth = $document.width() - 256,
groups = $.map(config.groups, function(id, i) { groups = $.map(config.groups, function(id, i) {
var title = Ox.getObjectById(sortKeys, id).title; var size = rightPanelWidth / 5 + (rightPanelWidth % 5 > i),
title = Ox.getObjectById(config.sortKeys, id).title;
return { return {
id: id, id: id,
conditions: [], conditions: [],
@ -369,11 +381,36 @@ $(function() {
} }
] ]
}), }),
size: rightPanelWidth / 5 + (rightPanelWidth % 5 > i), size: size,
title: title title: title
}; };
}); });
// Statusbar
$ui.statusbar = new Ox.Bar({
size: 16
})
.css({
paddingTop: "3px",
textAlign: "center"
})
.append(
new Ox.Element()
.css({
fontSize: "9px"
})
.append(
$ui.total = new Ox.Element("span")
)
.append(
new Ox.Element("span").html(" — ")
)
.append(
$ui.selected = new Ox.Element("span")
)
);
// Interface // Interface
$ui.app = new Ox.SplitPanel({ $ui.app = new Ox.SplitPanel({
@ -395,7 +432,8 @@ $(function() {
element: $ui.info = new Ox.Element(), element: $ui.info = new Ox.Element(),
size: 128 size: 128
} }
] ],
orientation: "vertical"
}), }),
size: 256 size: 256
}, },
@ -413,71 +451,77 @@ $(function() {
element: $ui.groupsOuterPanel = new Ox.SplitPanel({ element: $ui.groupsOuterPanel = new Ox.SplitPanel({
elements: [ elements: [
{ {
element: groups[0].element, element: $ui.groups[0] = groups[0].element,
size: groups[0].size size: groups[0].size
}, },
{ {
element: $ui.groupsInnerPanel = new Ox.SplitPanel({ element: $ui.groupsInnerPanel = new Ox.SplitPanel({
elements: [ elements: [
{ {
element: groups[1].element, element: $ui.groups[1] = groups[1].element,
size: groups[1].size size: groups[1].size
}, },
{ {
element: groups[2].element, element: $ui.groups[2] = groups[2].element,
size: groups[2].size size: groups[2].size
}, },
{ {
element: groups[3].element, element: $ui.groups[3] = groups[3].element,
size: groups[3].size size: groups[3].size
} }
] ],
orientation: "horizontal"
}) })
}, },
{ {
element: groups[4].element, element: $ui.groups[4] = groups[4].element,
size: groups[4].size size: groups[4].size
} },
] ],
orientation: "horizontal"
}), }),
size: 128 size: 128
}, },
{ {
element: $ui.list = constructList(user.ui.listView) element: $ui.list = constructList(user.ui.listView)
} }
] ],
orientation: "vertical"
}) })
} },
{ {
element: $ui.statusbar = new Ox.Bar({ size: 16 }), element: $ui.statusbar,
size: 16 size: 16
} }
] ],
}), orientation: "vertical"
}
]
}) })
} }
] ],
orientation: "horizontal"
})
}
],
orientation: "vertical"
}).appendTo($body); }).appendTo($body);
// Events // Events
Ox.Request.requests() && $loadingIcon.start(); Ox.Request.requests() && $ui.loadingIcon.start();
Ox.Event.bind("requestStart", function() { Ox.Event.bind("requestStart", function() {
Ox.print("requestStart") Ox.print("requestStart")
$loadingIcon.start(); $ui.loadingIcon.start();
}); });
Ox.Event.bind("requestStop", function() { Ox.Event.bind("requestStop", function() {
Ox.print("requestStop") Ox.print("requestStop")
$loadingIcon.stop(); $ui.loadingIcon.stop();
}); });
Ox.Event.bind("change_viewSelect", function(event, data) { Ox.Event.bind("change_viewSelect", function(event, data) {
$list.replaceWith(constructList(data.id)); $ui.list.replaceWith(constructList(data.id));
}); });
Ox.Event.bind("submit_find", function(event, data) { Ox.Event.bind("submit_findInput", function(event, data) {
findCondition = { findCondition = {
key: data.key == "all" ? "" : data.key, key: data.key == "all" ? "" : data.key,
value: data.value, value: data.value,
@ -485,7 +529,7 @@ $(function() {
}; };
$.each(groups, function(i, group) { $.each(groups, function(i, group) {
groups[i].conditions = []; groups[i].conditions = [];
$group[i].options({ $ui.groups[i].options({
request: function(options) { request: function(options) {
delete options.keys; delete options.keys;
return app.request("find", $.extend(options, { return app.request("find", $.extend(options, {
@ -495,7 +539,7 @@ $(function() {
} }
}); });
}); });
$list.options({ $ui.list.options({
request: function(options) { request: function(options) {
return app.request("find", $.extend(options, { return app.request("find", $.extend(options, {
query: constructQuery() query: constructQuery()
@ -506,7 +550,7 @@ $(function() {
$.each(groups, function(i, group) { $.each(groups, function(i, group) {
Ox.Event.bind("select_group_" + group.id, function(event, data) { Ox.Event.bind("select_group_" + group.id, function(event, data) {
$list.options({ $ui.list.options({
request: function(options) { request: function(options) {
groups[i].conditions = $.map(data.ids, function(v) { groups[i].conditions = $.map(data.ids, function(v) {
return { return {
@ -522,7 +566,7 @@ $(function() {
}); });
$.each(groups, function(i_, group_) { $.each(groups, function(i_, group_) {
if (i_ != i) { if (i_ != i) {
$group[i_].options({ $ui.groups[i_].options({
request: function(options) { request: function(options) {
delete options.keys; delete options.keys;
return app.request("find", $.extend(options, { return app.request("find", $.extend(options, {
@ -539,32 +583,31 @@ $(function() {
}); });
Ox.Event.bind("load_list", function(event, data) { Ox.Event.bind("load_list", function(event, data) {
$totals.html(constructStatus({ $ui.total.html(constructStatus("total", data));
"total": data, data = [];
"selected": {} $.each(config.totals, function(i, v) {
})); data[v.id] = 0;
var html = [ });
Ox.formatNumber(data.items) + " movie" + (data.items != 1 ? "s" : ""), $ui.selected.html(constructStatus("selected", data));
Ox.formatDuration(data.runtime, "medium"),
data.files + " file" + (data.files != 1 ? "s" : ""),
Ox.formatDuration(data.duration, "short"),
Ox.formatValue(data.size, "B"),
Ox.formatValue(data.pixels, "px")
];
$totals.html("Total: " + constructStatus(data) + " — Selected: " + constructStatus({
duration: 0,
files: 0,
items: 0,
pixels: 0,
runtime: 0,
size: 0
}));
}); });
Ox.Event.bind("sort_list", function(event, data) { Ox.Event.bind("sort_list", function(event, data) {
}); });
Ox.Event.bind("select_list", function(event, data) { Ox.Event.bind("select_list", function(event, data) {
app.request("find", {
query: {
conditions: $.map(data.ids, function(id, i) {
return {
key: "id",
value: id,
operator: ""
}
}),
operator: ","
}
}, function(result) {
$ui.selected.html(constructStatus("selected", result.data));
});
}); });
Ox.Event.bind("click_show_query", function(event, data) { Ox.Event.bind("click_show_query", function(event, data) {
var query = constructQuery(), var query = constructQuery(),
@ -590,13 +633,13 @@ $(function() {
function constructList(view) { function constructList(view) {
var $list; var $list;
if (view == "text") { if (view == "list") {
$list = new Ox.TextList({ $list = new Ox.TextList({
columns: $.map(config.sortKeys, function(key, i) { columns: $.map(config.sortKeys, function(key, i) {
return $.extend(key, { return $.extend({
visible: $.inArray(key.id, user.ui.columns) > -1, visible: $.inArray(key.id, user.ui.columns) > -1,
unique: key.id == "id" unique: key.id == "id"
}); }, key);
}), }),
id: "list", id: "list",
request: function(options) { request: function(options) {
@ -639,30 +682,26 @@ $(function() {
} }
function constructQuery(groupId) { function constructQuery(groupId) {
var conditions = $.merge(!Ox.isUndefined(user.ui.find.key) ? [user.ui.find] : [], $.map(groups, function(v, i) { var conditions = $.merge(!Ox.isUndefined(user.ui.find.key) ? [user.ui.find] : [], groups ? $.map(groups, function(v, i) {
if (v.id != groupId) { if (v.id != groupId) {
return v.conditions; return v.conditions;
} }
})); }) : []);
return { return {
conditions: conditions, conditions: conditions,
operator: conditions.length ? "," : "" operator: conditions.length ? "," : ""
}; };
} }
function constructStatus(data) { function constructStatus(key, data) {
var html = []; return Ox.toTitleCase(key) + ": " + [
$.each(data, function(k, v) {
html.push(Ox.toTitleCase(k) + ": " + [
Ox.formatNumber(data.items) + " movie" + (data.items != 1 ? "s" : ""), Ox.formatNumber(data.items) + " movie" + (data.items != 1 ? "s" : ""),
Ox.formatDuration(data.runtime, "medium"), Ox.formatDuration(data.runtime, "medium"),
data.files + " file" + (data.files != 1 ? "s" : ""), data.files + " file" + (data.files != 1 ? "s" : ""),
Ox.formatDuration(data.duration, "short"), Ox.formatDuration(data.duration, "short"),
Ox.formatValue(data.size, "B"), Ox.formatValue(data.size, "B"),
Ox.formatValue(data.pixels, "px") Ox.formatValue(data.pixels, "px")
].join(", ")); ].join(", ");
})
return html.join(" — ");
} }