var System=function(){
this.login=function(callback,email,password,firm_id){
server_call(callback,"__login",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.logout=function(callback){
server_call(callback,"__logout",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_login=function(callback,token){
server_call(callback,"get_login",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_dashboard=function(callback){
server_call(callback,"get_dashboard",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_firms=function(callback){
server_call(callback,"get_firms",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_domains=function(callback){
server_call(callback,"get_domains",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_firm=function(callback,firm_id){
server_call(callback,"get_firm",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.firm_update=function(callback,firm_id,r){
server_call(callback,"__update_firm",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.user_update=function(callback,user_id,r){
server_call(callback,"__user_update",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.user_signature_update=function(callback,user_id,signature){
server_call(callback,"__signature_update",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_activity=function(callback,activity_id){
server_call(callback,"get_activity",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_activities=function(callback,filter,sort){
server_call(callback,"get_activities",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_notification=function(callback,notification_id){
server_call(callback,"get_notification",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.email_notification=function(callback,notification_id){
server_call(callback,"__email_notification",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.email_notifications=function(callback,activity_id){
server_call(callback,"__email_notifications",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_notifications=function(callback,filter,sort,clear_view,_skip_rotator_){
server_call(callback,"get_notifications",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.firm_register=function(callback,r){
server_call(callback,"__firm_register",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.user_register=function(callback,r){
server_call(callback,"__user_register",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_users=function(callback,filter){
server_call(callback,"get_users",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_user=function(callback,user_id){
server_call(callback,"get_user",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.get_firm_setup=function(callback){
server_call(callback,"get_firm_setup",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.reset_email_passwords=function(callback,project_id){
server_call(callback,"__reset_email_passwords",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
this.reset_email_password=function(callback,user_id,project_id){
server_call(callback,"__reset_email_password",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1));
}
}
var system= new System();
var get_login=system.get_login;
var login=system.login;
var get_dashboard=system.get_dashboard;
var __page_widgets=[];
var page_widgets=[];
var login_status='__public__';
var vpage_name_register={};
var urls=[];
var p_url='';
var c_url='';
var global_params={};
var pageTimeout='';
function update_vpage_name(vpage,name){
if(name) name=vpages_setup[vpage][0]+' - '+name;
else name=vpages_setup[vpage][0];
for(var page in vpage_name_register) {
vpage_name_register[page](name);
}
}
function set_load_vpage(vpage,params,go_back,name){
if(typeof(params) !="undefined"){
for(var i in params) global_params[i]=params[i];
}
load_vpage(vpage,go_back,name);
}
function set_load_vpage_r(vpage,query_str,go_back,name){
set_load_vpage(vpage,set_params(query_str),go_back,name);
}
var set_params = function(query_str) {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
let params = {};
if (query_str ) {
query_str = query_str.replace(/^\/|\?/g, "");
var vars = query_str.split("&");
for (var i = 0; i < vars.length; i++) {
if (vars[i] != "") {
var pair = vars[i].split("=");
var var_name = pair.shift();
var var_data = pair.join("=");
// If first entry with this name
if (typeof params[var_name] === "undefined") {
params[var_name] = decodeURIComponent(var_data);
// If second entry with this name
} else if (typeof params[var_name] === "string") {
var arr = [ params[var_name], decodeURIComponent(var_data) ];
params[var_name] = arr;
// If third or later entry with this name
} else {
params[var_name].push(decodeURIComponent(var_data));
}
}
}
}
return params;
};
function go_back(){
if(urls.length>0){
let url=urls.pop();
let hurl=(url &&url.indexOf('?back=')==-1 && url.indexOf('&back=')==-1)?(((url.indexOf('?')==-1)?(url+'?'):(url+'&'))+'back=1'):url;
load_url(hurl,undefined,true);
}
}
function get_page_path(page) {
return page.replace(/\.*$/,'').replace(/^\//,'');
}
function load_url(url,_profile,go_back,name){
if(typeof(_profile)=="undefined") _profile=user_profile;
else user_profile=_profile
if(typeof(_profile) !="undefined" && Object.keys(_profile).length>0 ) login_status='_login__';
else login_status='__public__';
let p=_profile || user_profile;
//if( p &&!p.A05_signature && !p.token && p.A05_id) url='firm_users?action=edit&user_id='+p.A05_id;
if( url != (location.pathname+location.search).substr(1))
{
var History = window.history; // Note: We are using a capital H instead of a lowe
History.pushState(null, '', url);
}
c_url=url;
if(c_url !=p_url) {
global_params={};
if(p_url !='' && !go_back) urls.push(p_url);
p_url=url;
}
var w=url.split('?');
var x=(vpages_setup[w[0]] && vpages_setup[w[0]][3])?vpages_setup[w[0]][3]:w[0];
var a=x.split('?');
var vpage=(vpages_setup[w[0]] && vpages_setup[w[0]][3])?w[0]:a[0];
var query_str=a[1];
if(w[1] && query_str) query_str+='&'+w[1];
else if(w[1]) query_str=w[1];
set_load_vpage_r(vpage,query_str,go_back,name);
}
function get_rpage(vpage){
var x=(vpages_setup[vpage] && vpages_setup[vpage][3])?vpages_setup[vpage][3]:vpage;
var a=x.split('?');
var rpage=a[0];
return rpage;
}
function load_vpage( vpage,go_back,name)
{
if(vpage=='') vpage='dashboard';
var x=function(lstatus){
login_status=lstatus;
__page_widgets=page_widgets;
page_widgets = get_page_widgets(get_rpage(vpage), login_status);
ajaxRender.run(1, function() {
if(login_status=="__public__" || !vpages_setup[vpage] || ((user_profile.modules.indexOf('all')>=0 ||vpages_setup[vpage][2]=='' || user_profile.modules.indexOf(vpages_setup[vpage][2])>=0 ) && user_profile && user_profile.A05_priv>=vpages_setup[vpage][1])){
_previousData='';
sync_widgets(page_widgets,__page_widgets);
if(pageTimeout !=''){
clearTimeout(pageTimeout);
pageTimeout='';
}
update_vpage_name(vpage,name);
}
},page_widgets);
}
if(login_status=='__public__'){
get_login(function(data){
if(data){
user_profile=data;
x('__login__');
}else x('__public__');
},global_params['token']);
}else x('__login__');
}
var sync_widgets = function(active_widgets,inactive_widgets) {
for (var i = 0; i < active_widgets.length; i++) {
show_widget(active_widgets[i]);
}
for (var i = 0; i < inactive_widgets.length; i++) {
if (active_widgets.indexOf(inactive_widgets[i]) == -1) {
hide_widget(inactive_widgets[i]);
}
}
}
var hide_widget = function(widget) {
set_widget_state(widget, 'none');
}
var show_widget = function(widget) {
set_widget_state(widget, 'block');
}
var widget_state={};
var widget_pstate={};
var set_widget_state = function(widget, state) {
var widget_current_state = $('#' + widget).css('display');
var callpre = window["_" + widget + "__callpre"];
widget_state[widget]=state;
widget_pstate[widget]=widget_current_state;
set_state(widget, callpre);
}
var set_state = function(widget, callpre) {
if (typeof (callpre) == "function") {
callpre(widget_state[widget], widget_pstate[widget], function() {
var real_state = widget_state[widget] === 'block' ? '' : widget_state[widget];
if (widget_pstate[widget] != real_state) $('#' + widget).css('display', real_state);
});
} else {
var real_state = widget_state[widget] === 'block' ? '' : widget_state[widget];
if (widget_pstate[widget] != real_state)
$('#' + widget).css('display', real_state);
}
}
var get_page_widgets = function(vpage, login) {
var _page_ = clone_obj(__page__[login]);
var pagePath = vpage.split('/');
var _page_widgets_ = [];
var set_wp=function(parr){
_page_widgets_ = _page_widgets_.concat(parr);
}
for (var i = 0; i <= pagePath.length; i++) {
_page_widgets_ = _page_widgets_.concat(_page_['0']);
if (typeof (_page_[pagePath[i]]) == "undefined"
|| pagePath[i] == "index") {
set_wp(_page_['404']);
break;
} else {
if (Array.isArray(_page_[pagePath[i]])) {
set_wp(_page_[pagePath[i]]);
break;
} else {
if (typeof (_page_[pagePath[i]]) == 'object'){
_page_ = _page_[pagePath[i]];
}else {
set_wp(_page_['404']);
break;
}
}
}
}
_page_widgets_ = unique(_page_widgets_);
return _page_widgets_;
}
function p__body(){
var self=this;
this.root="p__body";
this.to_login;
this.processed=false;
this.navigation;
this.go_back=function(){
go_back();
}
this.temp=function(){
var html='';
html+='
';
html+='';
html+=' ';
html+='
';
html+='
';
html+=' ';
html+=' ';
html+=' ';
html+=' ';
html+=' ';
html+='
';
html+='
';
html+='
';
html+='
';
html+='
Back';
html+='
';
html+='
';
html+='
';
html+='';
html+='
';
html+='
';
html+='
';
html+='
';
html+='
';
html+='
';
html+=' ';
html+='
';
html+='
';
html+='
';
html+='
';
html+='
';
return html;
}
this.process=function(){
if(!self.processed){
self.processed=true;
$("#"+self.root).html(self.temp());
$('.back_button').click(
self.go_back
);
$(".fa-user").click(function() {
load_url('firm_users?action=edit&user_id='+user_profile.A05_id);
});
$(".fa-bell").click(function() {
$('.notification_text').html('');
load_url('personal_notifications');
});
$(".fa-sign-out").click(function(){
system.logout(function(){
load_url('dashboard',[]);
});
});
let x=function(){
system.get_notifications(function(notifications){
if(!notifications || notifications.length==0) $('.notification_text').html('');
else $('.notification_text').html(notifications.length);
},{'view':0},'',0,1);
};
x();
setInterval( x,30000);
self.navigation=new s__navigation_menu_item("#main_navigation",navigation_menu);
$(".menu_toggle").click(function() {
if( $("#rear_menu").hasClass('hide_menu')) $("#rear_menu").removeClass('hide_menu');
else $("#rear_menu").addClass('hide_menu');
});
vpage_name_register['p__body']=function(name){
self.set_menu_title(name);
}
$('.panel_icon').click(function(){
$('.panel_container').hide();
});
}
$("#firm_name").html((user_profile)?user_profile.A00_name:'');
$(".copyright").html((user_profile)?user_profile.A00_copyright:'');
if( !$("#rear_menu").hasClass('hide_menu')) $("#rear_menu").addClass('hide_menu');
if(urls.length==0) $('.back_button').hide();
else $('.back_button').show();
self.navigation.refresh();
self.navigation.set_url(c_url);
$("#main_content_top_right_bar").empty();
}
this.set_navigation_pending=function(menu_item,count){
self.navigation[menu_item].set_pending_count(count);
}
this.set_menu_title=function(menu_title){
$(".menu_title").html(menu_title);
}
this.callpre=function(state,pstate,callback){
if(user_profile.A05_priv<3) $(".menu_notification").hide();
else $(".menu_notification").show();
$('.profile_name').text(user_profile.A05_firstname+" "+user_profile.A05_lastname);
if(self.to_login) clearInterval(self.to_login);
self.to_login=setInterval(function(){
$('.profile_time').text( formatDuration(Math.round(Date.now() / 1000) -user_profile.A05_last_login));
},1000);
//$('.main_content').empty();
if(typeof(callback)=="function") callback();
}
}
var __p__body=new p__body();
function _p__body__data( callback )
{
__p__body.process();
callback();
}
var _p__body__callpre=__p__body.callpre;
ajaxRender.addCall(_p__body__data);
function p__login(){
var self=this;
this.root="p__login";
this.tmpl=function(domains){
var html='';
html+='';
html+='';
return html;
}
this.process=function(){
system.get_domains(function(domains){
let firm_id=0;
for(var i in domains){
let domain = domains[i];
if(domain==window.location.hostname) firm_id=i;
}
$("#"+self.root).html(self.tmpl((firm_id==0)?domains:null));
$(function() {
$("#page_overlay").fadeOut();
$(".login_button").click(function(e) {
e.preventDefault();
$(".login_warning").hide();
$(".login_button").hide();
$(".login_loading").show();
if($("#firm") && $("#firm").val()) firm_id=$("#firm").val();
login( function(data) {
if(data && Object.keys(data).length>0) {
load_url(c_url,data);
}else{
$(".login_loading").hide();
$(".login_part").fadeIn();
$(".login_button").show();
$(".login_warning").html("Invalid Login");
$(".login_warning").fadeIn();
$("#pass").val("");
$("#pass").focus();
}
},$("#user").val(), $("#pass").val(),firm_id);
});
});
});
}
}
var __p__login=new p__login();
function _p__login__data( callback )
{
__p__login.process();
callback();
}
ajaxRender.addCall(_p__login__data);
function c__admin_firms(){
var self=this;
this.root="c__admin_firms";
this.processed=false;
this.table;
this.filter={};
this.register;
this.top_bar;
this.columns={
}
this.process=function(){
if(!self.processed){
$(".main_content").append("
");
self.table=new s__admin_firms_table('#'+self.root);
self.register= new k__firm_register_form('.panel_content');
self.top_bar= new _top_bar();
self.processed=true;
}
}
this.create_register=function(){
self.top_bar.add_top_bar_button('register','Register','register','green','pencil-square',
function(){
self.register.process(
function(register_option){
if(Object.keys(register_option).length>0 && register_option['A00_name']){
system.firm_register(function(data){
self.table.process();
},register_option);
}
}
);
}
);
}
this.callpre=function(state,pstate,callback){
if(state !='none'){
self.table.init();
if(user_profile.A05_firm ==-1) self.create_register();
//self.create_panel();
self.table.process();
}
if(typeof(callback)=="function") callback();
}
}
var __c__admin_firms=new c__admin_firms();
function _c__admin_firms__data( callback )
{
__c__admin_firms.process();
callback();
}
var _c__admin_firms__callpre=__c__admin_firms.callpre;
ajaxRender.addCall(_c__admin_firms__data,"_p__body__data");
function c__dashboard(){
var self=this;
this.root="c__dashboard";
this.processed=false;
this.main_area=function(data){
var html='';
html+='';
html+='
Setup Signature
';
html+='
';
html+='
Change Password
';
if( user_profile && user_profile.modules &&(user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf('pr')>=0) ){
html+='
';
html+='
My Pending DTR
';
html+='
';
html+='
My Approved DTR
';
}
if( user_profile && user_profile.modules && (user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf('ts')>=0) ){
html+='
';
html+='
Pending Time Sheets
';
html+='
';
html+='
Approved Time Sheets
';
html+='
';
// html+='
Add Timesheet
';
}
if(user_profile && user_profile.modules && (user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf('pc')>=0 )){
html+='
';
html+='
Add Receipt
';
html+='
';
html+='
My Pending Receipts
';
html+='
';
html+='
My Pending Petty Cash Envelopes
';
}
/*
html+='
';
if(parseInt(data['project_all'])>0){
html+='
Production ';
html+='
Total: '+data['project_all']+'
';
html+='
Active: '+data['project_active']+'
';
html+='
Wrapped: '+data['project_wrapped']+'
';
html+='
Inactive: '+data['project_inactive']+'
';
html+='
';
}
if(parseInt(data['production_all'])>0){
html+='
';
html+='
DPR ';
html+='
Total: '+data['production_all']+'
';
html+='
Closed: '+data['production_closed']+'
';
html+='
Open: '+data['production_open']+'
';
html+='
';
}
if(parseInt(data['dtr_all'])>0 && data['dtr_all'] !=data['my_dtr_all']){
html+='
';
html+='
DTR ';
html+='
Total: '+data['dtr_all']+'
';
html+='
Closed: '+data['dtr_approved']+'
';
html+='
Open: '+data['dtr_open']+'
';
html+='
';
}
if(parseInt(data['my_dtr_all'])>0){
html+='
';
html+='
My DTR ';
html+='
Total: '+data['my_dtr_all']+'
';
html+='
Closed: '+data['my_dtr_approved']+'
';
html+='
Open: '+data['my_dtr_open']+'
';
html+='
';
}
*/
html+='
';
html+='';
return html;
}
this.process=function(data){
if(!self.processed){
$(".main_content").append("
");
self.processed=true;
}
$('#'+self.root).html(self.main_area(data));
}
this.callpre=function(state,pstate,callback){
if(typeof(callback)=="function") callback();
}
}
var __c__dashboard=new c__dashboard();
function _c__dashboard__data( callback )
{
get_dashboard(function(data){
__c__dashboard.process(data);
callback();
});
}
var _c__dashboard__callpre=__c__dashboard.callpre;
ajaxRender.addCall(_c__dashboard__data,"_p__body__data");
function c__firm_activities(){
var self=this;
this.root="c__firm_activities";
this.processed=false;
this.table;
this.filter;
this.filter_options={};
this.top_bar;
this.columns={
}
this.process=function(){
if(!self.processed){
$(".main_content").append("
");
self.table=new s__firm_activities_table('#'+self.root);
self.filter= new k__activity_filter_form('.panel_content');
self.top_bar= new _top_bar();
self.processed=true;
}
}
this.create_filter=function(){
self.top_bar.add_top_bar_button('filter','Filter','filter','green','filter',
function(){
self.filter.process(
self.filter_options,
function(filter_options){
self.filter_options=filter_options;
self.table.process(filter_options);
}
);
}
);
}
this.callpre=function(state,pstate,callback){
if(state !='none'){
self.table.init();
self.create_filter();
//self.create_panel();
self.filter_options={};
self.table.process(self.filter_options);
}
if(typeof(callback)=="function") callback();
}
}
var __c__firm_activities=new c__firm_activities();
function _c__firm_activities__data( callback )
{
__c__firm_activities.process();
callback();
}
var _c__firm_activities__callpre=__c__firm_activities.callpre;
ajaxRender.addCall(_c__firm_activities__data,"_p__body__data");
function c__firm_users(){
var self=this;
this.root="c__firm_users";
this.processed=false;
this.table;
this.users={};
this.filter={};
this.register_form;
this.filter_form;
this.top_bar;
this.columns={
}
this.process=function(){
if(!self.processed){
$(".main_content").append("
");
self.table=new s__firm_users_table('#'+self.root,self.reload);
self.register_form= new k__user_register_form('.panel_content');
self.filter_form = new k__user_filter_form('.panel_content');
self.top_bar= new _top_bar();
self.processed=true;
}
}
this.register_button=function(){
self.top_bar.add_top_bar_button('register','Register','register','green','pencil-square',
function(){
self.register_form.process(
function(register_options){
if(Object.keys(register_options).length>0){
system.user_register(function(data){
self.reload();
},register_options);
}
}
);
}
);
}
this.reset_emails_button=function(){
self.top_bar.add_top_bar_button('send_reset_emails','Send Everyone Reset Email','reset_password','green','envelope',
function(){
if(confirm('Are you sure?')){
system.reset_email_passwords(function(r){
if(r) alert('email sent');
},0);
}
}
);
}
this.filter_button=function(){
self.top_bar.add_top_bar_button('filter','Filter','filter','gray','filter',
function(){
self.filter_form.process(
self.filter,
function(filter_options){
let lfilter=self.filter;
self.filter = filter_options;
if(lfilter.activity_start || lfilter.activity_end ||self.filter.activity_start || self.filter.activity_end) self.reload();
else self.refresh();
}
);
}
);
/*
self.top_bar.add_top_bar_button('clear_filter','Clear Filter','clear_filter','white','refresh',
function(){
let lfilter=self.filter;
self.filter = {};
if(lfilter.activity_start || lfilter.activity_end) self.reload();
else self.refresh();
}
);
*/
}
this.reload=function(){
system.get_users(function(users){
self.users=users;
self.table.process(users,self.filter);
},self.filter);
}
this.refresh=function(){
self.table.process(self.users,self.filter);
}
this.callpre=function(state,pstate,callback){
if(state !='none'){
self.filter={};
self.table.init();
if(parseInt(user_profile.A05_priv)>=5) self.register_button();
if(parseInt(user_profile.A05_priv)>=5) self.reset_emails_button();
//self.create_panel();
self.filter_button();
self.reload();
}
if(typeof(callback)=="function") callback();
}
}
var __c__firm_users=new c__firm_users();
function _c__firm_users__data( callback )
{
__c__firm_users.process();
callback();
}
var _c__firm_users__callpre=__c__firm_users.callpre;
ajaxRender.addCall(_c__firm_users__data,"_p__body__data");
function c__notifications(){
var self=this;
this.root="c__notifications";
this.processed=false;
this.table;
this.filter;
this.filter_options={};
this.top_bar;
this.columns={
}
this.process=function(){
if(!self.processed){
$(".main_content").append("
");
self.table=new s__notifications_table('#'+self.root);
self.filter= new k__notification_filter_form('.panel_content');
self.top_bar= new _top_bar();
self.processed=true;
}
}
this.create_filter=function(){
self.top_bar.add_top_bar_button('filter','Filter','filter','green','filter',
function(){
self.filter.process(
self.filter_options,
function(filter_options){
// filter_options['user_id']=global_params.user_id || -1;
// filter_options['activity_id']=global_params.activity_id || 0;
self.filter_options=filter_options;
self.table.process(filter_options,'');
}
);
}
);
}
this.create_email_notifications=function(){
self.top_bar.add_top_bar_button('email_notifications','Email Notifications','email_notifications','blue','envelope-square',
function(){
if(confirm('Are you sure you want to send email to all members listed in this page?')){
system.email_notifications(function(){
alert('Notification reminder has been submitted to the listed members');
},global_params.activity_id ||0);
}
}
);
}
this.callpre=function(state,pstate,callback){
if(state !='none'){
self.table.init();
self.create_filter();
if(global_params.activity_id && user_profile.privs[0]>=15) self.create_email_notifications();
//self.create_panel();
self.table.process({'user_id':global_params.user_id || -1,'activity_id':global_params.activity_id || 0},'');
}
if(typeof(callback)=="function") callback();
}
}
var __c__notifications=new c__notifications();
function _c__notifications__data( callback )
{
__c__notifications.process();
callback();
}
var _c__notifications__callpre=__c__notifications.callpre;
ajaxRender.addCall(_c__notifications__data,"_p__body__data");
function c__user_profile(){
var self=this;
this.root="c__user_profile";
this.processed=false;
this.profile;
this.top_bar;
this.setup;
this.edit_form;
this.process=function(){
if(!self.processed){
$(".main_content").append("");
self.top_bar= new _top_bar();
self.edit_form= new k__user_edit_form('.panel_content');
self.profile=new s__user_profile('#'+self.root+'_top');
self.processed=true;
}
}
this.edit=function(user_id){
system.get_user(function(user){
self.edit_form.process(user,function(edit_option){
var r={};
for(var col in edit_option){
if(user[col] !=edit_option[col]) r[col]=edit_option[col];
}
if(Object.keys(r).length>0){
system.user_update(function(data){
refresh();
},user['A05_id'],r);
}
});
},user_id);
}
this.edit_button=function(){
self.top_bar.add_top_bar_button('edit','Edit Profile','edit','blue','pencil-square',
function(){
let user_id=global_params.user_id;
self.edit(user_id);
}
);
}
this.refresh=function(){
let user_id=global_params['user_id'] || 0;
system.get_user(function(user){
if(user){
self.profile.process(user);
self.association_table=new s__user_association_table('#'+self.root+'_bottom',self.setup);
self.association_table.process(user.projects);
}
},user_id);
}
this.callpre=function(state,pstate,callback){
if(state !='none'){
system.get_firm_setup(function(setup){
self.setup=setup;
self.refresh();
});
}
if(typeof(callback)=="function") callback();
}
}
var __c__user_profile=new c__user_profile();
function _c__user_profile__data( callback )
{
__c__user_profile.process();
callback();
}
var _c__user_profile__callpre=__c__user_profile.callpre;
ajaxRender.addCall(_c__user_profile__data,"_p__body__data");
var s__admin_firms_table=function(root){
var self=this;
this.root=root;
this.edit= new k__firm_edit_form('.panel_content');
this.table_tpl=function(){
var html='';
return html;
}
this.row_tpl=function(data){
var html='';
html +='';
html +=''+(data['A00_name'] ||'')+' ';
html +=''+(data['A00_address'] ||'')+' ';
html +=''+(data['A00_city'] ||'')+' ';
html +=''+(data['A00_state'] ||'')+' ';
html +=''+(data['A00_country'] ||'')+' ';
html +=''+(data['A00_phone'] ||'')+' ';
if(parseInt(user_profile.A05_priv)>=5) html +=' ';
html +=' ';
return html;
}
this.foot_tpl=function(summary){
var html='';
html+='
';
return html;
}
this.load_table=function(page_num){
self._load_table(root, system.get_firms);
}
this.process=function(){
self.load_table(1);
}
this.row_callback=function(){
if(user_profile.A05_priv>10){
$('.edit_button').click(
function(){
var firm_id=$(this).attr("data");
system.get_firm(function(firm){
self.edit.process(firm,function(edit_option){
var r={};
for(var col in edit_option){
r[col]=edit_option[col];
}
if(Object.keys(r).length>0){
system.firm_update(function(data){
self.load_table(-1);
},firm['A00_id'],r);
}
});
},firm_id);
}
);
}
}
}
s__admin_firms_table.prototype=_table_display.prototype;
var s__firm_activities_table=function(root){
var self=this;
this.root=root;
this.details= new k__activity_details_form('.panel_content');
this.table_tpl=function(){
var html='';
return html;
}
this.row_tpl=function(data){
var html='';
html +='';
html +=''+sec_to_date(data['Y00_timestamp'])+' ';
html +=''+((data['A04_name'])?data['A04_name']:'')+' ';
html +=''+data['A05_firstname']+' '+data['A05_lastname']+' ';
html +=''+data['Y00_function']+' ';
html +=' ';
return html;
}
this.foot_tpl=function(summary){
var html='';
html+='
';
return html;
}
this.load_table=function(filter,sort){
self._load_table(root, system.get_activities,filter,sort);
}
this.process=function(filter,sort){
self.load_table(filter,sort);
}
this.row_callback=function(){
$('.details_button').click(
function(){
var id=$(this).attr("data");
system.get_activity(function(activity){
self.details.process(activity,function(){
});
},id);
}
);
$('.notifications_button').click(
function(){
var id=$(this).attr("data");
load_url('notifications?user_id=0&activity_id='+id);
} );
}
}
s__firm_activities_table.prototype=_table_display.prototype;
var s__firm_users_table=function(root,refresh){
var self=this;
this.root=root;
this.edit= new k__user_edit_form('.panel_content');
this.table_tpl=function(){
var html='';
return html;
}
this.row_tpl=function(data){
var html='';
if(data){
html +='';
html +=''+data['A05_firstname']+' '+data['A05_lastname']+' ';
html +=''+((data['A05_email'] && data['A05_email'].indexOf('@')>=0)?data['A05_email']:'')+' ';
html +=''+((data['A05_phone'])?data['A05_phone']:'')+' ';
// html +=''+(data['projects'] || 0)+' ';
/*
html +='';
html+=''+(data['tr'] || '0')+'
';
if(data['tr'] != data['approved_tr']){
html+=' /
';
html+=''+(data['approved_tr'] || '0')+'
';
html+=' /
';
html+=''+(data['pending_tr'] || '0')+'
';
}
html+=' ';
*/
html+=' ';
html +=' ';
html +=' ';
html +=' ';
}
return html;
}
this.foot_tpl=function(summary){
var html='';
html+='
';
return html;
}
this.__edit=function(user_id){
let x=function(){
system.get_user(function(user){
self.edit.process(user,function(edit_option){
var r={};
for(var col in edit_option){
if(user[col] !=edit_option[col]) r[col]=edit_option[col];
}
if(Object.keys(r).length>0){
system.user_update(function(data){
refresh();
},user['A05_id'],r);
}
});
},user_id);
}
x();
}
this.process=function(users,filter){
self._load_data(self.apply_filter(users,filter));
if(global_params['action']=='edit' && global_params.user_id>0 && !global_params.back) self.__edit(global_params.user_id);
}
this.apply_filter=function(users,filter){
let project_id=filter.project || 0;
let department_id=filter.department || 0;
let position_id=filter.position || 0;
let name=filter.fullname || '';
let _users=[];
for(var i in users){
if(project_id==0 || users[i].projects && users[i].projects[project_id]){
let departments=[];
let projects=users[i].projects;
if(projects){
for(var _project_id in projects){
if(project_id==0 || project_id==_project_id) {
let _departments=projects[_project_id];
for(var _department_id in _departments){
if(departments[_department_id]){
departments[_department_id]=departments[_department_id].concat(_departments[_department_id]);
}else {
departments[_department_id]=_departments[_department_id];
}
}
}
}
}
if(department_id==0 || departments[department_id]){
let positions=[];
if(departments){
for(var _department_id in departments) {
if(department_id==0 || department_id==_department_id) positions = positions.concat(departments[_department_id]);
}
}
if(position_id==0 || positions.indexOf(position_id)>=0){
if(name=='' || (users[i].A05_firstname+' '+users[i].A05_lastname)==name) _users.push( users[i]);
}
}
}
}
return _users;
}
this.row_callback=function(){
$('.edit_button').click(
function(){
var user_id=$(this).attr("data");
self.__edit(user_id);
}
);
$('.user_profile').click(
function(){
var user_id=$(this).attr("user_id");
load_url('user_profile?user_id='+user_id,undefined,undefined,$(this).attr("name"));
}
);
$('.reset_button').click(function(){
let x=this;
var token=$(this).attr("data");
navigator.clipboard.writeText(location.protocol + '//' + location.host +'/dashboard?token='+token);
$(x).attr('src',"/icons/copy.svg");
setTimeout(function(){
$(x).attr('src',"/icons/link.png");
},1000);
});
}
}
s__firm_users_table.prototype=_table_display.prototype;
function s__navigation_menu_item(root,navigation_menu){
var self=this;
var priv=-1;
this.menu_tpl=function(branch,item,hide_arrow){
var html='';
html+='';
return html;
}
this.submenu_tpl=function(link,name){
var html='';
html+='';
return html;
}
this.reset_highlight_submenu_link=function(branch,item,link){
for(var submenu_item in item.submenu){
var link2=branch+"_"+submenu_item+"__link";
if(link2==link){
$("#"+link).addClass('submenu-selected');
}
else {
$('#'+link2).removeClass('submenu-selected');
}
}
}
this.set_url=function(url){
let vps=url.split("_");
var br=vps.shift();
var link='';
for(var branch in navigation_menu){
item=navigation_menu[branch];
$('#'+branch+'__menu').removeClass("selected");
self.reset_menu(branch,navigation_menu[branch],true);
if(typeof(item.submenu)=="undefined" && branch==url){
$('#'+branch+'__menu').addClass("selected");
}else if(br==branch && typeof(item.submenu) !="undefined"){
self.expand_menu(branch);
$('#'+branch+'__submenu').show();
let submenu_item=vps.join("_");
for(var sub_item in item.submenu){
if(sub_item==submenu_item){
link=branch+"_"+submenu_item+"__link";
}
}
self.reset_highlight_submenu_link(branch,item,link);
}
}
}
this.load_url=function(url,branch,item){
load_url(url);
}
this.set_link_click=function(branch,item,link,url){
$("#"+link).click(
function(){
self.reset_highlight_submenu_link(branch,item,link);
self.load_url(url,branch,item);
});
}
this.reset_menu=function(branch,item,true_reset){
$("#"+branch+"__arrow").removeClass('fa-angle-down');
$("#"+branch+"__arrow").addClass('fa-angle-left');
if(true_reset){
$('#'+branch+'__submenu').hide();
self.reset_highlight_submenu_link(branch,item,'');
}
}
this.expand_menu=function(branch){
$("#"+branch+"__arrow").removeClass('fa-angle-left');
$("#"+branch+"__arrow").addClass('fa-angle-down');
$('#'+branch+'__menu').addClass("selected");
}
this.set_menu_hover=function(branch){
$('#'+branch+'__menu').mouseover(
function(){
$('#'+branch+'__menu').addClass("is-hover");
}
);
$('#'+branch+'__menu').mouseout(
function(){
$('#'+branch+'__menu').removeClass("is-hover");
}
);
}
this.build_menu=function(branch,item){
var html='';
var urls='';
html+='';
$(root).append(html);
for(var submenu_item in item.submenu){
var link=branch+"_"+submenu_item+"__link";
var url=branch+"_"+submenu_item;
self.set_link_click(branch,item,link,url);
//urls+="'"+branch+"_"+submenu_item+"':{'0':['c__"+branch+"_"+submenu_item+"']},\n";
urls+=url+":'"+item.submenu[submenu_item]+"',\n";
}
return urls;
}
this.set_menu_click=function(branch,item){
$('#'+branch+"__menu").click(
function(){
if(typeof(item.submenu) !="undefined"){
$('#'+branch+'__submenu').toggle();
if( $('#'+branch+'__submenu').css('display')=='none') {
self.reset_menu(branch,item);
}else{
self.expand_menu(branch);
}
}else self.load_url(branch,branch,null);
}
);
}
this.refresh=function(){
let new_priv=( user_profile)?user_profile.A05_priv:0;
if(self.priv !=new_priv){
$(root).html('');
self.process();
}
}
this.process=function(){
var urls='';
self.priv=( user_profile)?user_profile.A05_priv:0;
for(var branch in navigation_menu){
if(!vpages_setup[branch] || (user_profile && user_profile.modules && ( user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf(vpages_setup[branch][2])>=0 ) && user_profile.A05_priv>=vpages_setup[branch][1])){
var item=navigation_menu[branch];
$(root).append(self.menu_tpl(branch,item,typeof(item.submenu)=="undefined"));
self.set_menu_hover(branch);
if(typeof(item.submenu) !="undefined"){
urls+=self.build_menu(branch,item);
}
self.set_menu_click(branch,item);
}
}
//console.log(urls);
}
this.set_pending_count=function(count){
if(!count) count=0;
if(count==0) $('#'+branch+"__pending_count").hide();
else $('#'+branch+"__pending_count").show();
$('#'+branch+"__pending_count").text(count);
}
self.process();
}
var s__notifications_table=function(root){
var self=this;
this.root=root;
this.sort;
this.users;
this.filter;
this.details= new k__notification_details_form('.panel_content');
this.table_tpl=function(){
var html='';
return html;
}
this.row_tpl=function(data){
var html='';
let creator=self.users[data.creator_id];
html +='';
html +=''+data['date']+' ';
if(global_params.activity_id) html +=''+(data['name'] || '')+' ';
else html +=''+(creator?creator.A05_firstname+' '+creator.A05_lastname:'')+' ';
html +=''+data['project']+' ';
html +=''+data['title']+' ';
html +=''+((data['emailed']=='-1')?'N':((data['email'].indexOf('@')==-1)?'N/A':'Y'))+' ';
html +=' ';
return html;
}
this.foot_tpl=function(summary){
var html='';
html+='
';
return html;
}
this.load_table=function(){
system.get_firm_setup(function(setup){
self.users=hash_data_array(setup.users,'A05_id');
self._load_table(root, system.get_notifications,self.filter,self.sort,1,0);
});
}
this.process=function(filter,sort){
self.filter=filter;
self.sort=sort;
self.load_table();
}
this.row_callback=function(){
$('.details_button').click(
function(){
var id=$(this).attr("data");
system.get_notification(function(n){
self.load_table();
self.details.process(n,function(){
});
},id);
}
);
}
}
s__notifications_table.prototype=_table_display.prototype;
var s__user_association_table=function(root,setup){
var self=this;
this.root=root;
this.table_tpl=function(){
var html='';
return html;
}
this.projects_to_association=function(projects){
let association=[];
let projects_=hash_data_array(setup['projects'],'A04_id');
let departments_=hash_data_array(setup['departments'],'A02_id');
let positions_=hash_data_array(setup['positions'],'A03_id');
for(var project_id in projects){
let departments=projects[project_id];
for(var department_id in departments){
let positions=departments[department_id];
for(var position_id in positions){
let days=positions[position_id]['days'];
let activity_start=positions[position_id]['date_start'];
let activity_end=positions[position_id]['date_end'];
association.push({'days':days,'department_id':department_id,'project_id':project_id,'position_id':position_id,
'department':((departments_[department_id])?departments_[department_id].A02_name:''),
'position':((positions_[position_id])?positions_[position_id].A03_name:''),
'project':((projects_[project_id])?projects_[project_id].A04_name:'(Deleted)'),
'activity':(activity_start+' '+activity_end)
});
}
}
}
return association;
}
this.process=function(projects){
self._load_data(self.projects_to_association(projects));
}
this.row_tpl=function(data){
var html='';
if(data){
html +='';
html +=''+data['activity']+' ';
html +=''+data['project']+' ';
html +=''+data['department']+' ';
html +=''+data['position']+' ';
html +=''+data['days']+' ';
html +=' ';
}
return html;
}
this.foot_tpl=function(){
var html='';
html+='
';
return html;
}
this.init();
this.row_callback=function(){
}
}
s__user_association_table.prototype=_table_display.prototype;
var s__user_profile=function(root){
var self=this;
this.root=root;
this.view_tpl=function(user){
var html='