added my account
diff --git a/public/js/website_utils.js b/public/js/website_utils.js
index 48124df..65f7a69 100644
--- a/public/js/website_utils.js
+++ b/public/js/website_utils.js
@@ -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(opts.callback)
+ 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 @@
$(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,
@@ -79,49 +108,52 @@
}
function getCookie(name) {
- return getCookies()[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;
- 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;
+ 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.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+/, "");
- };
+ String.prototype.trimLeft = function() {
+ return this.replace(/^\s+/, "");
+ };
}
if (typeof String.prototype.trimRight !== "function") {
- String.prototype.trimRight = function() {
- return this.replace(/\s+$/, "");
- };
+ 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;
- };
+ 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;
+ };
}
diff --git a/website/doctype/style_settings/style_settings.py b/website/doctype/style_settings/style_settings.py
index 1cc3467..71478a4 100644
--- a/website/doctype/style_settings/style_settings.py
+++ b/website/doctype/style_settings/style_settings.py
@@ -89,7 +89,7 @@
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):
diff --git a/website/helpers/account.py b/website/helpers/account.py
new file mode 100644
index 0000000..2bab370
--- /dev/null
+++ b/website/helpers/account.py
@@ -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 []
\ No newline at end of file
diff --git a/website/templates/pages/account.html b/website/templates/pages/account.html
new file mode 100644
index 0000000..9724651
--- /dev/null
+++ b/website/templates/pages/account.html
@@ -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 %}
\ No newline at end of file
diff --git a/website/templates/pages/profile.html b/website/templates/pages/profile.html
new file mode 100644
index 0000000..d0d4059
--- /dev/null
+++ b/website/templates/pages/profile.html
@@ -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 %}