blob: 71d012e44beaba10f251a909dc77115a9c009bc1 [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];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +053035 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehtad0251332012-02-21 17:26:50 +053036 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');
Rushabh Mehtab473a4d2012-03-01 13:58:17 +053044 if(wn.boot.profile.all_read.indexOf(dt)==-1) {
Rushabh Mehtad0251332012-02-21 17:26:50 +053045 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];
Rushabh Mehtab473a4d2012-03-01 13:58:17 +053054 if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) {
Rushabh Mehtad0251332012-02-21 17:26:50 +053055 var txt = $(this).text();
56 $(this).parent().css('color', '#999').html(txt);
57 }
Rushabh Mehta09d84b62012-09-21 19:46:24 +053058 });
59
60 // pages
61 $(wrapper).find('[data-role]').each(function() {
62 if(!has_common(user_roles, [$(this).attr("data-role"), "System Manager"])) {
63 var html = $(this).html();
64 $(this).parent().css('color', '#999');
65 $(this).replaceWith(html);
66 }
67 });
68}
Rushabh Mehtad0251332012-02-21 17:26:50 +053069
70// make list of reports
71
72erpnext.module_page.make_list = function(module, wrapper) {
73 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +053074 var $w = $(wrapper).find('.reports-list');
75 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
76 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
77
78 wrapper.list1 = new wn.ui.Listing({
79 parent: $parent1,
80 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +053081 render_row: function(row, data) {
82 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
83 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
84 data-doctype="%(parent_doc_type)s">\
85 %(criteria_name)s</a>', data))
86 },
Rushabh Mehta16aea342012-05-29 10:53:37 +053087 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +053088 no_refresh: true,
89 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +053090 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +053091 }
Rushabh Mehtad0251332012-02-21 17:26:50 +053092 });
Anand Doshi575545d2012-06-13 19:36:55 +053093 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +053094
95 wrapper.list2 = new wn.ui.Listing({
96 parent: $parent2,
97 method: 'utilities.get_report_list',
98 render_row: function(row, data) {
99 $(row).html(repl('<a href="#!Report2/%(ref_doctype)s/%(name)s" \
100 data-doctype="%(ref_doctype)s">\
101 %(name)s</a>', data))
102 },
103 args: { module: module },
104 no_refresh: true,
105 callback: function(r) {
106 erpnext.module_page.hide_links($parent2)
107 }
108 });
109 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530110
111 // show link to all reports
112 $parent1.find('.list-toolbar-wrapper')
113 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530114 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530115 $parent2.find('.list-toolbar-wrapper')
116 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530117 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530118}