blob: 9f0152eabb026a1d35070f67af2b81fe974a0cca [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
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053035wn.provide('wn.modules');
36$.extend(wn.modules, erpnext.modules);
37wn.modules['Core'] = 'Setup';
38
39wn.module_css_classes = {
40 'red': { start: '#A90329', middle: '#8F0222', end: '#6D0019' },
41 'brown': { start: '#723e02', middle: '#633501', end: '#4a2700' },
42 'green': { start: '#4b5602', middle: '#3f4901', end: '#313800' },
43 'blue': { start: '#026584', middle: '#025770', end: '#004256' },
44 'yellow': { start: '#be7902', middle: '#a66a02', end: '#865500' },
45 'purple': { start: '#4d017d', middle: '#410169', end: '#310050' },
46 'ocean': { start: '#02a47e', middle: '#018d6c', end: '#006a51' },
47 'pink': { start: '#a40281', middle: '#8d016e', end: '#6a0053' },
48 'grey': { start: '#545454', middle: '#484848', end: '#363636' },
49 'dark-red': { start: '#68021a', middle: '#590116', end: '#440010' },
50 'leaf-green': { start: '#b0a400', middle: '#968c00', end: '#726a00' },
51 //'dark-blue': { start: '#023bae', middle: '#013295', end: '#002672' },
52 'bright-green': { start: '#03ad1f', middle: '#02941a', end: '#007213' },
53 'bright-yellow': { start: '#ffd65e', middle: '#febf04', end: '#ed9017' },
54 'peacock': { start: '#026584', middle: '#026584', end: '#322476' },
55 'violet': { start: '#50448e', middle: '#473b7f', end: '#3a3169' },
56 'ultra-dark-green': { start: '#014333', middle: '#01372b', end: '#002a20' },
57}
58
59wn.module_css_map = {
60 'Accounts': 'blue',
61 'Selling': 'green',
62 'Stock': 'yellow',
63 'Buying': 'red',
64 'Support': 'purple',
65 'HR': 'ocean',
66 'Projects': 'violet',
67 'Production': 'dark-red',
68 'Website': 'leaf-green',
69 'Activity': 'brown',
70 'Setup': 'grey',
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053071 'To Do': 'bright-yellow',
72 'Messages': 'pink',
73 'Calendar': 'peacock',
74 'Knowledge Base': 'ultra-dark-green'
75}
76
Rushabh Mehta36841552012-11-13 16:44:27 +053077wn.get_module_color = function(module) {
78 try {
79 var color = wn.module_css_classes[wn.module_css_map[module]].middle;
80 } catch(e) {
81 var color = "#000";
82 }
83 return color;
84}
85
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053086
Rushabh Mehtad0251332012-02-21 17:26:50 +053087wn.provide('erpnext.module_page');
88
89erpnext.module_page.setup_page = function(module, wrapper) {
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053090 wrapper.appframe.set_marker(module);
Rushabh Mehtad0251332012-02-21 17:26:50 +053091 erpnext.module_page.hide_links(wrapper);
92 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +053093 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +053094 delay: { show: 500, hide: 100 }
95 });
96}
97
98// hide list links where the user does
99// not have read permissions
100
101erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530102 function replace_link(link) {
103 var txt = $(link).text();
104 $(link).parent().css('color', '#999');
105 $(link).replaceWith('<span title="No read permission">'
106 +txt+'</span>');
107 }
108
Rushabh Mehtad0251332012-02-21 17:26:50 +0530109 // lists
110 $(wrapper).find('[href*="List/"]').each(function() {
111 var href = $(this).attr('href');
112 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530113 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530114 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530115 }
116 });
117
118 // reports
119 $(wrapper).find('[data-doctype]').each(function() {
120 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530121 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530122 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530123 }
124 });
125
126 // single (forms)
127 $(wrapper).find('[href*="Form/"]').each(function() {
128 var href = $(this).attr('href');
129 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530130 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530131 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530132 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530133 });
134
135 // pages
136 $(wrapper).find('[data-role]').each(function() {
Anand Doshi90a54a02012-10-04 13:53:50 +0530137 // can define multiple roles
Anand Doshi08ca2702012-10-04 19:26:22 +0530138 var data_roles = $.map($(this).attr("data-role").split(","), function(role) {
Anand Doshi90a54a02012-10-04 13:53:50 +0530139 return role.trim(); });
140 if(!has_common(user_roles, ["System Manager"].concat(data_roles))) {
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530141 var html = $(this).html();
142 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530143 $(this).replaceWith('<span title="Only accessible by Roles: '+
144 $(this).attr("data-role")
145 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530146 }
147 });
148}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530149
150// make list of reports
151
152erpnext.module_page.make_list = function(module, wrapper) {
153 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530154 var $w = $(wrapper).find('.reports-list');
155 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
156 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
157
158 wrapper.list1 = new wn.ui.Listing({
159 parent: $parent1,
160 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530161 render_row: function(row, data) {
162 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
163 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
164 data-doctype="%(parent_doc_type)s">\
165 %(criteria_name)s</a>', data))
166 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530167 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530168 no_refresh: true,
169 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530170 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530171 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530172 });
Anand Doshi575545d2012-06-13 19:36:55 +0530173 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530174
175 wrapper.list2 = new wn.ui.Listing({
176 parent: $parent2,
177 method: 'utilities.get_report_list',
178 render_row: function(row, data) {
Nabin Hait367f0592012-10-04 18:49:14 +0530179 data.report_type = data.is_query_report
180 ? "query-report"
181 : repl("Report2/%(ref_doctype)s", data)
182
183 $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \
Rushabh Mehta16aea342012-05-29 10:53:37 +0530184 data-doctype="%(ref_doctype)s">\
185 %(name)s</a>', data))
186 },
187 args: { module: module },
188 no_refresh: true,
189 callback: function(r) {
190 erpnext.module_page.hide_links($parent2)
191 }
192 });
193 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530194
195 // show link to all reports
196 $parent1.find('.list-toolbar-wrapper')
197 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530198 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530199 $parent2.find('.list-toolbar-wrapper')
200 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530201 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530202}