Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 1 | wn.provide('erpnext.desktop'); |
| 2 | |
Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 3 | erpnext.desktop.refresh = function() { |
Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 4 | erpnext.desktop.render(); |
Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 5 | |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 6 | $("#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 Mehta | 2fe861f | 2013-02-19 15:54:15 +0530 | [diff] [blame] | 12 | wn.defaults.set_default("_desktop_items", new_order); |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 13 | } |
Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 14 | }); |
| 15 | } |
| 16 | |
| 17 | erpnext.desktop.render = function() { |
Rushabh Mehta | 84adf1b | 2012-12-28 10:30:46 +0530 | [diff] [blame] | 18 | document.title = "Desktop"; |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 19 | var add_icon = function(m) { |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 20 | var module = wn.modules[m]; |
| 21 | if(!module.label) |
| 22 | module.label = m; |
| 23 | module.name = m; |
Rushabh Mehta | 523aec4 | 2013-01-07 15:39:54 +0530 | [diff] [blame] | 24 | module.label = wn._(module.label); |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 25 | module.gradient_css = wn.get_gradient_css(module.color, 45); |
Anand Doshi | a6acdda | 2013-03-01 14:41:32 +0530 | [diff] [blame] | 26 | module._link = module.link.toLowerCase().replace("/", "-"); |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 27 | |
Rushabh Mehta | 6c8cef7 | 2013-01-24 16:30:50 +0530 | [diff] [blame] | 28 | $module_icon = $(repl('\ |
Anand Doshi | a6acdda | 2013-03-01 14:41:32 +0530 | [diff] [blame] | 29 | <div id="module-icon-%(_link)s" class="case-wrapper" \ |
Rushabh Mehta | 6c8cef7 | 2013-01-24 16:30:50 +0530 | [diff] [blame] | 30 | data-name="%(name)s" data-link="%(link)s">\ |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 31 | <div class="case-border" style="%(gradient_css)s">\ |
| 32 | <i class="%(icon)s"></i>\ |
Rushabh Mehta | 6c8cef7 | 2013-01-24 16:30:50 +0530 | [diff] [blame] | 33 | </div>\ |
Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 34 | <div class="case-label">%(label)s</div>\ |
Rushabh Mehta | 6c8cef7 | 2013-01-24 16:30:50 +0530 | [diff] [blame] | 35 | </div>', module)).click(function() { |
| 36 | wn.set_route($(this).attr("data-link")); |
| 37 | }).css({ |
| 38 | cursor:"pointer" |
| 39 | }).appendTo("#icon-grid"); |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 40 | } |
| 41 | |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 42 | // modules |
Rushabh Mehta | ff15349 | 2012-12-22 07:42:04 +0530 | [diff] [blame] | 43 | var modules_list = wn.user.get_desktop_items(); |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 44 | $.each(modules_list, function(i, m) { |
Rushabh Mehta | 86945fe | 2012-11-15 16:58:27 +0530 | [diff] [blame] | 45 | if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1) |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 46 | add_icon(m); |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 47 | }) |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 48 | |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 49 | // setup |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 50 | if(user_roles.indexOf('System Manager')!=-1) |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 51 | add_icon('Setup') |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 52 | |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 53 | // notifications |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 54 | erpnext.desktop.show_pending_notifications(); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | erpnext.desktop.show_pending_notifications = function() { |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 59 | var add_circle = function(str_module, id, title) { |
| 60 | var module = $('#'+str_module); |
Rushabh Mehta | 6c8cef7 | 2013-01-24 16:30:50 +0530 | [diff] [blame] | 61 | module.prepend( |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 62 | repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\ |
| 63 | <span class="circle-text"></span>\ |
Rushabh Mehta | 523aec4 | 2013-01-07 15:39:54 +0530 | [diff] [blame] | 64 | </div>', {id: id, title: wn._(title)})); |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 65 | |
| 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 Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 85 | add_circle('module-icon-messages', 'unread_messages', 'Unread Messages'); |
Rushabh Mehta | 5ade7ca | 2012-12-21 21:40:19 +0530 | [diff] [blame] | 86 | add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets'); |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 87 | add_circle('module-icon-todo', 'things_todo', 'Things To Do'); |
Anand Doshi | a6acdda | 2013-03-01 14:41:32 +0530 | [diff] [blame] | 88 | add_circle('module-icon-calendar-event', 'todays_events', 'Todays Events'); |
Rushabh Mehta | 7ac16fa | 2012-12-21 22:49:10 +0530 | [diff] [blame] | 89 | add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks'); |
Rushabh Mehta | 5ade7ca | 2012-12-21 21:40:19 +0530 | [diff] [blame] | 90 | add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions'); |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 91 | add_circle('module-icon-selling-home', 'open_leads', 'Open Leads'); |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 92 | |
Rushabh Mehta | 3948927 | 2012-05-03 10:44:44 +0530 | [diff] [blame] | 93 | erpnext.update_messages(); |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 94 | |
Anand Doshi | eaaf651 | 2012-02-24 15:29:07 +0530 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | pscript.onload_desktop = function() { |
| 98 | // load desktop |
| 99 | erpnext.desktop.refresh(); |
| 100 | } |
| 101 | |