blob: c668e1466cda7cc5e333f4e2f7984c0d475b5e12 [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',
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053033}
34
35// wn.modules is used in breadcrumbs for getting module home page
36wn.provide('wn.modules');
37$.extend(wn.modules, erpnext.modules);
38wn.modules['Core'] = 'Setup';
39
40wn.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
60wn.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 Mehta9d1faea2012-10-02 14:56:41 +053072 'To Do': 'bright-yellow',
73 'Messages': 'pink',
74 'Calendar': 'peacock',
75 'Knowledge Base': 'ultra-dark-green'
76}
77
78
Rushabh Mehtad0251332012-02-21 17:26:50 +053079wn.provide('erpnext.module_page');
80
81erpnext.module_page.setup_page = function(module, wrapper) {
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053082 wrapper.appframe.set_marker(module);
Rushabh Mehtad0251332012-02-21 17:26:50 +053083 erpnext.module_page.hide_links(wrapper);
84 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +053085 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +053086 delay: { show: 500, hide: 100 }
87 });
88}
89
90// hide list links where the user does
91// not have read permissions
92
93erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +053094 function replace_link(link) {
95 var txt = $(link).text();
96 $(link).parent().css('color', '#999');
97 $(link).replaceWith('<span title="No read permission">'
98 +txt+'</span>');
99 }
100
Rushabh Mehtad0251332012-02-21 17:26:50 +0530101 // lists
102 $(wrapper).find('[href*="List/"]').each(function() {
103 var href = $(this).attr('href');
104 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530105 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530106 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530107 }
108 });
109
110 // reports
111 $(wrapper).find('[data-doctype]').each(function() {
112 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530113 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530114 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530115 }
116 });
117
118 // single (forms)
119 $(wrapper).find('[href*="Form/"]').each(function() {
120 var href = $(this).attr('href');
121 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530122 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530123 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530124 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530125 });
126
127 // pages
128 $(wrapper).find('[data-role]').each(function() {
Anand Doshi90a54a02012-10-04 13:53:50 +0530129 // can define multiple roles
Anand Doshi08ca2702012-10-04 19:26:22 +0530130 var data_roles = $.map($(this).attr("data-role").split(","), function(role) {
Anand Doshi90a54a02012-10-04 13:53:50 +0530131 return role.trim(); });
132 if(!has_common(user_roles, ["System Manager"].concat(data_roles))) {
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530133 var html = $(this).html();
134 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530135 $(this).replaceWith('<span title="Only accessible by Roles: '+
136 $(this).attr("data-role")
137 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530138 }
139 });
140}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530141
142// make list of reports
143
144erpnext.module_page.make_list = function(module, wrapper) {
145 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530146 var $w = $(wrapper).find('.reports-list');
147 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
148 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
149
150 wrapper.list1 = new wn.ui.Listing({
151 parent: $parent1,
152 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530153 render_row: function(row, data) {
154 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
155 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
156 data-doctype="%(parent_doc_type)s">\
157 %(criteria_name)s</a>', data))
158 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530159 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530160 no_refresh: true,
161 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530162 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530163 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530164 });
Anand Doshi575545d2012-06-13 19:36:55 +0530165 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530166
167 wrapper.list2 = new wn.ui.Listing({
168 parent: $parent2,
169 method: 'utilities.get_report_list',
170 render_row: function(row, data) {
Nabin Hait367f0592012-10-04 18:49:14 +0530171 data.report_type = data.is_query_report
172 ? "query-report"
173 : repl("Report2/%(ref_doctype)s", data)
174
175 $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \
Rushabh Mehta16aea342012-05-29 10:53:37 +0530176 data-doctype="%(ref_doctype)s">\
177 %(name)s</a>', data))
178 },
179 args: { module: module },
180 no_refresh: true,
181 callback: function(r) {
182 erpnext.module_page.hide_links($parent2)
183 }
184 });
185 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530186
187 // show link to all reports
188 $parent1.find('.list-toolbar-wrapper')
189 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530190 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530191 $parent2.find('.list-toolbar-wrapper')
192 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530193 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530194}