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 | d3c9fb6 | 2012-12-21 18:27:40 +0530 | [diff] [blame] | 17 | wn.home_page = "desktop"; |
Rushabh Mehta | ce1d527 | 2013-01-09 16:39:27 +0530 | [diff] [blame] | 18 | wn.provide("wn.module_page"); |
| 19 | |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 20 | $.extend(wn.modules, { |
| 21 | "Selling": { |
| 22 | link: "selling-home", |
| 23 | color: "#3f4901", |
| 24 | icon: "icon-tag" |
| 25 | }, |
| 26 | "Accounts": { |
| 27 | link: "accounts-home", |
| 28 | color: "#025770", |
| 29 | icon: "icon-money" |
| 30 | }, |
| 31 | "Stock": { |
| 32 | link: "stock-home", |
| 33 | color: "#a66a02", |
| 34 | icon: "icon-truck" |
| 35 | }, |
| 36 | "Buying": { |
| 37 | link: "buying-home", |
| 38 | color: "#8F0222", |
| 39 | icon: "icon-shopping-cart" |
| 40 | }, |
| 41 | "Support": { |
| 42 | link: "support-home", |
| 43 | color: "#410169", |
| 44 | icon: "icon-phone" |
| 45 | }, |
| 46 | "Projects": { |
| 47 | link: "projects-home", |
| 48 | color: "#473b7f", |
| 49 | icon: "icon-tasks" |
| 50 | }, |
| 51 | "Manufacturing": { |
| 52 | link: "manufacturing-home", |
| 53 | color: "#590116", |
| 54 | icon: "icon-magic" |
| 55 | }, |
| 56 | "Website": { |
| 57 | link: "website-home", |
| 58 | color: "#968c00", |
| 59 | icon: "icon-globe" |
| 60 | }, |
| 61 | "HR": { |
| 62 | link: "hr-home", |
| 63 | color: "#018d6c", |
| 64 | label: "Human Resources", |
| 65 | icon: "icon-group" |
| 66 | }, |
| 67 | "Setup": { |
Rushabh Mehta | d3c9fb6 | 2012-12-21 18:27:40 +0530 | [diff] [blame] | 68 | link: "Setup", |
Rushabh Mehta | 946e6d4 | 2012-12-21 15:00:29 +0530 | [diff] [blame] | 69 | color: "#484848", |
| 70 | icon: "icon-wrench" |
| 71 | }, |
| 72 | "Activity": { |
| 73 | link: "activity", |
| 74 | color: "#633501", |
| 75 | icon: "icon-play" |
| 76 | }, |
| 77 | "To Do": { |
| 78 | link: "todo", |
| 79 | color: "#febf04", |
| 80 | icon: "icon-check" |
| 81 | }, |
| 82 | "Calendar": { |
| 83 | link: "calendar", |
| 84 | color: "#026584", |
| 85 | icon: "icon-calendar" |
| 86 | }, |
| 87 | "Messages": { |
| 88 | link: "messages", |
| 89 | color: "#8d016e", |
| 90 | icon: "icon-comments" |
| 91 | }, |
| 92 | "Knowledge Base": { |
| 93 | link: "questions", |
| 94 | color: "#01372b", |
| 95 | icon: "icon-question-sign" |
| 96 | }, |
| 97 | |
| 98 | }); |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 99 | |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 100 | wn.provide('erpnext.module_page'); |
| 101 | |
| 102 | erpnext.module_page.setup_page = function(module, wrapper) { |
| 103 | erpnext.module_page.hide_links(wrapper); |
| 104 | erpnext.module_page.make_list(module, wrapper); |
Rushabh Mehta | 35fabf7 | 2012-02-21 19:03:50 +0530 | [diff] [blame] | 105 | $(wrapper).find("a[title]").tooltip({ |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 106 | delay: { show: 500, hide: 100 } |
| 107 | }); |
Rushabh Mehta | d3c9fb6 | 2012-12-21 18:27:40 +0530 | [diff] [blame] | 108 | wrapper.appframe.add_home_breadcrumb(); |
| 109 | wrapper.appframe.add_breadcrumb(wn.modules[module].icon); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | // hide list links where the user does |
| 113 | // not have read permissions |
| 114 | |
| 115 | erpnext.module_page.hide_links = function(wrapper) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 116 | function replace_link(link) { |
| 117 | var txt = $(link).text(); |
| 118 | $(link).parent().css('color', '#999'); |
| 119 | $(link).replaceWith('<span title="No read permission">' |
| 120 | +txt+'</span>'); |
| 121 | } |
| 122 | |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 123 | // lists |
| 124 | $(wrapper).find('[href*="List/"]').each(function() { |
| 125 | var href = $(this).attr('href'); |
| 126 | var dt = href.split('/')[1]; |
Rushabh Mehta | 291449b | 2012-12-13 12:53:21 +0530 | [diff] [blame] | 127 | if(wn.boot.profile.all_read.indexOf(dt)==-1) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 128 | replace_link(this); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 129 | } |
| 130 | }); |
| 131 | |
| 132 | // reports |
| 133 | $(wrapper).find('[data-doctype]').each(function() { |
| 134 | var dt = $(this).attr('data-doctype'); |
Rushabh Mehta | b473a4d | 2012-03-01 13:58:17 +0530 | [diff] [blame] | 135 | if(wn.boot.profile.all_read.indexOf(dt)==-1) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 136 | replace_link(this); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 137 | } |
| 138 | }); |
| 139 | |
| 140 | // single (forms) |
| 141 | $(wrapper).find('[href*="Form/"]').each(function() { |
| 142 | var href = $(this).attr('href'); |
| 143 | var dt = href.split('/')[1]; |
Rushabh Mehta | 291449b | 2012-12-13 12:53:21 +0530 | [diff] [blame] | 144 | if(wn.boot.profile.all_read.indexOf(dt)==-1) { |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 145 | replace_link(this); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 146 | } |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 147 | }); |
| 148 | |
| 149 | // pages |
| 150 | $(wrapper).find('[data-role]').each(function() { |
Anand Doshi | 90a54a0 | 2012-10-04 13:53:50 +0530 | [diff] [blame] | 151 | // can define multiple roles |
Anand Doshi | 08ca270 | 2012-10-04 19:26:22 +0530 | [diff] [blame] | 152 | var data_roles = $.map($(this).attr("data-role").split(","), function(role) { |
Anand Doshi | 90a54a0 | 2012-10-04 13:53:50 +0530 | [diff] [blame] | 153 | return role.trim(); }); |
| 154 | if(!has_common(user_roles, ["System Manager"].concat(data_roles))) { |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 155 | var html = $(this).html(); |
| 156 | $(this).parent().css('color', '#999'); |
Rushabh Mehta | 224714c | 2012-09-28 10:23:27 +0530 | [diff] [blame] | 157 | $(this).replaceWith('<span title="Only accessible by Roles: '+ |
| 158 | $(this).attr("data-role") |
| 159 | +' and System Manager">'+html+'</span>'); |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 160 | } |
| 161 | }); |
| 162 | } |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 163 | |
| 164 | // make list of reports |
| 165 | |
| 166 | erpnext.module_page.make_list = function(module, wrapper) { |
| 167 | // make project listing |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 168 | var $w = $(wrapper).find('.reports-list'); |
| 169 | var $parent1 = $('<div style="width: 45%; float: left; margin-right: 4.5%"></div>').appendTo($w); |
| 170 | var $parent2 = $('<div style="width: 45%; float: left;"></div>').appendTo($w); |
| 171 | |
| 172 | wrapper.list1 = new wn.ui.Listing({ |
| 173 | parent: $parent1, |
| 174 | method: 'utilities.get_sc_list', |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 175 | render_row: function(row, data) { |
| 176 | if(!data.parent_doc_type) data.parent_doc_type = data.doc_type; |
| 177 | $(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \ |
| 178 | data-doctype="%(parent_doc_type)s">\ |
| 179 | %(criteria_name)s</a>', data)) |
| 180 | }, |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 181 | args: { module: module }, |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 182 | no_refresh: true, |
| 183 | callback: function(r) { |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 184 | erpnext.module_page.hide_links($parent1) |
Rushabh Mehta | a4f454f | 2012-02-29 19:19:01 +0530 | [diff] [blame] | 185 | } |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 186 | }); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 187 | wrapper.list1.run(); |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 188 | |
| 189 | wrapper.list2 = new wn.ui.Listing({ |
| 190 | parent: $parent2, |
| 191 | method: 'utilities.get_report_list', |
| 192 | render_row: function(row, data) { |
Nabin Hait | 367f059 | 2012-10-04 18:49:14 +0530 | [diff] [blame] | 193 | data.report_type = data.is_query_report |
| 194 | ? "query-report" |
| 195 | : repl("Report2/%(ref_doctype)s", data) |
| 196 | |
| 197 | $(row).html(repl('<a href="#!%(report_type)s/%(name)s" \ |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 198 | data-doctype="%(ref_doctype)s">\ |
| 199 | %(name)s</a>', data)) |
| 200 | }, |
| 201 | args: { module: module }, |
| 202 | no_refresh: true, |
| 203 | callback: function(r) { |
| 204 | erpnext.module_page.hide_links($parent2) |
| 205 | } |
| 206 | }); |
| 207 | wrapper.list2.run(); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 208 | |
| 209 | // show link to all reports |
| 210 | $parent1.find('.list-toolbar-wrapper') |
| 211 | .prepend("<div class=\"show-all-reports\">\ |
Rushabh Mehta | 4c56275 | 2012-06-14 11:05:09 +0530 | [diff] [blame] | 212 | <a href=\"#List/Search Criteria\"> [ List Of All Reports ]</a></div>"); |
Anand Doshi | 575545d | 2012-06-13 19:36:55 +0530 | [diff] [blame] | 213 | $parent2.find('.list-toolbar-wrapper') |
| 214 | .prepend("<div class=\"show-all-reports\">\ |
Rushabh Mehta | 4c56275 | 2012-06-14 11:05:09 +0530 | [diff] [blame] | 215 | <a href=\"#List/Report\"> [ List Of All Reports (New) ]</a></div>"); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 216 | } |