blob: b3537744e8439ba5283f7c6194f8278feef170ba [file] [log] [blame]
Anand Doshieaaf6512012-02-24 15:29:07 +05301wn.provide('erpnext.desktop');
2
3erpnext.desktop.gradient = "<style>\
4 .case-%(name)s {\
5 background: %(start)s; /* Old browsers */\
Anand Doshi0e140962012-03-01 12:16:02 +05306 background: -moz-radial-gradient(center, ellipse cover, %(start)s 0%, %(middle)s 44%, %(end)s 100%); /* FF3.6+ */\
7 background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,%(start)s), color-stop(44%,%(middle)s), color-stop(100%,%(end)s)); /* Chrome,Safari4+ */\
8 background: -webkit-radial-gradient(center, ellipse cover, %(start)s 0%,%(middle)s 44%,%(end)s 100%); /* Chrome10+,Safari5.1+ */\
9 background: -o-radial-gradient(center, ellipse cover, %(start)s 0%,%(middle)s 44%,%(end)s 100%); /* Opera 12+ */\
10 background: -ms-radial-gradient(center, ellipse cover, %(start)s 0%,%(middle)s 44%,%(end)s 100%); /* IE10+ */\
11 background: radial-gradient(center, ellipse cover, %(start)s 0%,%(middle)s 44%,%(end)s 100%); /* W3C */\
Anand Doshieaaf6512012-02-24 15:29:07 +053012 }\
13 </style>"
14
15erpnext.desktop.refresh = function() {
16 erpnext.desktop.add_classes();
17 erpnext.desktop.render();
18}
19
20erpnext.desktop.add_classes = function() {
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053021 $.each(wn.module_css_classes, function(i, v) {
22 v.name = i;
Anand Doshieaaf6512012-02-24 15:29:07 +053023 $(repl(erpnext.desktop.gradient, v)).appendTo('head');
24 });
25}
26
27erpnext.desktop.render = function() {
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053028 var icons = {
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053029 'Accounts': { sprite: 'account', label: 'Accounts'},
30 'Selling': { sprite: 'selling', label: 'Selling'},
31 'Stock': { sprite: 'stock', label: 'Stock'},
32 'Buying': { sprite: 'buying', label: 'Buying'},
33 'Support': { sprite: 'support', label: 'Support'},
34 'HR': { sprite: 'hr', label: 'Human<br />Resources'},
35 'Projects': { sprite: 'project', label: 'Projects'},
36 'Production': { sprite: 'production', label: 'Production'},
37 'Website': { sprite: 'website', label: 'Website'},
38 'Activity': { sprite: 'feed', label: 'Activity'},
39 'Setup': { sprite: 'setting', label: 'Setup'},
40 'Dashboard': { sprite: 'dashboard', label: 'Dashboard'},
41 'To Do': { sprite: 'todo', label: 'To Do'},
42 'Messages': { sprite: 'messages', label: 'Messages'},
43 'Calendar': { sprite: 'calendar', label: 'Calendar'},
44 'Knowledge Base': { sprite: 'kb', label: 'Knowledge<br />Base'}
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053045 }
Anand Doshieaaf6512012-02-24 15:29:07 +053046
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053047 var add_icon = function(m) {
48 var icon = icons[m];
49 icon.link = erpnext.modules[m];
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053050 icon.gradient = wn.module_css_map[m];
51
Rushabh Mehta17da7642012-02-28 18:56:56 +053052 $('#icon-grid').append(repl('\
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053053 <div id="%(sprite)s" class="case-wrapper"><a href="#!%(link)s">\
Anand Doshieaaf6512012-02-24 15:29:07 +053054 <div class="case-border case-%(gradient)s">\
55 <div class="sprite-image sprite-%(sprite)s"></div>\
56 </div></a>\
57 <div class="case-label">%(label)s</div>\
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053058 </div>', icon));
Rushabh Mehta17da7642012-02-28 18:56:56 +053059 }
60
Rushabh Mehta17da7642012-02-28 18:56:56 +053061 // setup
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053062 for(var i in wn.boot.modules_list) {
63 var m = wn.boot.modules_list[i];
Anand Doshi2d4139c2012-03-23 14:46:07 +053064 if(!in_list(['Setup', 'Dashboard'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053065 add_icon(m);
66 }
67
Rushabh Mehta428929b2012-03-01 11:24:45 +053068 if(user_roles.indexOf('Accounts Manager')!=-1)
69 add_icon('Dashboard')
70
Rushabh Mehta17da7642012-02-28 18:56:56 +053071 if(user_roles.indexOf('System Manager')!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053072 add_icon('Setup')
Rushabh Mehta17da7642012-02-28 18:56:56 +053073
74 // apps
Anand Doshidb628762012-02-24 17:56:00 +053075 erpnext.desktop.show_pending_notifications();
76
77}
78
79erpnext.desktop.show_pending_notifications = function() {
Anand Doshi7854f812012-03-14 12:01:13 +053080 var add_circle = function(str_module, id, title) {
81 var module = $('#'+str_module);
82 module.find('a:first').append(
83 repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
84 <span class="circle-text"></span>\
85 </div>', {id: id, title: title}));
86
87 var case_border = module.find('.case-border');
88 var circle = module.find('.circle');
89
90 var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
91 primary
92 .hover(
93 function() { secondary.addClass(hover_class); },
94 function() { secondary.removeClass(hover_class); })
95 .mousedown(function() { secondary.addClass(click_class); })
96 .mouseup(function() { secondary.removeClass(click_class); })
97 .focusin(function() { $(this).mousedown(); })
98 .focusout(function() { $(this).mouseup(); })
99 }
100
101 add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
102 add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
103
104 }
105
106 add_circle('messages', 'unread_messages', 'Unread Messages');
107 add_circle('support', 'open_support_tickets', 'Open Support Tickets');
108 add_circle('todo', 'things_todo', 'Things To Do');
109 add_circle('calendar', 'todays_events', 'Todays Events');
Rushabh Mehta07c94ce2012-06-04 12:57:23 +0530110 add_circle('project', 'open_tasks', 'Open Tasks');
Rushabh Mehtac7dbe292012-08-07 12:12:55 +0530111 add_circle('kb', 'unanswered_questions', 'Unanswered Questions');
Anand Doshi7854f812012-03-14 12:01:13 +0530112
Rushabh Mehta39489272012-05-03 10:44:44 +0530113 erpnext.update_messages();
Anand Doshidb628762012-02-24 17:56:00 +0530114
Anand Doshieaaf6512012-02-24 15:29:07 +0530115}
116
117pscript.onload_desktop = function() {
118 // load desktop
119 erpnext.desktop.refresh();
120}
121