Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 1 | wn.provide('erpnext.module_page'); |
| 2 | |
| 3 | erpnext.module_page.setup_page = function(module, wrapper) { |
| 4 | erpnext.module_page.hide_links(wrapper); |
| 5 | erpnext.module_page.make_list(module, wrapper); |
Rushabh Mehta | 35fabf7 | 2012-02-21 19:03:50 +0530 | [diff] [blame] | 6 | $(wrapper).find("a[title]").tooltip({ |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 7 | delay: { show: 500, hide: 100 } |
| 8 | }); |
| 9 | } |
| 10 | |
| 11 | // hide list links where the user does |
| 12 | // not have read permissions |
| 13 | |
| 14 | erpnext.module_page.hide_links = function(wrapper) { |
| 15 | // lists |
| 16 | $(wrapper).find('[href*="List/"]').each(function() { |
| 17 | var href = $(this).attr('href'); |
| 18 | var dt = href.split('/')[1]; |
| 19 | if(wn.boot.profile.can_read.indexOf(get_label_doctype(dt))==-1) { |
| 20 | var txt = $(this).text(); |
| 21 | $(this).parent().css('color', '#999').html(txt); |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | // reports |
| 26 | $(wrapper).find('[data-doctype]').each(function() { |
| 27 | var dt = $(this).attr('data-doctype'); |
| 28 | if(wn.boot.profile.can_read.indexOf(dt)==-1) { |
| 29 | var txt = $(this).text(); |
| 30 | $(this).parent().css('color', '#999').html(txt); |
| 31 | } |
| 32 | }); |
| 33 | |
| 34 | // single (forms) |
| 35 | $(wrapper).find('[href*="Form/"]').each(function() { |
| 36 | var href = $(this).attr('href'); |
| 37 | var dt = href.split('/')[1]; |
| 38 | if(wn.boot.profile.can_read.indexOf(get_label_doctype(dt))==-1) { |
| 39 | var txt = $(this).text(); |
| 40 | $(this).parent().css('color', '#999').html(txt); |
| 41 | } |
| 42 | });} |
| 43 | |
| 44 | // make list of reports |
| 45 | |
| 46 | erpnext.module_page.make_list = function(module, wrapper) { |
| 47 | // make project listing |
| 48 | wrapper.list = new wn.widgets.Listing({ |
| 49 | parent: $(wrapper).find('.reports-list').get(0), |
| 50 | method: 'utilities.get_report_list', |
| 51 | render_row: function(row, data) { |
| 52 | if(!data.parent_doc_type) data.parent_doc_type = data.doc_type; |
| 53 | $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \ |
| 54 | data-doctype="%(parent_doc_type)s">\ |
| 55 | %(criteria_name)s</a>', data)) |
| 56 | }, |
| 57 | args: { |
| 58 | module: module |
| 59 | }, |
| 60 | no_refresh: true |
| 61 | }); |
| 62 | wrapper.list.run(); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 63 | } |