blob: fc5f22bede805511df65749c61cbdd961f256799 [file] [log] [blame]
Anand Doshieaaf6512012-02-24 15:29:07 +05301wn.provide('erpnext.desktop');
2
Anand Doshieaaf6512012-02-24 15:29:07 +05303erpnext.desktop.refresh = function() {
Anand Doshieaaf6512012-02-24 15:29:07 +05304 erpnext.desktop.render();
Anand Doshieaaf6512012-02-24 15:29:07 +05305
Rushabh Mehta946e6d42012-12-21 15:00:29 +05306 $("#icon-grid").sortable({
7 update: function() {
8 new_order = [];
9 $("#icon-grid .case-wrapper").each(function(i, e) {
10 new_order.push($(this).attr("data-name"));
11 });
12 wn.user.set_default("_desktop_items", new_order);
13 }
Anand Doshieaaf6512012-02-24 15:29:07 +053014 });
15}
16
17erpnext.desktop.render = function() {
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053018 var add_icon = function(m) {
Rushabh Mehta946e6d42012-12-21 15:00:29 +053019 var module = wn.modules[m];
20 if(!module.label)
21 module.label = m;
22 module.name = m;
23 module.gradient_css = wn.get_gradient_css(module.color, 45);
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053024
Rushabh Mehta17da7642012-02-28 18:56:56 +053025 $('#icon-grid').append(repl('\
Rushabh Mehta946e6d42012-12-21 15:00:29 +053026 <div id="module-icon-%(link)s" class="case-wrapper" data-name="%(name)s"><a href="#%(link)s">\
27 <div class="case-border" style="%(gradient_css)s">\
28 <i class="%(icon)s"></i>\
Anand Doshieaaf6512012-02-24 15:29:07 +053029 </div></a>\
30 <div class="case-label">%(label)s</div>\
Rushabh Mehta946e6d42012-12-21 15:00:29 +053031 </div>', module));
Rushabh Mehta17da7642012-02-28 18:56:56 +053032 }
33
Rushabh Mehta946e6d42012-12-21 15:00:29 +053034 // modules
Rushabh Mehtaff153492012-12-22 07:42:04 +053035 var modules_list = wn.user.get_desktop_items();
Rushabh Mehta946e6d42012-12-21 15:00:29 +053036 $.each(modules_list, function(i, m) {
Rushabh Mehta86945fe2012-11-15 16:58:27 +053037 if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053038 add_icon(m);
Rushabh Mehta946e6d42012-12-21 15:00:29 +053039 })
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053040
Rushabh Mehta946e6d42012-12-21 15:00:29 +053041 // setup
Rushabh Mehta17da7642012-02-28 18:56:56 +053042 if(user_roles.indexOf('System Manager')!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053043 add_icon('Setup')
Rushabh Mehta17da7642012-02-28 18:56:56 +053044
Rushabh Mehta946e6d42012-12-21 15:00:29 +053045 // notifications
Anand Doshidb628762012-02-24 17:56:00 +053046 erpnext.desktop.show_pending_notifications();
47
48}
49
50erpnext.desktop.show_pending_notifications = function() {
Anand Doshi7854f812012-03-14 12:01:13 +053051 var add_circle = function(str_module, id, title) {
52 var module = $('#'+str_module);
53 module.find('a:first').append(
54 repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
55 <span class="circle-text"></span>\
56 </div>', {id: id, title: title}));
57
58 var case_border = module.find('.case-border');
59 var circle = module.find('.circle');
60
61 var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
62 primary
63 .hover(
64 function() { secondary.addClass(hover_class); },
65 function() { secondary.removeClass(hover_class); })
66 .mousedown(function() { secondary.addClass(click_class); })
67 .mouseup(function() { secondary.removeClass(click_class); })
68 .focusin(function() { $(this).mousedown(); })
69 .focusout(function() { $(this).mouseup(); })
70 }
71
72 add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
73 add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
74
75 }
76
Rushabh Mehta946e6d42012-12-21 15:00:29 +053077 add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
Rushabh Mehta5ade7ca2012-12-21 21:40:19 +053078 add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
Rushabh Mehta946e6d42012-12-21 15:00:29 +053079 add_circle('module-icon-todo', 'things_todo', 'Things To Do');
80 add_circle('module-icon-calendar', 'todays_events', 'Todays Events');
Rushabh Mehta7ac16fa2012-12-21 22:49:10 +053081 add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
Rushabh Mehta5ade7ca2012-12-21 21:40:19 +053082 add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
Anand Doshi7854f812012-03-14 12:01:13 +053083
Rushabh Mehta39489272012-05-03 10:44:44 +053084 erpnext.update_messages();
Anand Doshidb628762012-02-24 17:56:00 +053085
Anand Doshieaaf6512012-02-24 15:29:07 +053086}
87
88pscript.onload_desktop = function() {
89 // load desktop
90 erpnext.desktop.refresh();
91}
92