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.0 KiB

13 years ago
13 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // page container
  2. wn.provide('wn.pages');
  3. wn.provide('wn.views');
  4. wn.views.Container = Class.extend({
  5. init: function() {
  6. this.container = $('#body_div').get(0);
  7. this.page = null; // current page
  8. this.pagewidth = $('#body_div').width();
  9. this.pagemargin = 50;
  10. },
  11. add_page: function(label, onshow, onhide) {
  12. var page = $('<div class="content"></div>')
  13. .attr('id', "page-" + label)
  14. .appendTo(this.container).get(0);
  15. if(onshow)
  16. $(page).bind('show', onshow);
  17. if(onshow)
  18. $(page).bind('hide', onhide);
  19. page.label = label;
  20. wn.pages[label] = page;
  21. return page;
  22. },
  23. change_to: function(label) {
  24. if(this.page && this.page.label == label) {
  25. // don't trigger double events
  26. //$(this.page).trigger('show');
  27. return;
  28. }
  29. var me = this;
  30. if(label.tagName) {
  31. // if sent the div, get the table
  32. var page = label;
  33. } else {
  34. var page = wn.pages[label];
  35. }
  36. if(!page) {
  37. console.log('Page not found ' + label);
  38. return;
  39. }
  40. // hide current
  41. if(this.page && this.page != page) {
  42. $(this.page).toggle(false);
  43. $(this.page).trigger('hide');
  44. }
  45. // show new
  46. if(!this.page || this.page != page) {
  47. this.page = page;
  48. $(this.page).fadeIn();
  49. }
  50. this.page._route = window.location.hash;
  51. document.title = this.page.label;
  52. $(this.page).trigger('show');
  53. scroll(0,0);
  54. return this.page;
  55. }
  56. });
  57. wn.views.add_module_btn = function(parent, module) {
  58. $(parent).append(
  59. repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
  60. onclick="wn.set_route(\'%(module_small)s-home\')">\
  61. <i class="icon-home icon-white"></i> %(module)s Home\
  62. </span>', {module: module, module_small: module.toLowerCase()}));
  63. }
  64. wn.views.add_list_btn = function(parent, doctype) {
  65. $(parent).append(
  66. repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
  67. onclick="wn.set_route(\'List\', \'%(doctype)s\')">\
  68. <i class="icon-list icon-white"></i> %(doctype)s List\
  69. </span>', {doctype: doctype}));
  70. }