You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
2.3 KiB

  1. // route urls to their virtual pages
  2. // re-route map (for rename)
  3. wn.re_route = {};
  4. wn.route_titles = {};
  5. wn.route = function() {
  6. if(wn.re_route[window.location.hash]) {
  7. // after saving a doc, for example,
  8. // "New DocType 1" and the renamed "TestDocType", both exist in history
  9. // now if we try to go back,
  10. // it doesn't allow us to go back to the one prior to "New DocType 1"
  11. // Hence if this check is true, instead of changing location hash,
  12. // we just do a back to go to the doc previous to the "New DocType 1"
  13. var re_route_val = wn.get_route_str(wn.re_route[window.location.hash]);
  14. var cur_route_val = wn.get_route_str(wn._cur_route);
  15. if (decodeURIComponent(re_route_val) === decodeURIComponent(cur_route_val)) {
  16. window.history.back();
  17. return;
  18. } else {
  19. window.location.hash = wn.re_route[window.location.hash];
  20. }
  21. }
  22. wn._cur_route = window.location.hash;
  23. route = wn.get_route();
  24. switch (route[0]) {
  25. case "List":
  26. wn.views.doclistview.show(route[1]);
  27. break;
  28. case "Form":
  29. if(route.length>3) {
  30. route[2] = route.splice(2).join('/');
  31. }
  32. wn.views.formview.show(route[1], route[2]);
  33. break;
  34. case "Report":
  35. wn.views.reportview.show(route[1], route[2]);
  36. break;
  37. case "Report2":
  38. wn.views.reportview2.show();
  39. break;
  40. default:
  41. wn.views.pageview.show(route[0]);
  42. }
  43. if(wn.route_titles[window.location.hash]) {
  44. document.title = wn.route_titles[window.location.hash];
  45. }
  46. }
  47. wn.get_route = function(route) {
  48. // route for web [deprecated after cms2]
  49. // if(!wn.boot) {
  50. // return [window.page_name];
  51. // }
  52. // for app
  53. return $.map(wn.get_route_str(route).split('/'),
  54. function(r) { return decodeURIComponent(r); });
  55. }
  56. wn.get_route_str = function(route) {
  57. if(!route)
  58. route = window.location.hash;
  59. if(route.substr(0,1)=='#') route = route.substr(1);
  60. if(route.substr(0,1)=='!') route = route.substr(1);
  61. return route;
  62. }
  63. wn.set_route = function() {
  64. route = $.map(arguments, function(a) { return encodeURIComponent(a) }).join('/');
  65. window.location.hash = route;
  66. // Set favicon (app.js)
  67. wn.app.set_favicon();
  68. }
  69. wn._cur_route = null;
  70. $(window).bind('hashchange', function() {
  71. // save the title
  72. wn.route_titles[wn._cur_route] = document.title;
  73. if(window.location.hash==wn._cur_route)
  74. return;
  75. wn.route();
  76. });