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.setup_wizard_area = $a(wrapper.body, 'div', 'setup-wizard'); } // ================================== 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 '; $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('What appears here? 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 = '' + (strip(det[11]) ? det[11] : det[2]) + ' (' + cint(det[12]) + '): 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 = '' + r.unread_messages + ' 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('home', 'event_updates', 'get_status_details', user, function(r,rt) { home_status_bar.render(r.message); // render online users pscript.online_users_obj.render(r.message.online_users); pscript.online_users = r.message.online_users; // setup wizard if(r.message.setup_status) { new SetupWizard(r.message.setup_status) } } ); } // 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('Company Name : '+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; i1) { me.prev_next = $a(me.wrapper, 'div', 'prev-next'); // next me.next = $a(me.prev_next, 'span', 'link_type', null, 'Next Suggestion', function() { me.show_suggestion(me.cur_sugg+1) }); // prev me.prev = $a(me.prev_next, 'span', 'link_type', null, 'Previous Suggestion', function() { me.show_suggestion(me.cur_sugg-1) }); } if(me.status.ret.length) { me.show_suggestion(0); } else { me.suggest_area.innerHTML = 'Congratulations: '.bold() + 'You are now on your track... Good luck'; } }, show_suggestion: function(idx) { me.cur_sugg = idx; me.suggest_area.innerHTML = 'What you can do next: '.bold() + me.status.ret[idx]; // show hide prev, next if(me.status.ret.length>1) { $dh(me.prev); $dh(me.next); if(idx>0) $ds(me.prev); if(idx