Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

wntoolbar.js 9.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // requires
  2. // menu.js
  3. // search.js
  4. // datatype.js
  5. // dom.js
  6. var about_dialog;
  7. function WNToolbar(parent) {
  8. var me = this;
  9. this.setup = function() {
  10. this.wrapper = $a(parent, 'div', '', {color:'#FFF', padding:'2px 0px' });
  11. set_gradient(this.wrapper, '#444', '#000');
  12. this.table_wrapper = $a(this.wrapper, 'div', '', {marginLeft:'4px', padding:'2px'});
  13. this.body_tab = make_table(this.table_wrapper, 1, 3, '100%', ['0%','64%','36%'],{verticalAlign:'middle'});
  14. this.menu = new MenuToolbar($td(this.body_tab,0,1));
  15. this.setup_home();
  16. this.setup_new();
  17. this.setup_search();
  18. this.setup_recent();
  19. if(in_list(user_roles, 'Administrator'))
  20. this.setup_options();
  21. this.setup_help();
  22. this.setup_report_builder();
  23. this.setup_logout();
  24. }
  25. // Options
  26. // ----------------------------------------------------------------------------------------
  27. this.setup_options = function() {
  28. var tm = this.menu.add_top_menu('Pages', function() { }, "sprite-pages");
  29. var fn = function() {
  30. if(this.dt=='Page')
  31. loadpage(this.dn);
  32. else
  33. loaddoc(this.dt, this.dn);
  34. mclose();
  35. }
  36. // add start items
  37. profile.start_items.sort(function(a,b){return (a[4]-b[4])});
  38. for(var i=0;i< profile.start_items.length;i++) {
  39. var d = profile.start_items[i];
  40. var mi = this.menu.add_item('Pages',d[1], fn);
  41. mi.dt = d[0]; mi.dn = d[5]?d[5]:d[1];
  42. }
  43. }
  44. // Home
  45. // ----------------------------------------------------------------------------------------
  46. this.setup_home = function() {
  47. me.menu.add_top_menu('Home', function() { loadpage(home_page); }, "sprite-home");
  48. }
  49. // Recent
  50. // ----------------------------------------------------------------------------------------
  51. this.setup_recent = function() {
  52. this.rdocs = me.menu.add_top_menu('Recent', function() { }, "sprite-recent");
  53. this.rdocs.items = {};
  54. var fn = function() { // recent is only for forms
  55. loaddoc(this.dt, this.dn);
  56. mclose();
  57. }
  58. // add to recent
  59. this.rdocs.add = function(dt, dn, on_top) {
  60. var has_parent = false;
  61. if(locals[dt] && locals[dt][dn] && locals[dt][dn].parent) has_parent = true;
  62. if(!in_list(['Start Page','ToDo Item','Event','Search Criteria'], dt) && !has_parent) {
  63. // if there in list, only bring it to top
  64. if(this.items[dt+'-'+dn]) {
  65. var mi = this.items[dt+'-'+dn];
  66. mi.bring_to_top();
  67. return;
  68. }
  69. var tdn = dn;
  70. var rec_label = '<table style="width: 100%" cellspacing=0><tr>'
  71. +'<td style="width: 10%; vertical-align: middle;"><div class="status_flag" id="rec_'+dt+'-'+dn+'"></div></td>'
  72. +'<td style="width: 50%; text-decoration: underline; color: #22B; padding: 2px;">'+tdn+'</td>'
  73. +'<td style="font-size: 11px;">'+get_doctype_label(dt)+'</td></tr></table>';
  74. var mi = me.menu.add_item('Recent',rec_label,fn, on_top);
  75. mi.dt = dt; mi.dn = dn;
  76. this.items[dt+'-'+dn] = mi;
  77. if(pscript.on_recent_update)pscript.on_recent_update();
  78. }
  79. }
  80. // remove from recent
  81. this.rdocs.remove = function(dt, dn) {
  82. var it = me.rdocs.items[dt+'-'+dn];
  83. if(it)$dh(it);
  84. if(pscript.on_recent_update)pscript.on_recent_update();
  85. }
  86. this.rename_notify = function(dt, old, name) {
  87. me.rdocs.remove(dt, old);
  88. me.rdocs.add(dt, name, 1);
  89. }
  90. rename_observers.push(this);
  91. // add menu items
  92. try{ var rlist = JSON.parse(profile.recent); }
  93. catch(e) { return; /*old style-do nothing*/ }
  94. var m = rlist.length;
  95. if(m>15)m=15;
  96. for (var i=0;i<m;i++) {
  97. var rd = rlist[i]
  98. if(rd[1]) {
  99. var dt = rd[0]; var dn = rd[1];
  100. this.rdocs.add(dt, dn, 0);
  101. }
  102. }
  103. }
  104. // Tools
  105. // ----------------------------------------------------------------------------------------
  106. this.setup_help = function() {
  107. me.menu.add_top_menu('Tools', function() { }, "sprite-tools");
  108. this.menu.add_item('Tools','Error Console', function() { err_console.show(); });
  109. this.menu.add_item('Tools','Clear Cache', function() { $c('webnotes.session_cache.clear',{},function(r,rt){ show_alert(r.message); }) });
  110. if(has_common(user_roles,['Administrator','System Manager'])) {
  111. this.menu.add_item('Tools','Download Backup', function() { me.download_backup(); });
  112. }
  113. this.menu.add_item('Tools','Web Notes Framework', function() { show_about(); });
  114. }
  115. // New
  116. // ----------------------------------------------------------------------------------------
  117. this.setup_new = function() {
  118. me.menu.add_top_menu('New', function() { me.show_new(); }, 'sprite-new' );
  119. me.show_new = function() {
  120. if(!me.new_dialog) {
  121. var d = new Dialog(240, 140, "Create a new record");
  122. d.make_body(
  123. [['HTML','Select']
  124. ,['Button','Go', function() { me.new_dialog.hide(); new_doc(me.new_sel.inp.value); }]]);
  125. d.onshow = function(){
  126. me.new_sel.inp.focus();
  127. }
  128. me.new_dialog = d;
  129. // replace by labels
  130. var nl = profile.can_create.join(',').split(',');
  131. for(var i=0;i<nl.length;i++) nl[i]=get_doctype_label(nl[i]);
  132. // labels
  133. me.new_sel = new SelectWidget(d.widgets['Select'], nl.sort(), '200px');
  134. me.new_sel.onchange = function() { me.new_dialog.hide(); new_doc(me.new_sel.inp.value); }
  135. }
  136. me.new_dialog.show();
  137. }
  138. //this.new_sel.inp.onchange = function() { new_doc(me.new_sel.inp.value); this.value = 'Create New...'; }
  139. }
  140. // Report Builder
  141. // ----------------------------------------------------------------------------------------
  142. this.setup_report_builder = function() {
  143. me.menu.add_top_menu('Report', function() { me.show_rb(); }, 'sprite-report' );
  144. me.show_rb = function() {
  145. if(!me.rb_dialog) {
  146. var d = new Dialog(240, 140, "Build a report for");
  147. d.make_body(
  148. [['HTML','Select']
  149. ,['Button','Go', function() { me.rb_dialog.hide(); loadreport(me.rb_sel.inp.value, null, null, null, 1); }]]);
  150. d.onshow = function(){
  151. me.rb_sel.inp.focus();
  152. }
  153. me.rb_dialog = d;
  154. // replace by labels
  155. var nl = profile.can_get_report.join(',').split(',');
  156. for(var i=0;i<nl.length;i++) nl[i]=get_doctype_label(nl[i]);
  157. me.rb_sel = new SelectWidget(d.widgets['Select'], nl.sort(), '200px');
  158. me.rb_sel.onchange = function() { me.rb_dialog.hide(); loadreport(me.rb_sel.inp.value, null, null, null, 1); };
  159. }
  160. me.rb_dialog.show();
  161. }
  162. }
  163. // Setup Search
  164. // ----------------------------------------------------------------------------------------
  165. this.setup_search = function() {
  166. me.menu.add_top_menu('Search', function() { me.search_dialog.show(); }, 'sprite-search' );
  167. // make the dialog
  168. // ----------------
  169. var d = new Dialog(240, 140, "Quick Search");
  170. d.make_body(
  171. [['HTML','Select']
  172. ,['Button','Go', function() { me.open_quick_search(); }]]);
  173. d.onshow = function(){
  174. me.search_sel.inp.focus();
  175. }
  176. me.search_dialog = d;
  177. // enter key
  178. keypress_observers.push({notify_keypress: function(ev, keycode) {
  179. if(keycode==13 && me.search_dialog.display) me.open_quick_search();
  180. }});
  181. // select
  182. me.search_sel = new SelectWidget(d.widgets['Select'], [], '120px');
  183. me.search_sel.inp.value = 'Select...';
  184. me.open_quick_search = function() {
  185. me.search_dialog.hide();
  186. var v = sel_val(me.search_sel);
  187. if(v) selector.set_search(v);
  188. me.search_sel.disabled = 1;
  189. selector.show();
  190. }
  191. // replace by labels
  192. var nl = profile.can_read.join(',').split(',');
  193. for(var i=0;i<nl.length;i++) nl[i]=get_doctype_label(nl[i]);
  194. me.search_sel.set_options(nl.sort());
  195. me.search_sel.onchange = function() { me.open_quick_search(); }
  196. // make the selector dialog
  197. makeselector();
  198. }
  199. // Setup User / Logout area
  200. // ----------------------------------------------------------------------------------------
  201. this.setup_logout = function() {
  202. var w = $a($td(this.body_tab, 0, 2),'div','',{paddingTop:'2px', textAlign:'right'});
  203. this.right_table_style = {fontSize:'11px',verticalAlign:'middle',height:'20px',paddingLeft:'4px',paddingRight:'4px'};
  204. var t = make_table(w, 1, 6, null, [], this.right_table_style);
  205. $y(t,{cssFloat:'right', color:'#FFF'});
  206. $td(t,0,0).innerHTML = user_fullname;
  207. $td(t,0,1).innerHTML = '<span style="cursor: pointer;font-weight: bold" onclick="get_help()">Help</span>';
  208. $td(t,0,2).innerHTML = '<span style="cursor: pointer;font-weight: bold" onclick="get_feedback()">Feedback</span>';
  209. $td(t,0,3).innerHTML = '<span style="cursor: pointer;" onclick="loaddoc(\'Profile\', user)">Profile</span>';
  210. $td(t,0,4).innerHTML = '<span style="cursor: pointer;" onclick="logout()">Logout</span>';
  211. this.menu_table_right = t;
  212. $y($td(t,0,5), {width:'18px'});
  213. this.spinner = $a($td(t,0,5),'img','',{display:'none'}); this.spinner.src = 'images/ui/spinner.gif';
  214. }
  215. this.download_backup = function() {
  216. $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  217. }
  218. this.setup();
  219. }
  220. var get_help = function() {
  221. msgprint('Help not implemented');
  222. }
  223. var get_feedback = function() {
  224. // dialog
  225. var d = new Dialog(640, 320, "Please give your feedback");
  226. d.make_body(
  227. [['Text','Feedback']
  228. ,['Button','Send', function() {
  229. $c_obj('Feedback Control', 'get_feedback', d.widgets['Feedback'].value, function(r,rt) {
  230. d.hide(); if(r.message) msgprint(r.message);
  231. })
  232. } ]]
  233. );
  234. d.show();
  235. // send to Feedback Control
  236. }