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 | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 64 | 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 Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 71 | 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 Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 77 | args: { module: module }, |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 78 | no_refresh: true, |
| 79 | callback: function(r) { |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 80 | erpnext.module_page.hide_links($parent1) |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 81 | } |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 82 | }); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 83 | wrapper.list1.run(); |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 84 | |
| 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 Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 100 | |
| 101 | // show link to all reports |
| 102 | $parent1.find('.list-toolbar-wrapper') |
| 103 | .prepend("<div class=\"show-all-reports\">\ |
Rushabh Mehta | 4c56275 | 2012-06-14 11:05:09 +0530 | [diff] [blame] | 104 | <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>"); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 105 | $parent2.find('.list-toolbar-wrapper') |
| 106 | .prepend("<div class=\"show-all-reports\">\ |
Rushabh Mehta | 4c56275 | 2012-06-14 11:05:09 +0530 | [diff] [blame] | 107 | <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>"); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 108 | } |