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