blob: a3e7ee8ee8d521de4167e118397b5179c5ac7a0e [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 }
58 });}
59
60// make list of reports
61
62erpnext.module_page.make_list = function(module, wrapper) {
63 // make project listing
Rushabh Mehta16aea342012-05-29 10:53:37 +053064 var $w = $(wrapper).find('.reports-list');
65 var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w);
66 var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w);
67
68 wrapper.list1 = new wn.ui.Listing({
69 parent: $parent1,
70 method: 'utilities.get_sc_list',
Rushabh Mehtad0251332012-02-21 17:26:50 +053071 render_row: function(row, data) {
72 if(!data.parent_doc_type) data.parent_doc_type = data.doc_type;
73 $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
74 data-doctype="%(parent_doc_type)s">\
75 %(criteria_name)s</a>', data))
76 },
Rushabh Mehta16aea342012-05-29 10:53:37 +053077 args: { module: module },
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +053078 no_refresh: true,
79 callback: function(r) {
Rushabh Mehta16aea342012-05-29 10:53:37 +053080 erpnext.module_page.hide_links($parent1)
Rushabh Mehtaa4f454f2012-02-29 19:19:01 +053081 }
Rushabh Mehtad0251332012-02-21 17:26:50 +053082 });
Anand Doshi575545d2012-06-13 19:36:55 +053083 wrapper.list1.run();
Rushabh Mehta16aea342012-05-29 10:53:37 +053084
85 wrapper.list2 = new wn.ui.Listing({
86 parent: $parent2,
87 method: 'utilities.get_report_list',
88 render_row: function(row, data) {
89 $(row).html(repl('<a href="#!Report2/%(ref_doctype)s/%(name)s" \
90 data-doctype="%(ref_doctype)s">\
91 %(name)s</a>', data))
92 },
93 args: { module: module },
94 no_refresh: true,
95 callback: function(r) {
96 erpnext.module_page.hide_links($parent2)
97 }
98 });
99 wrapper.list2.run();
Anand Doshi575545d2012-06-13 19:36:55 +0530100
101 // show link to all reports
102 $parent1.find('.list-toolbar-wrapper')
103 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530104 <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>");
Anand Doshi575545d2012-06-13 19:36:55 +0530105 $parent2.find('.list-toolbar-wrapper')
106 .prepend("<div class=\"show-all-reports\">\
Rushabh Mehta4c562752012-06-14 11:05:09 +0530107 <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>");
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530108}