added home files

This commit is contained in:
Rushabh Mehta
2011-06-13 13:23:49 +05:30
parent 46e7b6bd4b
commit 1c59fba480
88 changed files with 3968 additions and 0 deletions

BIN
home/page/.DS_Store vendored Normal file

Binary file not shown.

0
home/page/__init__.py Normal file
View File

BIN
home/page/event_updates/.DS_Store vendored Normal file

Binary file not shown.

View File

View File

@@ -0,0 +1,17 @@
div.home-status {
margin: 7px;
padding: 5px;
color: #666;
}
span.home-status-link {
cursor: pointer;
text-decoration: underline;
}
span.home-status-unread {
padding: 2px 3px;
font-size: 11px;
color: #FFF;
background-color: RED;
}

View File

@@ -0,0 +1 @@
<div id="updates_div"></div>

View File

@@ -0,0 +1,748 @@
pscript['onload_Event Updates'] = function() {
if(user=='Guest') {
loadpage('Login Page');
return;
}
pscript.home_make_body();
pscript.home_make_status();
pscript.home_pre_process();
pscript.home_make_widgets();
}
// ==================================
pscript.home_make_body = function() {
var wrapper = page_body.pages['Event Updates'];
// body
wrapper.main_tab = make_table(wrapper,1,2,'100%',['70%','30%']);
$y(wrapper.main_tab, {tableLayout:'fixed'});
wrapper.body = $a($td(wrapper.main_tab, 0, 0), 'div', 'layout_wrapper');
wrapper.head = $a(wrapper.body, 'div');
wrapper.banner_area = $a(wrapper.head, 'div');
wrapper.toolbar_area = $a(wrapper.head, 'div');
wrapper.system_message_area = $a(wrapper.body, 'div', '',
{marginBottom:'16px', padding:'8px', backgroundColor:'#FFD', border:'1px dashed #AA6', display:'none'})
}
// ==================================
pscript.home_pre_process = function(wrapper) {
var wrapper = page_body.pages['Event Updates'];
var cp = locals['Control Panel']['Control Panel'];
// banner
if(cp.client_name) {
var banner = $a(wrapper.banner_area, 'div', '', {paddingBottom:'4px'})
banner.innerHTML = cp.client_name;
}
// complete registration
if(in_list(user_roles,'System Manager')) { pscript.complete_registration(); }
}
// Widgets
// ==================================
pscript.home_make_widgets = function() {
var wrapper = page_body.pages['Event Updates'];
var cell = $td(wrapper.main_tab, 0, 1);
// sidebar
sidebar = new wn.widgets.PageSidebar(cell, {
sections:[
{
title: 'Calendar',
display: function() { return !has_common(user_roles, ['Guest','Customer','Vendor'])},
render: function(wrapper) {
new HomeCalendar(new HomeWidget(wrapper, 'Calendar', 'Event'), wrapper);
}
},
{
title: 'To Do',
display: function() { return !has_common(user_roles, ['Guest','Customer','Vendor'])},
render: function(wrapper) {
new HomeToDo(new HomeWidget(wrapper, 'To Do', 'Item'));
}
},
{
title: 'Online Users',
display: function() { return !has_common(user_roles, ['Guest','Customer','Vendor'])},
render: function(wrapper) {
pscript.online_users_obj = new OnlineUsers(wrapper);
}
}
]
})
sidebar.refresh()
/*$y(cell,{padding:'0px 8px'});
new HomeCalendar(new HomeWidget(cell, 'Calendar', 'Event'));
new HomeToDo(new HomeWidget(cell, 'To Do', 'Item'));*/
new FeedList(wrapper.body);
}
OnlineUsers = function(wrapper) {
var me = this;
this.wrapper = wrapper;
this.my_company_link = function() {
$a($a(wrapper, 'div', '', {marginBottom:'7px'}), 'span', 'link_type',
{color:'#777', 'color:hover':'#FFF', fontSize:'11px'},
'See all users', function() {loadpage('My Company'); });
}
this.render = function(online_users) {
me.my_company_link();
if(online_users.length) {
var max = online_users.length; max = (max > 10 ? 10 : max)
for(var i=0; i<max; i++) {
new OneOnlineUser(me.wrapper, online_users[i]);
}
} else {
$a(wrapper, 'div', '', {'color':'#888'}, 'No user online!')
}
}
}
OneOnlineUser = function(wrapper, det) {
var name = cstr(det[1]) + ' ' + cstr(det[2]);
if(det[1]==user) name = 'You'
var div = $a(wrapper, 'div', '', {padding:'3px 0px'});
$a(div, 'div', '', {width:'7px', height:'7px', cssFloat:'left', margin:'5px', backgroundColor:'green'});
$a(div, 'div', '', {marginLeft:'3px'}, name);
}
HomeWidget = function(parent, heading, item) {
var me = this; this.item = item;
this.wrapper = $a(parent, 'div');
// body
this.body = $a(this.wrapper,'div','',{paddingBottom:'16px'});
this.footer = $a(this.wrapper,'div');
// add button
this.add_btn = $btn(this.footer,'+ Add ' + item,function(){me.add()});
// refresh
this.refresh_btn = $ln(this.footer,'Refresh',function() { me.refresh(); },{fontSize:'11px',marginLeft:'7px',color:'#888'});
}
HomeWidget.prototype.refresh = function() {
var me = this;
$di(this.working_img);
var callback = function(r,rt) {
$dh(me.working_img);
me.body.innerHTML = '';
// prepare (for calendar?)
if(me.decorator.setup_body) me.decorator.setup_body();
for(var i=0;i<r.message.length;i++) {
new HomeWidgetItem(me, r.message[i]);
}
if(!r.message.length) {
$a(me.body,'div','',{color:'#777'}, me.no_items_message);
}
}
$c_obj('Home Control',this.get_list_method,'',callback);
}
HomeWidget.prototype.make_dialog = function() {
var me = this;
if(!this.dialog) {
this.dialog = new wn.widgets.Dialog();
this.dialog.make({
width: 480,
title: 'New ' + this.item,
fields:this.dialog_fields
});
this.dialog.fields_dict.save.input.onclick = function() {
this.set_working();
me.decorator.save(this);
}
}
}
HomeWidget.prototype.add = function() {
this.make_dialog();
this.decorator.clear_dialog();
this.dialog.show();
}
// Item
// --------
HomeWidgetItem = function(widget, det) {
var me = this; this.det = det; this.widget = widget;
this.widget = widget; this.det = det;
// parent
if(widget.decorator.get_item_parent) parent = widget.decorator.get_item_parent(det);
else parent = widget.body;
if(!parent) return;
// wrapper
this.wrapper = $a(parent, 'div');
this.tab = make_table(this.wrapper, 1, 3, '100%', ['90%', '5%', '5%'],{paddingRight:'4px'});
// buttons
this.edit_btn = $a($td(this.tab,0,1),'div','wn-icon ' + 'ic-doc_edit', {cursor:'pointer'});
this.edit_btn.onclick = function() { me.edit(); }
this.del_btn = $a($td(this.tab,0,2),'div','wn-icon ' + 'ic-trash', {cursor:'pointer'});
this.del_btn.onclick = function() { me.delete_item(); }
widget.decorator.render_item(this, det);
}
HomeWidgetItem.prototype.edit = function() {
this.widget.make_dialog();
this.widget.decorator.set_dialog_values(this.det);
this.widget.dialog.show();
}
HomeWidgetItem.prototype.delete_item = function() {
var me = this;
this.wrapper.innerHTML = '<span style="color:#888">Deleting...</span>';
var callback = function(r,rt) {
$(me.wrapper).slideUp();
}
$c_obj('Home Control',this.widget.delete_method, this.widget.get_item_id(this.det) ,callback);
}
// Calendar
// ===========================
HomeCalendar = function(widget, wrapper) {
// calendar link
$ln(widget.footer,'Full Calendar',function() { loadpage('_calendar'); },{marginLeft:'7px', fontSize:'11px', color:'#888'})
this.widget = widget;
// methods
this.widget.get_list_method = 'get_events_list'
this.widget.delete_method = 'delete_event';
this.widget.no_items_message = 'You have no events in the next 7 days';
this.widget.get_item_id = function(det) { return det.name; }
this.widget.decorator = this;
var hl = [];
for(var i=0; i<24; i++) {
hl.push(((i+8) % 24) + ':00');
}
this.widget.dialog_fields = [
{fieldtype:'Date', fieldname:'event_date', label:'Event Date', reqd:1},
{fieldtype:'Time', fieldname:'event_hour', label:'Event Time', reqd:1},
{fieldtype:'Text', fieldname:'description', label:'Description', reqd:1},
{fieldtype:'Button', fieldname:'save', label:'Save'}
];
this.widget.refresh();
}
// create calendar grid
// --------------------
HomeCalendar.prototype.setup_body = function() {
var w = this.widget;
w.date_blocks = {};
for(var i=0; i<7; i++) {
var dt = dateutil.obj_to_str(dateutil.add_days(new Date(),i));
var div = $a(w.body, 'div', '', {padding:'4px 0px', borderBottom:'1px solid #AAA',display:'none'});
div.head = $a(div, 'div', '', {fontWeight:'bold', paddingBottom:'4px'});
div.head.innerHTML = (i==0 ? 'Today' : (i==1 ? 'Tomorrow' : dateutil.str_to_user(dt)))
w.date_blocks[dt] = div;
}
}
HomeCalendar.prototype.get_item_parent = function(det) {
var d = this.widget.date_blocks[det.event_date]; $ds(d);
return d;
}
HomeCalendar.prototype.render_item = function(item, det) {
var tab = make_table($td(item.tab, 0, 0), 1, 2, '100%', ['48px', null], {padding:'2px', lineHeight:'1.5em'});
$y(tab, {tableLayout:'fixed'});
$td(tab, 0, 0).innerHTML = '<span style="color:#888">' + det.event_hour + ':</span> ';
$a($td(tab, 0, 1), 'span', 'social', {}, replace_newlines(det.description));
if(det.ref_type && det.ref_name && det.ref_name != 'None') {
var span=$a($a($td(tab, 0, 1),'div'),'span','link_type');
span.innerHTML = det.ref_name; span.dt = det.ref_type;
span.onclick = function() { loaddoc(this.dt, this.innerHTML); }
}
}
HomeCalendar.prototype.clear_dialog = function() {
this.set_dialog_values({event_date:get_today(), event_hour:'8:00', description:''});
}
HomeCalendar.prototype.set_dialog_values = function(det) {
var d = this.widget.dialog;
d.set_values(det);
d.det = det;
}
HomeCalendar.prototype.save = function(btn) {
var d = this.widget.dialog;
var me = this;
var det = d.get_values();
if(!det) {
btn.done_working();
return;
}
det.name = d.det.name;
det.owner = user;
if(!det.event_type)
det.event_type = 'Private';
var callback = function(r,rt) {
btn.done_working();
me.widget.dialog.hide();
me.widget.refresh();
}
$c_obj('Home Control','edit_event',JSON.stringify(det),callback);
}
// Todo
// ===========================
HomeToDo = function(widget) {
this.widget = widget;
// methods
this.widget.get_list_method = 'get_todo_list';
this.widget.delete_method = 'remove_todo_item';
this.widget.no_items_message = 'Nothing to do?';
this.widget.get_item_id = function(det) { return det[0]; }
this.widget.decorator = this;
this.widget.dialog_fields = [
{fieldtype:'Date', fieldname:'date', label:'Event Date', reqd:1},
{fieldtype:'Text', fieldname:'description', label:'Description', reqd:1},
{fieldtype:'Check', fieldname:'checked', label:'Completed'},
{fieldtype:'Select', fieldname:'priority', label:'Priority', reqd:1, 'options':['Medium','High','Low'].join('\n')},
{fieldtype:'Button', fieldname:'save', label:'Save'}
];
this.widget.refresh();
}
HomeToDo.prototype.render_item = function(item, det) {
// priority tag
var tab = make_table($td(item.tab, 0, 0), 1, 2, '100%', ['48px', null], {padding:'2px'});
$y(tab, {tableLayout:'fixed'});
var span = $a($td(tab, 0, 0), 'span', '', {padding:'2px',color:'#FFF',fontSize:'10px'
,backgroundColor:(det[3]=='Low' ? '#888' : (det[3]=='High' ? '#EDA857' : '#687FD3'))});
$(span).css('-moz-border-radius','3px').css('-webkit-border-radius','3px');
span.innerHTML = det[3];
// text
var span = $a($td(tab, 0, 1), 'span', 'social', {lineHeight:'1.5em'}, replace_newlines(det[1]));
if(det[4]) $y(span,{textDecoration:'line-through'});
// if expired & open, then in red
if(!det[4] && dateutil.str_to_obj(det[2]) < new Date()) {
$y(span,{color:'RED'});
$a($td(tab, 0, 1), 'div', '', {fontSize:'10px', color:'#666'}, dateutil.str_to_user(det[2]) + ' (Overdue)');
} else {
$a($td(tab, 0, 1), 'div', '', {fontSize:'10px', color:'#666'}, dateutil.str_to_user(det[2]));
}
}
HomeToDo.prototype.clear_dialog = function() {
this.set_dialog_values(['','',get_today(),'Medium',0]);
}
HomeToDo.prototype.set_dialog_values = function(det) {
var d = this.widget.dialog;
d.set_values({
date: det[2],
priority: det[3],
description: det[1],
checked: det[4]
});
d.det = det;
}
HomeToDo.prototype.save = function(btn) {
var d = this.widget.dialog;
var me = this;
var det = d.get_values()
if(!det) {
btn.done_working();
return;
}
det.name = d.det ? d.det[0] : '';
var callback = function(r,rt) {
btn.done_working();
me.widget.dialog.hide();
me.widget.refresh();
}
$c_obj('Home Control','add_todo_item',JSON.stringify(det),callback);
}
// Feed
// ==================================
FeedList = function(parent) {
// settings
this.auto_feed_off = cint(sys_defaults.auto_feed_off);
this.wrapper = $a(parent, 'div');
this.make_head();
this.make_list();
this.list.run();
}
FeedList.prototype.make_head = function() {
var me = this;
this.head = $a(this.wrapper, 'div', '', {marginBottom:'8px'});
// 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')
})
// refresh
$a(this.head,'span','link_type',
{cursor:'pointer', marginLeft:'7px', fontSize:'11px'}, 'refresh',
function() { me.run(); }
);
}
FeedList.prototype.run = function() {
this.prev_date = null;
this.list.run();
}
FeedList.prototype.make_list = function() {
this.list_area = $a(this.wrapper,'div')
this.no_result = $a(this.wrapper, 'div','help_box',{display:'none'},'Nothing to show yet. Your feed will be updated as you start your activities')
var l = new Listing('Feed List',1);
var me = this;
// style
l.colwidths = ['100%']; l.page_len = 20;
l.opts.cell_style = {padding:'0px'};
l.opts.hide_rec_label = 1;
// build query
l.get_query = function(){
this.query = repl('select \
distinct t1.name, t1.doc_type, t1.doc_name, t1.subject, t1.modified_by, \
concat(ifnull(t2.first_name,""), " ", ifnull(t2.last_name,"")), t1.modified, t1.color \
from tabFeed t1, tabProfile t2, tabUserRole t3, tabDocPerm t4 \
where t1.doc_type = t4.parent \
and t2.name = t1.owner \
and t3.parent = "%(user)s" \
and t4.role = t3.role \
and ifnull(t4.`read`,0) = 1 \
order by t1.modified desc', {user:user})
this.query_max = ''
}
// render list ui
l.show_cell = function(cell,ri,ci,d){ me.render_feed(cell,ri,ci,d); }
// onrun
l.onrun = function(){ $(me.wrapper).fadeIn(); if(me.after_run) me.after_run(); }
// make
l.make(this.list_area);
$dh(l.btn_area);
this.list = l;
}
FeedList.prototype.after_run = function() {
this.list.has_data() ? $dh(this.no_result) : $ds(this.no_result)
}
FeedList.prototype.render_feed = function(cell,ri,ci,d) {
new FeedItem(cell, d[ri], this);
}
// Item
// -------------------------------
FeedItem = function(cell, det, feedlist) {
var me = this;
this.det = det; this.feedlist = feedlist;
this.wrapper = $a(cell,'div','',{paddingBottom:'4px'});
this.head = $a(this.wrapper,'div');
this.tab = make_table(this.wrapper, 1, 2, '100%', [(100/7)+'%', (600/7)+'%']);
$y(this.tab,{tableLayout:'fixed'})
// image
$y($td(this.tab,0,0),{textAlign:'right',paddingRight:'4px'});
// text
this.text_area = $a($td(this.tab,0,1), 'div');
this.render_references(this.text_area, det);
this.render_tag(det);
// add day separator
this.add_day_sep(det);
}
// Day separator
// -------------------------------------------------
FeedItem.prototype.add_day_sep = function(det) {
var me = this;
var prev_date = det[6].split(' ')[0];
var make_div = function() {
var div = $a(me.head, 'div', '',
{borderBottom:'1px solid #888', margin:'8px 0px', padding:'2px 0px', color:'#888', fontSize:'11px'});
div.innerHTML = comment_when(det[6], 1);
// today?
if(prev_date==get_today()) {
div.innerHTML = '';
span = $a(div, 'span', '', {padding:'2px', color:'#000', fontWeight:'bold'});
span.innerHTML = 'Today';
}
}
if(this.feedlist.prev_date && this.feedlist.prev_date != prev_date) { make_div(); }
if(!this.feedlist.prev_date) { make_div(); }
this.feedlist.prev_date = prev_date;
}
// Tag
// -------------------------------------------------
FeedItem.prototype.render_tag = function(det) {
tag = $a($td(this.tab,0,0), 'div', '',
{color:'#FFF', padding:'3px', textAlign:'right', fontSize:'11px', whiteSpace:'nowrap', overflow:'hidden', cursor:'pointer'});
$br(tag,'3px');
$y(tag, {backgroundColor:(det[7] ? det[7] : '#273')});
tag.innerHTML = get_doctype_label(det[1]);
tag.dt = det[1]
tag.onclick = function() { loaddocbrowser(this.dt); }
}
FeedItem.prototype.render_references = function(div, det) {
// name
div.tab = make_table(div, 1, 2, '100%', [null, '15%'])
//div.innerHTML = '<b>' + (strip(det[11]) ? det[11] : det[2]) + ' (' + cint(det[12]) + '): </b> has ' + det[7] + ' ';
var dt = det[1]; var dn = det[2]
// link
var allow = in_list(profile.can_read, dt);
var span = $a($td(div.tab,0,0), 'span', (allow ? 'link_type': ''), null, det[2]);
span.dt = dt; span.dn = dn;
if(allow) span.onclick = function() { loaddoc(this.dt, this.dn); }
// subject
if(det[3]) {
$a($td(div.tab,0,0), 'span', '', {marginLeft:'7px', color:'#444'}, det[3]);
}
// by
$y($td(div.tab,0,1), {fontSize:'11px'}).innerHTML = (strip(det[5]) ? det[5] : det[4]);
}
HomeStatusBar = function() {
var me = this;
var parent = page_body.pages['Event Updates'];
this.wrapper = $a($td(parent.main_tab, 0, 1), 'div', 'home-status', {}, 'Loading...');
$br(this.wrapper, '3px');
this.render = function(r) {
this.wrapper.innerHTML = '';
this.span = $a(this.wrapper, 'span', 'home-status-link')
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' : '');
} else {
this.span.innerHTML = 'No unread messages.';
}
}
}
pscript.home_make_status = function() {
var home_status_bar = new HomeStatusBar()
var wrapper = page_body.pages['Event Updates'];
// get values
$c_page('event_updates', '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);
// trial
if(pscript.is_erpnext_saas && cint(r.message.is_trial) && in_list(user_roles, 'System Manager')) {
pscript.trial_box = $a(div, 'div', 'help_box', {margin:'2px 8px 2px 0px'}, "Your Free Trial expires in " +
r.message.days_to_expiry + " days. When you are satisfied, please <span class='link_type' onclick='pscript.convert_to_paid()'>please click here</span> to convert to a paid account." +
"<br>To get help, view <a href='http://erpnext.blogspot.com/2011/02/getting-started-with-your-erpnext.html' target='_blank'>Getting Started with Your System</a> (opens in a new page)");
}
// render online users
pscript.online_users_obj.render(r.message.online_users);
pscript.online_users = r.message.online_users;
}
);
}
// show system message
// -------------------
pscript.convert_to_paid = function() {
var callback = function(r,rt) {
if(r.exc) { msgprint(r.exc); return; }
$(pscript.trial_box).slideUp();
}
$c_page('event_updates','event_updates','convert_to_paid','',callback)
}
// 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'), 'Dismiss',
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()
{
var reg_callback = function(r, rt){
if(r.message == 'No'){
var d = new Dialog(400, 200, "Please Complete Your Registration");
if(user != 'Administrator'){
d.no_cancel(); // Hide close image
$dh(page_body.wntoolbar.wrapper);
}
$($a(d.body,'div','', {margin:'8px', color:'#888'})).html('<b>Company Name : </b>'+locals['Control Panel']['Control Panel'].company_name);
d.make_body(
[
['Data','Company Abbreviation'],
['Select','Fiscal Year Start Date'],
['Select','Default Currency'],
['Button','Save'],
]);
//d.widgets['Save'].disabled = true; // disable Save button
pscript.make_dialog_field(d);
// submit details
d.widgets['Save'].onclick = function()
{
d.widgets['Save'].set_working();
flag = pscript.validate_fields(d);
if(flag)
{
var args = [
locals['Control Panel']['Control Panel'].company_name,
d.widgets['Company Abbreviation'].value,
d.widgets['Fiscal Year Start Date'].value,
d.widgets['Default Currency'].value
];
$c_obj('Setup Control','setup_account',JSON.stringify(args),function(r, rt){
sys_defaults = r.message;
d.hide();
$ds(page_body.wntoolbar.wrapper);
});
}
}
d.show();
}
}
$c_obj('Home Control','registration_complete','',reg_callback);
}
// make dialog fields
// ------------------
pscript.make_dialog_field = function(d)
{
// fiscal year format
fisc_format = d.widgets['Fiscal Year Start Date'];
add_sel_options(fisc_format, ['', '1st Jan', '1st Apr', '1st Jul', '1st Oct']);
// default currency
currency_list = ['', 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BYR', 'BZD', 'CAD', 'CDF', 'CFA', 'CFP', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EEK', 'EGP', 'ERN', 'ETB', 'EUR', 'EURO', 'FJD', 'FKP', 'FMG', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GQE', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LTL', 'LVL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZM', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NRs', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RMB', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SCR', 'SDG', 'SDR', 'SEK', 'SGD', 'SHP', 'SOS', 'SRD', 'STD', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TRY', 'TTD', 'TWD', 'TZS', 'UAE', 'UAH', 'UGX', 'USD', 'USh', 'UYU', 'UZS', 'VEB', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YEN', 'YER', 'YTL', 'ZAR', 'ZMK', 'ZWR'];
currency = d.widgets['Default Currency'];
add_sel_options(currency, currency_list);
}
// validate fields
// ---------------
pscript.validate_fields = function(d)
{
var lst = ['Company Abbreviation', 'Fiscal Year Start Date', 'Default Currency'];
var msg = 'Please enter the following fields';
var flag = 1;
for(var i=0; i<lst.length; i++)
{
if(!d.widgets[lst[i]].value){
flag = 0;
msg = msg + NEWLINE + lst[i];
}
}
if(!flag) alert(msg);
return flag;
}

View File

@@ -0,0 +1,56 @@
import webnotes
from webnotes.utils import cint
def get_online_users():
# get users
return webnotes.conn.sql("""SELECT DISTINCT t1.user, t2.first_name, t2.last_name
from tabSessions t1, tabProfile t2
where t1.user = t2.name
and t1.user not in ('Guest','Administrator')
and TIMESTAMPDIFF(HOUR,t1.lastupdate,NOW()) <= 1""", as_list=1) or []
#
# get unread messages
#
def get_unread_messages():
"returns unread (docstatus-0 messages for a user)"
return cint(webnotes.conn.sql("""SELECT COUNT(*) FROM `tabComment Widget Record`
WHERE comment_doctype='My Company'
AND comment_docname = %s
AND ifnull(docstatus,0)=0
""", webnotes.user.name)[0][0])
#
# Get toolbar items
#
def get_status_details(arg=None):
from webnotes.utils import cint, date_diff, nowdate
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')
return {
'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')
}
#
# Convert to a paid account
#
def convert_to_paid():
from server_tools.server_tools.gateway_utils import convert_to_paid_gateway
r = convert_to_paid_gateway()
if r['exc']:
webnotes.msgprint(r['exc'])
raise Exception, r['exc']
webnotes.msgprint('Thank you for choosing to convert to a Paid Account!')

View File

@@ -0,0 +1,36 @@
[
{
'author': None,
'category': None,
'content': None,
'creation': '2010-12-14 10:33:09',
'docstatus': 0,
'doctype': 'Page',
'file_list': None,
'icon': None,
'idx': None,
'keywords': None,
'menu_index': None,
'modified': '2010-12-23 11:48:49',
'modified_by': 'Administrator',
'module': 'Home',
'name': 'Event Updates',
'owner': 'Administrator',
'page_name': 'Event Updates',
'page_title': None,
'parent': None,
'parent_node': None,
'parentfield': None,
'parenttype': None,
'publish': None,
'script': None,
'show_in_menu': None,
'site_description': None,
'standard': 'Yes',
'static_content': None,
'style': None,
'stylesheet': None,
'template': None,
'write_content': None
}
]

View File

@@ -0,0 +1 @@
Event Updates

View File

View File

@@ -0,0 +1,82 @@
/* item */
div.my-company-member-item-selected {
background-color: #BBC;
}
/* profile */
.my-company-name-head {
font-size: 14px;
font-weight: bold;
margin-bottom: 7px;
}
.my-company-email {
margin-bottom: 7px;
color: #888;
}
.my-company-online-status {
font-weight: bold;
margin-left: 7px;
}
.my-company-status {
margin-bottom: 7px;
color: #888;
font-style: italics;
}
.my-company-bio {
margin-bottom: 7px;
}
.my-company-toolbar {
margin: 7px 0px;
}
/* conversation */
.my-company-input-wrapper {
color: #555;
padding: 13px;
}
.my-company-input-wrapper td {
vertical-align: bottom;
}
.my-company-input-wrapper textarea {
height: 3em;
font-size: 14px;
width: 100%;
margin: 7px 0px 3px 0px;
}
.my-company-input-wrapper button {
margin: 0px;
}
.my-company-conversation {
border-top: 1px solid #DDD;
}
.my-company-comment-wrapper {
padding: 7px;
border-bottom: 1px solid #DDD;
}
.my-company-timestamp {
color: #888;
font-size: 11px;
margin: 3px;
}
.my-company-conversation-head {
padding: 3px;
background-color: #DEDEDE;
color: #555;
font-size: 14px;
text-align: center;
}

View File

View File

@@ -0,0 +1,842 @@
pscript['onload_My Company'] = function() {
var wrapper = page_body.pages['My Company'];
// body
wrapper.head = new PageHeader(wrapper, 'People');
wrapper.body = $a(wrapper, 'div', '', {marginRight:'11px', marginTop:'11px'});
wrapper.message = $a(wrapper.body, 'div');
wrapper.tab = make_table(wrapper.body, 1, 2, '100%', ['25%','75%']);
$y(wrapper.tab, {tableLayout:'fixed'})
pscript.myc_make_toolbar(wrapper);
pscript.myc_make_list(wrapper);
if(pscript.is_erpnext_saas) {
pscript.myc_show_erpnext_message();
}
}
pscript.myc_make_toolbar = function(wrapper) {
if(has_common(user_roles, ['System Manager', 'Administrator'])) {
wrapper.head.add_button('Add User', pscript.myc_add_user)
}
}
//
// Only for erpnext product - show max users allowed
//
pscript.myc_show_erpnext_message = function() {
var callback = function(r, rt) {
if(r.exc) {msgprint(r.exc); return;}
$a(wrapper.message, 'div', 'help_box', '', 'You have ' + r.message.enabled
+ ' users enabled out of ' + r.message.max_user
+ '. Go to <a href="javascript:pscript.go_to_account_settings()">Account Settings</a> to increase the number of users');
}
$c_page('my_company', 'my_company', 'get_max_users', '', callback)
}
//
// Add user dialog and server call
//
pscript.myc_add_user = function() {
var d = new wn.widgets.Dialog({
title: 'Add User',
width: 400,
fields: [
{fieldtype:'Data', fieldname:'user',reqd:1,label:'Email Id of the user to add'},
{fieldtype:'Button', label:'Add', fieldname:'add'}
]
});
d.make();
d.fields_dict.add.input.onclick = function() {
v = d.get_values();
if(v) {
d.fields_dict.add.input.set_working();
$c_page('my_company', 'my_company', 'add_user', v, function(r,rt) {
if(r.exc) { msgprint(r.exc); return; }
else {
d.hide();
pscript.myc_refresh();
}
})
}
}
d.show();
}
pscript.myc_refresh = function() {
page_body.pages['My Company'].member_list.lst.run();
}
pscript.myc_make_list= function(wrapper) {
wrapper.member_list = new MemberList(wrapper)
}
pscript.get_fullname=function(uid) {
if(uid=='Administrator') return uid;
return page_body.pages['My Company'].member_list.member_items[uid].fullname;
}
//=============================================
MemberList = function(parent) {
var me = this;
this.profiles = {};
this.member_items = {};
this.role_objects = {};
this.cur_profile = null;
this.list_wrapper = $a($td(parent.tab,0,0), 'div', '', {marginLeft:'11px'});
this.profile_wrapper = $a($td(parent.tab,0,1), 'div', 'layout_wrapper', {marginLeft:'0px', height:'100%'});
this.no_user_selected = $a(this.profile_wrapper, 'div', 'help_box', null, 'Please select a user to view profile');
this.make_search();
if(pscript.online_users) {
this.make_list();
} else {
$c_page('event_updates', 'event_updates', 'get_online_users', '', function(r,rt) {
pscript.online_users = r.message;
me.make_list();
})
}
}
// ----------------------
MemberList.prototype.make_search = function() {
var me = this;
this.search_area = $a(this.list_wrapper, 'div', '', {textAlign:'center', padding:'8px'});
this.search_inp = $a(this.search_area, 'input', '', {fontSize:'14px', width:'80%'});
this.search_inp.set_empty = function() {
this.value = 'Search'; $fg(this,'#888');
}
this.search_inp.onfocus = function() {
$fg(this,'#000');
if(this.value=='Search')this.value = '';
}
this.search_inp.onchange = function() {
if(!this.value) this.set_empty();
}
this.search_inp.set_empty();
}
// ----------------------
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.query = repl("SELECT distinct ifnull(name,''), ifnull(concat_ws(' ', first_name, last_name),''), ifnull(messanger_status,''), ifnull(gender,''), ifnull(file_list,''), 0, enabled 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();
}
/*
Create / show profile
*/
MemberList.prototype.show_profile = function(uid, member_item) {
$dh(this.no_user_selected);
// if not exists, create
if(!this.profiles[uid]) {
if(!member_item) member_item = this.member_items[uid];
this.profiles[uid] = new MemberProfile(this.profile_wrapper, uid, member_item);
}
// hide current
if(this.cur_profile)
this.cur_profile.hide();
// show this
this.profiles[uid].show();
this.cur_profile = this.profiles[uid];
}
// Member Item
// List item of all profiles
// on the left hand sidebar of the page
MemberItem = function(parent, det, mlist) {
var me = this;
this.det = det;
this.wrapper = $a(parent, 'div');
this.enabled = det[6];
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;
}
}
this.refresh_name_link = function() {
// online / offline
$fg(this.name_link,'#00B');
if(!this.is_online())
$fg(this.name_link,'#444');
if(!this.enabled)
$fg(this.name_link,'#777');
}
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 other details like email id, name etc
this.set_details = function() {
// name
this.fullname = det[1] ? det[1] : det[0];
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 = this.fullname;
this.name_link.onclick = function() {
mlist.show_profile(me.det[0], me);
}
// "you" tag
if(user==det[0]) {
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];
// working img
var div = $a($td(this.tab, 0, 1), 'div');
this.working_img = $a(div,'img','',{display:'none'});
this.working_img.src = 'images/ui/button-load.gif';
this.refresh_name_link();
}
this.select = function() {
$(this.wrapper).addClass('my-company-member-item-selected');
}
this.deselect = function() {
$(this.wrapper).removeClass('my-company-member-item-selected');
}
this.set_image();
this.set_details();
// show initial
if(user==det[0]) me.name_link.onclick();
}
//
// Member Profile
// shows profile with Photo and conversation
//
MemberProfile = function(parent, uid, member_item) {
this.parent = parent;
this.uid = uid;
this.member_item = member_item;
var me = this;
// make the UI
this.make = function() {
this.wrapper = $a(this.parent, 'div', '', {display:'none'});
this.tab = make_table(this.wrapper, 3, 2,'100%',['120px',null],{padding:'3px'});
$y(this.tab, {tableLayout: 'fixed'});
this.make_image_and_bio();
this.make_toolbar();
this.make_message_list();
}
// create elements
this.make_image_and_bio = function() {
var rh = $td(this.tab, 0, 1);
// image
this.img = $a($td(this.tab, 0, 0), 'img','',{width:'80px', marginLeft:'10px'});
set_user_img(this.img, this.uid);
// details
this.name_area = $a(rh, 'div' , 'my-company-name-head');
var div = $a(rh, 'div', 'my-company-email');
this.email_area = $a(div, 'span');
this.online_status_area = $a(div, 'span', 'my-company-online-status');
this.bio_area = $a(rh, 'div', 'my-company-bio');
this.toolbar_area = $a(rh, 'div', 'my-company-toolbar');
this.status_span = $a(this.toolbar_area, 'span', '', {marginRight:'7px'});
}
// the toolbar
this.make_toolbar = function() {
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'});
}
}
// create the role object
this.show_roles = function() {
if(!this.role_object)
this.role_object = new RoleObj(this.uid);
this.role_object.dialog.show();
}
// delete user
// create a confirm dialog and call server method
this.delete_user = function() {
var cp = locals['Control Panel']['Control Panel'];
var d = new Dialog(400,200,'Delete User');
d.make_body([
['HTML','','Do you really want to remove '+this.uid+' from system?'],['Button','Delete']
]);
d.onshow = function() {
this.clear_inputs();
}
d.widgets['Delete'].onclick = function() {
this.set_working();
var callback = function(r,rt) {
d.hide();
if(r.exc) {
msgprint(r.exc);
return;
}
pscript.myc_refresh()
msgprint("User Deleted Successfully");
}
$c_page('my_company', 'my_company', 'delete_user', {'user': me.uid}, callback);
}
d.show();
}
// set enabled
this.set_enable_button = function() {
var me = this;
var act = this.profile.enabled ? 'Disable' : 'Enable';
if(this.status_button) {
this.status_button.innerHTML = act;
} else {
// make the button
this.status_button = $btn(this.toolbar_area, act, function() {
var callback = function(r,rt) {
locals['Profile'][me.profile.name].enabled = cint(r.message);
me.status_button.done_working();
me.refresh_enable_disable();
}
this.set_working();
$c_page('my_company','my_company', this.innerHTML.toLowerCase()+'_profile',me.profile.name, callback);
}, null, null, 1);
}
if(this.uid==user) $dh(this.status_button); else $di(this.status_button);
}
// render the details of the user from Profile
this.render = function() {
this.profile = locals['Profile'][uid];
scroll(0, 0);
// name
if(cstr(this.profile.first_name) || cstr(this.profile.last_name)) {
this.fullname = cstr(this.profile.first_name) + ' ' + cstr(this.profile.last_name);
} else {
this.fullname = this.profile.name;
}
this.name_area.innerHTML = this.fullname;
// email
this.email_area.innerHTML = this.profile.name;
// online / offline
this.online_status_area.innerHTML = (this.member_item.is_online() ? '(Online)' : '(Offline)')
if(this.member_item.is_online()) {
$y(this.online_status_area, {color:'green'});
}
// refresh enable / disabled
this.refresh_enable_disable();
// designation
this.bio_area.innerHTML = this.profile.designation ? ('Designation: ' + cstr(this.profile.designation) + '<br>') : '';
this.bio_area.innerHTML += this.profile.bio ? this.profile.bio : 'No bio';
new MemberConversation(this.wrapper, this.profile.name, this.fullname);
}
// refresh enable / disable
this.refresh_enable_disable = function() {
this.profile = locals['Profile'][this.uid]
if(!this.profile.enabled) {
$fg(this.name_area,'#999');
} else {
$fg(this.name_area,'#000');
}
this.member_item.enabled = this.profile.enabled;
this.member_item.refresh_name_link();
this.status_span.innerHTML = this.profile.enabled ? 'Enabled' : 'Disabled';
// set styles and buttons
if(has_common(['Administrator','System Manager'],user_roles)) {
this.set_enable_button();
}
}
// Load user profile (if not loaded)
this.load = function() {
if(locals['Profile'] && locals['Profile'][uid]) {
this.render();
return;
}
var callback = function(r,rt) {
$dh(me.member_item.working_img);
$ds(me.wrapper);
me.loading = 0;
me.render();
}
$ds(this.member_item.working_img);
$dh(this.wrapper);
this.loading = 1;
$c('webnotes.widgets.form.getdoc', {'name':this.uid, 'doctype':'Profile', 'user':user}, callback); // onload
}
// show / hide
this.show = function() {
if(!this.loading)$ds(this.wrapper);
// select profile
this.member_item.select();
}
this.hide = function() {
$dh(this.wrapper);
// select profile
this.member_item.deselect();
}
this.make_message_list = function() {
}
this.make();
this.load();
}
// Member conversation
// Between the current user and the displayed profile
// or if same, then the conversation with all other
// profiles
MemberConversation = function(parent, uid, fullname) {
var me = this;
this.wrapper = $a(parent, 'div', 'my-company-conversation');
this.fullname = fullname;
this.make = function() {
if(user!=uid) {
this.make_input();
}
this.make_list();
// set all messages
// as "read" (docstatus = 0)
if(user==uid) {
$c_page('my_company', 'my_company', 'set_read_all_messages', '', function(r,rt) { });
}
}
this.make_input = function() {
this.input_wrapper = $a(this.wrapper, 'div', 'my-company-input-wrapper');
var tab = make_table(this.input_wrapper, 1, 2, '100%', ['64%','36%'], {padding: '3px'})
this.input = $a($td(tab,0,0), 'textarea');
$(this.input).add_default_text( 'Send a message to ' + fullname);
// button
var div = $a(this.input_wrapper, 'div');
this.post = $btn(div, 'Post'.bold(), function() { me.post_message(); }, {margin:'0px 13px 0px 3px'})
this.post.set_disabled();
this.input.onkeyup = this.input.onchange = function() {
if(this.value) {
me.post.set_enabled();
} else {
me.post.set_disabled();
}
}
// notification check
this.notify_check = $a_input(div, 'checkbox', null);
$a(div, 'span', '', {marginLeft:'3px'}, 'Notify ' + fullname + ' by email')
}
this.post_message = function() {
if(me.input.value==$(me.input).attr('default_text')) {
msgprint('Please write a message first!'); return;
}
this.post.set_working();
$c_page('my_company', 'my_company', 'post_comment', {
uid: uid,
comment: $(me.input).val(),
notify: me.notify_check.checked ? 1 : 0
}, function(r,rt) {
$(me.input).val("").blur();
me.post.done_working();
if(r.exc) { msgprint(r.exc); return; }
me.notify_check.checked = false;
me.refresh();
})
}
this.make_list = function() {
this.lst_area = $a(this.wrapper, 'div', 'my-company-conversation', {padding:'7px 13px'});
if(user==uid) {
this.my_messages_box = $a(this.lst_area, 'div', 'my-company-conversation-head', {marginBottom:'7px'}, 'Messages by everyone to me<br>To send a message, click on the user on the left')
}
this.lst = new wn.widgets.Listing({
parent: this.lst_area,
no_result_message: (user==uid
? 'No messages by anyone yet'
: 'No messages yet. To start a conversation post a new message'),
get_query: function() {
if(uid==user) {
return repl("SELECT comment, owner, comment_docname, creation, docstatus " +
"FROM `tabComment Widget Record` "+
"WHERE comment_doctype='My Company' " +
"AND comment_docname='%(user)s' " +
"ORDER BY creation DESC ", {user:user});
} else {
return repl("SELECT comment, owner, comment_docname, creation, docstatus " +
"FROM `tabComment Widget Record` "+
"WHERE comment_doctype='My Company' " +
"AND ((owner='%(user)s' AND comment_docname='%(uid)s') " +
"OR (owner='%(uid)s' AND comment_docname='%(user)s')) " +
"ORDER BY creation DESC ", {uid:uid, user:user});
}
},
render_row: function(parent, data) {
new MemberCoversationComment(parent, data, me);
},
})
this.refresh();
}
this.refresh = function() {
me.lst.run()
}
this.make();
}
MemberCoversationComment = function(cell, det, conv) {
var me = this;
this.det = det;
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.onclick = function() {
page_body.pages['My Company'].member_list.show_profile(me.det[1]);
}
var st = (!det[4] ? {fontWeight: 'bold'} : null);
this.msg = $a(this.comment, 'span', 'social', st, ': ' + det[0]);
if(det[1]==user) {
$y(this.wrapper, {backgroundColor: '#D9D9F3'});
}
this.timestamp = $a(this.wrapper, 'div', 'my-company-timestamp', '', comment_when(det[3]));
}
// ========================== Role object =====================================
pscript.all_roles = null;
RoleObj = function(profile_id){
this.roles_dict = {};
this.profile_id = profile_id;
this.setup_done = 0;
var d = new Dialog(500,500,'Assign Roles');
d.make_body([
['HTML','roles']
]);
this.dialog = d;
this.make_role_body(profile_id);
this.make_help_body();
this.body.innerHTML = '<span style="color:#888">Loading...</span> <img src="images/ui/button-load.gif">'
var me=this;
d.onshow = function() {
if(!me.setup_done)
me.get_all_roles(me.profile_id);
}
}
// make role body
RoleObj.prototype.make_role_body = function(id){
var me = this;
var d = this.dialog;
this.role_div = $a(d.widgets['roles'],'div');
this.head = $a(this.role_div,'div','',{marginLeft:'4px', marginBottom:'4px',fontWeight:'bold'});
this.body = $a(this.role_div,'div');
this.footer = $a(this.role_div,'div');
this.update_btn = $btn(this.footer,'Update',function() { me.update_roles(me.profile_id); },{marginRight:'4px'},'',1);
}
// make help body
RoleObj.prototype.make_help_body = function(){
var me = this;
var d = this.dialog;
this.help_div = $a(d.widgets['roles'],'div');
var head = $a(this.help_div,'div'); this.help_div.head = head;
var body = $a(this.help_div,'div'); this.help_div.body = body;
var tail = $a(this.help_div,'div'); this.help_div.tail = tail;
var back_btn = $btn(tail,'Back', function() {
// back to assign roles
$(me.role_div).slideToggle('medium');
$(me.help_div).slideToggle('medium');
});
this.help_div.back_btn = back_btn;
$dh(this.help_div);
}
// get all roles
RoleObj.prototype.get_all_roles = function(id){
if(pscript.all_roles) {
this.make_roles(id);
return;
}
var me = this;
var callback = function(r,rt){
pscript.all_roles = r.message;
me.make_roles(id);
}
$c_obj('Company Control','get_all_roles','',callback);
}
// make roles
RoleObj.prototype.make_roles = function(id){
var me = this;
var list = pscript.all_roles;
me.setup_done = 1;
me.body.innerHTML = '';
var tbl = make_table( me.body, cint(list.length / 2) + 1,4,'100%',['5%','45%','5%','45%'],{padding:'4px'});
var in_right = 0; var ridx = 0;
for(i=0;i<list.length;i++){
var cidx = in_right * 2;
me.make_checkbox(tbl, ridx, cidx, list[i]);
me.make_label(tbl, ridx, cidx + 1, list[i]);
// change column
if(in_right) {in_right = 0; ridx++ } else in_right = 1;
}
me.get_user_roles(id);
}
// make checkbox
RoleObj.prototype.make_checkbox = function(tbl,ridx,cidx, role){
var me = this;
var a = $a_input($a($td(tbl, ridx, cidx),'div'),'checkbox');
a.role = role;
me.roles_dict[role] = a;
$y(a,{width:'20px'});
$y($td(tbl, ridx, cidx),{textAlign:'right'});
}
// make label
RoleObj.prototype.make_label = function(tbl, ridx, cidx, role){
var me = this;
var t = make_table($td(tbl, ridx, cidx),1,2,null,['16px', null],{marginRight:'5px'});
var ic = $a($td(t,0,0), 'img','',{cursor:'pointer', marginRight:'5px'});
ic.src= 'images/icons/help.gif';
ic.role = role;
ic.onclick = function(){
me.get_permissions(this.role);
}
$td(t,0,1).innerHTML= role;
}
// get user roles
RoleObj.prototype.get_user_roles = function(id){
var me = this;
me.head.innerHTML = 'Roles for ' + id;
$ds(me.role_div);
$dh(me.help_div);
var callback = function(r,rt){
me.set_user_roles(r.message);
}
$c_obj('Company Control','get_user_roles', id,callback);
}
// set user roles
RoleObj.prototype.set_user_roles = function(list){
var me = this;
for(d in me.roles_dict){
me.roles_dict[d].checked = 0;
}
for(l=0; l<list.length; l++){
me.roles_dict[list[l]].checked = 1;
}
}
// update roles
RoleObj.prototype.update_roles = function(id){
var me = this;
if(id == user && has_common(['System Manager'], user_roles) && !me.roles_dict['System Manager'].checked){
var callback = function(r,rt){
if(r.message){
if(r.message > 1){
var c = confirm("You have unchecked the System Manager role.\nYou will lose administrative rights and will not be able to set roles.\n\nDo you want to continue anyway?");
if(!c) return;
}
else{
var c = "There should be atleast one user with System Manager role.";
me.roles_dict['System Manager'].checked = 1;
}
}
me.set_roles(id);
}
$c_obj('Company Control','get_sm_count','',callback);
}
else{
me.set_roles(id);
}
}
// set roles
RoleObj.prototype.set_roles = function(id){
var me = this;
var role_list = [];
for(d in me.roles_dict){
if(me.roles_dict[d].checked){
role_list.push(d);
}
}
var callback = function(r,rt){
me.update_btn.done_working();
me.dialog.hide();
}
var arg = {'usr':id, 'role_list':role_list};
me.update_btn.set_working();
$c_obj('Company Control','update_roles',docstring(arg), callback);
}
// get permission
RoleObj.prototype.get_permissions = function(role){
var me = this;
var callback = function(r,rt){
$(me.help_div).slideToggle('medium');
$(me.role_div).slideToggle('medium');
me.set_permissions(r.message, role);
}
$c_obj('Company Control','get_permission',role,callback);
}
// set permission
RoleObj.prototype.set_permissions = function(perm, role){
var me = this;
me.help_div.body.innerHTML ='';
if(perm){
me.help_div.head.innerHTML = 'Permissions for ' + role + ':<br><br>';
perm_tbl = make_table(me.help_div.body,cint(perm.length)+2,7,'100%',['30%','10%','10%','10%','10%','10%','10%'],{padding:'4px'});
var head_lst = ['Document','Read','Write','Create','Submit','Cancel','Amend'];
for(var i=0; i<(head_lst.length-1);i++){
$td(perm_tbl,0,i).innerHTML= "<b>"+head_lst[i]+"</b>";
}
var accept_img1 = 'images/icons/accept.gif';
var cancel_img1 = 'images/icons/cancel.gif';
for(i=1; i<perm.length+1; i++){
$td(perm_tbl,i,0).innerHTML= get_doctype_label(perm[i-1][0]);
for(var j=1;j<(head_lst.length-1);j++){
if(perm[i-1][j]){
var accept_img = $a($td(perm_tbl,i,j), 'img'); accept_img.src= accept_img1;
}
else {
var cancel_img = $a($td(perm_tbl,i,j), 'img'); cancel_img.src= cancel_img1;
}
$y($td(perm_tbl,i,j),{textAlign:'center'});
}
}
}
else
me.help_div.head.innerHTML = 'No Permission set for ' + role + '.<br><br>';
}

View File

@@ -0,0 +1,130 @@
import webnotes
from webnotes.utils import cint, load_json, cstr
try: import json
except: import simplejson as json
def get_account_settings_url(arg=''):
import server_tools.server_tools.gateway_utils
return server_tools.server_tools.gateway_utils.get_account_settings_url()
#
# set max users
#
def get_max_users(arg=''):
from server_tools.server_tools.gateway_utils import get_max_users_gateway
return {
'max_users': get_max_users_gateway(),
'enabled': cint(webnotes.conn.sql("select count(*) from tabProfile where ifnull(enabled,0)=1 and name not in ('Administrator', 'Guest')")[0][0])
}
#
# enable profile in local
#
def enable_profile(arg=''):
webnotes.conn.sql("update tabProfile set enabled=1 where name=%s", arg)
return 1
#
# disable profile in local
#
def disable_profile(arg=''):
if arg=='Administrator':
return 'Cannot disable Administrator'
webnotes.conn.sql("update tabProfile set enabled=0 where name=%s", arg)
return 0
#
# delete user
#
def delete_user(args):
args = json.loads(args)
webnotes.conn.sql("update tabProfile set enabled=0, docstatus=2 where name=%s", args['user'])
# erpnext-saas
if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
from server_tools.server_tools.gateway_utils import remove_user_gateway
remove_user_gateway(args['user'])
#
# add user
#
def add_user(args):
args = json.loads(args)
add_profile(args['user'])
# erpnext-saas
if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
from server_tools.server_tools.gateway_utils import add_user_gateway
add_user_gateway(args['user'])
#
# add profile record
#
def add_profile(email):
from webnotes.utils import validate_email_add
from webnotes.model.doc import Document
sql = webnotes.conn.sql
if not email:
email = webnotes.form_dict.get('user')
if not validate_email_add(email):
raise Exception
return 'Invalid Email Id'
if sql("select name from tabProfile where name = %s", email):
# exists, enable it
sql("update tabProfile set enabled = 1, docstatus=0 where name = %s", email)
webnotes.msgprint('Profile exists, enabled it')
else:
# does not exist, create it!
pr = Document('Profile')
pr.name = email
pr.email = email
pr.enabled=1
pr.user_type='System User'
pr.save(1)
#
# post comment
#
def post_comment(arg):
arg = load_json(arg)
from webnotes.model.doc import Document
d = Document('Comment Widget Record')
d.comment_doctype = 'My Company'
d.comment_docname = arg['uid'] # to
d.owner = webnotes.user.name
d.comment = arg['comment']
d.save(1)
if cint(arg['notify']):
fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0]
if fn[0] or f[1]:
fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1])
else:
fn = webnotes.user.name
from webnotes.utils.email_lib import sendmail
from settings.doctype.notification_control.notification_control import get_formatted_message
message = '''A new comment has been posted on your page by %s:
<b>Comment:</b> %s
To answer, please login to your erpnext account!
''' % (fn, arg['comment'])
sendmail([arg['uid']], webnotes.user.name, get_formatted_message('New Comment', message), fn + ' has posted a new comment')
#
# update read messages
#
def set_read_all_messages(arg=''):
webnotes.conn.sql("""UPDATE `tabComment Widget Record`
SET docstatus = 1
WHERE comment_doctype = 'My Company'
AND comment_docname = %s
""", webnotes.user.name)

View File

@@ -0,0 +1,64 @@
[
{
'author': None,
'category': None,
'content': '',
'creation': '2010-12-14 10:33:09',
'docstatus': 0,
'doctype': 'Page',
'file_list': None,
'icon': None,
'idx': None,
'keywords': None,
'menu_index': None,
'modified': '2010-12-01 17:09:46',
'modified_by': 'Administrator',
'module': 'Home',
'name': 'My Company',
'owner': 'Administrator',
'page_name': 'My Company',
'page_title': None,
'parent': None,
'parent_node': None,
'parentfield': None,
'parenttype': None,
'publish': None,
'script': None,
'show_in_menu': 1,
'site_description': None,
'standard': 'Yes',
'static_content': '',
'style': '',
'stylesheet': None,
'template': None,
'write_content': None
},
{
'creation': '2010-12-14 10:33:09',
'docstatus': 0,
'doctype': 'Page Role',
'idx': 1,
'modified': '2010-12-14 10:33:09',
'modified_by': 'Administrator',
'name': 'PR000235',
'owner': 'Administrator',
'parent': 'My Company',
'parentfield': 'roles',
'parenttype': 'Page',
'role': 'Administrator'
},
{
'creation': '2010-12-14 10:33:09',
'docstatus': 0,
'doctype': 'Page Role',
'idx': 2,
'modified': '2010-12-14 10:33:09',
'modified_by': 'Administrator',
'name': 'PR000236',
'owner': 'nabin@webnotestech.com',
'parent': 'My Company',
'parentfield': 'roles',
'parenttype': 'Page',
'role': 'All'
}
]

View File

View File

@@ -0,0 +1,115 @@
pscript['onload_profile-settings'] = function() {
var wrapper = page_body.pages['profile-settings'];
wrapper.className = 'layout_wrapper';
pscript.myprofile = new MyProfile(wrapper)
}
MyProfile = function(wrapper) {
this.wrapper = wrapper;
var me = this;
this.make = function() {
this.head = new PageHeader(this.wrapper, 'My Profile Settings');
this.head.add_button('Change Password', this.change_password)
this.tab = make_table($a(this.wrapper, 'div', '', {marginTop:'19px'}),
1, 2, '90%', ['50%', '50%'], {padding:'11px'})
this.img = $a($td(this.tab, 0, 0), 'img');
set_user_img(this.img, user);
$btn($a($td(this.tab, 0, 0), 'div', '', {marginTop:'11px'}), 'Change Image', this.change_image)
this.make_form();
this.load_details();
}
this.load_details = function() {
$c_page('event_updates','profile_settings','get_user_details','',function(r, rt) {
me.form.set_values(r.message);
})
}
//
// form
//
this.make_form = function() {
var div = $a($td(this.tab, 0, 1), 'div');
this.form = new wn.widgets.FieldGroup()
this.form.make_fields(div, [
{fieldname:'first_name', fieldtype:'Data',label:'First Name',reqd:1},
{fieldname:'last_name', fieldtype:'Data',label:'Last Name',reqd:1},
{fieldname:'bio', fieldtype:'Text',label:'Bio'},
{fieldname:'update', fieldtype:'Button',label:'Update'}
]);
this.form.fields_dict.update.input.onclick = function() {
var v = me.form.get_values();
if(v) {
this.set_working();
var btn = this;
$c_page('event_updates','profile_settings','set_user_details',v,function(r, rt) {
btn.done_working();
})
}
}
}
//
// change password
//
this.change_password = function() {
var d = new wn.widgets.Dialog({
title:'Change Password',
width: 400,
fields: [
{fieldname:'old_password', fieldtype:'Password', label:'Old Password', reqd:1 },
{fieldname:'new_password', fieldtype:'Password', label:'New Password', reqd:1 },
{fieldname:'new_password1', fieldtype:'Password', label:'Re-type New Password', reqd:1 },
{fieldname:'change', fieldtype:'Button', label:'Change'}
]
})
d.make();
d.fields_dict.change.input.onclick = function() {
var v = d.get_values();
if(v) {
if(v.new_password != v.new_password1) {
msgprint('Passwords must match'); return;
}
this.set_working();
$c_page('event_updates','profile_settings','change_password',v,function(r,rt) {
if(!r.message && r.exc) { msgprint(r.exc); return; }
d.hide();
})
}
}
d.show();
}
//
// change image
//
this.change_image = function() {
if(!me.change_dialog) {
var d = new Dialog(400,200,'Set Your Profile Image');
d.make_body([
['HTML','wrapper']
]);
var w = d.widgets['wrapper'];
me.uploader = new Uploader(w, {thumbnail:'80px', server_obj:'Company Control', method:'update_profile_image'}, pscript.user_image_upload)
me.change_dialog = d;
}
me.change_dialog.show();
}
this.make();
}
pscript.user_image_upload = function(fid) {
msgprint('File Uploaded');
if(fid) {
pscript.myprofile.change_dialog.hide();
set_user_img(pscript.myprofile.img, user, null, fid);
}
}

View File

@@ -0,0 +1,34 @@
import webnotes
from webnotes.utils import load_json, cint, nowdate
#
# change profile (remote)
#
def change_password(arg):
arg = load_json(arg)
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
import server_tools.server_tools.gateway_utils
webnotes.msgprint(server_tools.server_tools.gateway_utils.change_password(arg['old_password'], arg['new_password'])['message'])
else:
if not webnotes.conn.sql('select name from tabProfile where name=%s and password=password(%s)', (webnotes.session['user'], arg['old_password'])):
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.msgprint('Password Updated');
def get_user_details(arg=None):
"Returns user first name, last name and bio"
return webnotes.conn.sql("select first_name, last_name, bio from tabProfile where name=%s", webnotes.user.name, as_dict=1)[0]
def set_user_details(arg=None):
"updates user details given in argument"
from webnotes.model.doc import Document
p = Document('Profile', webnotes.user.name)
p.fields.update(load_json(arg))
p.save()
webnotes.msgprint('Updated')

View File

@@ -0,0 +1,36 @@
[
{
'author': None,
'category': 'Standard',
'content': None,
'creation': '2011-04-13 12:08:59',
'docstatus': 0,
'doctype': 'Page',
'file_list': None,
'icon': None,
'idx': None,
'keywords': None,
'menu_index': None,
'modified': '2011-04-13 12:08:59',
'modified_by': 'Administrator',
'module': 'Home',
'name': 'profile-settings',
'owner': 'Administrator',
'page_name': 'Profile Settings',
'page_title': None,
'parent': None,
'parent_node': None,
'parentfield': None,
'parenttype': None,
'publish': None,
'script': None,
'show_in_menu': None,
'site_description': None,
'standard': 'Yes',
'static_content': None,
'style': None,
'stylesheet': None,
'template': None,
'write_content': None
}
]