mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
synced timestamps
This commit is contained in:
0
home/page/dashboard/__init__.py
Normal file
0
home/page/dashboard/__init__.py
Normal file
12
home/page/dashboard/dashboard.css
Normal file
12
home/page/dashboard/dashboard.css
Normal file
@@ -0,0 +1,12 @@
|
||||
div.dashboard_table td {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
div.dashboard-title {
|
||||
font-weight: bold;
|
||||
padding: '3px 0px';
|
||||
}
|
||||
|
||||
div.dashboard-graph {
|
||||
height: 180px;
|
||||
}
|
||||
8
home/page/dashboard/dashboard.html
Normal file
8
home/page/dashboard/dashboard.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="layout_wrapper dashboard">
|
||||
<div class="header"></div>
|
||||
<div class="body">
|
||||
<!-- 4x2 table to show the dashboards-->
|
||||
<div class="help_box">Loading...</div>
|
||||
<div class="dashboard_table"></div>
|
||||
</div>
|
||||
</div>
|
||||
142
home/page/dashboard/dashboard.js
Normal file
142
home/page/dashboard/dashboard.js
Normal file
@@ -0,0 +1,142 @@
|
||||
pscript.onload_dashboard = function() {
|
||||
// load jqplot
|
||||
$.scriptPath = 'js/'
|
||||
$.require(['jquery/jquery.jqplot.min.js',
|
||||
'jquery/jqplot-plugins/jqplot.barRenderer.js',
|
||||
'jquery/jqplot-plugins/jqplot.canvasAxisTickRenderer.min.js',
|
||||
'jquery/jqplot-plugins/jqplot.canvasTextRenderer.min.js',
|
||||
'jquery/jqplot-plugins/jqplot.categoryAxisRenderer.min.js']);
|
||||
|
||||
|
||||
pscript.dashboard_settings = {
|
||||
company: sys_defaults.company,
|
||||
start: dateutil.obj_to_str(dateutil.add_days(new Date(), -180)),
|
||||
end: dateutil.obj_to_str(new Date()),
|
||||
interval: 30
|
||||
}
|
||||
|
||||
var ph = new PageHeader($('.dashboard .header').get(0), 'Dashboard');
|
||||
var db = new Dashboard();
|
||||
|
||||
ph.add_button('Settings', db.show_settings);
|
||||
|
||||
db.refresh();
|
||||
|
||||
}
|
||||
|
||||
Dashboard = function() {
|
||||
var me = this;
|
||||
$.extend(me, {
|
||||
refresh: function() {
|
||||
$('.dashboard .help_box').css('display', 'block');
|
||||
$c_page('home', 'dashboard', 'load_dashboard', JSON.stringify(pscript.dashboard_settings), function(r,rt) {
|
||||
$('.dashboard .help_box').css('display', 'none');
|
||||
me.render(r.message);
|
||||
})
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
$('.dashboard_table').html('');
|
||||
var t = make_table($('.dashboard_table').get(0), 4, 2, '100%', ['50%', '50%'], {padding: '5px'});
|
||||
var ridx=0; var cidx=0;
|
||||
for(var i=0; i< data.length; i++) {
|
||||
// switch columns and rows
|
||||
if(cidx==2) { cidx=0; ridx++}
|
||||
|
||||
// give an id!
|
||||
var cell = $td(t,ridx,cidx);
|
||||
var title = $a(cell, 'div', 'dashboard-title', '', data[i][0].title);
|
||||
var parent = $a(cell, 'div', 'dashboard-graph');
|
||||
if(data[i][0].comment);
|
||||
var comment = $a(cell, 'div', 'comment', '', data[i][0].comment)
|
||||
|
||||
parent.id = '_dashboard' + ridx + '-' + cidx;
|
||||
|
||||
// render graph
|
||||
me.render_graph(parent.id, data[i][1], data[i][0].fillColor);
|
||||
cidx++;
|
||||
}
|
||||
},
|
||||
|
||||
render_graph: function(parent, values, fillColor) {
|
||||
var vl = [];
|
||||
$.each(values, function(i,v) {
|
||||
vl.push([dateutil.str_to_user(v[0]), v[1]]);
|
||||
});
|
||||
$.jqplot(parent, [vl], {
|
||||
seriesDefaults:{
|
||||
renderer:$.jqplot.BarRenderer,
|
||||
rendererOptions: {fillToZero: true},
|
||||
},
|
||||
axes: {
|
||||
// Use a category axis on the x axis and use our custom ticks.
|
||||
xaxis: {
|
||||
min: 0,
|
||||
renderer: $.jqplot.CategoryAxisRenderer,
|
||||
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
|
||||
tickOptions: {
|
||||
angle: -30,
|
||||
fontSize: '8pt'
|
||||
}
|
||||
},
|
||||
// Pad the y axis just a little so bars can get close to, but
|
||||
// not touch, the grid boundaries. 1.2 is the default padding.
|
||||
yaxis: {
|
||||
min: 0,
|
||||
pad: 1.05,
|
||||
tickOptions: {formatString: '%d'}
|
||||
}
|
||||
},
|
||||
seriesColors: [fillColor]
|
||||
});
|
||||
},
|
||||
|
||||
show_settings: function() {
|
||||
var d = new wn.widgets.Dialog({
|
||||
title: 'Set Company Settings',
|
||||
width: 500,
|
||||
fields: [
|
||||
{
|
||||
label:'Company',
|
||||
reqd: 1,
|
||||
fieldname:'company',
|
||||
fieldtype:'Link',
|
||||
options: 'Company'
|
||||
},
|
||||
{
|
||||
label:'Start Date',
|
||||
reqd: 1,
|
||||
fieldname:'start',
|
||||
fieldtype:'Date',
|
||||
},
|
||||
{
|
||||
label:'End Date',
|
||||
reqd: 1,
|
||||
fieldname:'end',
|
||||
fieldtype:'Date',
|
||||
},
|
||||
{
|
||||
label:'Interval',
|
||||
reqd: 1,
|
||||
fieldname:'interval',
|
||||
fieldtype:'Int'
|
||||
},
|
||||
{
|
||||
label:'Regenerate',
|
||||
fieldname:'refresh',
|
||||
fieldtype:'Button'
|
||||
}
|
||||
]
|
||||
});
|
||||
d.onshow = function() {
|
||||
d.set_values(pscript.dashboard_settings);
|
||||
}
|
||||
d.fields_dict.refresh.input.onclick = function() {
|
||||
pscript.dashboard_settings = d.get_values();
|
||||
me.refresh();
|
||||
d.hide();
|
||||
}
|
||||
d.show();
|
||||
}
|
||||
})
|
||||
}
|
||||
260
home/page/dashboard/dashboard.py
Normal file
260
home/page/dashboard/dashboard.py
Normal file
@@ -0,0 +1,260 @@
|
||||
dashboards = [
|
||||
{
|
||||
'type': 'account',
|
||||
'account': 'Income',
|
||||
'title': 'Income',
|
||||
'fillColor': '#90EE90'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'account',
|
||||
'account': 'Expenses',
|
||||
'title': 'Expenses',
|
||||
'fillColor': '#90EE90'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'receivables',
|
||||
'title': 'Receivables',
|
||||
'fillColor': '#FFE4B5'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'payables',
|
||||
'title': 'Payables',
|
||||
'fillColor': '#FFE4B5'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'collection',
|
||||
'title': 'Collection',
|
||||
'comment':'This info comes from the accounts your have marked as "Bank or Cash"',
|
||||
'fillColor': '#DDA0DD'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'payments',
|
||||
'title': 'Payments',
|
||||
'comment':'This info comes from the accounts your have marked as "Bank or Cash"',
|
||||
'fillColor': '#DDA0DD'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'creation',
|
||||
'doctype': 'Quotation',
|
||||
'title': 'New Quotations',
|
||||
'fillColor': '#ADD8E6'
|
||||
},
|
||||
|
||||
{
|
||||
'type': 'creation',
|
||||
'doctype': 'Sales Order',
|
||||
'title': 'New Orders',
|
||||
'fillColor': '#ADD8E6'
|
||||
}
|
||||
]
|
||||
|
||||
class DashboardWidget:
|
||||
def __init__(self, company, start, end, interval):
|
||||
from webnotes.utils import getdate
|
||||
from webnotes.model.code import get_obj
|
||||
import webnotes
|
||||
|
||||
self.company = company
|
||||
self.abbr = webnotes.conn.get_value('Company', company, 'abbr')
|
||||
self.start = getdate(start)
|
||||
self.end = getdate(end)
|
||||
|
||||
self.interval = interval
|
||||
|
||||
self.glc = get_obj('GL Control')
|
||||
self.cash_accounts = [d[0] for d in webnotes.conn.sql("""
|
||||
select name from tabAccount
|
||||
where account_type='Bank or Cash'
|
||||
and company = %s and docstatus = 0
|
||||
""", company)]
|
||||
|
||||
self.receivables_group = webnotes.conn.get_value('Company', company,'receivables_group')
|
||||
self.payables_group = webnotes.conn.get_value('Company', company,'payables_group')
|
||||
|
||||
# list of bank and cash accounts
|
||||
self.bc_list = [s[0] for s in webnotes.conn.sql("select name from tabAccount where account_type='Bank or Cash'")]
|
||||
|
||||
|
||||
def timeline(self):
|
||||
"""
|
||||
get the timeline for the dashboard
|
||||
"""
|
||||
import webnotes
|
||||
from webnotes.utils import add_days
|
||||
tl = []
|
||||
|
||||
if self.start > self.end:
|
||||
webnotes.msgprint("Start must be before end", raise_exception=1)
|
||||
|
||||
curr = self.start
|
||||
tl.append(curr)
|
||||
|
||||
while curr < self.end:
|
||||
curr = add_days(curr, self.interval, 'date')
|
||||
tl.append(curr)
|
||||
|
||||
tl.append(self.end)
|
||||
|
||||
return tl
|
||||
|
||||
def generate(self, opts):
|
||||
"""
|
||||
Generate the dasboard
|
||||
"""
|
||||
from webnotes.utils import flt
|
||||
tl = self.timeline()
|
||||
self.out = []
|
||||
|
||||
for i in range(len(tl)-1):
|
||||
self.out.append([tl[i+1].strftime('%Y-%m-%d'), flt(self.value(opts, tl[i], tl[i+1])) or 0])
|
||||
|
||||
return self.out
|
||||
|
||||
def get_account_balance(self, acc, start):
|
||||
"""
|
||||
Get as on account balance
|
||||
"""
|
||||
import webnotes
|
||||
# add abbreviation to company
|
||||
|
||||
if not acc.endswith(self.abbr):
|
||||
acc += ' - ' + self.abbr
|
||||
|
||||
# get other reqd parameters
|
||||
try:
|
||||
globals().update(webnotes.conn.sql('select debit_or_credit, lft, rgt from tabAccount where name=%s', acc, as_dict=1)[0])
|
||||
except Exception,e:
|
||||
webnotes.msgprint('Wrongly defined account: ' + acc)
|
||||
print acc
|
||||
raise e
|
||||
|
||||
return self.glc.get_as_on_balance(acc, self.get_fiscal_year(start), start, debit_or_credit, lft, rgt)
|
||||
|
||||
def get_fiscal_year(self, dt):
|
||||
"""
|
||||
get fiscal year from date
|
||||
"""
|
||||
import webnotes
|
||||
return webnotes.conn.sql("""
|
||||
select name from `tabFiscal Year`
|
||||
where year_start_date <= %s and
|
||||
DATE_ADD(year_start_date, INTERVAL 1 YEAR) >= %s
|
||||
""", (dt, dt))[0][0]
|
||||
|
||||
def get_creation_trend(self, doctype, start, end):
|
||||
"""
|
||||
Get creation # of creations in period
|
||||
"""
|
||||
import webnotes
|
||||
return int(webnotes.conn.sql("""
|
||||
select count(*) from `tab%s` where creation between %s and %s and docstatus=1
|
||||
""" % (doctype, '%s','%s'), (start, end))[0][0])
|
||||
|
||||
def get_account_amt(self, acc, start, end, debit_or_credit):
|
||||
"""
|
||||
Get debit, credit over a period
|
||||
"""
|
||||
import webnotes
|
||||
# add abbreviation to company
|
||||
|
||||
if not acc.endswith(self.abbr):
|
||||
acc += ' - ' + self.abbr
|
||||
|
||||
ret = webnotes.conn.sql("""
|
||||
select ifnull(sum(ifnull(t1.debit,0)),0), ifnull(sum(ifnull(t1.credit,0)),0)
|
||||
from `tabGL Entry` t1, tabAccount t2
|
||||
where t1.account = t2.name
|
||||
and t2.is_pl_account = 'Yes'
|
||||
and t2.debit_or_credit=%s
|
||||
and ifnull(t1.is_cancelled, 'No')='No'
|
||||
and t1.posting_date between %s and %s
|
||||
""", (debit_or_credit, start, end))[0]
|
||||
|
||||
return debit_or_credit=='Credit' and float(ret[1]-ret[0]) or float(ret[0]-ret[1])
|
||||
|
||||
def get_bank_amt(self, debit_or_credit, master_type, start, end):
|
||||
"""
|
||||
Get collection (reduction in receivables over a period)
|
||||
"""
|
||||
import webnotes
|
||||
|
||||
reg = '('+'|'.join(self.bc_list) + ')'
|
||||
|
||||
return webnotes.conn.sql("""
|
||||
select sum(t1.%s)
|
||||
from `tabGL Entry` t1, tabAccount t2
|
||||
where t1.account = t2.name
|
||||
and t2.master_type='%s'
|
||||
and t1.%s > 0
|
||||
and t1.against REGEXP '%s'
|
||||
and ifnull(t1.is_cancelled, 'No')='No'
|
||||
and t1.posting_date between '%s' and '%s'
|
||||
""" % (debit_or_credit, master_type, debit_or_credit, reg, start, end))[0][0]
|
||||
|
||||
|
||||
def value(self, opts, start, end):
|
||||
"""
|
||||
Value of the series on a particular date
|
||||
"""
|
||||
import webnotes
|
||||
if opts['type']=='account':
|
||||
debit_or_credit = 'Debit'
|
||||
if opts['account']=='Income':
|
||||
debit_or_credit = 'Credit'
|
||||
|
||||
return self.get_account_amt(opts['account'], start, end, debit_or_credit)
|
||||
|
||||
elif opts['type']=='receivables':
|
||||
return self.get_account_balance(self.receivables_group, end)[2]
|
||||
|
||||
elif opts['type']=='payables':
|
||||
return self.get_account_balance(self.payables_group, end)[2]
|
||||
|
||||
elif opts['type']=='collection':
|
||||
return self.get_bank_amt('credit', 'Customer', start, end)
|
||||
|
||||
elif opts['type']=='payments':
|
||||
return self.get_bank_amt('debit', 'Supplier', start, end)
|
||||
|
||||
elif opts['type']=='creation':
|
||||
return self.get_creation_trend(opts['doctype'], start, end)
|
||||
|
||||
|
||||
def load_dashboard(args):
|
||||
"""
|
||||
Get dashboard based on
|
||||
1. Company (default company)
|
||||
2. Start Date (last 3 months)
|
||||
3. End Date (today)
|
||||
4. Interval (7 days)
|
||||
"""
|
||||
dl = []
|
||||
import json
|
||||
args = json.loads(args)
|
||||
dw = DashboardWidget(args['company'], args['start'], args['end'], int(args['interval']))
|
||||
|
||||
# render the dashboards
|
||||
for d in dashboards:
|
||||
dl.append([d, dw.generate(d)])
|
||||
|
||||
return dl
|
||||
|
||||
if __name__=='__main__':
|
||||
import sys
|
||||
sys.path.append('/var/www/webnotes/wnframework/cgi-bin')
|
||||
from webnotes.db import Database
|
||||
import webnotes
|
||||
webnotes.conn = Database(use_default=1)
|
||||
webnotes.session = {'user':'Administrator'}
|
||||
print load_dashboard("""{
|
||||
"company": "My Test",
|
||||
"start": "2011-05-01",
|
||||
"end": "2011-08-01",
|
||||
"interval": "7"
|
||||
}""")
|
||||
49
home/page/dashboard/dashboard.txt
Normal file
49
home/page/dashboard/dashboard.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
# Page, dashboard
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2011-08-25 16:22:44',
|
||||
'docstatus': 0,
|
||||
'modified': '2011-08-25 16:22:54',
|
||||
'modified_by': 'Administrator',
|
||||
'owner': 'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Page
|
||||
{
|
||||
'category': 'Standard',
|
||||
'doctype': 'Page',
|
||||
'module': 'Home',
|
||||
'name': '__common__',
|
||||
'page_name': 'Dashboard',
|
||||
'standard': 'Yes'
|
||||
},
|
||||
|
||||
# These values are common for all Page Role
|
||||
{
|
||||
'doctype': 'Page Role',
|
||||
'name': '__common__',
|
||||
'parent': 'dashboard',
|
||||
'parentfield': 'roles',
|
||||
'parenttype': 'Page'
|
||||
},
|
||||
|
||||
# Page, dashboard
|
||||
{
|
||||
'doctype': 'Page',
|
||||
'name': 'dashboard'
|
||||
},
|
||||
|
||||
# Page Role
|
||||
{
|
||||
'doctype': 'Page Role',
|
||||
'role': 'System Manager'
|
||||
},
|
||||
|
||||
# Page Role
|
||||
{
|
||||
'doctype': 'Page Role',
|
||||
'role': 'Accounts Manager'
|
||||
}
|
||||
]
|
||||
@@ -25,12 +25,7 @@ pscript.home_make_body = function() {
|
||||
|
||||
wrapper.banner_area = $a(wrapper.head, 'div');
|
||||
|
||||
wrapper.setup_wizard_area = $a(wrapper.body, 'div', 'setup-wizard')
|
||||
|
||||
wrapper.system_message_area = $a(wrapper.body, 'div', '',
|
||||
{marginBottom:'16px', padding:'8px', backgroundColor:'#FFD', border:'1px dashed #AA6', display:'none'})
|
||||
|
||||
|
||||
wrapper.setup_wizard_area = $a(wrapper.body, 'div', 'setup-wizard');
|
||||
}
|
||||
|
||||
// ==================================
|
||||
@@ -436,8 +431,8 @@ FeedList.prototype.make_head = function() {
|
||||
// head
|
||||
|
||||
$a(this.head,'h1','', {display:'inline'}, 'Home');
|
||||
$a(this.head,'span','link_type', {marginLeft:'7px'}, '[?]', function() {
|
||||
msgprint('<b>What appears here?</b> This is where you get updates of everything you are allowed to access and generates an update')
|
||||
$a(this.head,'span','link_type', {marginLeft:'7px'}, 'help', function() {
|
||||
msgprint('<b>What appears here?</b> This is where you get updates of everything you are permitted to follow')
|
||||
})
|
||||
|
||||
// refresh
|
||||
@@ -445,6 +440,11 @@ FeedList.prototype.make_head = function() {
|
||||
{cursor:'pointer', marginLeft:'7px', fontSize:'11px'}, 'refresh',
|
||||
function() { me.run(); }
|
||||
);
|
||||
|
||||
if(has_common(user_roles, ['System Manager','Accounts Manager'])) {
|
||||
$btn(this.head, 'Dashboard', function() {loadpage('dashboard'); }, {marginLeft:'7px'})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
FeedList.prototype.run = function() {
|
||||
@@ -594,14 +594,15 @@ HomeStatusBar = function() {
|
||||
|
||||
this.render = function(r) {
|
||||
this.wrapper.innerHTML = '';
|
||||
this.span = $a(this.wrapper, 'span', 'home-status-link')
|
||||
this.span = $a(this.wrapper, 'span', 'link_type', {fontWeight:'bold'});
|
||||
this.span.onclick = function() { loadpage('My Company') }
|
||||
|
||||
if(r.unread_messages) {
|
||||
this.span.innerHTML = '<span class="home-status-unread">' + r.unread_messages + '</span> unread message' + (cint(r.unread_messages) > 1 ? 's' : '');
|
||||
this.span.innerHTML = '<span class="home-status-unread">' + r.unread_messages + '</span> unread';
|
||||
} else {
|
||||
this.span.innerHTML = 'No unread messages.';
|
||||
this.span.innerHTML = 'Team / Messages';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,11 +614,7 @@ pscript.home_make_status = function() {
|
||||
$c_page('home', 'event_updates', 'get_status_details', user,
|
||||
function(r,rt) {
|
||||
home_status_bar.render(r.message);
|
||||
|
||||
// system_messages
|
||||
if(r.message.system_message)
|
||||
pscript.show_system_message(wrapper, r.message.system_message);
|
||||
|
||||
|
||||
// render online users
|
||||
pscript.online_users_obj.render(r.message.online_users);
|
||||
pscript.online_users = r.message.online_users;
|
||||
@@ -630,24 +627,6 @@ pscript.home_make_status = function() {
|
||||
);
|
||||
}
|
||||
|
||||
// show system message
|
||||
// -------------------
|
||||
pscript.show_system_message = function(wrapper, msg) {
|
||||
$ds(wrapper.system_message_area);
|
||||
var txt = $a(wrapper.system_message_area, 'div', '', {lineHeight:'1.6em'});
|
||||
txt.innerHTML = msg;
|
||||
|
||||
var span = $ln($a(wrapper.system_message_area, 'div', '', {textAlign:'right'}), 'Dismiss'.bold(),
|
||||
function(me) {
|
||||
me.set_working();
|
||||
$c_obj('Home Control', 'dismiss_message', '', function(r,rt) {
|
||||
me.done_working();
|
||||
$(wrapper.system_message_area).slideUp();
|
||||
});
|
||||
}, {fontSize:'11px'}
|
||||
)
|
||||
}
|
||||
|
||||
// complete my company registration
|
||||
// --------------------------------
|
||||
pscript.complete_registration = function()
|
||||
|
||||
@@ -28,18 +28,11 @@ def get_status_details(arg=None):
|
||||
|
||||
online = get_online_users()
|
||||
|
||||
# system messages
|
||||
msg_id = webnotes.conn.get_global('system_message_id')
|
||||
msg = ''
|
||||
|
||||
if msg_id and msg_id != webnotes.conn.get_global('system_message_id', webnotes.session['user']):
|
||||
msg = webnotes.conn.get_global('system_message')
|
||||
|
||||
# system messages
|
||||
ret = {
|
||||
'user_count': len(online) or 0,
|
||||
'unread_messages': get_unread_messages(),
|
||||
'online_users': online or [],
|
||||
'system_message':msg,
|
||||
'is_trial': webnotes.conn.get_global('is_trial'),
|
||||
'days_to_expiry': (webnotes.conn.get_global('days_to_expiry') or '0'),
|
||||
'setup_status': get_setup_status()
|
||||
@@ -56,7 +49,20 @@ def get_setup_status():
|
||||
percent = 20
|
||||
ret = []
|
||||
|
||||
if not webnotes.conn.get_value('Personalize', None, 'header_html'):
|
||||
def is_header_set():
|
||||
header = webnotes.conn.get_value('Control Panel', None, 'client_name') or ''
|
||||
|
||||
if header.startswith('<div style="padding:4px; font-size:20px;">'\
|
||||
+webnotes.conn.get_value('Control Panel', None, 'company_name')):
|
||||
return False
|
||||
|
||||
elif 'Banner Comes Here' in header:
|
||||
return False
|
||||
|
||||
else:
|
||||
return True
|
||||
|
||||
if not is_header_set():
|
||||
ret.append('<a href="#!Form/Personalize/Personalize">Upload your company banner</a>')
|
||||
else:
|
||||
percent += 20
|
||||
|
||||
@@ -134,24 +134,28 @@ MemberList.prototype.make_search = function() {
|
||||
MemberList.prototype.make_list = function() {
|
||||
var me = this;
|
||||
this.lst_area = $a(this.list_wrapper, 'div');
|
||||
this.lst = new Listing('Profiles',1);
|
||||
this.lst.colwidths = ['100%'];
|
||||
this.lst.opts.cell_style = {padding:'0px'}
|
||||
this.lst.get_query = function() {
|
||||
var c1 = '';
|
||||
if(me.search_inp.value && me.search_inp.value != 'Search') {
|
||||
var c1 = repl(' AND (first_name LIKE "%(txt)s" OR last_name LIKE "%(txt)s" OR name LIKE "%(txt)s")', {txt:'%' + me.search_inp.value + '%'});
|
||||
|
||||
this.lst = new wn.widgets.Listing({
|
||||
parent: this.lst_area,
|
||||
as_dict: 1,
|
||||
get_query: function() {
|
||||
var c1 = '';
|
||||
if(me.search_inp.value && me.search_inp.value != 'Search') {
|
||||
var c1 = repl(' AND (first_name LIKE "%(txt)s" OR last_name LIKE "%(txt)s" OR name LIKE "%(txt)s")', {txt:'%' + me.search_inp.value + '%'});
|
||||
}
|
||||
|
||||
return repl("SELECT name, \
|
||||
ifnull(concat_ws(' ', first_name, last_name),'') as full_name, \
|
||||
gender, file_list, enabled \
|
||||
FROM tabProfile \
|
||||
WHERE docstatus != 2 \
|
||||
AND name not in ('Guest','Administrator') %(cond)s \
|
||||
ORDER BY name asc",{cond:c1});
|
||||
},
|
||||
render_row: function(parent, data) {
|
||||
me.member_items[data.name] = new MemberItem(parent, data, me);
|
||||
}
|
||||
|
||||
this.query = repl("SELECT distinct ifnull(name,''), ifnull(concat_ws(' ', first_name, last_name),''), \
|
||||
ifnull(messanger_status,''), ifnull(gender,''), ifnull(file_list,''), 0, enabled, last_login \
|
||||
from tabProfile where docstatus != 2 AND name not in ('Guest','Administrator') %(cond)s \
|
||||
ORDER BY name asc",{cond:c1});
|
||||
}
|
||||
this.lst.make(this.lst_area);
|
||||
this.lst.show_cell= function(cell, ri, ci, d) {
|
||||
me.member_items[d[ri][0]] = new MemberItem(cell, d[ri], me);
|
||||
}
|
||||
});
|
||||
this.lst.run();
|
||||
}
|
||||
|
||||
@@ -186,14 +190,14 @@ MemberItem = function(parent, det, mlist) {
|
||||
var me = this;
|
||||
this.det = det;
|
||||
this.wrapper = $a(parent, 'div');
|
||||
this.enabled = det[6];
|
||||
this.enabled = det.enabled;
|
||||
|
||||
this.tab = make_table(this.wrapper, 1,2,'100%', ['20%', '70%'], {padding:'4px', overflow:'hidden'});
|
||||
$y(this.tab, {tableLayout:'fixed', borderCollapse:'collapse'})
|
||||
|
||||
this.is_online = function() {
|
||||
for(var i=0;i<pscript.online_users.length;i++) {
|
||||
if(det[0]==pscript.online_users[i][0]) return true;
|
||||
if(det.name==pscript.online_users[i][0]) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,30 +214,30 @@ MemberItem = function(parent, det, mlist) {
|
||||
this.set_image = function() {
|
||||
// image
|
||||
this.img = $a($td(this.tab,0,0),'img','',{width:'41px'});
|
||||
set_user_img(this.img, det[0], null,
|
||||
(det[4] ? det[4].split(NEWLINE)[0].split(',')[1] : ('no_img_' + (det[3]=='Female' ? 'f' : 'm'))));
|
||||
set_user_img(this.img, det.name, null,
|
||||
(det.file_list ? det.file_list.split(NEWLINE)[0].split(',')[1] : ('no_img_' + (det.gender=='Female' ? 'f' : 'm'))));
|
||||
}
|
||||
|
||||
// set other details like email id, name etc
|
||||
this.set_details = function() {
|
||||
// name
|
||||
this.fullname = det[1] ? det[1] : det[0];
|
||||
this.fullname = det.full_name || det.name;
|
||||
var div = $a($td(this.tab, 0, 1), 'div', '', {fontWeight: 'bold',padding:'2px 0px'});
|
||||
this.name_link = $a(div,'span','link_type');
|
||||
this.name_link.innerHTML = crop(this.fullname, 15);
|
||||
this.name_link.onclick = function() {
|
||||
mlist.show_profile(me.det[0], me);
|
||||
mlist.show_profile(me.det.name, me);
|
||||
}
|
||||
|
||||
// "you" tag
|
||||
if(user==det[0]) {
|
||||
if(user==det.name) {
|
||||
var span = $a(div,'span','',{padding:'2px' ,marginLeft:'3px'});
|
||||
span.innerHTML = '(You)'
|
||||
}
|
||||
|
||||
// email id
|
||||
var div = $a($td(this.tab, 0, 1), 'div', '', {color: '#777', fontSize:'11px'});
|
||||
div.innerHTML = det[0];
|
||||
div.innerHTML = det.name;
|
||||
|
||||
// working img
|
||||
var div = $a($td(this.tab, 0, 1), 'div');
|
||||
@@ -256,7 +260,7 @@ MemberItem = function(parent, det, mlist) {
|
||||
this.set_details();
|
||||
|
||||
// show initial
|
||||
if(user==det[0]) me.name_link.onclick();
|
||||
if(user==det.name) me.name_link.onclick();
|
||||
}
|
||||
|
||||
|
||||
@@ -305,6 +309,7 @@ MemberProfile = function(parent, uid, member_item) {
|
||||
if(has_common(['Administrator','System Manager'],user_roles)) {
|
||||
var roles_btn = $btn(this.toolbar_area, 'Set Roles', function() { me.show_roles() },{marginRight:'3px'});
|
||||
var delete_btn = $btn(this.toolbar_area, 'Delete User', function() { me.delete_user(); },{marginRight:'3px'});
|
||||
var ip_btn = $btn(this.toolbar_area, 'Securty Settings', function() { me.set_security(); },{marginRight:'3px'});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +320,74 @@ MemberProfile = function(parent, uid, member_item) {
|
||||
this.role_object.dialog.show();
|
||||
}
|
||||
|
||||
// show securty settings
|
||||
this.set_security = function() {
|
||||
var d = new wn.widgets.Dialog({
|
||||
title: 'Set User Security',
|
||||
width: 500,
|
||||
fields: [
|
||||
{
|
||||
label:'IP Address',
|
||||
description: 'Restrict user login by IP address, partial ips (111.111.111), \
|
||||
multiple addresses (separated by commas) allowed',
|
||||
fieldname:'restrict_ip',
|
||||
fieldtype:'Data'
|
||||
},
|
||||
|
||||
{
|
||||
label:'Login After',
|
||||
description: 'User can only login after this hour (0-24)',
|
||||
fieldtype: 'Int',
|
||||
fieldname: 'login_after'
|
||||
},
|
||||
|
||||
{
|
||||
label:'Login Before',
|
||||
description: 'User can only login before this hour (0-24)',
|
||||
fieldtype: 'Int',
|
||||
fieldname: 'login_before'
|
||||
},
|
||||
|
||||
{
|
||||
label:'New Password',
|
||||
description: 'Update the current user password',
|
||||
fieldtype: 'Data',
|
||||
fieldname: 'new_password'
|
||||
},
|
||||
|
||||
{
|
||||
label:'Update',
|
||||
fieldtype:'Button',
|
||||
fieldname:'update'
|
||||
}
|
||||
]
|
||||
});
|
||||
d.onshow = function() {
|
||||
d.set_values({
|
||||
restrict_ip: me.profile.restrict_ip || '',
|
||||
login_before: me.profile.login_before || '',
|
||||
login_after: me.profile.login_after || '',
|
||||
new_password: ''
|
||||
})
|
||||
}
|
||||
d.fields_dict.update.input.onclick = function() {
|
||||
var btn = this;
|
||||
this.set_working();
|
||||
var args = d.get_values();
|
||||
args.user = me.profile.name;
|
||||
$c_page('home', 'my_company', 'update_security', JSON.stringify(args), function(r,rt) {
|
||||
if(r.exc) {
|
||||
msgprint(r.exc);
|
||||
btn.done_working();
|
||||
return;
|
||||
}
|
||||
$.extend(me.profile, d.get_values());
|
||||
d.hide();
|
||||
});
|
||||
}
|
||||
d.show();
|
||||
}
|
||||
|
||||
// delete user
|
||||
// create a confirm dialog and call server method
|
||||
this.delete_user = function() {
|
||||
@@ -534,6 +607,7 @@ MemberConversation = function(parent, uid, fullname) {
|
||||
|
||||
this.lst = new wn.widgets.Listing({
|
||||
parent: this.lst_area,
|
||||
as_dict: 1,
|
||||
no_result_message: (user==uid
|
||||
? 'No messages by anyone yet'
|
||||
: 'No messages yet. To start a conversation post a new message'),
|
||||
@@ -577,18 +651,18 @@ MemberCoversationComment = function(cell, det, conv) {
|
||||
this.wrapper = $a(cell, 'div', 'my-company-comment-wrapper');
|
||||
this.comment = $a(this.wrapper, 'div', 'my-company-comment');
|
||||
|
||||
this.user = $a(this.comment, 'span', 'link_type', {fontWeight:'bold'}, pscript.get_fullname(det[1]));
|
||||
this.user = $a(this.comment, 'span', 'link_type', {fontWeight:'bold'}, pscript.get_fullname(det.owner));
|
||||
this.user.onclick = function() {
|
||||
page_body.pages['My Company'].member_list.show_profile(me.det[1]);
|
||||
page_body.pages['My Company'].member_list.show_profile(me.det.owner);
|
||||
}
|
||||
|
||||
var st = (!det[4] ? {fontWeight: 'bold'} : null);
|
||||
this.msg = $a(this.comment, 'span', 'social', st, ': ' + det[0]);
|
||||
var st = (!det.docstatus ? {fontWeight: 'bold'} : null);
|
||||
this.msg = $a(this.comment, 'span', 'social', st, ': ' + det.comment);
|
||||
|
||||
if(det[1]==user) {
|
||||
if(det.full_name==user) {
|
||||
$y(this.wrapper, {backgroundColor: '#D9D9F3'});
|
||||
}
|
||||
this.timestamp = $a(this.wrapper, 'div', 'my-company-timestamp', '', comment_when(det[3]));
|
||||
this.timestamp = $a(this.wrapper, 'div', 'my-company-timestamp', '', comment_when(det.creation));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -129,3 +129,19 @@ def set_read_all_messages(arg=''):
|
||||
WHERE comment_doctype = 'My Company'
|
||||
AND comment_docname = %s
|
||||
""", webnotes.user.name)
|
||||
|
||||
def update_security(args=''):
|
||||
import json
|
||||
args = json.loads(args)
|
||||
webnotes.conn.set_value('Profile', args['user'], 'restrict_ip', args.get('restrict_ip'))
|
||||
webnotes.conn.set_value('Profile', args['user'], 'login_after', args.get('login_after'))
|
||||
webnotes.conn.set_value('Profile', args['user'], 'login_before', args.get('login_before'))
|
||||
|
||||
if 'new_password' in args:
|
||||
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
|
||||
import server_tools.gateway_utils
|
||||
webnotes.msgprint(server_tools.gateway_utils.change_password('', args['new_password'])['message'])
|
||||
else:
|
||||
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
|
||||
|
||||
webnotes.msgprint('Settings Updated')
|
||||
@@ -16,7 +16,7 @@ def change_password(arg):
|
||||
webnotes.msgprint('Old password is not correct', raise_exception=1)
|
||||
|
||||
from webnotes.utils import nowdate
|
||||
webnotes.conn.sql("update tabProfile set password=password(%s), password_last_updated=%s where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
|
||||
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
|
||||
webnotes.msgprint('Password Updated');
|
||||
|
||||
def get_user_details(arg=None):
|
||||
@@ -56,4 +56,4 @@ def set_user_image(arg=None):
|
||||
fa.save()
|
||||
|
||||
uh.set_callback('window.parent.upload_callback("%s", "%s")' \
|
||||
% (webnotes.form_dict['uploader_id'], fa.get_fid(0)))
|
||||
% (webnotes.form_dict['uploader_id'], fa.get_fid(0)))
|
||||
|
||||
Reference in New Issue
Block a user