blob: dbd11b0b3903181ee2f814e7854e0d695911a4c5 [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) {
31 // lists
32 $(wrapper).find('[href*="List/"]').each(function() {
33 var href = $(this).attr('href');
34 var dt = href.split('/')[1];
35 if(wn.boot.profile.can_read.indexOf(get_label_doctype(dt))==-1) {
36 var txt = $(this).text();
37 $(this).parent().css('color', '#999').html(txt);
38 }
39 });
40
41 // reports
42 $(wrapper).find('[data-doctype]').each(function() {
43 var dt = $(this).attr('data-doctype');
44 if(wn.boot.profile.can_read.indexOf(dt)==-1) {
45 var txt = $(this).text();
46 $(this).parent().css('color', '#999').html(txt);
47 }
48 });
49
50 // single (forms)
51 $(wrapper).find('[href*="Form/"]').each(function() {
52 var href = $(this).attr('href');
53 var dt = href.split('/')[1];
54 if(wn.boot.profile.can_read.indexOf(get_label_doctype(dt))==-1) {
55 var txt = $(this).text();
56 $(this).parent().css('color', '#999').html(txt);
57 }
58 });}
59
60// make list of reports
61
62erpnext.module_page.make_list = function(module, wrapper) {
63 // make project listing
64 wrapper.list = new wn.widgets.Listing({
65 parent: $(wrapper).find('.reports-list').get(0),
66 method: 'utilities.get_report_list',
67 render_row: function(row, data) {
68 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
69 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
70 data-doctype="%(parent_doc_type)s">\
71 %(criteria_name)s</a>', data))
72 },
73 args: {
74 module: module
75 },
76 no_refresh: true
77 });
78 wrapper.list.run();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053079}