added my account
This commit is contained in:
parent
1755b36ba3
commit
a75efa76f9
@ -1,35 +1,67 @@
|
|||||||
|
|
||||||
var erpnext = {};
|
var erpnext = {};
|
||||||
|
var wn = {};
|
||||||
|
|
||||||
// Add / update a new Lead / Communication
|
// Add / update a new Lead / Communication
|
||||||
// subject, sender, description
|
// subject, sender, description
|
||||||
erpnext.send_message = function(opts) {
|
erpnext.send_message = function(opts) {
|
||||||
|
wn.call({
|
||||||
|
type: "POST",
|
||||||
|
method: "website.helpers.contact.send_message",
|
||||||
|
args: opts,
|
||||||
|
callback: opts.callback
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
wn.call = function(opts) {
|
||||||
if(opts.btn) {
|
if(opts.btn) {
|
||||||
|
var $spinner = $('<img src="lib/images/ui/button-load.gif">').appendTo($(opts.btn).parent())
|
||||||
$(opts.btn).attr("disabled", "disabled");
|
$(opts.btn).attr("disabled", "disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(opts.msg) {
|
||||||
|
$(opts.msg).toggle(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "server.py",
|
url: "server.py",
|
||||||
data: {
|
data: opts.args,
|
||||||
cmd: "website.helpers.contact.send_message",
|
|
||||||
subject: opts.subject,
|
|
||||||
sender: opts.sender,
|
|
||||||
status: opts.status,
|
|
||||||
_type: "POST",
|
|
||||||
message: typeof opts.message == "string"
|
|
||||||
? opts.message
|
|
||||||
: JSON.stringify(opts.message)
|
|
||||||
},
|
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if(opts.btn) {
|
if(opts.btn) {
|
||||||
$(opts.btn).attr("disabled", false);
|
$(opts.btn).attr("disabled", false);
|
||||||
|
$spinner.remove();
|
||||||
|
}
|
||||||
|
if(data.exc) {
|
||||||
|
console.log(data.exc);
|
||||||
|
}
|
||||||
|
if(opts.msg && data.message) {
|
||||||
|
$(opts.msg).html(data.message).toggle(true);
|
||||||
}
|
}
|
||||||
if(opts.callback)
|
if(opts.callback)
|
||||||
opts.callback(data);
|
opts.callback(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the user tools
|
// Setup the user tools
|
||||||
@ -37,11 +69,8 @@ erpnext.send_message = function(opts) {
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// update login
|
// update login
|
||||||
var full_name = getCookie("full_name");
|
var full_name = getCookie("full_name");
|
||||||
if(full_name && full_name.substr(0,1)=='"') {
|
|
||||||
full_name = full_name.substr(1, full_name.length-2);
|
|
||||||
}
|
|
||||||
if(full_name) {
|
if(full_name) {
|
||||||
$("#user-tools").html(repl('<a href="account" title="My Account">%(full_name)s</a> | \
|
$("#user-tools").html(repl('<a href="account" title="My Account" id="user-full-name">%(full_name)s</a> | \
|
||||||
<a href="cart" title="Shopping Cart"><i class="icon-shopping-cart"></i> (%(count)s)</a> | \
|
<a href="cart" title="Shopping Cart"><i class="icon-shopping-cart"></i> (%(count)s)</a> | \
|
||||||
<a href="server.py?cmd=web_logout" title="Sign Out"><i class="icon-signout"></i></a>', {
|
<a href="server.py?cmd=web_logout" title="Sign Out"><i class="icon-signout"></i></a>', {
|
||||||
full_name: full_name,
|
full_name: full_name,
|
||||||
@ -79,49 +108,52 @@ function repl(s, dict) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
return getCookies()[name];
|
return getCookies()[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCookies() {
|
function getCookies() {
|
||||||
var c = document.cookie, v = 0, cookies = {};
|
var c = document.cookie, v = 0, cookies = {};
|
||||||
if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
|
if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
|
||||||
c = RegExp.$1;
|
c = RegExp.$1;
|
||||||
v = 1;
|
v = 1;
|
||||||
}
|
}
|
||||||
if (v === 0) {
|
if (v === 0) {
|
||||||
c.split(/[,;]/).map(function(cookie) {
|
c.split(/[,;]/).map(function(cookie) {
|
||||||
var parts = cookie.split(/=/, 2),
|
var parts = cookie.split(/=/, 2),
|
||||||
name = decodeURIComponent(parts[0].trimLeft()),
|
name = decodeURIComponent(parts[0].trimLeft()),
|
||||||
value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
|
value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
|
||||||
cookies[name] = value;
|
if(value.charAt(0)==='"') {
|
||||||
});
|
value = value.substr(1, value.length-2);
|
||||||
} 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) {
|
cookies[name] = value;
|
||||||
var name = $0,
|
});
|
||||||
value = $1.charAt(0) === '"'
|
} else {
|
||||||
? $1.substr(1, -1).replace(/\\(.)/g, "$1")
|
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) {
|
||||||
: $1;
|
var name = $0,
|
||||||
cookies[name] = value;
|
value = $1.charAt(0) === '"'
|
||||||
});
|
? $1.substr(1, -1).replace(/\\(.)/g, "$1")
|
||||||
}
|
: $1;
|
||||||
return cookies;
|
cookies[name] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof String.prototype.trimLeft !== "function") {
|
if (typeof String.prototype.trimLeft !== "function") {
|
||||||
String.prototype.trimLeft = function() {
|
String.prototype.trimLeft = function() {
|
||||||
return this.replace(/^\s+/, "");
|
return this.replace(/^\s+/, "");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (typeof String.prototype.trimRight !== "function") {
|
if (typeof String.prototype.trimRight !== "function") {
|
||||||
String.prototype.trimRight = function() {
|
String.prototype.trimRight = function() {
|
||||||
return this.replace(/\s+$/, "");
|
return this.replace(/\s+$/, "");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (typeof Array.prototype.map !== "function") {
|
if (typeof Array.prototype.map !== "function") {
|
||||||
Array.prototype.map = function(callback, thisArg) {
|
Array.prototype.map = function(callback, thisArg) {
|
||||||
for (var i=0, n=this.length, a=[]; i<n; i++) {
|
for (var i=0, n=this.length, a=[]; i<n; i++) {
|
||||||
if (i in this) a[i] = callback.call(thisArg, this[i]);
|
if (i in this) a[i] = callback.call(thisArg, this[i]);
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ class DocType:
|
|||||||
|
|
||||||
self.doc.at_import = ""
|
self.doc.at_import = ""
|
||||||
for f in fonts:
|
for f in fonts:
|
||||||
self.doc.at_import += "\n@import url(http://fonts.googleapis.com/css?family=%s:400,700);" % f.replace(" ", "+")
|
self.doc.at_import += "\n@import url(https://fonts.googleapis.com/css?family=%s:400,700);" % f.replace(" ", "+")
|
||||||
|
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
|
23
website/helpers/account.py
Normal file
23
website/helpers/account.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
|
||||||
|
# License: GNU General Public License (v3). For more information see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import webnotes
|
||||||
|
from webnotes.utils import cstr
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def get_orders():
|
||||||
|
# find customer id
|
||||||
|
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
|
||||||
|
"customer")
|
||||||
|
|
||||||
|
if customer:
|
||||||
|
orders = webnotes.conn.sql("""select name, creation, currency from `tabSales Order`
|
||||||
|
where customer=%s""", customer, as_dict=1)
|
||||||
|
for order in orders:
|
||||||
|
order.items = webnotes.conn.sql("""select item_name, qty, export_rate, delivered_qty
|
||||||
|
from `tabSales Order Item` where parent=%s order by idx""", order.name, as_dict=1)
|
||||||
|
return orders
|
||||||
|
else:
|
||||||
|
return []
|
65
website/templates/pages/account.html
Normal file
65
website/templates/pages/account.html
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
{% extends "html/page.html" %}
|
||||||
|
|
||||||
|
{% set title="My Account" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="span12">
|
||||||
|
<p class="pull-right"><a href="profile">Change my name, password</a></p>
|
||||||
|
<h3>My Orders</h3>
|
||||||
|
<div id="order-list">
|
||||||
|
<div class="progress progress-striped active">
|
||||||
|
<div class="bar" style="width: 100%;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<h3>My Tickets</h3>
|
||||||
|
<div id="ticket-list">
|
||||||
|
<div class="progress progress-striped active">
|
||||||
|
<div class="bar" style="width: 100%;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var order_start = 0,
|
||||||
|
ticket_start = 0;
|
||||||
|
|
||||||
|
wn.call({
|
||||||
|
method: "website.helpers.account.get_orders",
|
||||||
|
args: {
|
||||||
|
start: order_start
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
$("#order-list .progress").remove();
|
||||||
|
var $list = $("#order-list");
|
||||||
|
|
||||||
|
if(!(r.message && r.message.length)) {
|
||||||
|
$list.html("<div class='alert'>No Orders Yet</div>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.each(r.message, function(i, order) {
|
||||||
|
|
||||||
|
// parent
|
||||||
|
var $order = $(repl('<div class="row">\
|
||||||
|
<div class="span4"><a href="order?id=%(name)s">%(name)s</a></span3>\
|
||||||
|
</div>', order)).appendTo($list);
|
||||||
|
|
||||||
|
// items
|
||||||
|
$.each(order.items || [], function(i, item) {
|
||||||
|
var $item = $(repl('<div class="span8">\
|
||||||
|
<div class="row">\
|
||||||
|
<div class="span4">%(item_name)s</div>\
|
||||||
|
<div class="span2">%(export_rate)s</div>\
|
||||||
|
<div class="span2">%(status)s</div>\
|
||||||
|
</div>\
|
||||||
|
</div>', item)).appendTo($order);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("<hr>").appendTo($order);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
51
website/templates/pages/profile.html
Normal file
51
website/templates/pages/profile.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{% extends "html/page.html" %}
|
||||||
|
|
||||||
|
{% set title="My Profile" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="span9">
|
||||||
|
<h2>My Profile</h2>
|
||||||
|
<hr>
|
||||||
|
<div class="alert" id="message" style="display: none;"></div>
|
||||||
|
<form class="form-horizontal">
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label" for="fullname">Full Name</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" id="fullname" placeholder="Your Name">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label" for="password">Password</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="password" id="password" placeholder="Password">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<button id="update_profile" type="submit" class="btn">Update</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$("#fullname").val(getCookie("full_name") || "");
|
||||||
|
$("#update_profile").click(function() {
|
||||||
|
wn.call({
|
||||||
|
method: "core.doctype.profile.profile.update_profile",
|
||||||
|
type: "POST",
|
||||||
|
args: {
|
||||||
|
fullname: $("#fullname").val(),
|
||||||
|
password: $("#password").val()
|
||||||
|
},
|
||||||
|
btn: this,
|
||||||
|
msg: $("#message"),
|
||||||
|
callback: function(r) {
|
||||||
|
if(!r.exc) $("#user-full-name").html($("#fullname").val());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user