blob: aec0f02aa8ea4acb9ba9823657e8ddb38e429b47 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301// 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 Mehta4dc2f432012-02-21 10:30:43 +053017wn.provide('erpnext.navbar');
Rushabh Mehta865c00a2012-01-24 14:33:21 +053018
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 Mehtac01b7e92012-03-21 12:29:56 +053027erpnext.navbar.Navbar = Class.extend({
Rushabh Mehta865c00a2012-01-24 14:33:21 +053028 init: function() {
29 this.make();
Rushabh Mehta7018b192012-02-02 13:42:28 +053030 $('.brand').html(wn.boot.website_settings.brand_html);
Rushabh Mehta865c00a2012-01-24 14:33:21 +053031 this.make_items();
Rushabh Mehta6e156c72012-02-21 11:19:24 +053032 $('.dropdown-toggle').dropdown();
Rushabh Mehtad0251332012-02-21 17:26:50 +053033 },
Rushabh Mehta865c00a2012-01-24 14:33:21 +053034 make: function() {
Rushabh Mehta4dc2f432012-02-21 10:30:43 +053035 $('header').append('<div class="navbar navbar-fixed-top">\
36 <div class="navbar-inner">\
Rushabh Mehta865c00a2012-01-24 14:33:21 +053037 <div class="container">\
Rushabh Mehta7018b192012-02-02 13:42:28 +053038 <a class="brand">[brand]</a>\
Rushabh Mehta865c00a2012-01-24 14:33:21 +053039 <ul class="nav">\
40 </ul>\
41 <img src="lib/images/ui/spinner.gif" id="spinner"/>\
Rushabh Mehta6e156c72012-02-21 11:19:24 +053042 <ul class="nav pull-right">\
Rushabh Mehta865c00a2012-01-24 14:33:21 +053043 <li><a href="#!Login Page">Login</a></li>\
44 </ul>\
45 </div>\
46 </div>\
47 </div>');
Rushabh Mehta7018b192012-02-02 13:42:28 +053048 $('.brand').attr('href', '#!' + (wn.boot.website_settings.home_page || 'Login Page'))
Rushabh Mehta865c00a2012-01-24 14:33:21 +053049 },
50 make_items: function() {
Rushabh Mehtaaa848be2012-02-17 12:06:33 +053051 var items = wn.boot.website_menus;
52
53 // parent labels
Rushabh Mehta865c00a2012-01-24 14:33:21 +053054 for(var i=0;i<items.length;i++) {
55 var item = items[i];
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053056 if(!item.parent_label && item.parentfield=='top_bar_items') {
Rushabh Mehtaf35992f2012-02-07 10:39:17 +053057 item.route = item.url || item.custom_page;
Rushabh Mehtaaa848be2012-02-17 12:06:33 +053058 $('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 Mehta4dc2f432012-02-21 10:30:43 +053071 $parent_li.find('a:first').addClass('dropdown-toggle')
72 .attr('data-toggle', 'dropdown')
Rushabh Mehtad0251332012-02-21 17:26:50 +053073 .attr('href', '')
74 .append('<b class="caret"></b>')
75 .click(function() {
76 return false;
77 });
Rushabh Mehtaaa848be2012-02-17 12:06:33 +053078 $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 Mehta865c00a2012-01-24 14:33:21 +053083 }
84 }
85 }
86});
87
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053088
89// footer
90erpnext.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">&copy; %(copyright)s</div>\
96 <div class="web-footer-powered">Powered by \
97 <a href="https://erpnext.com">erpnext.com</a></div>\
Rushabh Mehta7018b192012-02-02 13:42:28 +053098 </div>', wn.boot.website_settings));
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053099 this.make_items();
100 },
101 make_items: function() {
Rushabh Mehta7018b192012-02-02 13:42:28 +0530102 var items = wn.boot.website_menus
Rushabh Mehtaab1148c2012-01-31 18:01:16 +0530103 for(var i=0;i<items.length;i++) {
104 var item = items[i];
105 if(!item.parent_label && item.parentfield=='footer_items') {
Rushabh Mehtaf35992f2012-02-07 10:39:17 +0530106 item.route = item.url || item.custom_page;
Rushabh Mehtaab1148c2012-01-31 18:01:16 +0530107 $('.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 Mehtaafaac602012-02-14 11:44:13 +0530114$(document).bind('startup', function() {
Rushabh Mehtab6f80882012-03-23 14:19:49 +0530115 erpnext.footer = new erpnext.Footer();
Rushabh Mehtac01b7e92012-03-21 12:29:56 +0530116 erpnext.navbar.navbar = new erpnext.navbar.Navbar();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530117})