選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.js 3.9 KiB

13年前
14年前
13年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // App.js
  2. // dialog container
  3. var popup_cont;
  4. var session = {};
  5. if(!wn) var wn = {};
  6. function startup() {
  7. popup_cont = $a(document.getElementsByTagName('body')[0], 'div');
  8. // Globals
  9. // ---------------------------------
  10. var setup_globals = function(r) {
  11. wn.boot = r;
  12. profile = r.profile;
  13. user = r.profile.name;
  14. user_fullname = wn.user_info(user).fullname;
  15. user_defaults = profile.defaults;
  16. user_roles = profile.roles;
  17. user_email = profile.email;
  18. home_page = r.home_page;
  19. _p.letter_heads = r.letter_heads;
  20. sys_defaults = r.sysdefaults;
  21. // bc
  22. session.rt = profile.can_read;
  23. if(r.ipinfo) session.ipinfo = r.ipinfo;
  24. session.dt_labels = r.dt_labels;
  25. session.rev_dt_labels = {} // reverse lookup - get doctype by label
  26. if(r.dt_labels) {
  27. for(key in r.dt_labels)session.rev_dt_labels[r.dt_labels[key]] = key;
  28. }
  29. // control panel
  30. wn.control_panel = r.control_panel;
  31. }
  32. var setup_viewport = function() {
  33. wn.container = new wn.views.Container();
  34. // toolbar
  35. if(user=='Guest')
  36. user_defaults.hide_webnotes_toolbar = 1;
  37. if(!cint(user_defaults.hide_webnotes_toolbar) || user=='Administrator') {
  38. wn.container.wntoolbar = new wn.ui.toolbar.Toolbar();
  39. }
  40. // startup code
  41. $(document).trigger('startup');
  42. try{
  43. if(wn.control_panel.custom_startup_code)
  44. eval(wn.control_panel.custom_startup_code);
  45. } catch(e) {
  46. errprint(e);
  47. }
  48. // open an existing page or record
  49. var t = to_open();
  50. if(t) {
  51. window.location.hash = t;
  52. set_favicon();
  53. } else if(home_page) {
  54. loadpage(home_page);
  55. }
  56. wn.route();
  57. $dh('startup_div');
  58. $ds('body_div');
  59. }
  60. var callback = function(r,rt) {
  61. if(r.exc) console.log(r.exc);
  62. setup_globals(r);
  63. setup_viewport();
  64. }
  65. if(wn.boot) {
  66. LocalDB.sync(wn.boot.docs);
  67. callback(wn.boot, '');
  68. if(wn.boot.error_messages)
  69. console.log(wn.boot.error_messages)
  70. if(wn.boot.server_messages)
  71. msgprint(wn.boot.server_messages);
  72. } else {
  73. if($i('startup_div'))
  74. $c('startup',{},callback,null,1);
  75. }
  76. }
  77. function to_open() {
  78. if(get_url_arg('page'))
  79. return get_url_arg('page');
  80. var h = location.hash;
  81. if(h) {
  82. return h.substr(1);
  83. }
  84. }
  85. function logout() {
  86. $c('logout', args = {}, function(r,rt) {
  87. if(r.exc) {
  88. msgprint(r.exc);
  89. return;
  90. }
  91. redirect_to_login();
  92. });
  93. }
  94. function redirect_to_login() {
  95. if(login_file)
  96. window.location.href = login_file;
  97. else {
  98. window.location.reload();
  99. }
  100. }
  101. // default print style
  102. _p.def_print_style_body = "html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }" + "\npre { margin:0; padding:0;}"
  103. _p.def_print_style_other = "\n.simpletable, .noborder { border-collapse: collapse; margin-bottom: 10px;}"
  104. +"\n.simpletable td {border: 1pt solid #000; vertical-align: top; padding: 2px; }"
  105. +"\n.noborder td { vertical-align: top; }"
  106. _p.go = function(html) {
  107. var d = document.createElement('div')
  108. d.innerHTML = html
  109. $(d).printElement();
  110. }
  111. _p.preview = function(html) {
  112. var w = window.open('');
  113. w.document.write(html)
  114. w.document.close();
  115. }
  116. var resize_observers = []
  117. function set_resize_observer(fn) {
  118. if(resize_observers.indexOf(fn)==-1) resize_observers.push(fn);
  119. }
  120. window.onresize = function() {
  121. return;
  122. var ht = get_window_height();
  123. for(var i=0; i< resize_observers.length; i++){
  124. resize_observers[i](ht);
  125. }
  126. }
  127. get_window_height = function() {
  128. var ht = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight ? document.documentElement.offsetHeight : document.body.offsetHeight;
  129. return ht;
  130. }
  131. // favicon disappears when window.location.hash value is changed in firefox
  132. // This is used to mitigate this favicon bug in firefox
  133. function set_favicon() {
  134. var link = $('link[type="image/x-icon"]').remove().attr("href");
  135. var favicon ='\
  136. <link rel="shortcut icon" href="' + link + '" type="image/x-icon"> \
  137. <link rel="icon" href="' + link + '" type="image/x-icon">'
  138. $(favicon).appendTo('head');
  139. }