diff options
Diffstat (limited to 'theme/list_lib.js')
-rw-r--r-- | theme/list_lib.js | 184 |
1 files changed, 140 insertions, 44 deletions
diff --git a/theme/list_lib.js b/theme/list_lib.js index 6fde5417c..6ca82ea51 100644 --- a/theme/list_lib.js +++ b/theme/list_lib.js @@ -47,7 +47,7 @@ function updateView(start, end) var divelist = document.getElementById('diveslist'); divelist.innerHTML = ""; for (var i = start; i <= end; i++) { - divelist.innerHTML += '<ul id="' + itemsToShow[i] + '" onclick="toggleExpantion(this)"</ul>'; + divelist.innerHTML += '<ul id="' + itemsToShow[i] + '" onclick="toggleExpantion(event, this)"</ul>'; expand(document.getElementById(itemsToShow[i])); items[itemsToShow[i]].expanded = true; }; @@ -63,7 +63,7 @@ function addHTML(indexes) var divelist = document.getElementById('diveslist'); divelist.innerHTML = ""; for (var i = 0; i < indexes.length; i++) { - divelist.innerHTML += '<ul id="' + indexes[i] + '" onclick="toggleExpantion(this)"</ul>'; + divelist.innerHTML += '<ul id="' + indexes[i] + '" onclick="toggleExpantion(event, this)"</ul>'; expand(document.getElementById(indexes[i])); itemsToShow[indexes[i]].expanded = true; }; @@ -165,8 +165,11 @@ function setNumberOfDives(e) viewInPage(); } -function toggleExpantion(ul) +function toggleExpantion(e, ul) { + if (e.toElement.localName === "a" ) { + return; + } if (!items[ul.id].expanded) { expand(ul); items[ul.id].expanded = true; @@ -200,8 +203,8 @@ function getlimited(dive) '<div class="item">' + dive.date + '</div>' + '<div class="item">' + dive.time + '</div>' + '<div class="item_large">' + dive.location + '</div>' + - '<div class="item">' + dive.temperature.air + '</div>' + - '<div class="item">' + dive.temperature.water + '</div></div>'; + '<div class="item">' + dive.dive_duration + '</div>' + + '<div class="item">' + put_depth_unit(dive.maxdepth) + " " + depth_unit + '</div></div>'; }; function getExpanded(dive) @@ -214,7 +217,7 @@ function getExpanded(dive) '</td></tr></table>' + '<table><tr><td class="words">' + translate.Air_Temp + ': </td><td>' + dive.temperature.air + '</td><td class="words"> ' + translate.Water_Temp + ': </td><td>' + dive.temperature.water + - '</td></tr></table><table><tr><td class="words">' + translate.Duration + ': </td><td>' + dive.dive_duration + + '</td></tr></table><table><tr><td class="words">' + translate.Max_Depth + ': </td><td>' + put_depth_unit(dive.maxdepth) + " " + depth_unit + '</td></tr><tr><td class="words">' + translate.Duration + ': </td><td>' + dive.dive_duration + '</td></tr><tr><td class="words">' + translate.DiveMaster + ': </td><td>' + dive.divemaster + '</td></tr><tr><td class="words"><p>' + translate.Buddy + ': </p></td><td>' + dive.buddy + '</td></tr><tr><td class="words">' + translate.Suit + ': </td><td>' + dive.suit + @@ -266,8 +269,8 @@ each col. sorted asc or des var number = true; var time = true; var date = true; -var air = true; -var water = true; +var duration = true; +var depth = true; var locat = true; /* @@ -307,18 +310,18 @@ function list_sort(sortOn) sort_it(sortOn, cmpTimeAsc); } break; - case '4': //Air temp - if (air) { - sort_it(sortOn, cmpAtempDes); + case '4': //Duration + if (duration) { + sort_it(sortOn, cmpDurDes); } else { - sort_it(sortOn, cmpAtempAsc); + sort_it(sortOn, cmpDurAsc); } break; - case '5': //Water temp - if (water) { - sort_it(sortOn, cmpWtempDes); + case '5': //Max Depth + if (depth) { + sort_it(sortOn, cmpDepthDes); } else { - sort_it(sortOn, cmpWtempAsc); + sort_it(sortOn, cmpDepthAsc); } break; case '6': //Location @@ -343,11 +346,11 @@ function toggle_sort_state(sortOn) case '3': //time time = 1 - time; break; - case '4': //Air temp - air = 1 - air; + case '4': //Duration + duration = 1 - duration; break; - case '5': //Water temp - water = 1 - water; + case '5': //depth + depth = 1 - depth; break; case '6': //Location locat = 1 - locat; @@ -404,24 +407,24 @@ function cmpDateDes(j, iSmaller) return items[j].date > items[iSmaller].date; } -function cmpAtempAsc(j, iSmaller) +function cmpDurAsc(j, iSmaller) { - return parseFloat(items[j].temperature.air, 10) < parseFloat(items[iSmaller].temperature.air, 10); + return items[j].duration < items[iSmaller].duration; } -function cmpAtempDes(j, iSmaller) +function cmpDurDes(j, iSmaller) { - return parseFloat(items[j].temperature.air, 10) > parseFloat(items[iSmaller].temperature.air, 10); + return items[j].duration > items[iSmaller].duration; } -function cmpWtempAsc(j, iSmaller) +function cmpDepthAsc(j, iSmaller) { - return parseFloat(items[j].temperature.water, 10) < parseFloat(items[iSmaller].temperature.water, 10); + return items[j].maxdepth < items[iSmaller].maxdepth; } -function cmpWtempDes(j, iSmaller) +function cmpDepthDes(j, iSmaller) { - return parseFloat(items[j].temperature.water, 10) > parseFloat(items[iSmaller].temperature.water, 10); + return items[j].maxdepth > items[iSmaller].maxdepth; } function sort_it(sortOn, function_) @@ -773,7 +776,7 @@ function expand_trip(trip) trips[trip].expanded = true; var d = document.getElementById("trip_dive_list_" + trip); for (var j in trips[trip].dives) { - d.innerHTML += '<ul id="' + trips[trip].dives[j].number + '" onclick="toggleExpantion(this)" onmouseover="highlight(this)"' + + d.innerHTML += '<ul id="' + trips[trip].dives[j].number + '" onclick="toggleExpantion(event, this)" onmouseover="highlight(this)"' + ' onmouseout="unhighlight(this)">' + getlimited(trips[trip].dives[j]) + '</ul>'; } } @@ -805,6 +808,14 @@ var points; //reference to the samples array of the shown dive. var ZERO_C_IN_MKELVIN = 273150; var plot1; +function firstNonZero() +{ + for(var i = 0; i <= items[dive_id].samples.length-1; i++){ + if(items[dive_id].samples[i][2] !== 0) + return items[dive_id].samples[i][2]; + } +} + function lastNonZero() { for(var i = items[dive_id].samples.length-1; i >= 0; i--){ @@ -847,7 +858,8 @@ function get_cylinder_HTML(cylinder) var cEPressure = cylinder.EPressure; if (cSPressure === "--") { - cSPressure = Math.round(put_pressure_unit(items[dive_id].samples[0][2])).toFixed(1) + " " + pressure_unit; + var nonZeroCSPressure = firstNonZero(); + cSPressure = Math.round(put_pressure_unit(nonZeroCSPressure)).toFixed(1) + " " + pressure_unit; } if (cEPressure === "--") { @@ -855,7 +867,14 @@ function get_cylinder_HTML(cylinder) cEPressure = Math.round(put_pressure_unit(nonZeroCEPressure)).toFixed(1) + " " + pressure_unit; } - return '<tr><td class="Cyl">' + cylinder.Type + '</td><td class="Cyl">' + cylinder.Size + '</td><td class="Cyl">' + cylinder.WPressure + '</td>' + '<td class="Cyl">' + cSPressure + '</td><td class="Cyl">' + cEPressure + '</td><td class="Cyl">' + cylinder.O2 + '</td></tr>'; + var pressure_string = cylinder.O2; + if (cylinder.O2 !== "Air") { + pressure_string = 'O2: ' + cylinder.O2; + } + if (cylinder.He && cylinder.He !== "0.0%") { + pressure_string += ' / He: ' + cylinder.He; + } + return '<tr><td class="Cyl">' + cylinder.Type + '</td><td class="Cyl">' + cylinder.Size + '</td><td class="Cyl">' + cylinder.WPressure + '</td>' + '<td class="Cyl">' + cSPressure + '</td><td class="Cyl">' + cEPressure + '</td><td class="Cyl">' + pressure_string + '</td></tr>'; } /** @@ -880,7 +899,7 @@ function get_event_value(event) if (event.type == 11 || event.type == 25) { // gas change var he = event.value >> 16; var o2 = event.value & 0xffff; - return 'He: ' + he + ' - O2: ' + o2; + return 'O2: ' + o2 + ' / He: ' + he; } if (event.type == 23) { // heading return event.value; @@ -940,7 +959,7 @@ function get_dive_HTML(dive) '</td></tr></table>' + '<table><tr><td class="words">' + translate.Air_Temp + ': </td><td>' + dive.temperature.air + '</td><td class="words"> ' + translate.Water_Temp + ': </td><td>' + dive.temperature.water + - '</td></tr></table><table><tr><td class="words">' + translate.Duration + ': </td><td>' + dive.dive_duration + + '</td></tr></table><table><tr><td class="words">' + translate.Max_Depth + ': </td><td>' + put_depth_unit(dive.maxdepth) + " " + depth_unit + '</td></tr><tr><td class="words">' + translate.Duration + ': </td><td>' + dive.dive_duration + '</td></tr><tr><td class="words">' + translate.DiveMaster + ': </td><td>' + dive.divemaster + '</td></tr><tr><td class="words"><p>' + translate.Buddy + ': </p></td><td>' + dive.buddy + '</td></tr><tr><td class="words">' + translate.Suit + ': </td><td>' + dive.suit + @@ -978,19 +997,93 @@ function get_status_HTML(dive) '</td><td class="words"> CNS: </td><td>' + dive.cns + '</td></tr></table>'; }; -function get_dive_photos(dive) +/** +* Dive Photo View +*/ + +var success; +var error; +var missing_ids; + +function show_loaded_photos() +{ + //dive photos in the current dive + var dive = items[dive_id]; + var slider = ""; + document.getElementById("divephotos").style.display = 'block'; + for (var i = 0; i < dive.photos.length; i++) { + slider += '<img src="' + location.pathname + '_files/photos/' + dive.photos[i].filename + '" alt="" height="240" width="240">'; + } + document.getElementById("slider").innerHTML = slider; +} + +function remove_missing_photos() { + //dive photos in the current dive + var dive = items[dive_id]; + var actually_removed = 0; + + console.log(missing_ids.length); + for(i = 0; i < missing_ids.length; i++){ + dive.photos.splice(missing_ids[i] - actually_removed, 1); + actually_removed++; + } +} + +function check_loaded_photos() +{ + //hide the photos div if all photos are missing + if (error >= items[dive_id].photos.length) { + document.getElementById("divephotos").style.display = 'none'; + return; + } + + //remove missing photos from the list + remove_missing_photos(); + + //view all remaining photos + show_loaded_photos(); +} + +function check_loading_finished() +{ + //if all images wasn't loaded yet + if (success + error < items[dive_id].photos.length) + return; + + check_loaded_photos(); +} + +function load_photo(url, i) { + var img = new Image(); + img.onload = function() { + success++; + check_loading_finished(); + }; + img.onerror = function() { + error++; + missing_ids.push(i); + check_loading_finished(); + }; + img.src = url; +} + +function load_all_photos(dive) +{ + //init + success = 0; + error = 0; + missing_ids = new Array(); + + //exit if no photos in this dive. if (!dive.photos || dive.photos.length <= 0) { document.getElementById("divephotos").style.display = 'none'; return ""; } - var slider = ""; - document.getElementById("divephotos").style.display = 'block'; + for (var i = 0; i < dive.photos.length; i++) { - slider += '<img src="' + location.pathname + - '_files/photos/' + dive.photos[i].filename + '" alt="" height="240" width="240">'; + load_photo(location.pathname + '_files/photos/' + dive.photos[i].filename, i); } - return slider; } function prev_photo() @@ -1001,7 +1094,7 @@ function prev_photo() items[dive_id].photos[i] = items[dive_id].photos[i + 1] } items[dive_id].photos[i] = temp; - document.getElementById("slider").innerHTML = get_dive_photos(items[dive_id]); + show_loaded_photos(); } function next_photo() @@ -1012,9 +1105,12 @@ function next_photo() items[dive_id].photos[i] = items[dive_id].photos[i - 1] } items[dive_id].photos[0] = temp; - document.getElementById("slider").innerHTML = get_dive_photos(items[dive_id]); + show_loaded_photos(); } +/** +* Helper functions +*/ function mkelvin_to_C(mkelvin) { return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0; @@ -1250,7 +1346,7 @@ function showDiveDetails(dive) document.getElementById("dive_equipment").innerHTML += get_weights_HTML(items[dive_id]); document.getElementById("bookmarks").innerHTML = get_bookmarks_HTML(items[dive_id]); document.getElementById("divestats").innerHTML = get_status_HTML(items[dive_id]); - document.getElementById("slider").innerHTML = get_dive_photos(items[dive_id]); + load_all_photos(items[dive_id]); setDiveTitle(items[dive_id]); //hide the list of dives and show the canvas. @@ -1328,8 +1424,8 @@ function translate_page() document.getElementById("date_header").innerHTML = translate.Date; document.getElementById("time_header").innerHTML = translate.Time; document.getElementById("location_header").innerHTML = translate.Location; - document.getElementById("air_temp_header").innerHTML = translate.Air_Temp; - document.getElementById("water_temp_header").innerHTML = translate.Water_Temp; + document.getElementById("duration_header").innerHTML = translate.Duration; + document.getElementById("maxdepth_header").innerHTML = translate.Max_Depth; document.getElementById("adv_srch_sp").innerHTML = translate.Advanced_Search; document.getElementById("expnd_all_btn").innerHTML = translate.Expand_All; document.getElementById("claps_all_btn").innerHTML = translate.Collapse_All; |