[website] [minor] moving to framework

This commit is contained in:
Anand Doshi 2013-09-11 15:31:58 +05:30
parent 21a63c41b7
commit 1be588ca5f
33 changed files with 277 additions and 39 deletions

View file

@ -27,7 +27,8 @@
{
"public/js/all-web.min.js": [
"lib/public/js/lib/bootstrap.min.js",
"lib/public/js/wn/misc/number_format.js"
"lib/public/js/wn/misc/number_format.js",
"lib/website/js/website.js"
]
},

View file

@ -185,7 +185,7 @@ def get_website_settings():
t['child_items'] = []
t['child_items'].append(d)
break
context = webnotes._dict({
'top_bar_items': top_items,
'footer_items': webnotes.conn.sql("""\
@ -193,7 +193,10 @@ def get_website_settings():
where parent='Website Settings' and parentfield='footer_items'
order by idx asc""", as_dict=1),
"webnotes": webnotes,
"utils": webnotes.utils
"utils": webnotes.utils,
"post_login": [
{"label": "Logout", "url": "server.py?cmd=web_logout", "icon": "icon-signout"},
]
})
settings = webnotes.doc("Website Settings", "Website Settings")
@ -216,7 +219,7 @@ def get_website_settings():
try:
import startup.webutils
if hasattr(startup.webutils, "get_website_settings"):
context.update(startup.webutils.get_website_settings())
startup.webutils.get_website_settings(context)
except:
pass
return context

View file

@ -131,16 +131,34 @@ div.web-footer {
margin-left: -10px;
}
.hidden-sm-inline {
.hidden-xs-inline, .hidden-xs-inline-block {
display: none;
}
@media (min-width: 768px) {
.hidden-sm-inline {
.hidden-xs-inline {
display: inline;
}
.hidden-xs-inline-block {
display: inline-block;
}
}
.visible-xs-inline {
display: inline;
}
.visible-xs-inline-block {
display: inline-block;
}
@media (min-width: 768px) {
.visible-xs-inline, .visible-xs-inline-block {
display: none;
}
}
.panel-heading,
.panel-body {
padding-left: 15px;

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals
"""

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
cur_frm.cscript.refresh = function(doc) {
if(!doc.__islocal && doc.published && !doc.email_sent) {

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
// js inside blog page

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
$(document).ready(function() {

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
cur_frm.cscript.onload_post_render = function() {

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals
import webnotes

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals
import webnotes

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
$.extend(cur_frm.cscript, {
layout: function(doc) {

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals
import webnotes

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
import os
import webnotes

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
// update parent select

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals
import webnotes

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt
// MIT License. See license.txt
cur_frm.cscript.refresh = function(doc) {
cur_frm.set_intro("");

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

View file

@ -1,5 +1,5 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
# MIT License. See license.txt
# For license information, please see license.txt

191
website/js/website.js Normal file
View file

@ -0,0 +1,191 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// MIT License. See license.txt
if(!window.wn) wn = {};
wn.call = function(opts) {
if(opts.btn) {
$(opts.btn).prop("disabled", true);
}
if(opts.msg) {
$(opts.msg).toggle(false);
}
if(!opts.args) opts.args = {};
// get or post?
if(!opts.args._type) {
opts.args._type = opts.type || "GET";
}
// method
if(opts.method) {
opts.args.cmd = opts.method;
}
// stringify
$.each(opts.args, function(key, val) {
if(typeof val != "string") {
opts.args[key] = JSON.stringify(val);
}
});
$.ajax({
type: "POST",
url: "server.py",
data: opts.args,
dataType: "json",
success: function(data) {
if(opts.btn) {
$(opts.btn).prop("disabled", false);
}
if(data.exc) {
if(opts.btn) {
$(opts.btn).addClass("btn-danger");
setTimeout(function() { $(opts.btn).removeClass("btn-danger"); }, 1000);
}
try {
var err = JSON.parse(data.exc);
if($.isArray(err)) {
err = err.join("\n");
}
console.error ? console.error(err) : console.log(err);
} catch(e) {
console.log(data.exc);
}
} else{
if(opts.btn) {
$(opts.btn).addClass("btn-success");
setTimeout(function() { $(opts.btn).removeClass("btn-success"); }, 1000);
}
}
if(opts.msg && data.message) {
$(opts.msg).html(data.message).toggle(true);
}
if(opts.callback)
opts.callback(data);
},
error: function(response) {
console.error ? console.error(response) : console.log(response);
}
});
return false;
}
// Utility functions
function valid_email(id) {
if(id.toLowerCase().search("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")==-1)
return 0; else return 1; }
var validate_email = valid_email;
function get_url_arg(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if(results == null)
return "";
else
return decodeURIComponent(results[1]);
}
function make_query_string(obj) {
var query_params = [];
$.each(obj, function(k, v) { query_params.push(encodeURIComponent(k) + "=" + encodeURIComponent(v)); });
return "?" + query_params.join("&");
}
function repl(s, dict) {
if(s==null)return '';
for(key in dict) {
s = s.split("%("+key+")s").join(dict[key]);
}
return s;
}
function replace_all(s, t1, t2) {
return s.split(t1).join(t2);
}
function getCookie(name) {
return getCookies()[name];
}
function getCookies() {
var c = document.cookie, v = 0, cookies = {};
if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
c = RegExp.$1;
v = 1;
}
if (v === 0) {
c.split(/[,;]/).map(function(cookie) {
var parts = cookie.split(/=/, 2),
name = decodeURIComponent(parts[0].trimLeft()),
value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
if(value && value.charAt(0)==='"') {
value = value.substr(1, value.length-2);
}
cookies[name] = value;
});
} else {
c.match(/(?:^|\s+)([!#$%&'*+\-.0-9A-Z^`a-z|~]+)=([!#$%&'*+\-.0-9A-Z^`a-z|~]*|"(?:[\x20-\x7E\x80\xFF]|\\[\x00-\x7F])*")(?=\s*[,;]|$)/g).map(function($0, $1) {
var name = $0,
value = $1.charAt(0) === '"'
? $1.substr(1, -1).replace(/\\(.)/g, "$1")
: $1;
cookies[name] = value;
});
}
return cookies;
}
if (typeof String.prototype.trimLeft !== "function") {
String.prototype.trimLeft = function() {
return this.replace(/^\s+/, "");
};
}
if (typeof String.prototype.trimRight !== "function") {
String.prototype.trimRight = function() {
return this.replace(/\s+$/, "");
};
}
if (typeof Array.prototype.map !== "function") {
Array.prototype.map = function(callback, thisArg) {
for (var i=0, n=this.length, a=[]; i<n; i++) {
if (i in this) a[i] = callback.call(thisArg, this[i]);
}
return a;
};
}
function remove_script_and_style(txt) {
return (!txt || (txt.indexOf("<script>")===-1 && txt.indexOf("<style>")===-1)) ? txt :
$("<div></div>").html(txt).find("script,noscript,style,title,meta").remove().end().html();
}
function is_html(txt) {
if(txt.indexOf("<br>")==-1 && txt.indexOf("<p")==-1
&& txt.indexOf("<img")==-1 && txt.indexOf("<div")==-1) {
return false;
}
return true;
}
function ask_to_login() {
if(!full_name) {
if(localStorage) {
localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
}
window.location.href = "login";
}
}
// check if logged in?
$(document).ready(function() {
window.full_name = getCookie("full_name");
$("#website-login").toggleClass("hide", full_name ? true : false);
$("#website-post-login").toggleClass("hide", full_name ? false : true);
});

View file

@ -1,5 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt"
// MIT License. See license.txt"
wn.module_page["Website"] = [
{

View file

@ -24,7 +24,6 @@
<body>
{% block navbar %}{% include "lib/website/templates/includes/navbar.html" %}{% endblock %}
<div class="container">
{% block toolbar %}{% endblock %}
{% block banner %}{% endblock %}
<div class="content" id="page-{{ name }}" style="display: block;">
{% block content %}{% endblock %}

View file

@ -22,9 +22,7 @@
{% endif %}
</div>
{% endif %}
{% block powered %}<p style="float: right; clear: right;">
<a style="font-size: 90%; color: #888;" href="http://getwebnotes.org">Built on Web Notes</a>
</p>{% endblock %}
<p style="float: right; clear: right;" id="website-login"><a href="login">Login</a></p>
<div class="web-footer-menu">
<ul>
{% for item in footer_items %}
@ -36,6 +34,12 @@
{% if copyright %}<div class="web-footer-copyright">&copy; {{ copyright }}</div>{% endif %}
{% if footer_address %}{{ footer_address }}{% endif %}
{% block extension %}{% endblock %}
<p style="float: right; clear: both; margin: 15px auto;">
{% block powered %}
<a style="font-size: 90%; color: #aaa;" href="http://getwebnotes.org">Built on Web Notes</a>
{% endblock %}
</p>
</div>
</div>
</div>

View file

@ -10,19 +10,20 @@
<a class="navbar-brand" href="index">{{ brand_html or "<i class='icon-home'></i>"}}</a>
</div>
<div class="collapse navbar-collapse navbar-responsive-collapse">
<ul class="nav navbar-nav">
<ul class="nav navbar-nav navbar-left">
{%- for page in top_bar_items -%}
{% if not page.parent_label -%}
<li data-label="{{ page.label }}" {% if page.child_items %} class="dropdown"{% endif %}>
<a href="{{ page.url or '#' }}" {% if page.child_items %} class="dropdown-toggle" onclick="return false;" data-toggle="dropdown"{% endif %} {{ page.target or ''}}>
{{ page.label }}
{%- if page.child_items -%}
<b class="caret"></b>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{%- for child in page.child_items -%}
<li data-label="{{ child.label }}">
<a {% if child.indent %} style="padding-left: {{(int(child.indent)+1)*15 }}px"{% endif %} href="{{ child.url }}" {{ child.target or '' }}>{{ child.label }}</a>
<a {% if child.indent %} style="padding-left: {{((child.indent|int)+1)*15 }}px"{% endif %}
href="{{ child.url }}" {{ child.target or '' }}>{{ child.label }}</a>
</li>
{%- endfor -%}
</ul>
@ -33,6 +34,27 @@
{%- endif -%}
{%- endfor %}
</ul>
<ul class="nav navbar-nav navbar-right">
<!-- post login tools -->
<li id="website-post-login" data-label="website-post-login" class="dropdown">
<a href="#" class="dropdown-toggle" onclick="return false;" data-toggle="dropdown">
<i class="icon-cog"></i><span class="visible-xs-inline"><span class="caret"></span></span>
</a>
<ul class="dropdown-menu">
{%- for child in post_login -%}
<li data-label="{{ child.label }}" {% if child.class %}class="{{ child.class }}"{% endif %}>
{% if child.url -%}
<a {% if child.indent -%}style="padding-left: {{((child.indent|int)+1)*15 }}px"{%- endif %}
href="{{ child.url }}" {{ child.target or '' }}>
{% if child.icon %}<i class="icon-fixed-width {{ child.icon }}"></i> {% endif %}
{{ child.label }}
</a>
{%- endif %}
</li>
{%- endfor -%}
</ul>
</li>
</ul>
</div>
</div>
</div>