From 4b90c959c9a65c2b42250b2fcfc9a8ffbf63fd7e Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 23 Oct 2012 18:53:22 -0500 Subject: Worked on the "Make Default" cookie code --- .../new/javascript/dataset_select_menu.coffee | 78 +- .../static/new/javascript/dataset_select_menu.js | 83 +- .../static/new/js_external/jquery.cookie.js | 72 + wqflask/wqflask/static/new/js_external/json2.js | 1750 ++++++-------------- wqflask/wqflask/templates/new_index_page.html | 15 +- 5 files changed, 688 insertions(+), 1310 deletions(-) create mode 100644 wqflask/wqflask/static/new/js_external/jquery.cookie.js diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee b/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee index c2a9b11d..df891826 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee +++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee @@ -1,8 +1,11 @@ $ -> + ## Handle menu changes + process_json = (data) -> window.jdata = data populate_species() + apply_default() $.ajax '/static/new/javascript/dataset_menu_structure', dataType: 'json' @@ -11,42 +14,97 @@ $ -> populate_species = -> species_list = @jdata.species redo_dropdown($('#species'), species_list) - populate_groups() + populate_group() - populate_groups = -> + populate_group = -> + console.log("in populate group") species = $('#species').val() group_list = @jdata.groups[species] redo_dropdown($('#group'), group_list) - populate_types() + populate_type() - populate_types = -> + populate_type = -> species = $('#species').val() group = $('#group').val() type_list = @jdata.types[species][group] redo_dropdown($('#type'), type_list) - populate_datasets() + populate_dataset() - populate_datasets = -> + populate_dataset = -> species = $('#species').val() group = $('#group').val() type = $('#type').val() + console.log("sgt:", species, group, type) dataset_list = @jdata.datasets[species][group][type] + console.log("pop_dataset:", dataset_list) redo_dropdown($('#dataset'), dataset_list) redo_dropdown = (dropdown, items) -> + console.log("in redo:", dropdown, items) dropdown.empty() for item in items dropdown.append($("").val(item[0]).text(item[1])) - + $('#species').change => - populate_groups() + populate_group() $('#group').change => - populate_types() + populate_type() $('#type').change => - populate_datasets() + populate_dataset() + + ## Info buttons + + open_window = (url, name) -> + options = "menubar=1,toolbar=1,location=1,resizable=1,status=1,scrollbars=1,directories=1,width=900" + open(url, name, options).focus() + + group_info = -> + species = $('#species').val() + group = $('#group').val() + url = "/" + species + "Cross.html#" + group + open_window(url, "Group Info") + + $('#group_info').click(group_info) + dataset_info = -> + dataset = $('#dataset').val() + url = "/webqtl/main.py?FormID=sharinginfo&InfoPageName=" + dataset + open_window(url, "Dataset Info") + + $('#dataset_info').click(dataset_info) + + + ## Handle setting new default drop downs + + make_default = -> + holder = {} + for item in ['species', 'group', 'type', 'dataset'] + holder[item] = $("##{item}").val() + jholder = JSON.stringify(holder) + $.cookie('search_defaults', jholder, + expires: 365) + + apply_default = -> + defaults = $.cookie('search_defaults') + if not defaults + return + defaults = $.parseJSON(defaults) + + for item in [['species', 'group'] + ['group', 'type'] + ['type', 'dataset'], + ['dataset', null]] + + $("##{item[0]}").val(defaults[item[0]]) + if item[1] + window["populate_" + item[1]] + + + + $("#make_default").click(make_default) + ## ##* function: based on different browser use, will have different initial actions; diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js index 8f684f6a..655aac15 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js +++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js @@ -2,11 +2,12 @@ (function() { $(function() { - var populate_datasets, populate_groups, populate_species, populate_types, process_json, redo_dropdown, + var apply_default, dataset_info, group_info, make_default, open_window, populate_dataset, populate_group, populate_species, populate_type, process_json, redo_dropdown, _this = this; process_json = function(data) { window.jdata = data; - return populate_species(); + populate_species(); + return apply_default(); }; $.ajax('/static/new/javascript/dataset_menu_structure', { dataType: 'json', @@ -16,33 +17,37 @@ var species_list; species_list = this.jdata.species; redo_dropdown($('#species'), species_list); - return populate_groups(); + return populate_group(); }; - populate_groups = function() { + populate_group = function() { var group_list, species; + console.log("in populate group"); species = $('#species').val(); group_list = this.jdata.groups[species]; redo_dropdown($('#group'), group_list); - return populate_types(); + return populate_type(); }; - populate_types = function() { + populate_type = function() { var group, species, type_list; species = $('#species').val(); group = $('#group').val(); type_list = this.jdata.types[species][group]; redo_dropdown($('#type'), type_list); - return populate_datasets(); + return populate_dataset(); }; - populate_datasets = function() { + populate_dataset = function() { var dataset_list, group, species, type; species = $('#species').val(); group = $('#group').val(); type = $('#type').val(); + console.log("sgt:", species, group, type); dataset_list = this.jdata.datasets[species][group][type]; + console.log("pop_dataset:", dataset_list); return redo_dropdown($('#dataset'), dataset_list); }; redo_dropdown = function(dropdown, items) { var item, _i, _len, _results; + console.log("in redo:", dropdown, items); dropdown.empty(); _results = []; for (_i = 0, _len = items.length; _i < _len; _i++) { @@ -52,14 +57,68 @@ return _results; }; $('#species').change(function() { - return populate_groups(); + return populate_group(); }); $('#group').change(function() { - return populate_types(); + return populate_type(); }); - return $('#type').change(function() { - return populate_datasets(); + $('#type').change(function() { + return populate_dataset(); }); + open_window = function(url, name) { + var options; + options = "menubar=1,toolbar=1,location=1,resizable=1,status=1,scrollbars=1,directories=1,width=900"; + return open(url, name, options).focus(); + }; + group_info = function() { + var group, species, url; + species = $('#species').val(); + group = $('#group').val(); + url = "/" + species + "Cross.html#" + group; + return open_window(url, "Group Info"); + }; + $('#group_info').click(group_info); + dataset_info = function() { + var dataset, url; + dataset = $('#dataset').val(); + url = "/webqtl/main.py?FormID=sharinginfo&InfoPageName=" + dataset; + return open_window(url, "Dataset Info"); + }; + $('#dataset_info').click(dataset_info); + make_default = function() { + var holder, item, jholder, _i, _len, _ref; + holder = {}; + _ref = ['species', 'group', 'type', 'dataset']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + item = _ref[_i]; + holder[item] = $("#" + item).val(); + } + jholder = JSON.stringify(holder); + return $.cookie('search_defaults', jholder, { + expires: 365 + }); + }; + apply_default = function() { + var defaults, item, _i, _len, _ref, _results; + defaults = $.cookie('search_defaults'); + if (!defaults) { + return; + } + defaults = $.parseJSON(defaults); + _ref = [['species', 'group'], ['group', 'type'], ['type', 'dataset'], ['dataset', null]]; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + item = _ref[_i]; + $("#" + item[0]).val(defaults[item[0]]); + if (item[1]) { + _results.push(window["populate_" + item[1]]); + } else { + _results.push(void 0); + } + } + return _results; + }; + return $("#make_default").click(make_default); }); }).call(this); diff --git a/wqflask/wqflask/static/new/js_external/jquery.cookie.js b/wqflask/wqflask/static/new/js_external/jquery.cookie.js new file mode 100644 index 00000000..2d4c05a8 --- /dev/null +++ b/wqflask/wqflask/static/new/js_external/jquery.cookie.js @@ -0,0 +1,72 @@ +/*! + * jQuery Cookie Plugin v1.3 + * https://github.com/carhartl/jquery-cookie + * + * Copyright 2011, Klaus Hartl + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://www.opensource.org/licenses/mit-license.php + * http://www.opensource.org/licenses/GPL-2.0 + */ +(function ($, document, undefined) { + + var pluses = /\+/g; + + function raw(s) { + return s; + } + + function decoded(s) { + return decodeURIComponent(s.replace(pluses, ' ')); + } + + var config = $.cookie = function (key, value, options) { + + // write + if (value !== undefined) { + options = $.extend({}, config.defaults, options); + + if (value === null) { + options.expires = -1; + } + + if (typeof options.expires === 'number') { + var days = options.expires, t = options.expires = new Date(); + t.setDate(t.getDate() + days); + } + + value = config.json ? JSON.stringify(value) : String(value); + + return (document.cookie = [ + encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), + options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE + options.path ? '; path=' + options.path : '', + options.domain ? '; domain=' + options.domain : '', + options.secure ? '; secure' : '' + ].join('')); + } + + // read + var decode = config.raw ? raw : decoded; + var cookies = document.cookie.split('; '); + for (var i = 0, l = cookies.length; i < l; i++) { + var parts = cookies[i].split('='); + if (decode(parts.shift()) === key) { + var cookie = decode(parts.join('=')); + return config.json ? JSON.parse(cookie) : cookie; + } + } + + return null; + }; + + config.defaults = {}; + + $.removeCookie = function (key, options) { + if ($.cookie(key) !== null) { + $.cookie(key, null, options); + return true; + } + return false; + }; + +})(jQuery, document); diff --git a/wqflask/wqflask/static/new/js_external/json2.js b/wqflask/wqflask/static/new/js_external/json2.js index 2373c74d..c7745df8 100644 --- a/wqflask/wqflask/static/new/js_external/json2.js +++ b/wqflask/wqflask/static/new/js_external/json2.js @@ -1,1298 +1,486 @@ - +/* + json2.js + 2012-10-08 + Public Domain. - - -
- - -
- 1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 -344 -345 -346 -347 -348 -349 -350 -351 -352 -353 -354 -355 -356 -357 -358 -359 -360 -361 -362 -363 -364 -365 -366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 -384 -385 -386 -387 -388 -389 -390 -391 -392 -393 -394 -395 -396 -397 -398 -399 -400 -401 -402 -403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -- |
-
- |
-
Headers
--# This is an <h1> tag -## This is an <h2> tag -###### This is an <h6> tag-
Text styles
--*This text will be italic* -_This will also be italic_ -**This text will be bold** -__This will also be bold__ - -*You **can** combine them* --
Unordered
--* Item 1 -* Item 2 - * Item 2a - * Item 2b-
Ordered
--1. Item 1 -2. Item 2 -3. Item 3 - * Item 3a - * Item 3b-
Images
-- -Format:  --
Links
--http://github.com - automatic! -[GitHub](http://github.com)-
Blockquotes
--As Kanye West said: - -> We're living the future so -> the present is our past. --
Syntax highlighting with GFM
-
-```javascript
-function fancyAlert(arg) {
- if(arg) {
- $.facebox({div:'#foo'})
- }
+ Values that do not have JSON representations, such as undefined or
+ functions, will not be serialized. Such values in objects will be
+ dropped; in arrays they will be replaced with null. You can use
+ a replacer function to replace those with JSON values.
+ JSON.stringify(undefined) returns undefined.
+
+ The optional space parameter produces a stringification of the
+ value that is filled with line breaks and indentation to make it
+ easier to read.
+
+ If the space parameter is a non-empty string, then that string will
+ be used for indentation. If the space parameter is a number, then
+ the indentation will be that many spaces.
+
+ Example:
+
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
+ // text is '["e",{"pluribus":"unum"}]'
+
+
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
+
+ text = JSON.stringify([new Date()], function (key, value) {
+ return this[key] instanceof Date ?
+ 'Date(' + this[key] + ')' : value;
+ });
+ // text is '["Date(---current time---)"]'
+
+
+ JSON.parse(text, reviver)
+ This method parses a JSON text to produce an object or array.
+ It can throw a SyntaxError exception.
+
+ The optional reviver parameter is a function that can filter and
+ transform the results. It receives each of the keys and values,
+ and its return value is used instead of the original value.
+ If it returns what it received, then the structure is not modified.
+ If it returns undefined then the member is deleted.
+
+ Example:
+
+ // Parse the text. Values that look like ISO date strings will
+ // be converted to Date objects.
+
+ myData = JSON.parse(text, function (key, value) {
+ var a;
+ if (typeof value === 'string') {
+ a =
+/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
+ if (a) {
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
+ +a[5], +a[6]));
+ }
+ }
+ return value;
+ });
+
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
+ var d;
+ if (typeof value === 'string' &&
+ value.slice(0, 5) === 'Date(' &&
+ value.slice(-1) === ')') {
+ d = new Date(value.slice(5, -1));
+ if (d) {
+ return d;
+ }
+ }
+ return value;
+ });
+
+
+ This is a reference implementation. You are free to copy, modify, or
+ redistribute.
+*/
+
+/*jslint evil: true, regexp: true */
+
+/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
+ test, toJSON, toString, valueOf
+*/
+
+
+// Create a JSON object only if one does not already exist. We create the
+// methods in a closure to avoid creating global variables.
+
+if (typeof JSON !== 'object') {
+ JSON = {};
}
-```
- Or, indent your code 4 spaces
--Here is a Python code example -without syntax highlighting: - - def foo: - if not bar: - return true-
Inline code for comments
--I think you should use an -`<addr>` element here instead.-
- Designed and coded by Sam Ockman, Xiaodong Zhou, Christian Fernandez, + Designed and coded by Sam Ockman, Xiaodong Zhou, + Christian Fernandez, Ning Liu, Rudi Alberts, Elissa Chesler, Jintao Wang, Kenneth Manly, Robert W. Williams, and colleagues.
@@ -409,6 +408,8 @@ + +