blob: 772a561f72539a426c6265ca3a91fc589f92c9e8 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301// 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 Mehta9d1faea2012-10-02 14:56:41 +053017erpnext.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',
30 'Calendar': 'calendar',
31 'Messages': 'messages',
32 'Knowledge Base': 'questions',
33 'Dashboard': 'dashboard'
34}
35
36// wn.modules is used in breadcrumbs for getting module home page
37wn.provide('wn.modules');
38$.extend(wn.modules, erpnext.modules);
39wn.modules['Core'] = 'Setup';
40
41wn.module_css_classes = {
42 'red': { start: '#A90329', middle: '#8F0222', end: '#6D0019' },
43 'brown': { start: '#723e02', middle: '#633501', end: '#4a2700' },
44 'green': { start: '#4b5602', middle: '#3f4901', end: '#313800' },
45 'blue': { start: '#026584', middle: '#025770', end: '#004256' },
46 'yellow': { start: '#be7902', middle: '#a66a02', end: '#865500' },
47 'purple': { start: '#4d017d', middle: '#410169', end: '#310050' },
48 'ocean': { start: '#02a47e', middle: '#018d6c', end: '#006a51' },
49 'pink': { start: '#a40281', middle: '#8d016e', end: '#6a0053' },
50 'grey': { start: '#545454', middle: '#484848', end: '#363636' },
51 'dark-red': { start: '#68021a', middle: '#590116', end: '#440010' },
52 'leaf-green': { start: '#b0a400', middle: '#968c00', end: '#726a00' },
53 //'dark-blue': { start: '#023bae', middle: '#013295', end: '#002672' },
54 'bright-green': { start: '#03ad1f', middle: '#02941a', end: '#007213' },
55 'bright-yellow': { start: '#ffd65e', middle: '#febf04', end: '#ed9017' },
56 'peacock': { start: '#026584', middle: '#026584', end: '#322476' },
57 'violet': { start: '#50448e', middle: '#473b7f', end: '#3a3169' },
58 'ultra-dark-green': { start: '#014333', middle: '#01372b', end: '#002a20' },
59}
60
61wn.module_css_map = {
62 'Accounts': 'blue',
63 'Selling': 'green',
64 'Stock': 'yellow',
65 'Buying': 'red',
66 'Support': 'purple',
67 'HR': 'ocean',
68 'Projects': 'violet',
69 'Production': 'dark-red',
70 'Website': 'leaf-green',
71 'Activity': 'brown',
72 'Setup': 'grey',
73 'Dashboard': 'bright-green',
74 'To Do': 'bright-yellow',
75 'Messages': 'pink',
76 'Calendar': 'peacock',
77 'Knowledge Base': 'ultra-dark-green'
78}
79
80
Rushabh Mehtad0251332012-02-21 17:26:50 +053081wn.provide('erpnext.module_page');
82
83erpnext.module_page.setup_page = function(module, wrapper) {
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053084 wrapper.appframe.set_marker(module);
Rushabh Mehtad0251332012-02-21 17:26:50 +053085 erpnext.module_page.hide_links(wrapper);
86 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +053087 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +053088 delay: { show: 500, hide: 100 }
89 });
90}
91
92// hide list links where the user does
93// not have read permissions
94
95erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +053096 function replace_link(link) {
97 var txt = $(link).text();
98 $(link).parent().css('color', '#999');
99 $(link).replaceWith('<span title="No read permission">'
100 +txt+'</span>');
101 }
102
Rushabh Mehtad0251332012-02-21 17:26:50 +0530103 // lists
104 $(wrapper).find('[href*="List/"]').each(function() {
105 var href = $(this).attr('href');
106 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530107 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530108 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530109 }
110 });
111
112 // reports
113 $(wrapper).find('[data-doctype]').each(function() {
114 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530115 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530116 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530117 }
118 });
119
120 // single (forms)
121 $(wrapper).find('[href*="Form/"]').each(function() {
122 var href = $(this).attr('href');
123 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530124 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530125 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530126 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530127 });
128
129 // pages
130 $(wrapper).find('[data-role]').each(function() {
Anand Doshi90a54a02012-10-04 13:53:50 +0530131 // can define multiple roles
132 var data_roles = $(this).attr("data-role").split(",").map(function(role) {
133 return role.trim(); });
134 if(!has_common(user_roles, ["System Manager"].concat(data_roles))) {
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530135 var html = $(this).html();
136 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530137 $(this).replaceWith('<span title="Only accessible by Roles: '+
138 $(this).attr("data-role")
139 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530140 }
141 });
142}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530143
144// make list of reports
145
146erpnext.module_page.make_list = function(module, wrapper) {
147 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530148 var $w = $(wrapper).find('.reports-list');
149 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
150 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
151
152 wrapper.list1 = new wn.ui.Listing({
153 parent: $parent1,
154 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530155 render_row: function(row, data) {
156 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
157 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
158 data-doctype="%(parent_doc_type)s">\
159 %(criteria_name)s</a>', data))
160 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530161 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530162 no_refresh: true,
163 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530164 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530165 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530166 });
Anand Doshi575545d2012-06-13 19:36:55 +0530167 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530168
169 wrapper.list2 = new wn.ui.Listing({
170 parent: $parent2,
171 method: 'utilities.get_report_list',
172 render_row: function(row, data) {
Anand Doshicdba51c2012-10-04 18:11:29 +0530173 data.report_type = data.is_query_report ? "query-report" : "Report2"
174 $(row).html(repl('<a href="#!%(report_type)s/%(ref_doctype)s/%(name)s" \
Rushabh Mehta16aea342012-05-29 10:53:37 +0530175 data-doctype="%(ref_doctype)s">\
176 %(name)s</a>', data))
177 },
178 args: { module: module },
179 no_refresh: true,
180 callback: function(r) {
181 erpnext.module_page.hide_links($parent2)
182 }
183 });
184 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530185
186 // show link to all reports
187 $parent1.find('.list-toolbar-wrapper')
188 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530189 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530190 $parent2.find('.list-toolbar-wrapper')
191 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530192 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530193}