blob: 5c572dda8edc94488cd253599999aa8bf5726bfd [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 Mehtad3c9fb62012-12-21 18:27:40 +053017wn.home_page = "desktop";
Rushabh Mehtace1d5272013-01-09 16:39:27 +053018wn.provide("wn.module_page");
19
Rushabh Mehta946e6d42012-12-21 15:00:29 +053020$.extend(wn.modules, {
21 "Selling": {
22 link: "selling-home",
23 color: "#3f4901",
24 icon: "icon-tag"
25 },
26 "Accounts": {
27 link: "accounts-home",
28 color: "#025770",
29 icon: "icon-money"
30 },
31 "Stock": {
32 link: "stock-home",
33 color: "#a66a02",
34 icon: "icon-truck"
35 },
36 "Buying": {
37 link: "buying-home",
38 color: "#8F0222",
39 icon: "icon-shopping-cart"
40 },
41 "Support": {
42 link: "support-home",
43 color: "#410169",
44 icon: "icon-phone"
45 },
46 "Projects": {
47 link: "projects-home",
48 color: "#473b7f",
49 icon: "icon-tasks"
50 },
51 "Manufacturing": {
52 link: "manufacturing-home",
53 color: "#590116",
54 icon: "icon-magic"
55 },
56 "Website": {
57 link: "website-home",
58 color: "#968c00",
59 icon: "icon-globe"
60 },
61 "HR": {
62 link: "hr-home",
63 color: "#018d6c",
64 label: "Human Resources",
65 icon: "icon-group"
66 },
67 "Setup": {
Rushabh Mehtad3c9fb62012-12-21 18:27:40 +053068 link: "Setup",
Rushabh Mehta946e6d42012-12-21 15:00:29 +053069 color: "#484848",
70 icon: "icon-wrench"
71 },
72 "Activity": {
73 link: "activity",
74 color: "#633501",
75 icon: "icon-play"
76 },
77 "To Do": {
78 link: "todo",
79 color: "#febf04",
80 icon: "icon-check"
81 },
82 "Calendar": {
83 link: "calendar",
84 color: "#026584",
85 icon: "icon-calendar"
86 },
87 "Messages": {
88 link: "messages",
89 color: "#8d016e",
90 icon: "icon-comments"
91 },
92 "Knowledge Base": {
93 link: "questions",
94 color: "#01372b",
95 icon: "icon-question-sign"
96 },
97
98});
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053099
Rushabh Mehtad0251332012-02-21 17:26:50 +0530100wn.provide('erpnext.module_page');
101
102erpnext.module_page.setup_page = function(module, wrapper) {
103 erpnext.module_page.hide_links(wrapper);
104 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +0530105 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +0530106 delay: { show: 500, hide: 100 }
107 });
Rushabh Mehtad3c9fb62012-12-21 18:27:40 +0530108 wrapper.appframe.add_home_breadcrumb();
109 wrapper.appframe.add_breadcrumb(wn.modules[module].icon);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530110}
111
112// hide list links where the user does
113// not have read permissions
114
115erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530116 function replace_link(link) {
117 var txt = $(link).text();
118 $(link).parent().css('color', '#999');
119 $(link).replaceWith('<span title="No read permission">'
120 +txt+'</span>');
121 }
122
Rushabh Mehtad0251332012-02-21 17:26:50 +0530123 // lists
124 $(wrapper).find('[href*="List/"]').each(function() {
125 var href = $(this).attr('href');
126 var dt = href.split('/')[1];
Rushabh Mehta291449b2012-12-13 12:53:21 +0530127 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530128 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530129 }
130 });
131
132 // reports
133 $(wrapper).find('[data-doctype]').each(function() {
134 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530135 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530136 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530137 }
138 });
139
140 // single (forms)
141 $(wrapper).find('[href*="Form/"]').each(function() {
142 var href = $(this).attr('href');
143 var dt = href.split('/')[1];
Rushabh Mehta291449b2012-12-13 12:53:21 +0530144 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530145 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530146 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530147 });
148
149 // pages
150 $(wrapper).find('[data-role]').each(function() {
Anand Doshi90a54a02012-10-04 13:53:50 +0530151 // can define multiple roles
Anand Doshi08ca2702012-10-04 19:26:22 +0530152 var data_roles = $.map($(this).attr("data-role").split(","), function(role) {
Anand Doshi90a54a02012-10-04 13:53:50 +0530153 return role.trim(); });
154 if(!has_common(user_roles, ["System Manager"].concat(data_roles))) {
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530155 var html = $(this).html();
156 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530157 $(this).replaceWith('<span title="Only accessible by Roles: '+
158 $(this).attr("data-role")
159 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530160 }
161 });
162}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530163
164// make list of reports
165
166erpnext.module_page.make_list = function(module, wrapper) {
167 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530168 var $w = $(wrapper).find('.reports-list');
169 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
170 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
171
172 wrapper.list1 = new wn.ui.Listing({
173 parent: $parent1,
174 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530175 render_row: function(row, data) {
176 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
177 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
178 data-doctype="%(parent_doc_type)s">\
179 %(criteria_name)s</a>', data))
180 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530181 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530182 no_refresh: true,
183 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530184 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530185 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530186 });
Anand Doshi575545d2012-06-13 19:36:55 +0530187 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530188
189 wrapper.list2 = new wn.ui.Listing({
190 parent: $parent2,
191 method: 'utilities.get_report_list',
192 render_row: function(row, data) {
Nabin Hait367f0592012-10-04 18:49:14 +0530193 data.report_type = data.is_query_report
194 ? "query-report"
195 : repl("Report2/%(ref_doctype)s", data)
196
197 $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \
Rushabh Mehta16aea342012-05-29 10:53:37 +0530198 data-doctype="%(ref_doctype)s">\
199 %(name)s</a>', data))
200 },
201 args: { module: module },
202 no_refresh: true,
203 callback: function(r) {
204 erpnext.module_page.hide_links($parent2)
205 }
206 });
207 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530208
209 // show link to all reports
210 $parent1.find('.list-toolbar-wrapper')
211 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530212 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530213 $parent2.find('.list-toolbar-wrapper')
214 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530215 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530216}