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 | 4dc2f43 | 2012-02-21 10:30:43 +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 | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 30 | $('.brand').html(wn.boot.website_settings.brand_html); |
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>\ |
| 41 | <img src="lib/images/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 | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 43 | <li><a href="#!Login Page">Login</a></li>\ |
| 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 | f35992f | 2012-02-07 10:39:17 +0530 | [diff] [blame] | 57 | item.route = item.url || item.custom_page; |
Rushabh Mehta | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 58 | $('header .nav:first').append(repl('<li data-label="%(label)s">\ |
| 59 | <a href="#!%(route)s">%(label)s</a></li>', item)) |
| 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 | aa848be | 2012-02-17 12:06:33 +0530 | [diff] [blame] | 78 | $parent_li.append('<ul class="dropdown-menu"></ul>'); |
| 79 | } |
| 80 | item.route = item.url || item.custom_page; |
| 81 | $parent_li.find('.dropdown-menu').append(repl('<li data-label="%(label)s">\ |
| 82 | <a href="#!%(route)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 | |
| 89 | // footer |
| 90 | erpnext.Footer = Class.extend({ |
| 91 | init: function() { |
| 92 | $('footer').html(repl('<div class="web-footer">\ |
| 93 | <div class="web-footer-menu"><ul></ul></div>\ |
| 94 | <div class="web-footer-address">%(address)s</div>\ |
| 95 | <div class="web-footer-copyright">© %(copyright)s</div>\ |
| 96 | <div class="web-footer-powered">Powered by \ |
| 97 | <a href="https://erpnext.com">erpnext.com</a></div>\ |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 98 | </div>', wn.boot.website_settings)); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 99 | this.make_items(); |
| 100 | }, |
| 101 | make_items: function() { |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 102 | var items = wn.boot.website_menus |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 103 | for(var i=0;i<items.length;i++) { |
| 104 | var item = items[i]; |
| 105 | if(!item.parent_label && item.parentfield=='footer_items') { |
Rushabh Mehta | f35992f | 2012-02-07 10:39:17 +0530 | [diff] [blame] | 106 | item.route = item.url || item.custom_page; |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 107 | $('.web-footer-menu ul').append(repl('<li><a href="#!%(route)s" \ |
| 108 | data-label="%(label)s">%(label)s</a></li>', item)) |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | }); |
| 113 | |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 114 | $(document).bind('startup', function() { |
| 115 | erpnext.footer = new erpnext.Footer(); |
Rushabh Mehta | 4dc2f43 | 2012-02-21 10:30:43 +0530 | [diff] [blame] | 116 | erpnext.navbar.navbar = new erpnext.navbar.navbar(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 117 | }) |