blob: 752d3699fd8c47b3851d8d4e458f4be7f30c4b26 [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 Mehta946e6d42012-12-21 15:00:29 +053018$.extend(wn.modules, {
19 "Selling": {
20 link: "selling-home",
21 color: "#3f4901",
22 icon: "icon-tag"
23 },
24 "Accounts": {
25 link: "accounts-home",
26 color: "#025770",
27 icon: "icon-money"
28 },
29 "Stock": {
30 link: "stock-home",
31 color: "#a66a02",
32 icon: "icon-truck"
33 },
34 "Buying": {
35 link: "buying-home",
36 color: "#8F0222",
37 icon: "icon-shopping-cart"
38 },
39 "Support": {
40 link: "support-home",
41 color: "#410169",
42 icon: "icon-phone"
43 },
44 "Projects": {
45 link: "projects-home",
46 color: "#473b7f",
47 icon: "icon-tasks"
48 },
49 "Manufacturing": {
50 link: "manufacturing-home",
51 color: "#590116",
52 icon: "icon-magic"
53 },
54 "Website": {
55 link: "website-home",
56 color: "#968c00",
57 icon: "icon-globe"
58 },
59 "HR": {
60 link: "hr-home",
61 color: "#018d6c",
62 label: "Human Resources",
63 icon: "icon-group"
64 },
65 "Setup": {
Rushabh Mehtad3c9fb62012-12-21 18:27:40 +053066 link: "Setup",
Rushabh Mehta946e6d42012-12-21 15:00:29 +053067 color: "#484848",
68 icon: "icon-wrench"
69 },
70 "Activity": {
71 link: "activity",
72 color: "#633501",
73 icon: "icon-play"
74 },
75 "To Do": {
76 link: "todo",
77 color: "#febf04",
78 icon: "icon-check"
79 },
80 "Calendar": {
81 link: "calendar",
82 color: "#026584",
83 icon: "icon-calendar"
84 },
85 "Messages": {
86 link: "messages",
87 color: "#8d016e",
88 icon: "icon-comments"
89 },
90 "Knowledge Base": {
91 link: "questions",
92 color: "#01372b",
93 icon: "icon-question-sign"
94 },
95
96});
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053097
Rushabh Mehtad0251332012-02-21 17:26:50 +053098wn.provide('erpnext.module_page');
99
100erpnext.module_page.setup_page = function(module, wrapper) {
101 erpnext.module_page.hide_links(wrapper);
102 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +0530103 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +0530104 delay: { show: 500, hide: 100 }
105 });
Rushabh Mehtad3c9fb62012-12-21 18:27:40 +0530106 wrapper.appframe.add_home_breadcrumb();
107 wrapper.appframe.add_breadcrumb(wn.modules[module].icon);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530108}
109
110// hide list links where the user does
111// not have read permissions
112
113erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530114 function replace_link(link) {
115 var txt = $(link).text();
116 $(link).parent().css('color', '#999');
117 $(link).replaceWith('<span title="No read permission">'
118 +txt+'</span>');
119 }
120
Rushabh Mehtad0251332012-02-21 17:26:50 +0530121 // lists
122 $(wrapper).find('[href*="List/"]').each(function() {
123 var href = $(this).attr('href');
124 var dt = href.split('/')[1];
Rushabh Mehta291449b2012-12-13 12:53:21 +0530125 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530126 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530127 }
128 });
129
130 // reports
131 $(wrapper).find('[data-doctype]').each(function() {
132 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +0530133 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530134 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530135 }
136 });
137
138 // single (forms)
139 $(wrapper).find('[href*="Form/"]').each(function() {
140 var href = $(this).attr('href');
141 var dt = href.split('/')[1];
Rushabh Mehta291449b2012-12-13 12:53:21 +0530142 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +0530143 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +0530144 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530145 });
146
147 // pages
148 $(wrapper).find('[data-role]').each(function() {
Anand Doshi90a54a02012-10-04 13:53:50 +0530149 // can define multiple roles
Anand Doshi08ca2702012-10-04 19:26:22 +0530150 var data_roles = $.map($(this).attr("data-role").split(","), function(role) {
Anand Doshi90a54a02012-10-04 13:53:50 +0530151 return role.trim(); });
152 if(!has_common(user_roles, ["System Manager"].concat(data_roles))) {
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530153 var html = $(this).html();
154 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +0530155 $(this).replaceWith('<span title="Only accessible by Roles: '+
156 $(this).attr("data-role")
157 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +0530158 }
159 });
160}
Rushabh Mehtad0251332012-02-21 17:26:50 +0530161
162// make list of reports
163
164erpnext.module_page.make_list = function(module, wrapper) {
165 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +0530166 var $w = $(wrapper).find('.reports-list');
167 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
168 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
169
170 wrapper.list1 = new wn.ui.Listing({
171 parent: $parent1,
172 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +0530173 render_row: function(row, data) {
174 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
175 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
176 data-doctype="%(parent_doc_type)s">\
177 %(criteria_name)s</a>', data))
178 },
Rushabh Mehta16aea342012-05-29 10:53:37 +0530179 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530180 no_refresh: true,
181 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +0530182 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +0530183 }
Rushabh Mehtad0251332012-02-21 17:26:50 +0530184 });
Anand Doshi575545d2012-06-13 19:36:55 +0530185 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530186
187 wrapper.list2 = new wn.ui.Listing({
188 parent: $parent2,
189 method: 'utilities.get_report_list',
190 render_row: function(row, data) {
Nabin Hait367f0592012-10-04 18:49:14 +0530191 data.report_type = data.is_query_report
192 ? "query-report"
193 : repl("Report2/%(ref_doctype)s", data)
194
195 $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \
Rushabh Mehta16aea342012-05-29 10:53:37 +0530196 data-doctype="%(ref_doctype)s">\
197 %(name)s</a>', data))
198 },
199 args: { module: module },
200 no_refresh: true,
201 callback: function(r) {
202 erpnext.module_page.hide_links($parent2)
203 }
204 });
205 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530206
207 // show link to all reports
208 $parent1.find('.list-toolbar-wrapper')
209 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530210 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530211 $parent2.find('.list-toolbar-wrapper')
212 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530213 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530214}