Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | // 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 Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 17 | wn.provide('erpnext.module_page'); |
| 18 | |
| 19 | erpnext.module_page.setup_page = function(module, wrapper) { |
| 20 | erpnext.module_page.hide_links(wrapper); |
| 21 | erpnext.module_page.make_list(module, wrapper); |
Rushabh Mehta | 35fabf7 | 2012-02-21 19:03:50 +0530 | [diff] [blame] | 22 | $(wrapper).find("a[title]").tooltip({ |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 23 | delay: { show: 500, hide: 100 } |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | // hide list links where the user does |
| 28 | // not have read permissions |
| 29 | |
| 30 | erpnext.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 Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 35 | if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 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'); |
Rushabh Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 44 | if(wn.boot.profile.all_read.indexOf(dt)==-1) { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 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]; |
Rushabh Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 54 | if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1) { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 55 | var txt = $(this).text(); |
| 56 | $(this).parent().css('color', '#999').html(txt); |
| 57 | } |
| 58 | });} |
| 59 | |
| 60 | // make list of reports |
| 61 | |
| 62 | erpnext.module_page.make_list = function(module, wrapper) { |
| 63 | // make project listing |
Rushabh Mehta | f81a64e | 2012-03-07 18:19:41 +0530 | [diff] [blame] | 64 | wrapper.list = new wn.ui.Listing({ |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 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 | }, |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 76 | no_refresh: true, |
| 77 | callback: function(r) { |
| 78 | erpnext.module_page.hide_links(wrapper) |
| 79 | } |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 80 | }); |
| 81 | wrapper.list.run(); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 82 | } |