added my account

This commit is contained in:
Rushabh Mehta 2013-03-19 17:59:49 +05:30
parent 1755b36ba3
commit a75efa76f9
5 changed files with 223 additions and 52 deletions

View File

@ -1,35 +1,67 @@
var erpnext = {};
var wn = {};
// Add / update a new Lead / Communication
// subject, sender, description
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) {
var $spinner = $('<img src="lib/images/ui/button-load.gif">').appendTo($(opts.btn).parent())
$(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({
type: "POST",
url: "server.py",
data: {
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)
},
data: opts.args,
dataType: "json",
success: function(data) {
if(opts.btn) {
$(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)
opts.callback(data);
}
});
return false;
}
// Setup the user tools
@ -37,11 +69,8 @@ erpnext.send_message = function(opts) {
$(document).ready(function() {
// update login
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) {
$("#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="server.py?cmd=web_logout" title="Sign Out"><i class="icon-signout"></i></a>', {
full_name: full_name,
@ -93,6 +122,9 @@ function getCookies() {
var parts = cookie.split(/=/, 2),
name = decodeURIComponent(parts[0].trimLeft()),
value = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;
if(value.charAt(0)==='"') {
value = value.substr(1, value.length-2);
}
cookies[name] = value;
});
} else {

View File

@ -89,7 +89,7 @@ class DocType:
self.doc.at_import = ""
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):

View 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 []

View 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 %}

View 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 %}