Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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