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.

container.js 2.3 KiB

12 vuotta sitten
13 vuotta sitten
12 vuotta sitten
13 vuotta sitten
11 vuotta sitten
13 vuotta sitten
13 vuotta sitten
12 vuotta sitten
12 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // page container
  4. wn.provide('wn.pages');
  5. wn.provide('wn.views');
  6. wn.views.Container = Class.extend({
  7. _intro: "Container contains pages inside `#container` and manages \
  8. page creation, switching",
  9. init: function() {
  10. this.container = $('#body_div').get(0);
  11. this.page = null; // current page
  12. this.pagewidth = $('#body_div').width();
  13. this.pagemargin = 50;
  14. },
  15. add_page: function(label, onshow, onhide) {
  16. var page = $('<div class="content"></div>')
  17. .attr('id', "page-" + label)
  18. .toggle(false)
  19. .appendTo(this.container).get(0);
  20. if(onshow)
  21. $(page).bind('show', onshow);
  22. if(onshow)
  23. $(page).bind('hide', onhide);
  24. page.label = label;
  25. wn.pages[label] = page;
  26. return page;
  27. },
  28. change_to: function(label) {
  29. if(this.page && this.page.label === label) {
  30. $(this.page).trigger('show');
  31. return;
  32. }
  33. var me = this;
  34. if(label.tagName) {
  35. // if sent the div, get the table
  36. var page = label;
  37. } else {
  38. var page = wn.pages[label];
  39. }
  40. if(!page) {
  41. console.log(wn._('Page not found')+ ': ' + label);
  42. return;
  43. }
  44. // hide dialog
  45. if(cur_dialog && cur_dialog.display && !cur_dialog.keep_open) {
  46. cur_dialog.hide();
  47. }
  48. // hide current
  49. if(this.page && this.page != page) {
  50. $(this.page).toggle(false);
  51. $(this.page).trigger('hide');
  52. }
  53. // show new
  54. if(!this.page || this.page != page) {
  55. this.page = page;
  56. //$(this.page).fadeIn();
  57. $(this.page).toggle(true);
  58. }
  59. $(document).trigger("page-change");
  60. this.page._route = window.location.hash;
  61. $(this.page).trigger('show');
  62. scroll(0,0);
  63. return this.page;
  64. }
  65. });
  66. wn.views.Factory = Class.extend({
  67. init: function(opts) {
  68. $.extend(this, opts);
  69. },
  70. show: function() {
  71. var page_name = wn.get_route_str(),
  72. me = this;
  73. if(wn.pages[page_name]) {
  74. wn.container.change_to(wn.pages[page_name]);
  75. } else {
  76. var route = wn.get_route();
  77. if(route[1]) {
  78. me.make(route);
  79. } else {
  80. wn.show_not_found(route);
  81. }
  82. }
  83. },
  84. make_page: function(double_column) {
  85. var page_name = wn.get_route_str(),
  86. page = wn.container.add_page(page_name);
  87. wn.ui.make_app_page({
  88. parent: page,
  89. single_column: !double_column
  90. });
  91. wn.container.change_to(page_name);
  92. return page;
  93. }
  94. })