blob: 914df8116d857e4f12766f9ca1d5020f2981c8e2 [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 Mehtad0251332012-02-21 17:26:50 +053017wn.provide('erpnext.module_page');
18
19erpnext.module_page.setup_page = function(module, wrapper) {
20 erpnext.module_page.hide_links(wrapper);
21 erpnext.module_page.make_list(module, wrapper);
Rushabh Mehta35fabf72012-02-21 19:03:50 +053022 $(wrapper).find("a[title]").tooltip({
Rushabh Mehtad0251332012-02-21 17:26:50 +053023 delay: { show: 500, hide: 100 }
24 });
25}
26
27// hide list links where the user does
28// not have read permissions
29
30erpnext.module_page.hide_links = function(wrapper) {
Rushabh Mehta224714c2012-09-28 10:23:27 +053031 function replace_link(link) {
32 var txt = $(link).text();
33 $(link).parent().css('color', '#999');
34 $(link).replaceWith('<span title="No read permission">'
35 +txt+'</span>');
36 }
37
Rushabh Mehtad0251332012-02-21 17:26:50 +053038 // lists
39 $(wrapper).find('[href*="List/"]').each(function() {
40 var href = $(this).attr('href');
41 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +053042 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +053043 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +053044 }
45 });
46
47 // reports
48 $(wrapper).find('[data-doctype]').each(function() {
49 var dt = $(this).attr('data-doctype');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +053050 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +053051 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +053052 }
53 });
54
55 // single (forms)
56 $(wrapper).find('[href*="Form/"]').each(function() {
57 var href = $(this).attr('href');
58 var dt = href.split('/')[1];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +053059 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehta224714c2012-09-28 10:23:27 +053060 replace_link(this);
Rushabh Mehtad0251332012-02-21 17:26:50 +053061 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +053062 });
63
64 // pages
65 $(wrapper).find('[data-role]').each(function() {
66 if(!has_common(user_roles, [$(this).attr("data-role"), "System Manager"])) {
67 var html = $(this).html();
68 $(this).parent().css('color', '#999');
Rushabh Mehta224714c2012-09-28 10:23:27 +053069 $(this).replaceWith('<span title="Only accessible by Roles: '+
70 $(this).attr("data-role")
71 +' and System Manager">'+html+'</span>');
Rushabh Mehta09d84b62012-09-21 19:46:24 +053072 }
73 });
74}
Rushabh Mehtad0251332012-02-21 17:26:50 +053075
76// make list of reports
77
78erpnext.module_page.make_list = function(module, wrapper) {
79 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +053080 var $w = $(wrapper).find('.reports-list');
81 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
82 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
83
84 wrapper.list1 = new wn.ui.Listing({
85 parent: $parent1,
86 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +053087 render_row: function(row, data) {
88 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
89 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
90 data-doctype="%(parent_doc_type)s">\
91 %(criteria_name)s</a>', data))
92 },
Rushabh Mehta16aea342012-05-29 10:53:37 +053093 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +053094 no_refresh: true,
95 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +053096 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +053097 }
Rushabh Mehtad0251332012-02-21 17:26:50 +053098 });
Anand Doshi575545d2012-06-13 19:36:55 +053099 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +0530100
101 wrapper.list2 = new wn.ui.Listing({
102 parent: $parent2,
103 method: 'utilities.get_report_list',
104 render_row: function(row, data) {
105 $(row).html(repl('<a href="#!Report2/%(ref_doctype)s/%(name)s" \
106 data-doctype="%(ref_doctype)s">\
107 %(name)s</a>', data))
108 },
109 args: { module: module },
110 no_refresh: true,
111 callback: function(r) {
112 erpnext.module_page.hide_links($parent2)
113 }
114 });
115 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530116
117 // show link to all reports
118 $parent1.find('.list-toolbar-wrapper')
119 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530120 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530121 $parent2.find('.list-toolbar-wrapper')
122 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530123 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530124}