blob: f9a3b544a20b95b5209249c5429218d86aef1248 [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'},
Anand Doshi89e2dd82012-12-10 19:01:10 +053036 'Manufacturing': { sprite: 'manufacturing', label: 'Manufacturing'},
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053037 'Website': { sprite: 'website', label: 'Website'},
38 'Activity': { sprite: 'feed', label: 'Activity'},
39 'Setup': { sprite: 'setting', label: 'Setup'},
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053040 'To Do': { sprite: 'todo', label: 'To Do'},
41 'Messages': { sprite: 'messages', label: 'Messages'},
42 'Calendar': { sprite: 'calendar', label: 'Calendar'},
43 'Knowledge Base': { sprite: 'kb', label: 'Knowledge<br />Base'}
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053044 }
Anand Doshieaaf6512012-02-24 15:29:07 +053045
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053046 var add_icon = function(m) {
47 var icon = icons[m];
48 icon.link = erpnext.modules[m];
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053049 icon.gradient = wn.module_css_map[m];
50
Rushabh Mehta17da7642012-02-28 18:56:56 +053051 $('#icon-grid').append(repl('\
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053052 <div id="%(sprite)s" class="case-wrapper"><a href="#!%(link)s">\
Anand Doshieaaf6512012-02-24 15:29:07 +053053 <div class="case-border case-%(gradient)s">\
54 <div class="sprite-image sprite-%(sprite)s"></div>\
55 </div></a>\
56 <div class="case-label">%(label)s</div>\
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053057 </div>', icon));
Rushabh Mehta17da7642012-02-28 18:56:56 +053058 }
59
Rushabh Mehta17da7642012-02-28 18:56:56 +053060 // setup
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053061 for(var i in wn.boot.modules_list) {
62 var m = wn.boot.modules_list[i];
Rushabh Mehta86945fe2012-11-15 16:58:27 +053063 if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053064 add_icon(m);
65 }
66
Rushabh Mehta428929b2012-03-01 11:24:45 +053067
Rushabh Mehta17da7642012-02-28 18:56:56 +053068 if(user_roles.indexOf('System Manager')!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053069 add_icon('Setup')
Rushabh Mehta17da7642012-02-28 18:56:56 +053070
71 // apps
Anand Doshidb628762012-02-24 17:56:00 +053072 erpnext.desktop.show_pending_notifications();
73
74}
75
76erpnext.desktop.show_pending_notifications = function() {
Anand Doshi7854f812012-03-14 12:01:13 +053077 var add_circle = function(str_module, id, title) {
78 var module = $('#'+str_module);
79 module.find('a:first').append(
80 repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
81 <span class="circle-text"></span>\
82 </div>', {id: id, title: title}));
83
84 var case_border = module.find('.case-border');
85 var circle = module.find('.circle');
86
87 var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
88 primary
89 .hover(
90 function() { secondary.addClass(hover_class); },
91 function() { secondary.removeClass(hover_class); })
92 .mousedown(function() { secondary.addClass(click_class); })
93 .mouseup(function() { secondary.removeClass(click_class); })
94 .focusin(function() { $(this).mousedown(); })
95 .focusout(function() { $(this).mouseup(); })
96 }
97
98 add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
99 add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
100
101 }
102
103 add_circle('messages', 'unread_messages', 'Unread Messages');
104 add_circle('support', 'open_support_tickets', 'Open Support Tickets');
105 add_circle('todo', 'things_todo', 'Things To Do');
106 add_circle('calendar', 'todays_events', 'Todays Events');
Rushabh Mehta07c94ce2012-06-04 12:57:23 +0530107 add_circle('project', 'open_tasks', 'Open Tasks');
Rushabh Mehtac7dbe292012-08-07 12:12:55 +0530108 add_circle('kb', 'unanswered_questions', 'Unanswered Questions');
Anand Doshi7854f812012-03-14 12:01:13 +0530109
Rushabh Mehta39489272012-05-03 10:44:44 +0530110 erpnext.update_messages();
Anand Doshidb628762012-02-24 17:56:00 +0530111
Anand Doshieaaf6512012-02-24 15:29:07 +0530112}
113
114pscript.onload_desktop = function() {
115 // load desktop
116 erpnext.desktop.refresh();
117}
118