$(function() { //Ox.debug = Ox.print; //Ox.print = function() {}; var $body = $("body"), $document = $(document), $window = $(window), config = { appId: "oxdb", appName: "0xDB", findKeys: [ { id: "all", title: "All" }, { id: "title", title: "Title", autocomplete: true }, { id: "director", title: "Director", autocomplete: true }, { id: "country", title: "Country", autocomplete: true }, { id: "year", title: "Year", autocomplete: true }, { id: "language", title: "Language", autocomplete: true }, { id: "writer", title: "Writer", autocomplete: true }, { id: "producer", title: "Producer", autocomplete: true }, { id: "cinematographer", title: "Cinematographer", autocomplete: true }, { id: "editor", title: "Editor", autocomplete: true }, { id: "actor", title: "Actor", autocomplete: true }, { id: "character", title: "Character", autocomplete: true }, { id: "name", title: "Name", autocomplete: true }, { id: "genre", title: "Genre", autocomplete: true }, { id: "keyword", title: "Keyword", autocomplete: true }, { id: "summary", title: "Summary" }, { id: "dialog", title: "Dialog" } ], groups: ["director", "country", "year", "language", "genre"], itemViews: [ { id: "info", title: "Info" }, { id: "statistics", title: "Statistics" }, { id: "clips", title: "Clips" }, { id: "timeline", title: "Timeline" }, { id: "map", title: "Map" }, { id: "calendar", title: "Calendar" }, { id: "files", title: "Files", admin: true } ], listViews: [ { id: "list", title: "as List" }, { id: "icons", title: "as Icons" }, { id: "info", title: "with Info" }, { id: "clips", title: "with Clips" }, { id: "timelines", title: "with Timelines" }, { id: "maps", title: "with Maps" }, { id: "calendars", title: "with Calendars" }, { id: "clip", title: "as Clips" }, { id: "map", title: "on Map" }, { id: "calendar", title: "on Calendar" }, ], sections: [ { id: "history", title: "History" }, { id: "lists", title: "My Lists" }, { id: "public", title: "Public Lists" }, { id: "featured", title: "Featured Lists" } ], sortKeys: [ { id: "title", title: "Title", operator: "", align: "left", width: 180, removable: false }, { id: "director", title: "Director", operator: "", align: "left", width: 180, removable: false }, { id: "country", title: "Country", operator: "", align: "left", width: 120 }, { id: "year", title: "Year", operator: "-", align: "right", width: 60 }, { id: "language", title: "Language", operator: "", align: "left", width: 120 }, { id: "runtime", title: "Runtime", operator: "", align: "right", width: 60 }, { id: "writer", title: "Writer", operator: "", align: "left", width: 180 }, { id: "producer", title: "Producer", operator: "", align: "left", width: 180 }, { id: "cinematographer", title: "Cinematographer", operator: "", align: "left", width: 180 }, { id: "editor", title: "Editor", operator: "", align: "left", width: 180 }, { id: "actors", title: "Number of Actors", operator: "-", align: "right", width: 60 }, { id: "genre", title: "Genre", operator: "", align: "left", width: 120 }, { id: "keywords", title: "Number of Keywords", operator: "-", align: "right", width: 60 }, { id: "summary", title: "Words in Summary", operator: "-", align: "right", width: 60 }, { id: "trivia", title: "Words in Trivia", operator: "-", align: "right", width: 60 }, { id: "releasedate", title: "Release Date", operator: "-", align: "left", width: 90 }, { id: "budget", title: "Budget", operator: "-", align: "right", width: 90 }, { id: "gross", title: "Gross", operator: "-", align: "right", width: 90 }, { id: "profit", title: "Profit", operator: "-", align: "right", width: 90 }, { id: "rating", title: "Rating", operator: "-", align: "right", width: 60 }, { id: "votes", title: "Votes", operator: "-", align: "right", width: 90 }, { id: "id", title: "ID", 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: "color", title: "Color", operator: "", align: "left", width: 90 }, { id: "saturation", title: "Saturation", operator: "-", align: "right", width: 60 }, { id: "brightness", title: "Brightness", operator: "-", align: "right", width: 60 }, { id: "volume", title: "Volume", operator: "-", align: "right", width: 60 }, { id: "clips", title: "Clips", operator: "-", align: "right", width: 60 }, { id: "cuts", title: "Cuts", operator: "-", align: "right", width: 60 }, { id: "cutsperminute", title: "Cuts per Minute", operator: "-", align: "right", width: 60 }, { id: "words", title: "Words", operator: "-", align: "right", width: 60 }, { id: "wordsperminute", title: "Words per Minute", operator: "-", align: "right", width: 60 }, { id: "resolution", title: "Resolution", operator: "-", align: "left", width: 90 }, { id: "pixels", title: "Pixels", operator: "-", align: "right", width: 90 }, { id: "size", title: "Size", operator: "-", align: "right", width: 90 }, { id: "bitrate", title: "Bitrate", operator: "-", align: "right", width: 90 }, { id: "files", title: "Files", operator: "-", align: "right", width: 60 }, { id: "filename", title: "Filename", operator: "", align: "left", width: 180 }, { id: "published", title: "Date Published", 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: { group: "guest", ui: { columns: ["id", "title", "director", "country", "year", "language", "runtime", "genre"], find: { conditions: [{ key: "", value: "", operator: "" }], operator: "" }, itemView: "info", listsSize: 192, listView: "list", sections: ["history", "lists", "public", "featured"], showGroups: true, showInfo: true, showLists: true, showMovies: true, sort: [ { key: "director", operator: "" } ], theme: $.browser.mozilla ? "classic" : "modern" }, username: "" } }, user = config.userSettings, $ui = { groups: [] }, ui = { infoRatio: 4 / 3, selectedMovies: [] }, // Objects Query = (function() { function constructFind(query) { Ox.print("cF", query) return $.map(query.conditions, function(v, i) { if (!Ox.isUndefined(v.conditions)) { return "[" + constructFind(v) + "]"; } else { return v.value !== "" ? v.key + (v.key ? ":" : "") + constructValue(v.value, v.operator) : null; } }).join(query.operator); } function constructValue(value, operator) { operator = operator.replace("=", "^$"); if (operator.indexOf("$") > -1) { value = operator.substr(0, operator.length - 1) + value + "$" } else { value = operator + value; } return value; } function mergeFind() { } function parseFind(str) { var find = { conditions: [], operator: "" }, subconditions = str.match(/\[.*?\]/g) || []; $.each(subconditions, function(i, v) { subconditions[i] = v.substr(1, v.length - 2); str = str.replace(v, "[" + i + "]"); }); if (str.indexOf(",") > -1) { find.operator = "&"; } else if (str.indexOf("|") > -1) { find.operator = "|"; } Ox.print("pF", str, find.operator) find.conditions = $.map(find.operator === "" ? [str] : str.split(find.operator == "&" ? "," : "|"), function(v, i) { Ox.print("v", v) var ret, kv; if (v[0] == "[") { Ox.print("recursion", subconditions) ret = parseFind(subconditions[parseInt(v.substr(1, v.length - 2))]); } else { kv = ((v.indexOf(":") > - 1 ? "" : ":") + v).split(":"); ret = $.extend({ key: kv[0] }, parseValue(kv[1])); } return ret; }); return find; } function parseValue(str) { var value = { value: str, operator: "" }; if (value.value[0] == "!") { value.operator = "!" value.value = value.value.substr(1); } if ("^<>".indexOf(value.value[0]) > -1) { value.operator += value.value[0]; value.value = value.value.substr(1); } if (value.value.substr(-1) == "$") { value.operator += "$"; value.value = value.value.substr(0, value.value.length - 1); } value.operator = value.operator.replace("^$", "="); return value; } return { fromString: function(str) { var query = Ox.unserialize(str), sort = []; if ("find" in query) { user.ui.find = parseFind(query.find); Ox.print("user.ui.find", user.ui.find) } if ("sort" in query) { sort = query.sort.split(",") user.ui.sort = $.map(query.sort.split(","), function(v, i) { var hasOperator = "+-".indexOf(v[0]) > -1, key = hasOperator ? query.sort.substr(1) : query.sort, operator = hasOperator ? v[0].replace("+", "") : Ox.getObjectById(config.sortKeys, key).operator; return { key: key, operator: operator }; }); } if ("view" in query) { user.ui.listView = query.view; } }, toObject: function(groupId) { Ox.print("tO", user.ui.find.conditions) // the inner $.merge() creates a clone var conditions = $.merge($.merge([], user.ui.find.conditions), groups ? $.map(groups, function(v, i) { if (v.id != groupId && v.conditions.length) { return v.conditions.length == 1 ? v.conditions : { conditions: v.conditions, operator: "|" }; } }) : []), operator = conditions.length < 2 ? "" : ","; Ox.print(groupId, user.ui.find, conditions); return { conditions: conditions, operator: operator }; }, toString: function() { Ox.print("tS", user.ui.find) return Ox.serialize({ find: constructFind(Query.toObject()), sort: user.ui.sort[0].operator + user.ui.sort[0].key, view: user.ui.listView }); } }; })(); // App Query.fromString(location.hash.substr(1)); Ox.print("user.ui", user.ui) document.title = config.appName; Ox.theme(user.ui.theme); app = new Ox.App({ name: config.appName, requestURL: "/api/" }); // MainMenu $ui.mainMenu = new Ox.MainMenu({ extras: [ $ui.loadingIcon = new Ox.LoadingIcon({ size: "medium" }) ], menus: [ { id: config.appId, title: config.appName, items: [ { id: "about", title: "About" }, {}, { id: "home", title: "Home Screen" }, { id: "faq", title: "Frequently Asked Questions" }, { id: "tos", title: "Terms of Service" }, {}, { id: "contact", title: "Contact" } ] }, { id: "user", title: "User", items: [ { id: "username", title: "User: not logged in", disabled: true }, {}, { id: "preferences", title: "Preferences", disabled: true, keyboard: "control ," }, {}, { id: "register", title: "Create an Account..." }, { id: "login", title: "Login..." } ] }, { id: "list", title: "List", items: [ { id: "history", title: "History", items: [ { id: "allmovies", title: "All Movies" } ] }, { id: "lists", title: "View List", items: [ { id: "favorites", title: "Favorites" } ] }, { id: "features", title: "View Feature", items: [ { id: "situationistfilm", title: "Situationist Film" }, { id: "timelines", title: "Timelines" } ] }, {}, { id: "newlist", title: "New List...", keyboard: "control n" }, { id: "newlistfromselection", title: "New List from Selection...", disabled: true, keyboard: "shift control n" }, { id: "newsmartlist", title: "New Smart List...", keyboard: "alt control n" }, { id: "newsmartlistfromresults", title: "New Smart List from Results...", keyboard: "shift alt control n" }, {}, { id: "addmovietolist", title: ["Add Selected Movie to List...", "Add Selected Movies to List..."], disabled: true }, {}, { id: "setposterframe", title: "Set Poster Frame", disabled: true } ]}, { id: "edit", title: "Edit", items: [ { id: "undo", title: "Undo", disabled: true, keyboard: "control z" }, { id: "redo", title: "Redo", disabled: true, keyboard: "shift control z" }, {}, { id: "cut", title: "Cut", disabled: true, keyboard: "control x" }, { id: "copy", title: "Copy", disabled: true, keyboard: "control c" }, { id: "paste", title: "Paste", disabled: true, keyboard: "control v" }, { id: "delete", title: "Delete", disabled: true, keyboard: "delete" }, {}, { id: "selectall", title: "Select All", disabled: true, keyboard: "control a" }, { id: "selectnone", title: "Select None", disabled: true, keyboard: "shift control a" }, { id: "invertselection", title: "Invert Selection", disabled: true, keyboard: "alt control a" } ] }, { id: "view", title: "View", items: [ { id: "movies", title: "View Movies", items: $.map(config.listViews, function(view, i) { return $.extend({ checked: user.ui.listView == view.id, group: "viewmovies" }, view); }) }, { id: "icons", title: "Icons", items: [ { id: "poster", title: "Poster" }, { id: "still", title: "Still" }, { id: "timeline", title: "Timeline" } ] }, { id: "info", title: "Info", items: [ { id: "poster", title: "Poster" }, { id: "video", title: "Video" } ] }, {}, { id: "openmovie", title: ["Open Movie", "Open Movies"], disabled: true, items: $.map(config.itemViews, function(view, i) { return view; }) }, {}, { id: "lists", title: "Hide Lists", keyboard: "shift l" }, { id: "info", title: "Hide Info", keyboard: "shift i" }, { id: "groups", title: "Hide Groups", keyboard: "shift g" }, { id: "movies", title: "Hide Movies", disabled: true, keyboard: "shift m" } ]}, { id: "sort", title: "Sort", items: [ { id: "sortmovies", title: "Sort Movies by", items: $.map(config.sortKeys, function(key, i) { return $.extend({ checked: user.ui.sort[0].key == key.id, group: "sortmovies" }, key); }) }, { id: "ordermovies", title: "Order Movies", items: [ { 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: "advancedsort", title: "Advanced Sort...", keyboard: "shift control s" }, {}, { id: "groupsstuff", title: "Groups Stuff" } ] }, { id: "find", title: "Find", items: [ { id: "find", title: "Find", items: $.map(config.findKeys, function(key, i) { return $.extend({ checked: user.ui.find.key == key.id || user.ui.find.key === "" && key.id == "all", group: "find" }, key) }) }, { id: "advancedfind", title: "Advanced Find...", keyboard: "shift control f" } ] }, { id: "code", title: "Code", items: [ { id: "download", title: "Download" }, { id: "contribute", title: "Contribute" }, { id: "report", title: "Report a Bug" }, ] }, { id: "help", title: "Help", items: [ { id: "help", title: config.appName + " Help", keyboard: "shift ?" } ] }, { id: "debug", title: "Debug", items: [ { id: "query", title: "Show Query" } ]} ] }); // Lists $ui.lists = new Ox.Element(); $ui.sections = []; $.each(user.ui.sections, function(i, id) { var section = new Ox.CollapsePanel({ size: "small", title: Ox.getObjectById(config.sections, id).title }); $ui.sections.push(section); section.$content.append( $("