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.

пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 11 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 12 година
пре 11 година
пре 11 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.provide('wn.views.pageview');
  4. wn.provide("wn.standard_pages");
  5. wn.views.pageview = {
  6. with_page: function(name, callback) {
  7. if(in_list(keys(wn.standard_pages), name)) {
  8. if(!wn.pages[name]) {
  9. wn.standard_pages[name]();
  10. }
  11. callback();
  12. return;
  13. }
  14. if((locals.Page && locals.Page[name]) || name==window.page_name) {
  15. // already loaded
  16. callback();
  17. } else if(localStorage["_page:" + name] && wn.boot.developer_mode!=1) {
  18. // cached in local storage
  19. wn.model.sync(JSON.parse(localStorage["_page:" + name]));
  20. callback();
  21. } else {
  22. // get fresh
  23. return wn.call({
  24. method: 'webnotes.widgets.page.getpage',
  25. args: {'name':name },
  26. callback: function(r) {
  27. localStorage["_page:" + name] = JSON.stringify(r.docs);
  28. callback();
  29. }
  30. });
  31. }
  32. },
  33. show: function(name) {
  34. if(!name) name = (wn.boot ? wn.boot.home_page : window.page_name);
  35. wn.model.with_doctype("Page", function() {
  36. wn.views.pageview.with_page(name, function(r) {
  37. if(r && r.exc) {
  38. if(!r['403'])
  39. wn.show_not_found(name);
  40. } else if(!wn.pages[name]) {
  41. new wn.views.Page(name);
  42. }
  43. wn.container.change_to(name);
  44. });
  45. });
  46. }
  47. }
  48. wn.views.Page = Class.extend({
  49. init: function(name, wrapper) {
  50. this.name = name;
  51. var me = this;
  52. // web home page
  53. if(name==window.page_name) {
  54. this.wrapper = document.getElementById('page-' + name);
  55. this.wrapper.label = document.title || window.page_name;
  56. this.wrapper.page_name = window.page_name;
  57. wn.pages[window.page_name] = this.wrapper;
  58. } else {
  59. this.pagedoc = locals.Page[this.name];
  60. if(!this.pagedoc) {
  61. wn.show_not_found(name);
  62. return;
  63. }
  64. this.wrapper = wn.container.add_page(this.name);
  65. this.wrapper.label = this.pagedoc.title || this.pagedoc.name;
  66. this.wrapper.page_name = this.pagedoc.name;
  67. // set content, script and style
  68. if(this.pagedoc.content)
  69. this.wrapper.innerHTML = this.pagedoc.content;
  70. wn.dom.eval(this.pagedoc.__script || this.pagedoc.script || '');
  71. wn.dom.set_style(this.pagedoc.style || '');
  72. }
  73. this.trigger('onload');
  74. // set events
  75. $(this.wrapper).bind('show', function() {
  76. cur_frm = null;
  77. me.trigger('onshow');
  78. me.trigger('refresh');
  79. });
  80. },
  81. trigger: function(eventname) {
  82. var me = this;
  83. if(pscript[eventname+'_'+this.name]) {
  84. pscript[eventname+'_'+this.name](me.wrapper);
  85. } else if(me.wrapper[eventname]) {
  86. me.wrapper[eventname](me.wrapper);
  87. }
  88. }
  89. })
  90. wn.show_not_found = function(page_name) {
  91. wn.show_message_page(page_name, '<i class="icon-exclamation-sign"></i> ' + wn._("Not Found"),
  92. wn._("Sorry we were unable to find what you were looking for."));
  93. }
  94. wn.show_not_permitted = function(page_name) {
  95. wn.show_message_page(page_name, '<i class="icon-exclamation-sign"></i> ' +wn._("Not Permitted"),
  96. wn._("Sorry you are not permitted to view this page."));
  97. }
  98. wn.show_message_page = function(page_name, title, message) {
  99. if(!page_name) page_name = wn.get_route_str();
  100. var page = wn.pages[page_name] || wn.container.add_page(page_name);
  101. $(page).html('<div class="appframe">\
  102. <div style="margin: 50px; text-align:center;">\
  103. <h3>'+title+'</h3><br>\
  104. <p>'+message+'</p><br>\
  105. <p><a href="#">Home <i class="icon-home"></i></a></p>\
  106. </div>\
  107. </div>');
  108. wn.container.change_to(page_name);
  109. }