blob: c298b68218c82cb40da61c611c8c47c3c328489f [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 });
Rushabh Mehta2fe861f2013-02-19 15:54:15 +053012 wn.defaults.set_default("_desktop_items", new_order);
Rushabh Mehta946e6d42012-12-21 15:00:29 +053013 }
Anand Doshieaaf6512012-02-24 15:29:07 +053014 });
15}
16
17erpnext.desktop.render = function() {
Rushabh Mehta84adf1b2012-12-28 10:30:46 +053018 document.title = "Desktop";
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053019 var add_icon = function(m) {
Rushabh Mehta946e6d42012-12-21 15:00:29 +053020 var module = wn.modules[m];
21 if(!module.label)
22 module.label = m;
23 module.name = m;
Rushabh Mehta523aec42013-01-07 15:39:54 +053024 module.label = wn._(module.label);
Rushabh Mehta946e6d42012-12-21 15:00:29 +053025 module.gradient_css = wn.get_gradient_css(module.color, 45);
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053026
Rushabh Mehta6c8cef72013-01-24 16:30:50 +053027 $module_icon = $(repl('\
28 <div id="module-icon-%(link)s" class="case-wrapper" \
29 data-name="%(name)s" data-link="%(link)s">\
Rushabh Mehta946e6d42012-12-21 15:00:29 +053030 <div class="case-border" style="%(gradient_css)s">\
31 <i class="%(icon)s"></i>\
Rushabh Mehta6c8cef72013-01-24 16:30:50 +053032 </div>\
Anand Doshieaaf6512012-02-24 15:29:07 +053033 <div class="case-label">%(label)s</div>\
Rushabh Mehta6c8cef72013-01-24 16:30:50 +053034 </div>', module)).click(function() {
35 wn.set_route($(this).attr("data-link"));
36 }).css({
37 cursor:"pointer"
38 }).appendTo("#icon-grid");
Rushabh Mehta17da7642012-02-28 18:56:56 +053039 }
40
Rushabh Mehta946e6d42012-12-21 15:00:29 +053041 // modules
Rushabh Mehtaff153492012-12-22 07:42:04 +053042 var modules_list = wn.user.get_desktop_items();
Rushabh Mehta946e6d42012-12-21 15:00:29 +053043 $.each(modules_list, function(i, m) {
Rushabh Mehta86945fe2012-11-15 16:58:27 +053044 if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053045 add_icon(m);
Rushabh Mehta946e6d42012-12-21 15:00:29 +053046 })
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053047
Rushabh Mehta946e6d42012-12-21 15:00:29 +053048 // setup
Rushabh Mehta17da7642012-02-28 18:56:56 +053049 if(user_roles.indexOf('System Manager')!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053050 add_icon('Setup')
Rushabh Mehta17da7642012-02-28 18:56:56 +053051
Rushabh Mehta946e6d42012-12-21 15:00:29 +053052 // notifications
Anand Doshidb628762012-02-24 17:56:00 +053053 erpnext.desktop.show_pending_notifications();
54
55}
56
57erpnext.desktop.show_pending_notifications = function() {
Anand Doshi7854f812012-03-14 12:01:13 +053058 var add_circle = function(str_module, id, title) {
59 var module = $('#'+str_module);
Rushabh Mehta6c8cef72013-01-24 16:30:50 +053060 module.prepend(
Anand Doshi7854f812012-03-14 12:01:13 +053061 repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
62 <span class="circle-text"></span>\
Rushabh Mehta523aec42013-01-07 15:39:54 +053063 </div>', {id: id, title: wn._(title)}));
Anand Doshi7854f812012-03-14 12:01:13 +053064
65 var case_border = module.find('.case-border');
66 var circle = module.find('.circle');
67
68 var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
69 primary
70 .hover(
71 function() { secondary.addClass(hover_class); },
72 function() { secondary.removeClass(hover_class); })
73 .mousedown(function() { secondary.addClass(click_class); })
74 .mouseup(function() { secondary.removeClass(click_class); })
75 .focusin(function() { $(this).mousedown(); })
76 .focusout(function() { $(this).mouseup(); })
77 }
78
79 add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
80 add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
81
82 }
83
Rushabh Mehta946e6d42012-12-21 15:00:29 +053084 add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
Rushabh Mehta5ade7ca2012-12-21 21:40:19 +053085 add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
Rushabh Mehta946e6d42012-12-21 15:00:29 +053086 add_circle('module-icon-todo', 'things_todo', 'Things To Do');
87 add_circle('module-icon-calendar', 'todays_events', 'Todays Events');
Rushabh Mehta7ac16fa2012-12-21 22:49:10 +053088 add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
Rushabh Mehta5ade7ca2012-12-21 21:40:19 +053089 add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
Rushabh Mehta2e5db352013-01-16 11:34:26 +053090 add_circle('module-icon-selling-home', 'open_leads', 'Open Leads');
Anand Doshi7854f812012-03-14 12:01:13 +053091
Rushabh Mehta39489272012-05-03 10:44:44 +053092 erpnext.update_messages();
Anand Doshidb628762012-02-24 17:56:00 +053093
Anand Doshieaaf6512012-02-24 15:29:07 +053094}
95
96pscript.onload_desktop = function() {
97 // load desktop
98 erpnext.desktop.refresh();
99}
100