blob: 70bd656c0179180c5b093c516bab858babcb1c08 [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 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;
24 module.gradient_css = wn.get_gradient_css(module.color, 45);
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053025
Rushabh Mehta17da7642012-02-28 18:56:56 +053026 $('#icon-grid').append(repl('\
Rushabh Mehta946e6d42012-12-21 15:00:29 +053027 <div id="module-icon-%(link)s" class="case-wrapper" data-name="%(name)s"><a href="#%(link)s">\
28 <div class="case-border" style="%(gradient_css)s">\
29 <i class="%(icon)s"></i>\
Anand Doshieaaf6512012-02-24 15:29:07 +053030 </div></a>\
31 <div class="case-label">%(label)s</div>\
Rushabh Mehta946e6d42012-12-21 15:00:29 +053032 </div>', module));
Rushabh Mehta17da7642012-02-28 18:56:56 +053033 }
34
Rushabh Mehta946e6d42012-12-21 15:00:29 +053035 // modules
Rushabh Mehtaff153492012-12-22 07:42:04 +053036 var modules_list = wn.user.get_desktop_items();
Rushabh Mehta946e6d42012-12-21 15:00:29 +053037 $.each(modules_list, function(i, m) {
Rushabh Mehta86945fe2012-11-15 16:58:27 +053038 if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053039 add_icon(m);
Rushabh Mehta946e6d42012-12-21 15:00:29 +053040 })
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053041
Rushabh Mehta946e6d42012-12-21 15:00:29 +053042 // setup
Rushabh Mehta17da7642012-02-28 18:56:56 +053043 if(user_roles.indexOf('System Manager')!=-1)
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053044 add_icon('Setup')
Rushabh Mehta17da7642012-02-28 18:56:56 +053045
Rushabh Mehta946e6d42012-12-21 15:00:29 +053046 // notifications
Anand Doshidb628762012-02-24 17:56:00 +053047 erpnext.desktop.show_pending_notifications();
48
49}
50
51erpnext.desktop.show_pending_notifications = function() {
Anand Doshi7854f812012-03-14 12:01:13 +053052 var add_circle = function(str_module, id, title) {
53 var module = $('#'+str_module);
54 module.find('a:first').append(
55 repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
56 <span class="circle-text"></span>\
57 </div>', {id: id, title: title}));
58
59 var case_border = module.find('.case-border');
60 var circle = module.find('.circle');
61
62 var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
63 primary
64 .hover(
65 function() { secondary.addClass(hover_class); },
66 function() { secondary.removeClass(hover_class); })
67 .mousedown(function() { secondary.addClass(click_class); })
68 .mouseup(function() { secondary.removeClass(click_class); })
69 .focusin(function() { $(this).mousedown(); })
70 .focusout(function() { $(this).mouseup(); })
71 }
72
73 add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
74 add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
75
76 }
77
Rushabh Mehta946e6d42012-12-21 15:00:29 +053078 add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
Rushabh Mehta5ade7ca2012-12-21 21:40:19 +053079 add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
Rushabh Mehta946e6d42012-12-21 15:00:29 +053080 add_circle('module-icon-todo', 'things_todo', 'Things To Do');
81 add_circle('module-icon-calendar', 'todays_events', 'Todays Events');
Rushabh Mehta7ac16fa2012-12-21 22:49:10 +053082 add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
Rushabh Mehta5ade7ca2012-12-21 21:40:19 +053083 add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
Anand Doshi7854f812012-03-14 12:01:13 +053084
Rushabh Mehta39489272012-05-03 10:44:44 +053085 erpnext.update_messages();
Anand Doshidb628762012-02-24 17:56:00 +053086
Anand Doshieaaf6512012-02-24 15:29:07 +053087}
88
89pscript.onload_desktop = function() {
90 // load desktop
91 erpnext.desktop.refresh();
92}
93