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 | 4dc2f43 | 2012-02-21 10:30:43 +0530 | [diff] [blame] | 17 | wn.provide('erpnext.navbar'); |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | <li class="dropdown">\ |
| 21 | <a class="dropdown-toggle" href="#" onclick="return false;"></a>\ |
| 22 | <ul class="dropdown-menu" id="toolbar-user">\ |
| 23 | </ul>\ |
| 24 | </li>\ |
| 25 | */ |
| 26 | |
Rushabh Mehta | c01b7e9 | 2012-03-21 12:29:56 +0530 | [diff] [blame] | 27 | erpnext.navbar.Navbar = Class.extend({ |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 28 | init: function() { |
| 29 | this.make(); |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 30 | $('.brand').html(wn.boot.website_settings.brand_html || sys_defaults.company); |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 31 | this.make_items(); |
Rushabh Mehta | 6e156c7 | 2012-02-21 11:19:24 +0530 | [diff] [blame] | 32 | $('.dropdown-toggle').dropdown(); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 33 | }, |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 34 | make: function() { |
Rushabh Mehta | 4dc2f43 | 2012-02-21 10:30:43 +0530 | [diff] [blame] | 35 | $('header').append('<div class="navbar navbar-fixed-top">\ |
| 36 | <div class="navbar-inner">\ |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 37 | <div class="container">\ |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 38 | <a class="brand">[brand]</a>\ |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 39 | <ul class="nav">\ |
| 40 | </ul>\ |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 41 | <img src="images/lib/ui/spinner.gif" id="spinner"/>\ |
Rushabh Mehta | 6e156c7 | 2012-02-21 11:19:24 +0530 | [diff] [blame] | 42 | <ul class="nav pull-right">\ |
Rushabh Mehta | f9c766a | 2012-05-04 11:41:57 +0530 | [diff] [blame] | 43 | <li id="login-topbar-item"><a href="#!Login Page">Login</a></li>\ |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 44 | </ul>\ |
| 45 | </div>\ |
| 46 | </div>\ |
| 47 | </div>'); |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 48 | $('.brand').attr('href', '#!' + (wn.boot.website_settings.home_page || 'Login Page')) |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 49 | }, |
| 50 | make_items: function() { |
Rushabh Mehta | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 51 | var items = wn.boot.website_menus; |
| 52 | |
| 53 | // parent labels |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 54 | for(var i=0;i<items.length;i++) { |
| 55 | var item = items[i]; |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 56 | if(!item.parent_label && item.parentfield=='top_bar_items') { |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 57 | erpnext.header_link_settings(item); |
Rushabh Mehta | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 58 | $('header .nav:first').append(repl('<li data-label="%(label)s">\ |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 59 | <a href="%(route)s" %(target)s>%(label)s</a></li>', item)); |
Rushabh Mehta | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | // child labels |
| 64 | for(var i=0;i<items.length;i++) { |
| 65 | var item = items[i]; |
| 66 | if(item.parent_label && item.parentfield=='top_bar_items') { |
| 67 | // check if parent label has class "dropdown" |
| 68 | $parent_li = $(repl('header li[data-label="%(parent_label)s"]', item)); |
| 69 | if(!$parent_li.hasClass('dropdown')) { |
| 70 | $parent_li.addClass('dropdown'); |
Rushabh Mehta | 4dc2f43 | 2012-02-21 10:30:43 +0530 | [diff] [blame] | 71 | $parent_li.find('a:first').addClass('dropdown-toggle') |
| 72 | .attr('data-toggle', 'dropdown') |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 73 | .attr('href', '') |
| 74 | .append('<b class="caret"></b>') |
| 75 | .click(function() { |
| 76 | return false; |
| 77 | }); |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 78 | $parent_li.append(''); |
Rushabh Mehta | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 79 | } |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 80 | erpnext.header_link_settings(item); |
Rushabh Mehta | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 81 | $parent_li.find('.dropdown-menu').append(repl('<li data-label="%(label)s">\ |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 82 | <a href="%(route)s" %(target)s>%(label)s</a></li>', item)) |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | } |
| 86 | }); |
| 87 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 88 | // footer |
| 89 | erpnext.Footer = Class.extend({ |
| 90 | init: function() { |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 91 | if(!wn.boot.website_settings.copyright) { |
| 92 | wn.boot.website_settings.copyright = sys_defaults.company; |
| 93 | } |
| 94 | if(!wn.boot.website_settings.address) { |
| 95 | wn.boot.website_settings.address = ''; |
| 96 | } |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 97 | $('footer').html(repl('<div class="web-footer">\ |
| 98 | <div class="web-footer-menu"><ul></ul></div>\ |
Rushabh Mehta | 8360a5f | 2012-05-01 16:23:05 +0530 | [diff] [blame] | 99 | <div class="web-footer-copyright">© %(copyright)s</div>\ |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 100 | </div>', wn.boot.website_settings)); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 101 | this.make_items(); |
| 102 | }, |
| 103 | make_items: function() { |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 104 | var items = wn.boot.website_menus |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 105 | for(var i=0;i<items.length;i++) { |
| 106 | var item = items[i]; |
| 107 | if(!item.parent_label && item.parentfield=='footer_items') { |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 108 | erpnext.header_link_settings(item); |
| 109 | $('.web-footer-menu ul').append(repl('<li><a href="%(route)s" %(target)s\ |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 110 | data-label="%(label)s">%(label)s</a></li>', item)) |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | }); |
| 115 | |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 116 | // customize hard / soft links |
| 117 | erpnext.header_link_settings = function(item) { |
| 118 | item.route = item.url || item.custom_page; |
Rushabh Mehta | a0571fe | 2012-05-02 10:20:40 +0530 | [diff] [blame] | 119 | if(item.route && item.route.substr(0,4)=='http') { |
Rushabh Mehta | 6f8e9e9 | 2012-05-01 13:41:44 +0530 | [diff] [blame] | 120 | item.target = 'target="_blank"'; |
| 121 | } else { |
| 122 | item.target = ''; |
| 123 | item.route = '#!' + item.route; |
| 124 | } |
| 125 | } |
| 126 | |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 127 | $(document).bind('startup', function() { |
Rushabh Mehta | b6f8088 | 2012-03-23 14:19:49 +0530 | [diff] [blame] | 128 | erpnext.footer = new erpnext.Footer(); |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 129 | //erpnext.navbar.navbar = new erpnext.navbar.Navbar(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 130 | }) |