Sourced wnframework-modules from Google Code as erpnext

This commit is contained in:
Pratik Vyas
2011-06-08 14:37:15 +05:30
commit c1e6e4c752
1680 changed files with 162635 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
[
{
'_last_update': None,
'creation': '2010-11-30 22:41:39',
'disabled': 'No',
'docstatus': 0,
'doctype': 'Module Def',
'doctype_list': None,
'file_list': None,
'idx': None,
'is_hidden': 'No',
'last_updated_date': '2010-12-01 17:37:00',
'modified': '2010-12-13 11:50:27',
'modified_by': 'Administrator',
'module_desc': None,
'module_icon': 'chart_organisation.png',
'module_label': 'Members',
'module_name': 'My Company',
'module_page': 'My Company',
'module_seq': 2,
'name': 'My Company',
'owner': 'Administrator',
'parent': None,
'parentfield': None,
'parenttype': None,
'trash_reason': None,
'widget_code': None
},
{
'click_function': None,
'creation': '2011-03-24 15:04:46',
'description': None,
'display_name': None,
'doc_name': 'Forms',
'doc_type': 'Separator',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 1,
'modified': '2011-03-24 15:04:46',
'modified_by': 'Administrator',
'name': '000003090',
'owner': 'Administrator',
'parent': 'My Company',
'parentfield': 'items',
'parenttype': 'Module Def'
},
{
'click_function': None,
'creation': '2010-12-01 17:37:40',
'description': None,
'display_name': 'Social Badge',
'doc_name': 'Social Badge',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 2,
'modified': '2011-03-24 15:04:46',
'modified_by': 'Administrator',
'name': 'MDI00279',
'owner': 'Administrator',
'parent': 'My Company',
'parentfield': 'items',
'parenttype': 'Module Def'
},
{
'click_function': None,
'creation': '2011-03-24 15:04:46',
'description': None,
'display_name': None,
'doc_name': 'Pages',
'doc_type': 'Separator',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 3,
'modified': '2011-03-24 15:04:46',
'modified_by': 'Administrator',
'name': '000003091',
'owner': 'Administrator',
'parent': 'My Company',
'parentfield': 'items',
'parenttype': 'Module Def'
},
{
'click_function': None,
'creation': '2010-12-01 17:37:40',
'description': None,
'display_name': 'My Company',
'doc_name': 'My Company',
'doc_type': 'Pages',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 4,
'modified': '2011-03-24 15:04:46',
'modified_by': 'Administrator',
'name': 'MDI00281',
'owner': 'Administrator',
'parent': 'My Company',
'parentfield': 'items',
'parenttype': 'Module Def'
},
{
'creation': '2010-12-13 11:49:53',
'docstatus': 0,
'doctype': 'Module Def Role',
'idx': 1,
'modified': '2010-12-13 11:50:27',
'modified_by': 'Administrator',
'name': 'MDR00075',
'owner': 'Administrator',
'parent': 'My Company',
'parentfield': 'roles',
'parenttype': 'Module Def',
'role': 'All'
}
]

0
my_company/__init__.py Normal file
View File

View File

View File

@@ -0,0 +1,90 @@
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
# All roles of Role Master
def get_all_roles(self):
r_list=sql("select name from `tabRole` where name not in ('All','Guest','Administrator','Customer','Supplier') and docstatus != 2")
if r_list[0][0]:
r_list = [x[0] for x in r_list]
return r_list
# Get all permissions for given role
def get_permission(self,role):
perm = sql("select distinct t1.`parent`, t1.`read`, t1.`write`, t1.`create`, t1.`submit`,t1.`cancel`,t1.`amend` from `tabDocPerm` t1, `tabDocType` t2 where t1.`role` ='%s' and t1.docstatus !=2 and ifnull(t1.permlevel, 0) = 0 and t1.`read` = 1 and t2.module != 'Recycle Bin' and t1.parent=t2.name " % role)
return perm or ''
# Get roles for given user
def get_user_roles(self,usr):
r_list=sql("select role from `tabUserRole` where parent=%s and role not in ('All','Guest')",usr)
if r_list:
return [r[0] for r in r_list]
else:
return ''
# Update roles of given user
def update_roles(self,arg):
arg = eval(arg)
sql("delete from `tabUserRole` where parenttype='Profile' and parent ='%s'" % (cstr(arg['usr'])))
role_list = arg['role_list'].split(',')
for r in role_list:
pr=Document('UserRole')
pr.parent = arg['usr']
pr.parenttype = 'Profile'
pr.role = r
pr.parentfield = 'userroles'
pr.save(1)
sql("delete from __SessionCache where user=%s", cstr(arg['usr']))
# Save profile
def save_profile(self,arg):
arg = eval(arg)
p = Document('Profile', session['user'])
for k in arg:
p.fields[k] = arg[k]
p.save()
def update_profile_image(self, fid, fname):
sql("update tabProfile set file_list = '%s,%s' where name='%s'" % (fname, fid, session['user']))
def get_login_url(self):
return session['data']['login_from']
def get_user_info(self):
usr = sql("select count(name) from tabProfile where docstatus != 2 and name not in ('Guest','Administrator')")
usr = usr and usr[0][0] or 0
ol = sql("select count(distinct t1.name) from tabProfile t1, tabSessions t2 where t1.name = t2.user and t1.name not in('Guest','Administrator') and TIMESTAMPDIFF(HOUR,t2.lastupdate,NOW()) <= 1 and t1.docstatus != 2 and t1.enabled=1")
ol = ol and ol[0][0] or 0
ac = sql("select count(name) from tabProfile where enabled=1 and docstatus != 2 and name not in ('Guest', 'Administrator')")
ac = ac and ac[0][0] or 0
inac = sql("select count(name) from tabProfile where (enabled=0 or enabled is null or enabled = '') and docstatus != 2 and name not in ('Guest','Administrator')")
inac = inac and inac[0][0] or 0
return usr, ol, ac, inac
def get_sm_count(self) :
return sql("select count(t1.parent) from tabUserRole t1, tabProfile t2 where t1.role='System Manager' and t1.parent = t2.name and t2.enabled=1")[0][0] or 0

View File

@@ -0,0 +1 @@
[{'section_style': 'Simple', 'is_transaction_doc': None, 'creation': '2010-11-30 22:41:39', 'search_fields': None, 'module': 'My Company', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': 1, 'allow_rename': None, 'smallicon': '', 'allow_attach': None, 'show_in_menu': None, 'max_attachments': None, 'version': 43, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': None, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': '', 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': '', 'name': 'Company Control', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-11-17 16:25:34', 'server_code_error': ' ', 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}]

View File

View File

View File

@@ -0,0 +1,118 @@
pscript['onload_My Company']=function(){var wrapper=page_body.pages['My Company'];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)}}
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)}
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();}
MemberList.prototype.show_profile=function(uid,member_item){$dh(this.no_user_selected);if(!this.profiles[uid]){if(!member_item)member_item=this.member_items[uid];this.profiles[uid]=new MemberProfile(this.profile_wrapper,uid,member_item);}
if(this.cur_profile)
this.cur_profile.hide();this.profiles[uid].show();this.cur_profile=this.profiles[uid];}
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(){$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(){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'))));}
this.set_details=function(){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);}
if(user==det[0]){var span=$a(div,'span','',{padding:'2px',marginLeft:'3px'});span.innerHTML='(You)'}
var div=$a($td(this.tab,0,1),'div','',{color:'#777',fontSize:'11px'});div.innerHTML=det[0];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();if(user==det[0])me.name_link.onclick();}
MemberProfile=function(parent,uid,member_item){this.parent=parent;this.uid=uid;this.member_item=member_item;var me=this;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();}
this.make_image_and_bio=function(){var rh=$td(this.tab,0,1);this.img=$a($td(this.tab,0,0),'img','',{width:'80px',marginLeft:'10px'});set_user_img(this.img,this.uid);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'});}
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'});}}
this.show_roles=function(){if(!this.role_object)
this.role_object=new RoleObj(this.uid);this.role_object.dialog.show();}
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();}
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{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);}
this.render=function(){this.profile=locals['Profile'][uid];scroll(0,0);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;this.email_area.innerHTML=this.profile.name;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'});}
this.refresh_enable_disable();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);}
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';if(has_common(['Administrator','System Manager'],user_roles)){this.set_enable_button();}}
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);}
this.show=function(){if(!this.loading)$ds(this.wrapper);this.member_item.select();}
this.hide=function(){$dh(this.wrapper);this.member_item.deselect();}
this.make_message_list=function(){}
this.make();this.load();}
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();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);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();}}
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]));}
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);}}
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);}
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(){$(me.role_div).slideToggle('medium');$(me.help_div).slideToggle('medium');});this.help_div.back_btn=back_btn;$dh(this.help_div);}
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);}
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]);if(in_right){in_right=0;ridx++}else in_right=1;}
me.get_user_roles(id);}
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'});}
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;}
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);}
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;}}
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);}}
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);}
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);}
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,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

@@ -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 @@
[{'creation': '2010-06-29 12:40:20', 'module': 'My Company', 'doctype': 'Page', 'owner': 'Administrator', 'style': '', 'modified_by': 'Administrator', 'script': None, 'show_in_menu': 1, 'content': None, 'page_name': 'My Company', 'menu_index': None, 'docstatus': 0, 'parent': None, 'standard': 'Yes', 'icon': None, 'name': 'My Company', 'idx': None, 'static_content': None, 'modified': '2010-12-01 17:09:46', 'parenttype': None, 'parent_node': None, 'parentfield': None}, {'modified_by': 'Administrator', 'name': 'PR000143', 'parent': 'My Company', 'creation': '2010-06-29 16:40:26', 'modified': '2010-12-01 17:09:46', 'doctype': 'Page Role', 'idx': 1, 'parenttype': 'Page', 'role': 'Administrator', 'owner': 'Administrator', 'docstatus': 0, 'parentfield': 'roles'}, {'modified_by': 'Administrator', 'name': 'PR000153', 'parent': 'My Company', 'creation': '2010-08-06 20:18:55', 'modified': '2010-12-01 17:09:46', 'doctype': 'Page Role', 'idx': 2, 'parenttype': 'Page', 'role': 'All', 'owner': 'nabin@webnotestech.com', 'docstatus': 0, 'parentfield': 'roles'}]