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.
 
 
 
 
 
 

94 lines
2.3 KiB

  1. // misc user functions
  2. wn.user_info = function(uid) {
  3. var def = {
  4. 'fullname':uid,
  5. 'image': 'lib/images/ui/avatar.png'
  6. }
  7. if(!wn.boot.user_info) return def
  8. if(!wn.boot.user_info[uid]) return def
  9. if(!wn.boot.user_info[uid].fullname)
  10. wn.boot.user_info[uid].fullname = uid;
  11. if(!wn.boot.user_info[uid].image)
  12. wn.boot.user_info[uid].image = def.image;
  13. return wn.boot.user_info[uid];
  14. }
  15. wn.avatar = function(user, large, title) {
  16. var image = wn.utils.get_file_link(wn.user_info(user).image);
  17. var to_size = large ? 72 : 30;
  18. if(!title) title = wn.user_info(user).fullname;
  19. return repl('<span class="avatar" title="%(title)s" style="width: %(len)s; \
  20. height: %(len)s; border-radius: %(len)s; overflow: hidden;">\
  21. <img src="%(image)s"></span>', {
  22. image: image,
  23. len: to_size + "px",
  24. title: title
  25. });
  26. }
  27. wn.provide('wn.user');
  28. $.extend(wn.user, {
  29. name: (wn.boot ? wn.boot.profile.name : 'Guest'),
  30. has_role: function(rl) {
  31. if(typeof rl=='string')
  32. rl = [rl];
  33. for(var i in rl) {
  34. if((wn.boot ? wn.boot.profile.roles : ['Guest']).indexOf(rl[i])!=-1)
  35. return true;
  36. }
  37. },
  38. set_default: function(key, value, callback) {
  39. if(typeof value=="string")
  40. value = JSON.stringify(value);
  41. wn.boot.profile.defaults[key] = value;
  42. wn.call({
  43. method: "webnotes.client.set_default",
  44. args: {
  45. key: key,
  46. value: value
  47. },
  48. callback: callback || function(r) {}
  49. });
  50. },
  51. get_default: function(key) {
  52. var value = wn.boot.profile.defaults[key];
  53. if(value) {
  54. try {
  55. return JSON.parse(value)
  56. } catch(e) {
  57. return value;
  58. }
  59. }
  60. },
  61. get_desktop_items: function() {
  62. var user_list = wn.user.get_default("_desktop_items");
  63. if(user_list && user_list.length)
  64. var modules_list = user_list;
  65. else
  66. try {
  67. var modules_list = JSON.parse(wn.boot.modules_list);
  68. } catch(e) {
  69. }
  70. if(!modules_list) modules_list = keys(wn.modules);
  71. return modules_list;
  72. },
  73. is_report_manager: function() {
  74. return wn.user.has_role(['Administrator', 'System Manager', 'Report Manager']);
  75. }
  76. })
  77. // wn.session_alive is true if user shows mouse movement in 30 seconds
  78. wn.session_alive = true;
  79. $(document).bind('mousemove', function() {
  80. wn.session_alive = true;
  81. if(wn.session_alive_timeout)
  82. clearTimeout(wn.session_alive_timeout);
  83. wn.session_alive_timeout = setTimeout('wn.session_alive=false;', 30000);
  84. })