4 /** Javascript for local persistent selection. */
7 var get_storage = function() {
8 if (!sessionStorage.persistentSelection) {
9 sessionStorage.persistentSelection = JSON.stringify([]);
11 return JSON.parse(sessionStorage.persistentSelection);
14 var put_storage = function(lst) {
15 sessionStorage.persistentSelection = JSON.stringify(lst);
18 var add_selection = function(uuid, name, href, type) {
19 var lst = get_storage();
20 lst.push({"uuid": uuid, "name": name, "href": href, "type": type});
25 var remove_selection = function(uuid) {
26 var lst = get_storage();
27 for (var i = 0; i < lst.length; i++) {
28 if (lst[i].uuid == uuid) {
37 var remove_selection_click = function(e) {
38 remove_selection($(this).attr('name'));
41 var update_count = function(e) {
42 var lst = get_storage();
43 $("#persistent-selection-count").text(lst.length);
45 $('#persistent-selection-list > li > table').empty();
47 for (var i = 0; i < lst.length; i++) {
48 $('#persistent-selection-list > li > table').append("<tr>"
49 + "<td style=\"vertical-align: top\">"
50 + "<span style=\"padding-right: 1em\">" + lst[i].type + "</span>"
54 + "<span><a href=\"" + lst[i].href + "\">" + lst[i].name + "</a></span>"
58 + "<a href=\"#\" class=\"remove-selection\" name=\"" + lst[i].uuid + "\">"
59 + "<span class=\"glyphicon glyphicon-trash pull-right\"></span>"
65 $('#persistent-selection-list > li > table').html("<tr><td>No selections.</td></tr>");
68 var checkboxes = $('.persistent-selection:checkbox');
69 for (i = 0; i < checkboxes.length; i++) {
70 for (var j = 0; j < lst.length; j++) {
71 if (lst[j].uuid == $(checkboxes[i]).val()) {
72 checkboxes[i].checked = true;
76 if (j == lst.length) {
77 checkboxes[i].checked = false;
81 $('.remove-selection').on('click', remove_selection_click);
85 on('change', '.persistent-selection:checkbox', function(e) {
86 //console.log($(this));
87 //console.log($(this).val());
90 if ($(this).is(":checked")) {
91 add_selection($(this).val(), $(this).attr('friendly_name'), $(this).attr('href'), $(this).attr('friendly_type'));
94 remove_selection($(this).val());
99 $(window).on('load storage', update_count);