blob: a9e82d6ff8d181908f93029b4d7dda2421cf6875 [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() {
131 if(!has_common(user_roles, [$(this).attr("data-role"), "System Manager"])) {
132 var html = $(this).html();
133 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530134 $(this).replaceWith('<span title="Only accessible by Roles: '+
135 $(this).attr("data-role")
136 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530137 }
138 });
139}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530140
141// make list of reports
142
143erpnext.module_page.make_list = function(module, wrapper) {
144 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530145 var $w = $(wrapper).find('.reports-list');
146 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
147 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
148
149 wrapper.list1 = new wn.ui.Listing({
150 parent: $parent1,
151 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530152 render_row: function(row, data) {
153 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
154 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
155 data-doctype="%(parent_doc_type)s">\
156 %(criteria_name)s</a>', data))
157 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530158 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530159 no_refresh: true,
160 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530161 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530162 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530163 });
Anand Doshi575545d2012-06-13 19:36:55 +0530164 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530165
166 wrapper.list2 = new wn.ui.Listing({
167 parent: $parent2,
168 method: 'utilities.get_report_list',
169 render_row: function(row, data) {
170 $(row).html(repl('<a href="#!Report2/%(ref_doctype)s/%(name)s" \
171 data-doctype="%(ref_doctype)s">\
172 %(name)s</a>', data))
173 },
174 args: { module: module },
175 no_refresh: true,
176 callback: function(r) {
177 erpnext.module_page.hide_links($parent2)
178 }
179 });
180 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530181
182 // show link to all reports
183 $parent1.find('.list-toolbar-wrapper')
184 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530185 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530186 $parent2.find('.list-toolbar-wrapper')
187 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530188 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530189}