$(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" } ], user: { group: "guest", ui: { columns: ["id", "title", "director", "country", "year", "language", "runtime", "genre", "releasedate"], // find: { conditions: [{ key: "", value: "", operator: "" }], operator: "" }, findQuery: { conditions: [], operator: "" }, groupsQuery: { conditions: [], operator: "|" }, groupsSize: 128, itemView: "info", listQuery: { conditions: [], operator: "" }, 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.user, $ui = { groups: [] }, ui = { infoRatio: 4 / 3, selectedMovies: [] }, // Objects Query = (function() { function constructFind(query) { Ox.print("cF", query) return /*encodeURI(*/$.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: decodeURI(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.findQuery = parseFind(query.find); Ox.print("user.ui.findQuery", user.ui.findQuery) } 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.findQuery.conditions) // the inner $.merge() creates a clone var conditions = $.merge($.merge([], user.ui.listQuery.conditions), user.ui.findQuery.conditions); $.merge(conditions, groups ? $.map(groups, function(v, i) { if (v.id != groupId && v.query.conditions.length) { return v.query.conditions.length == 1 ? v.query.conditions : v.query; } }) : []), operator = conditions.length < 2 ? "" : ","; // fixme: should be & 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/" }); $("