PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/bycycle/tripplanner/static/js/bycycle/result.js

https://bitbucket.org/wyatt/bycycle.tripplanner
JavaScript | 91 lines | 78 code | 8 blank | 5 comment | 1 complexity | 1a18d49c3674042416d4534adf44b6fe MD5 | raw file
Possible License(s): GPL-3.0
  1. define(['jquery', 'bycycle'], function ($, bycycle) {
  2. /**
  3. * Result Base Class
  4. *
  5. * @param data {Object} Raw result data
  6. */
  7. var Result = function (data) {
  8. $.extend(this, data);
  9. this.overlays = [];
  10. };
  11. Result.prototype = {
  12. addOverlay: function () {
  13. var overlays = $.makeArray(arguments);
  14. for (var i = 0, len = overlays.length; i < len; ++i) {
  15. this.overlays.push(overlays[i]);
  16. }
  17. }
  18. };
  19. var LookupResult = bycycle.inheritFrom(Result, {
  20. constructor: function (data) {
  21. this.superType.call(this, data);
  22. var id = this.id,
  23. llString = this.lat_long.coordinates.join(','),
  24. address = this.address,
  25. oneLineAddress = address.replace(/\n+/, ', ');
  26. this.coordinates = this.point.coordinates;
  27. this.llString = llString;
  28. this.htmlAddress = address.replace(/\n+/, '<br>');
  29. this.oneLineAddress = oneLineAddress;
  30. this.popup = $('<div>');
  31. this.popupContent = (
  32. $('<div>')
  33. .append(
  34. $('<div>').html(this.htmlAddress))
  35. .append(
  36. $('<div>')
  37. .append($('<a>').attr('href', '#').text('Get directions from').click(
  38. function (event) {
  39. event.preventDefault();
  40. byCycle.UI.getDirectionsFrom(oneLineAddress, id, llString);
  41. }
  42. ))
  43. )
  44. .append(
  45. $('<div>')
  46. .append($('<a>').attr('href', '#').text('Get directions to').click(
  47. function (event) {
  48. event.preventDefault();
  49. byCycle.UI.getDirectionsTo(oneLineAddress, id, llString);
  50. }
  51. ))
  52. )
  53. .append(
  54. $('<div>')
  55. .append(
  56. $('<a>').attr('href', '#').text('Remove').click(function (event) {
  57. event.preventDefault();
  58. byCycle.UI.removeResult(id);
  59. })
  60. )
  61. )
  62. );
  63. }
  64. });
  65. var Route = bycycle.inheritFrom(Result, {
  66. constructor: function (data) {
  67. this.superType.call(this, data);
  68. var linestring = this.linestring,
  69. coordinates = linestring.coordinates;
  70. this.id = ['route', '-', this.start.id, '-', this.end.id].join(''),
  71. this.start = new LookupResult(this.start);
  72. this.start.popupContent = this.start.htmlAddress;
  73. this.end = new LookupResult(this.end);
  74. this.end.popupContent = this.end.htmlAddress;
  75. this.coordinates = coordinates;
  76. this.encodedPolyline = this.linestring_encoded;
  77. }
  78. });
  79. return {
  80. LookupResult: LookupResult,
  81. Route: Route
  82. }
  83. });