diff --git a/conf/index.html b/conf/template.html similarity index 77% rename from conf/index.html rename to conf/template.html index 7b97e53af3..9d62b7cd91 100644 --- a/conf/index.html +++ b/conf/template.html @@ -12,8 +12,19 @@ {% if script %} {% endif %} diff --git a/js/core.js b/js/core.js index 4fd6421205..6a3bb87aff 100644 --- a/js/core.js +++ b/js/core.js @@ -32,7 +32,7 @@ if(!console) { /* start the application */ -$(document).bind('ready', function() { +$(document).ready(function() { wn.versions.check(); wn.provide('wn.app'); $.extend(wn.app, new wn.Application()); diff --git a/js/core.min.js b/js/core.min.js index 86570b2a4a..c77c58f6d8 100644 --- a/js/core.min.js +++ b/js/core.min.js @@ -57,7 +57,8 @@ return repl('
%(letter)s
',args);}} -wn.get_cookie=function(c){var t=""+document.cookie;var ind=t.indexOf(c);if(ind==-1||c=="")return"";var ind1=t.indexOf(';',ind);if(ind1==-1)ind1=t.length;return unescape(t.substring(ind+c.length+1,ind1));} +wn.get_cookie=function(c){var clist=(document.cookie+'').split(';');var cookies={};for(var i=0;i').html(label).attr('value',value).appendTo(this);} @@ -130,7 +131,8 @@ wn.re_route={} wn.route=function(){if(wn.re_route[window.location.hash]){window.location.hash=wn.re_route[window.location.hash];} wn._cur_route=window.location.hash;route=wn.get_route();switch(route[0]){case"List":wn.views.doclistview.show(route[1]);break;case"Form":if(route.length>3){route[2]=route.splice(2).join('/');} wn.views.formview.show(route[1],route[2]);break;case"Report":wn.views.reportview.show(route[1],route[2]);break;case"Report2":wn.views.reportview2.show();break;default:wn.views.pageview.show(route[0]);}} -wn.get_route=function(route){return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});} +wn.get_route=function(route){if(!wn.boot){return[window.page_name];} +return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});} wn.get_route_str=function(route){if(!route) route=window.location.hash;if(route.substr(0,1)=='#')route=route.substr(1);if(route.substr(0,1)=='!')route=route.substr(1);return route;} wn.set_route=function(){route=$.map(arguments,function(a){return encodeURIComponent(a)}).join('/');window.location.hash=route;wn.app.set_favicon();} @@ -248,9 +250,9 @@ wn.views.add_list_btn=function(parent,doctype){$(parent).append(repl('\

Not Found


\ @@ -281,4 +283,4 @@ wn.request.call({args:args,success:opts.callback,error:opts.error,btn:opts.btn,f * lib/js/core.js */ if(!console){var console={log:function(txt){}}} -$(document).bind('ready',function(){wn.versions.check();wn.provide('wn.app');$.extend(wn.app,new wn.Application());}); \ No newline at end of file +$(document).ready(function(){wn.versions.check();wn.provide('wn.app');$.extend(wn.app,new wn.Application());}); \ No newline at end of file diff --git a/js/wn/app.js b/js/wn/app.js index 92bef1c6c9..700766c40c 100644 --- a/js/wn/app.js +++ b/js/wn/app.js @@ -55,11 +55,16 @@ wn.Application = Class.extend({ // favicon this.set_favicon(); + // trigger app startup $(document).trigger('startup'); - // route to home page - wn.route(); + if(wn.boot) { + // route to home page + wn.route(); + } + + $(document).trigger('app_ready'); }, load_bootinfo: function() { if(wn.boot) { diff --git a/js/wn/dom.js b/js/wn/dom.js index 58c36f03ce..cd38300500 100644 --- a/js/wn/dom.js +++ b/js/wn/dom.js @@ -111,12 +111,13 @@ wn.dom = { } wn.get_cookie = function(c) { - var t=""+document.cookie; - var ind=t.indexOf(c); - if (ind==-1 || c=="") return ""; - var ind1=t.indexOf(';',ind); - if (ind1==-1) ind1=t.length; - return unescape(t.substring(ind+c.length+1,ind1)); + var clist = (document.cookie+'').split(';'); + var cookies = {}; + for(var i=0;iLogin Page - -

Powered by Web Notes Framework

\ No newline at end of file diff --git a/py/webnotes/__init__.py b/py/webnotes/__init__.py index 1e35ab6870..c97af4a990 100644 --- a/py/webnotes/__init__.py +++ b/py/webnotes/__init__.py @@ -213,12 +213,13 @@ def clear_cache(user=None): from webnotes.session_cache import clear clear(user) -def get_roles(): +def get_roles(user=None): """get roles of current user""" - if session['user']=='Guest': + if not user: + user = session['user'] + + if user=='Guest': return ['Guest'] - roles = [r[0] for r in conn.sql("""select distinct role from tabUserRole - where parent=%s and role!='All'""", session['user'])] - - return roles + ['All'] + return [r[0] for r in conn.sql("""select distinct role from tabUserRole + where parent=%s and role!='All'""", user)] + ['All'] diff --git a/py/webnotes/boot.py b/py/webnotes/boot.py index 35ab8498eb..b8b2515f31 100644 --- a/py/webnotes/boot.py +++ b/py/webnotes/boot.py @@ -52,7 +52,7 @@ def get_bootinfo(): bootinfo['sid'] = webnotes.session['sid']; # home page - get_home_page(bootinfo, doclist) + add_home_page(bootinfo, doclist) # ipinfo if webnotes.session['data'].get('ipinfo'): @@ -99,12 +99,13 @@ def get_profile(bootinfo): bootinfo['profile'] = webnotes.user.load_profile() webnotes.session['data']['profile'] = bootinfo['profile'] -def get_home_page(bootinfo, doclist): +def add_home_page(bootinfo, doclist): """load home page""" import webnotes import webnotes.widgets.page + import webnotes.cms - home_page = webnotes.user.get_home_page() or 'Login Page' + home_page = webnotes.cms.get_home_page(webnotes.session['user']) or 'Login Page' try: page_doclist = webnotes.widgets.page.get(home_page) diff --git a/py/webnotes/cms/__init__.py b/py/webnotes/cms/__init__.py index eb3037d139..42a9706412 100644 --- a/py/webnotes/cms/__init__.py +++ b/py/webnotes/cms/__init__.py @@ -1,48 +1,3 @@ -""" -make index, wn.js, wn.css pages -- rebuild all pages on change of website settings (toolbar) -- if home, write index.html -""" -def make(version): - import os - import webnotes - from webnotes.model.code import get_obj - from jinja2 import Template - - webnotes.connect() - - # get web home - home_page = webnotes.conn.get_default("web_home_page") or 'Login Page' - - page = get_obj('Page', home_page) - page.get_from_files() - - os.chdir('public') - - page.write_cms_page(home_page=True) - - # script - wn.js - import startup.event_handlers - if hasattr(startup.event_handlers, 'get_web_script'): - with open('js/wn-web.js', 'w') as f: - - script = 'window._version_number = "%s";\n' % version - script += 'window.home_page = "%s";\n' % home_page - - script += startup.event_handlers.get_web_script() - - f.write(script) - - # style - wn.css - if hasattr(startup.event_handlers, 'get_web_style'): - with open('css/wn-web.css', 'w') as f: - f.write(startup.event_handlers.get_web_style()) - - # make app.html - with open('../lib/conf/app.html', 'r') as app_template: - with open('app.html', 'w') as app: - app.write(Template(app_template.read()).render(version=version)) - def page_name(title): """truncated page name""" @@ -50,3 +5,18 @@ def page_name(title): name = title.lower() name = re.sub('[~!@#$%^&*()<>,."\']', '', name) return '-'.join(name.split()[:4]) + +def get_home_page(user=None): + """get home page for user""" + if not user: + user = 'Guest' + import webnotes + hpl = webnotes.conn.sql("""select home_page + from `tabDefault Home Page` + where parent='Control Panel' + and role in ('%s') order by idx asc limit 1""" % "', '".join(webnotes.get_roles(user))) + + if hpl: + return hpl[0][0] + else: + return webnotes.conn.get_value('Control Panel',None,'home_page') or 'Login Page' \ No newline at end of file diff --git a/py/webnotes/cms/index.py b/py/webnotes/cms/index.py deleted file mode 100644 index 7cfe1efd6c..0000000000 --- a/py/webnotes/cms/index.py +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) -# -# MIT License (MIT) -# -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -""" -Generate index.cgi html - -Loads index.html from the template with: - -1. bootinfo -2. static html of home / if _escaped_fragment_ is given -3. top menus and bottom menus - -""" - -import webnotes - -body_html = """ -
- -
-
-
- -
-""" - -def get(): - """get index html""" - import webnotes - from jinja2 import Template - - with open('lib/conf/index.html', 'r') as f: - template = Template(f.read()) - - # google crawler - if '_escaped_fragment_' in webnotes.form: - page = webnotes.form_dict['_escaped_fragment_'] - if not page: - page = webnotes.user.get_home_page() - - return template.render(bootinfo = '', style_tag='', version='0', analytics_code = '', - script_tag = '', body_html=html_snapshot(page), ajax_meta_tag = '', - title=webnotes.conn.get_value('Page', page, 'title')) - - # home page - else: - import webnotes.session_cache - from build.project import get_version - import json - - bootdict = webnotes.session_cache.get() - bootinfo = """var wn = {}; wn.boot = %s;""" % json.dumps(bootdict) - - return template.render(bootinfo = bootinfo, version = get_version(), - script_tag = script_tag, style_tag = style_tag, body_html=body_html % '') - -def html_snapshot(page): - """get html snapshot for search bot""" - from webnotes.widgets.page import get_page_html - from webnotes.model.doc import Document - - doc = Document('Website Settings', 'Website Settings') - doc.content = get_page_html(page) - doc.header_menu = doc.footer_menu = '' - doc.page_name = page - - for m in webnotes.conn.sql("""select parentfield, label, url, custom_page - from `tabTop Bar Item` where parent='Top Bar Settings' order by idx""", as_dict=1): - - m['std_page'] = m.get('url') or m.get('custom_page') - - if m['parentfield']=='top_bar_items': - doc.header_menu += '
  • %(label)s
  • ' % m - else: - doc.footer_menu += '
  • %(label)s
  • ' % m - - return """ -
    -

    %(brand_html)s

    -
      - %(header_menu)s -
    -
    - %(content)s - - """ % doc.fields - - diff --git a/py/webnotes/cms/make.py b/py/webnotes/cms/make.py new file mode 100644 index 0000000000..c90795f57f --- /dev/null +++ b/py/webnotes/cms/make.py @@ -0,0 +1,45 @@ +""" +make index, wn.js, wn.css pages +- rebuild all pages on change of website settings (toolbar) +""" +def make(version): + import os + import webnotes + from webnotes.model.code import get_obj + from jinja2 import Template + from webnotes.cms import page_name, get_home_page + + webnotes.connect() + + # get web home + home_page = get_home_page('Guest') + + page = get_obj('Page', home_page) + + os.chdir('public') + + page.write_cms_page(home_page=True) + + # script - wn.js + import startup.event_handlers + if hasattr(startup.event_handlers, 'get_web_script'): + with open('js/wn-web.js', 'w') as f: + + script = 'window._version_number = "%s";\n' % version + script += 'window.home_page = "%s";\n' % home_page + + script += startup.event_handlers.get_web_script() + + f.write(script) + + # style - wn.css + if hasattr(startup.event_handlers, 'get_web_style'): + with open('css/wn-web.css', 'w') as f: + f.write(startup.event_handlers.get_web_style()) + + # make app.html + with open('../lib/conf/app.html', 'r') as app_template: + with open('app.html', 'w') as app: + app.write(Template(app_template.read()).render(version=version)) + + diff --git a/py/webnotes/profile.py b/py/webnotes/profile.py index eb7de9970a..324d0ddc61 100644 --- a/py/webnotes/profile.py +++ b/py/webnotes/profile.py @@ -131,19 +131,6 @@ class Profile: self.can_read += self.can_write self.all_read += self.can_read - def get_home_page(self): - """ - Get the name of the user's home page from the `Control Panel` - """ - hpl = webnotes.conn.sql("""select home_page from `tabDefault Home Page` - where parent='Control Panel' - and role in ('%s') order by idx asc limit 1""" % "', '".join(self.get_roles())) - - if hpl: - return hpl[0][0] - else: - return webnotes.conn.get_value('Control Panel',None,'home_page') or 'Login Page' - def get_defaults(self): """ Get the user's default values based on user and role profile