Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | // ERPNext - web based ERP (http://erpnext.com) |
| 2 | // Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 17 | erpnext.modules = { |
| 18 | 'Selling': 'selling-home', |
| 19 | 'Accounts': 'accounts-home', |
| 20 | 'Stock': 'stock-home', |
| 21 | 'Buying': 'buying-home', |
| 22 | 'Support': 'support-home', |
| 23 | 'Projects': 'projects-home', |
| 24 | 'Production': 'production-home', |
| 25 | 'Website': 'website-home', |
| 26 | 'HR': 'hr-home', |
| 27 | 'Setup': 'Setup', |
| 28 | 'Activity': 'activity', |
| 29 | 'To Do': 'todo', |
Rushabh Mehta | 059c184 | 2012-11-15 13:26:00 +0530 | [diff] [blame] | 30 | 'Core': 'setup', |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 31 | 'Calendar': 'calendar', |
| 32 | 'Messages': 'messages', |
| 33 | 'Knowledge Base': 'questions', |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 34 | } |
| 35 | |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 36 | wn.provide('wn.modules'); |
| 37 | $.extend(wn.modules, erpnext.modules); |
| 38 | wn.modules['Core'] = 'Setup'; |
| 39 | |
| 40 | wn.module_css_classes = { |
| 41 | 'red': { start: '#A90329', middle: '#8F0222', end: '#6D0019' }, |
| 42 | 'brown': { start: '#723e02', middle: '#633501', end: '#4a2700' }, |
| 43 | 'green': { start: '#4b5602', middle: '#3f4901', end: '#313800' }, |
| 44 | 'blue': { start: '#026584', middle: '#025770', end: '#004256' }, |
| 45 | 'yellow': { start: '#be7902', middle: '#a66a02', end: '#865500' }, |
| 46 | 'purple': { start: '#4d017d', middle: '#410169', end: '#310050' }, |
| 47 | 'ocean': { start: '#02a47e', middle: '#018d6c', end: '#006a51' }, |
| 48 | 'pink': { start: '#a40281', middle: '#8d016e', end: '#6a0053' }, |
| 49 | 'grey': { start: '#545454', middle: '#484848', end: '#363636' }, |
| 50 | 'dark-red': { start: '#68021a', middle: '#590116', end: '#440010' }, |
| 51 | 'leaf-green': { start: '#b0a400', middle: '#968c00', end: '#726a00' }, |
| 52 | //'dark-blue': { start: '#023bae', middle: '#013295', end: '#002672' }, |
| 53 | 'bright-green': { start: '#03ad1f', middle: '#02941a', end: '#007213' }, |
| 54 | 'bright-yellow': { start: '#ffd65e', middle: '#febf04', end: '#ed9017' }, |
| 55 | 'peacock': { start: '#026584', middle: '#026584', end: '#322476' }, |
| 56 | 'violet': { start: '#50448e', middle: '#473b7f', end: '#3a3169' }, |
| 57 | 'ultra-dark-green': { start: '#014333', middle: '#01372b', end: '#002a20' }, |
| 58 | } |
| 59 | |
| 60 | wn.module_css_map = { |
| 61 | 'Accounts': 'blue', |
| 62 | 'Selling': 'green', |
| 63 | 'Stock': 'yellow', |
| 64 | 'Buying': 'red', |
| 65 | 'Support': 'purple', |
| 66 | 'HR': 'ocean', |
| 67 | 'Projects': 'violet', |
| 68 | 'Production': 'dark-red', |
| 69 | 'Website': 'leaf-green', |
| 70 | 'Activity': 'brown', |
| 71 | 'Setup': 'grey', |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 72 | 'To Do': 'bright-yellow', |
| 73 | 'Messages': 'pink', |
| 74 | 'Calendar': 'peacock', |
| 75 | 'Knowledge Base': 'ultra-dark-green' |
| 76 | } |
| 77 | |
Rushabh Mehta | 3684155 | 2012-11-13 16:44:27 +0530 | [diff] [blame] | 78 | wn.get_module_color = function(module) { |
| 79 | try { |
| 80 | var color = wn.module_css_classes[wn.module_css_map[module]].middle; |
| 81 | } catch(e) { |
| 82 | var color = "#000"; |
| 83 | } |
| 84 | return color; |
| 85 | } |
| 86 | |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 87 | |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 88 | wn.provide('erpnext.module_page'); |
| 89 | |
| 90 | erpnext.module_page.setup_page = function(module, wrapper) { |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 91 | wrapper.appframe.set_marker(module); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 92 | erpnext.module_page.hide_links(wrapper); |
| 93 | erpnext.module_page.make_list(module, wrapper); |
Rushabh Mehta | 35fabf7 | 2012-02-21 19:03:50 +0530 | [diff] [blame] | 94 | $(wrapper).find("a[title]").tooltip({ |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 95 | delay: { show: 500, hide: 100 } |
| 96 | }); |
| 97 | } |
| 98 | |
| 99 | // hide list links where the user does |
| 100 | // not have read permissions |
| 101 | |
| 102 | erpnext.module_page.hide_links = function(wrapper) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 103 | function replace_link(link) { |
| 104 | var txt = $(link).text(); |
| 105 | $(link).parent().css('color', '#999'); |
| 106 | $(link).replaceWith('<span title="No read permission">' |
| 107 | +txt+'</span>'); |
| 108 | } |
| 109 | |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 110 | // lists |
| 111 | $(wrapper).find('[href*="List/"]').each(function() { |
| 112 | var href = $(this).attr('href'); |
| 113 | var dt = href.split('/')[1]; |
Rushabh Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 114 | if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 115 | replace_link(this); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 116 | } |
| 117 | }); |
| 118 | |
| 119 | // reports |
| 120 | $(wrapper).find('[data-doctype]').each(function() { |
| 121 | var dt = $(this).attr('data-doctype'); |
Rushabh Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 122 | if(wn.boot.profile.all_read.indexOf(dt)==-1) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 123 | replace_link(this); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 124 | } |
| 125 | }); |
| 126 | |
| 127 | // single (forms) |
| 128 | $(wrapper).find('[href*="Form/"]').each(function() { |
| 129 | var href = $(this).attr('href'); |
| 130 | var dt = href.split('/')[1]; |
Rushabh Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 131 | if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 132 | replace_link(this); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 133 | } |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 134 | }); |
| 135 | |
| 136 | // pages |
| 137 | $(wrapper).find('[data-role]').each(function() { |
Anand Doshi | 90a54a0 | 2012-10-04 13:53:50 +0530 | [diff] [blame] | 138 | // can define multiple roles |
Anand Doshi | 08ca270 | 2012-10-04 19:26:22 +0530 | [diff] [blame] | 139 | var data_roles = $.map($(this).attr("data-role").split(","), function(role) { |
Anand Doshi | 90a54a0 | 2012-10-04 13:53:50 +0530 | [diff] [blame] | 140 | return role.trim(); }); |
| 141 | if(!has_common(user_roles, ["System Manager"].concat(data_roles))) { |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 142 | var html = $(this).html(); |
| 143 | $(this).parent().css('color', '#999'); |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 144 | $(this).replaceWith('<span title="Only accessible by Roles: '+ |
| 145 | $(this).attr("data-role") |
| 146 | +' and System Manager">'+html+'</span>'); |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 147 | } |
| 148 | }); |
| 149 | } |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 150 | |
| 151 | // make list of reports |
| 152 | |
| 153 | erpnext.module_page.make_list = function(module, wrapper) { |
| 154 | // make project listing |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 155 | var $w = $(wrapper).find('.reports-list'); |
| 156 | var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w); |
| 157 | var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w); |
| 158 | |
| 159 | wrapper.list1 = new wn.ui.Listing({ |
| 160 | parent: $parent1, |
| 161 | method: 'utilities.get_sc_list', |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 162 | render_row: function(row, data) { |
| 163 | if(!data.parent_doc_type) data.parent_doc_type = data.doc_type; |
| 164 | $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \ |
| 165 | data-doctype="%(parent_doc_type)s">\ |
| 166 | %(criteria_name)s</a>', data)) |
| 167 | }, |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 168 | args: { module: module }, |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 169 | no_refresh: true, |
| 170 | callback: function(r) { |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 171 | erpnext.module_page.hide_links($parent1) |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 172 | } |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 173 | }); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 174 | wrapper.list1.run(); |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 175 | |
| 176 | wrapper.list2 = new wn.ui.Listing({ |
| 177 | parent: $parent2, |
| 178 | method: 'utilities.get_report_list', |
| 179 | render_row: function(row, data) { |
Nabin Hait | 367f059 | 2012-10-04 18:49:14 +0530 | [diff] [blame] | 180 | data.report_type = data.is_query_report |
| 181 | ? "query-report" |
| 182 | : repl("Report2/%(ref_doctype)s", data) |
| 183 | |
| 184 | $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \ |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 185 | data-doctype="%(ref_doctype)s">\ |
| 186 | %(name)s</a>', data)) |
| 187 | }, |
| 188 | args: { module: module }, |
| 189 | no_refresh: true, |
| 190 | callback: function(r) { |
| 191 | erpnext.module_page.hide_links($parent2) |
| 192 | } |
| 193 | }); |
| 194 | wrapper.list2.run(); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 195 | |
| 196 | // show link to all reports |
| 197 | $parent1.find('.list-toolbar-wrapper') |
| 198 | .prepend("<div class=\"show-all-reports\">\ |
Rushabh Mehta | 4c56275 | 2012-06-14 11:05:09 +0530 | [diff] [blame] | 199 | <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>"); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 200 | $parent2.find('.list-toolbar-wrapper') |
| 201 | .prepend("<div class=\"show-all-reports\">\ |
Rushabh Mehta | 4c56275 | 2012-06-14 11:05:09 +0530 | [diff] [blame] | 202 | <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>"); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 203 | } |