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