blob: c90aac678523163e6c8ea6e0d6492541bddcfd7a [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 Mehta946e6d42012-12-21 15:00:29 +053017$.extend(wn.modules, {
18 "Selling": {
19 link: "selling-home",
20 color: "#3f4901",
21 icon: "icon-tag"
22 },
23 "Accounts": {
24 link: "accounts-home",
25 color: "#025770",
26 icon: "icon-money"
27 },
28 "Stock": {
29 link: "stock-home",
30 color: "#a66a02",
31 icon: "icon-truck"
32 },
33 "Buying": {
34 link: "buying-home",
35 color: "#8F0222",
36 icon: "icon-shopping-cart"
37 },
38 "Support": {
39 link: "support-home",
40 color: "#410169",
41 icon: "icon-phone"
42 },
43 "Projects": {
44 link: "projects-home",
45 color: "#473b7f",
46 icon: "icon-tasks"
47 },
48 "Manufacturing": {
49 link: "manufacturing-home",
50 color: "#590116",
51 icon: "icon-magic"
52 },
53 "Website": {
54 link: "website-home",
55 color: "#968c00",
56 icon: "icon-globe"
57 },
58 "HR": {
59 link: "hr-home",
60 color: "#018d6c",
61 label: "Human Resources",
62 icon: "icon-group"
63 },
64 "Setup": {
65 link: "hr-home",
66 color: "#484848",
67 icon: "icon-wrench"
68 },
69 "Activity": {
70 link: "activity",
71 color: "#633501",
72 icon: "icon-play"
73 },
74 "To Do": {
75 link: "todo",
76 color: "#febf04",
77 icon: "icon-check"
78 },
79 "Calendar": {
80 link: "calendar",
81 color: "#026584",
82 icon: "icon-calendar"
83 },
84 "Messages": {
85 link: "messages",
86 color: "#8d016e",
87 icon: "icon-comments"
88 },
89 "Knowledge Base": {
90 link: "questions",
91 color: "#01372b",
92 icon: "icon-question-sign"
93 },
94
95});
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053096
Rushabh Mehtad0251332012-02-21 17:26:50 +053097wn.provide('erpnext.module_page');
98
99erpnext.module_page.setup_page = function(module, wrapper) {
100 erpnext.module_page.hide_links(wrapper);
101 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +0530102 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +0530103 delay: { show: 500, hide: 100 }
104 });
105}
106
107// hide list links where the user does
108// not have read permissions
109
110erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530111 function replace_link(link) {
112 var txt = $(link).text();
113 $(link).parent().css('color', '#999');
114 $(link).replaceWith('<span title="No read permission">'
115 +txt+'</span>');
116 }
117
Rushabh Mehtad0251332012-02-21 17:26:50 +0530118 // lists
119 $(wrapper).find('[href*="List/"]').each(function() {
120 var href = $(this).attr('href');
121 var dt = href.split('/')[1];
Rushabh Mehta291449b2012-12-13 12:53:21 +0530122 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530123 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530124 }
125 });
126
127 // reports
128 $(wrapper).find('[data-doctype]').each(function() {
129 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530130 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530131 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530132 }
133 });
134
135 // single (forms)
136 $(wrapper).find('[href*="Form/"]').each(function() {
137 var href = $(this).attr('href');
138 var dt = href.split('/')[1];
Rushabh Mehta291449b2012-12-13 12:53:21 +0530139 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530140 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530141 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530142 });
143
144 // pages
145 $(wrapper).find('[data-role]').each(function() {
Anand Doshi90a54a02012-10-04 13:53:50 +0530146 // can define multiple roles
Anand Doshi08ca2702012-10-04 19:26:22 +0530147 var data_roles = $.map($(this).attr("data-role").split(","), function(role) {
Anand Doshi90a54a02012-10-04 13:53:50 +0530148 return role.trim(); });
149 if(!has_common(user_roles, ["System Manager"].concat(data_roles))) {
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530150 var html = $(this).html();
151 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530152 $(this).replaceWith('<span title="Only accessible by Roles: '+
153 $(this).attr("data-role")
154 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530155 }
156 });
157}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530158
159// make list of reports
160
161erpnext.module_page.make_list = function(module, wrapper) {
162 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530163 var $w = $(wrapper).find('.reports-list');
164 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
165 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
166
167 wrapper.list1 = new wn.ui.Listing({
168 parent: $parent1,
169 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530170 render_row: function(row, data) {
171 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
172 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
173 data-doctype="%(parent_doc_type)s">\
174 %(criteria_name)s</a>', data))
175 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530176 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530177 no_refresh: true,
178 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530179 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530180 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530181 });
Anand Doshi575545d2012-06-13 19:36:55 +0530182 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530183
184 wrapper.list2 = new wn.ui.Listing({
185 parent: $parent2,
186 method: 'utilities.get_report_list',
187 render_row: function(row, data) {
Nabin Hait367f0592012-10-04 18:49:14 +0530188 data.report_type = data.is_query_report
189 ? "query-report"
190 : repl("Report2/%(ref_doctype)s", data)
191
192 $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \
Rushabh Mehta16aea342012-05-29 10:53:37 +0530193 data-doctype="%(ref_doctype)s">\
194 %(name)s</a>', data))
195 },
196 args: { module: module },
197 no_refresh: true,
198 callback: function(r) {
199 erpnext.module_page.hide_links($parent2)
200 }
201 });
202 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530203
204 // show link to all reports
205 $parent1.find('.list-toolbar-wrapper')
206 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530207 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530208 $parent2.find('.list-toolbar-wrapper')
209 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530210 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530211}