[website] [cleanup] added website pages to framework

This commit is contained in:
Rushabh Mehta 2013-04-03 16:36:53 +05:30
parent 3211552c06
commit 158d6b3d28
11 changed files with 359 additions and 34 deletions

View file

@ -1,12 +1,5 @@
{
"modules": {
"Activity": {
"type": "page",
"link": "activity",
"color": "#633501",
"icon": "icon-play",
"label": "Activity"
},
"To Do": {
"type": "page",
"link": "todo",
@ -28,5 +21,29 @@
"label": "Messages",
"icon": "icon-comments"
}
},
"web": {
"pages": {
"404": {
"template": "lib/templates/pages/404"
},
"error": {
"no_cache": true,
"template": "lib/templates/pages/error"
},
"login": {
"template": "lib/templates/pages/login"
},
"message": {
"no_cache": true,
"template": "lib/templates/pages/message"
},
"print": {
"no_cache": true,
"template": "lib/templates/pages/print",
"args_method": "core.doctype.print_format.print_format.get_args"
}
},
"generators": {}
}
}

25
templates/base.html Normal file
View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<meta name="generator" content="wnframework">
<script type="text/javascript" src="lib/js/lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="js/all-web.min.js"></script>
<script type="text/javascript" src="js/wn-web.js"></script>
<link type="text/css" rel="stylesheet" href="css/all-web.css">
<link type="text/css" rel="stylesheet" href="css/wn-web.css">
<link rel="shortcut icon" href="{{ favicon }}" type="image/x-icon">
<link rel="icon" href="{{ favicon }}" type="image/x-icon">
{% if description -%}
<meta name="description" content="{{ description }}">
{%- endif %}
{% block header -%}
{%- endblock %}
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>

43
templates/css/login.css Normal file
View file

@ -0,0 +1,43 @@
<style>
#login_wrapper {
width: 300px;
margin: 70px auto;
}
#login_wrapper,
#login_wrapper h3 {
color: #333;
}
#login_wrapper a {
color: #0088cc;
}
.layout-wrapper {
background-color: #fff;
padding: 10px;
box-shadow: 1px 1px 3px 3px #ccc;
font-size: 12px;
min-height: 100px;
border-radius: 5px;
}
#login_wrapper h3 {
text-align: center;
}
.login-banner {
margin-bottom: 20px;
}
.login-box td {
padding: 8px;
}
.login-box td input {
margin-bottom: 0px;
}
.login-footer {
text-align: center;
padding: 15px;
}
</style>

97
templates/js/login.js Normal file
View file

@ -0,0 +1,97 @@
var login = {};
$(document).ready(function(wrapper) {
$('#login_btn').click(login.do_login)
$('#password').keypress(function(ev){
if(ev.which==13 && $('#password').val()) {
$('form').submit(function() {
login.do_login();
return false;
});
}
});
$(document).trigger('login_rendered');
})
// Login
login.do_login = function(){
var args = {};
if(window.is_sign_up) {
args.cmd = "core.doctype.profile.profile.sign_up";
args.email = $("#login_id").val();
args.full_name = $("#full_name").val();
if(!args.email || !valid_email(args.email) || !args.full_name) {
login.set_message("Valid email and name required.");
return false;
}
} else if(window.is_forgot) {
args.cmd = "reset_password";
args.user = $("#login_id").val();
if(!args.user) {
login.set_message("Valid Login Id required.");
return false;
}
} else {
args.cmd = "login"
args.usr = $("#login_id").val();
args.pwd = $("#password").val();
if(!args.usr || !args.pwd) {
login.set_message("Both login and password required.");
return false;
}
}
$('#login_btn').attr("disabled", "disabled");
$("#login-spinner").toggle(true);
$('#login_message').toggle(false);
$.ajax({
type: "POST",
url: "server.py",
data: args,
dataType: "json",
success: function(data) {
$("input").val("");
$("#login-spinner").toggle(false);
$('#login_btn').attr("disabled", false);
if(data.message=="Logged In") {
window.location.href = "app.html";
} else if(data.message=="No App") {
window.location.href = "index";
} else {
login.set_message(data.message);
}
}
})
return false;
}
login.sign_up = function() {
$("#login_wrapper h3").html("Sign Up");
$("#login-label").html("Email Id");
$("#password-row, #sign-up-wrapper, #login_message").toggle(false);
$("#full-name-row").toggle(true);
$("#login_btn").html("Register");
$("#forgot-wrapper").html("<a onclick='location.reload()' href='#'>Login</a>")
window.is_sign_up = true;
}
login.show_forgot_password = function() {
$("#login_wrapper h3").html("Forgot");
$("#login-label").html("Email Id");
$("#password-row, #sign-up-wrapper, #login_message").toggle(false);
$("#login_btn").html("Send Password");
$("#forgot-wrapper").html("<a onclick='location.reload()' href='#'>Login</a>")
window.is_forgot = true;
}
login.set_message = function(message, color) {
$('#login_message').html(message).toggle(true);
}

14
templates/pages/404.html Normal file
View file

@ -0,0 +1,14 @@
{% extends "app/website/templates/html/outer.html" %}
{% set title="Not Found" %}
{% block content %}
<div class="content">
<div class="layout-wrapper layout-main">
<h3><i class="icon-exclamation-sign"></i> Page missing or moved</h3>
<br>
<p>We are very sorry for this, but the page you are looking for is missing
(this could be because of a typo in the address) or moved.</p>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,13 @@
{% extends "lib/templates/base.html" %}
{% set title="Error" %}
{% block body %}
<div class="container">
<div class="outer well">
<h3><i class="icon-exclamation-sign"></i> Oops, a server error has occured</h3>
<br>
<pre>%(error)s</pre>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,62 @@
{% extends "lib/templates/base.html" %}
{% block header %}
<script>
{% include "lib/templates/js/login.js" %}
</script>
{% include "lib/templates/css/login.css" %}
{% endblock %}
{% set title="Login" %}
{% block body %}
<div class="container" id='login_wrapper'>
<div class='layout-wrapper layout-main'>
<p id="login_message" class="alert" style="display: none;"></p>
<h3><i class="icon-lock" style="margin-top: 7px"></i> Login</h3>
<form autocomplete="on">
<table border="0" class="login-box">
<tbody>
<tr>
<td style="text-align: right; padding: 3px;"
id="login-label">Login Id</td>
<td><input id="login_id" type="text" style="width: 180px"/></td>
</tr>
<tr id="password-row">
<td style="text-align: right; padding: 3px;" >Password</td>
<td><input id="password" type="password" style="width: 180px" /></td>
</tr>
<tr id="full-name-row" style="display: none;">
<td style="text-align: right; padding: 3px;">Full Name</td>
<td><input id="full_name" type="text" style="width: 180px" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<button type="submit" id="login_btn"
class="btn btn-small btn-primary">Login</button>
<img src="lib/images/ui/button-load.gif" id="login-spinner"
style="display: none;">
</td>
</tr>
</tbody>
</table>
</form>
<br>
<p style="text-align: center" id="forgot-wrapper">
<a id="forgot-password" style="cursor:pointer"
onclick="return login.show_forgot_password()">Forgot Password</a></p>
<p style="text-align: center" id="sign-up-wrapper">
New user? <a id="sign-up" style="cursor:pointer"
onclick="return login.sign_up()">Sign Up</a></p>
</div>
</div>
<div class="web-footer login-footer container">
<a href="index.html">Home</a> |
<a href="https://erpnext.com">ERPNext</a><br><br>
{% if copyright %}
<div class="web-footer-copyright">&copy; {{ copyright }}
{% endif %}
</div>
{% endblock %}

View file

@ -0,0 +1,11 @@
{% extends "lib/templates/base.html" %}
{% set title=webnotes.message_title %}
{% block block %}
<div class="container">
<div class="outer well">
{{ webnotes.message }}
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Print Format</title>
<meta name="generator" content="wnframework">
<style>
{{ css }}
</style>
</head>
<body>
{{ body }}
</body>
{%- if comment -%}
<!-- {{ comment }} -->
{%- endif -%}
</html>

View file

@ -401,17 +401,24 @@ def repsond_as_web_page(title, html):
response['type'] = 'page'
response['page_name'] = 'message.html'
_config = None
def get_config():
import webnotes.utils, json
global _config
if not _config:
import webnotes.utils, json
config = _dict({"modules": {}})
with open(webnotes.utils.get_path("lib", "config.json"), "r") as configf:
framework_config = json.loads(configf.read())
config.modules.update(framework_config["modules"])
_config = _dict({"modules": {}, "web": _dict({"pages": {}, "generators": {}})})
with open(webnotes.utils.get_path("lib", "config.json"), "r") as configf:
framework_config = json.loads(configf.read())
_config.modules.update(framework_config["modules"])
_config.web.pages.update(framework_config["web"]["pages"])
_config.web.generators.update(framework_config["web"]["generators"])
with open(webnotes.utils.get_path("app", "config.json"), "r") as configf:
app_config = json.loads(configf.read())
config.modules.update(app_config["modules"])
with open(webnotes.utils.get_path("app", "config.json"), "r") as configf:
app_config = json.loads(configf.read())
_config.modules.update(app_config["modules"])
_config.web.pages.update(app_config["web"]["pages"])
_config.web.generators.update(app_config["web"]["generators"])
return config
return _config

View file

@ -76,8 +76,8 @@ def update_page_name(doc, title):
"""set page_name and check if it is unique"""
webnotes.conn.set(doc, "page_name", page_name(title))
if doc.page_name in standard_pages:
webnotes.conn.sql("""Page Name cannot be one of %s""" % ', '.join(standard_pages))
if doc.page_name in get_standard_pages():
webnotes.conn.sql("""Page Name cannot be one of %s""" % ', '.join(get_standard_pages()))
res = webnotes.conn.sql("""\
select count(*) from `tab%s`
@ -103,26 +103,35 @@ def build_html(args):
args["len"] = len
jenv = Environment(loader = FileSystemLoader(get_templates_path()))
html = jenv.get_template(args['template']).render(args)
jenv = Environment(loader = FileSystemLoader(webnotes.utils.get_base_path()))
template_name = args['template']
if not template_name.endswith(".html"):
template_name = template_name + ".html"
html = jenv.get_template(template_name).render(args)
return html
def get_standard_pages():
return webnotes.get_config()["web"]["pages"].keys()
def prepare_args(page_name):
if page_name == 'index':
page_name = get_home_page()
if page_name in standard_pages:
pages = get_page_settings()
if page_name in pages:
page_info = pages[page_name]
args = webnotes._dict({
'template': 'pages/%s.html' % page_name,
'template': page_info["template"],
'name': page_name,
})
if page_name in page_settings_map:
target = page_settings_map[page_name]
if "." in target:
args.update(webnotes.get_method(target)())
else:
args.obj = webnotes.bean(page_settings_map[page_name]).obj
# additional args
if "args_method" in page_info:
args.update(webnotes.get_method(page_info["args_method"])())
elif "args_doctype" in page_info:
args.obj = webnotes.bean(page_info["args_doctype"]).obj
else:
args = get_doc_fields(page_name)
@ -145,7 +154,7 @@ def get_doc_fields(page_name):
obj.prepare_template_args()
args = obj.doc.fields
args['template'] = page_map[doc_type].template
args['template'] = get_generators()[doc_type]["template"]
args['obj'] = obj
args['int'] = int
@ -153,10 +162,10 @@ def get_doc_fields(page_name):
def get_source_doc(page_name):
"""get source doc for the given page name"""
for doctype in page_map:
for doctype in get_generators():
name = webnotes.conn.sql("""select name from `tab%s` where
page_name=%s and ifnull(%s, 0)=1""" % (doctype, "%s",
page_map[doctype].condition_field), page_name)
get_generators()[doctype]["condition_field"]), page_name)
if name:
return doctype, name[0][0]
@ -171,9 +180,8 @@ def clear_cache(page_name=None):
cache.delete_value("page:" + p)
def get_all_pages():
all_pages = standard_pages
all_pages += page_settings_map.keys()
for doctype in page_map:
all_pages = get_standard_pages()
for doctype in get_generators():
all_pages += [p[0] for p in webnotes.conn.sql("""select distinct page_name
from `tab%s`""" % doctype) if p[0]]
@ -208,4 +216,14 @@ def get_hex_shade(color, percent):
percent = percent * 2
return p(r) + p(g) + p(b)
def get_standard_pages():
return webnotes.get_config()["web"]["pages"].keys()
def get_generators():
return webnotes.get_config()["web"]["generators"]
def get_page_settings():
return webnotes.get_config()["web"]["pages"]