var System=function(){ this.switch_firm=function(callback,firm_id){ server_call(callback,"__switch_firm",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } 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,signaturebase64){ server_call(callback,"__signature_upload",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.check_email=function(callback,email){ server_call(callback,"check_email",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.user_signature_upload=function(callback,user_id,signaturebase64){ server_call(callback,"__signature_upload",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)); } this.get_ground_truths=function(callback,type){ server_call(callback,"get_ground_truths",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_ground_truth=function(callback,truth_id){ server_call(callback,"get_ground_truth",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.update_ground_truth=function(callback,truth_id,r){ server_call(callback,"__update_ground_truth",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_metrics=function(callback,type){ server_call(callback,"get_ground_runs",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.add_metric=function(callback,type,r){ server_call(callback,"__add_ground_run",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_metric=function(callback,run_id){ server_call(callback,"get_ground_run",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.update_metric=function(callback,run_id,r){ server_call(callback,"__update_ground_run",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_metric_stats=function(callback,run_id){ server_call(callback,"get_ground_stats",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_metric_stat=function(callback,stat_id){ server_call(callback,"get_ground_stat",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 && user_profile.modules&& (user_profile.modules.indexOf('all')>=0 ||vpages_setup[vpage][2]=='' || user_profile.modules.indexOf(vpages_setup[vpage][2])>=0 ) && (user_profile.A05_priv>=vpages_setup[vpage][1]|| user_profile.A05_firm ==-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.switch_firm=function(){ let firm=$('#firm').val(); system.switch_firm(function(profile){ user_profile=profile; load_url('dashboard'); },firm); } this.build_firm_switch=function(firms,firm){ if(firms){ var html=' '; $('#firm_switch').html(html); $('#firm').change(self.switch_firm); } } this.temp=function(){ var html=''; html+=''; html+='
'; html+='
'; html+='
'; html+='
'; html+=''; html+='
'; html+='
'; html+='
'; html+=''; html+=''; html+='
'; html+='
'; html+='
'; html+=' '; html+='
'; html+=' '; html+=' '; html+=' '; html+='
'; 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').removeClass('panel_fullscreen'); $('.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'); let firms=(user_profile)?user_profile.firms:[]; let firm=(user_profile)?user_profile.A05_firm:0; self.build_firm_switch(firms,firm); if(urls.length==0) $('.back_button').css("visibility", "hidden"); else $('.back_button').css("visibility", "visible"); 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+='
'; html+='
'; 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__admin_ground_truths(){ var self=this; this.root="c__admin_ground_truths"; 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_ground_truths_table('#'+self.root); self.top_bar= new _top_bar(); self.processed=true; } } this.callpre=function(state,pstate,callback){ if(state !='none'){ self.table.init(); //self.create_panel(); self.table.process(); } if(typeof(callback)=="function") callback(); } } var __c__admin_ground_truths=new c__admin_ground_truths(); function _c__admin_ground_truths__data( callback ) { __c__admin_ground_truths.process(); callback(); } var _c__admin_ground_truths__callpre=__c__admin_ground_truths.callpre; ajaxRender.addCall(_c__admin_ground_truths__data,"_p__body__data"); function c__admin_metric_stats(){ var self=this; this.root="c__admin_metric_stats"; 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_metric_stats_table('#'+self.root); self.top_bar= new _top_bar(); self.processed=true; } } this.callpre=function(state,pstate,callback){ if(state !='none'){ self.table.init(); //self.create_panel(); self.table.process(); } if(typeof(callback)=="function") callback(); } } var __c__admin_metric_stats=new c__admin_metric_stats(); function _c__admin_metric_stats__data( callback ) { __c__admin_metric_stats.process(); callback(); } var _c__admin_metric_stats__callpre=__c__admin_metric_stats.callpre; ajaxRender.addCall(_c__admin_metric_stats__data,"_p__body__data"); function c__admin_metrics(){ var self=this; this.root="c__admin_metrics"; this.processed=false; this.table; this.filter={}; this.top_bar; this.add; this.columns={ } this.process=function(){ if(!self.processed){ $(".main_content").append(""); self.table=new s__admin_metrics_table('#'+self.root); self.add= new k__metric_add_form('.panel_content'); self.top_bar= new _top_bar(); self.processed=true; } } this.create_run=function(){ self.top_bar.add_top_bar_button('run_cs','Schedule CS Run','run_cs','green','pencil-square', function(){ self.add.process( function(add_option){ system.add_metric(function(data){ self.table.process(); },'cs',add_option); } ); } ); } this.callpre=function(state,pstate,callback){ if(state !='none'){ self.table.init(); //self.create_panel(); self.create_run(); self.table.process(); } if(typeof(callback)=="function") callback(); } } var __c__admin_metrics=new c__admin_metrics(); function _c__admin_metrics__data( callback ) { __c__admin_metrics.process(); callback(); } var _c__admin_metrics__callpre=__c__admin_metrics.callpre; ajaxRender.addCall(_c__admin_metrics__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['journal_all'])>0){ html+='
'; html+='

DPR

'; html+='
Total: '+data['journal_all']+'
'; html+='
Closed: '+data['journal_closed']+'
'; html+='
Open: '+data['journal_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='
'; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
NameAddressCityStateCountryPhone
'; 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__admin_ground_truths_table=function(root){ var self=this; this.root=root; this.edit= new k__ground_truth_edit_form('.panel_content'); this.table_tpl=function(){ var html='
'; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
FirmProductionDayTypeFile
'; return html; } this.row_tpl=function(data){ var html=''; html +=''; html +=''+(data['A00_name'] ||'')+''; html +=''+(data['A04_name'] ||'')+''; html +=''+(data['B04_title'] ||'')+''; html +=''+(data['D00_type'] ||'')+''; html +=''+(data['B04_'+data['D00_type']] ||'')+''; 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_ground_truths,''); } this.process=function(){ self.load_table(1); } this.row_callback=function(){ $('.edit_button').click( function(){ var truth_id=$(this).attr("data"); system.get_ground_truth(function(truth){ self.edit.process(truth,function(edit_option){ var r={}; for(var col in edit_option){ r[col]=edit_option[col]; } if(Object.keys(r).length>0){ system.update_ground_truth(function(data){ self.load_table(-1); },truth_id,r); } }); },truth_id); } ); $('.download_file').click( function(){ let type=$(this).attr("type"); let firm_id=$(this).attr("firm_id"); let project_id=$(this).attr("project_id"); let journal_id=$(this).attr("journal_id"); let params=encodeURI(JSON.stringify({'project_id':project_id,'journal_id':journal_id,'firm_id':firm_id})); document.location.href=getDownloadUrl()+'func=download_'+type+'¶ms='+params; } ); } } s__admin_ground_truths_table.prototype=_table_display.prototype; var s__admin_metric_stats_table=function(root){ var self=this; this.root=root; this.edit= new k__metric_stat_edit_form('.panel_content'); this.table_tpl=function(){ var html='
'; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
DateFileCorrectness %
'; return html; } this.row_tpl=function(data){ var html=''; html +=''; html +=''+sec_to_date(data['D01_creation_date'])+''; html +=''+(data['B04_'+data['D00_type']] ||'')+''; html +=''+(data['D02_correctness'] ||'i0')+''; 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_metric_stats,global_params.run_id); } this.process=function(){ self.load_table(1); } this.row_callback=function(){ $('.edit_button').click( function(){ var stat_id=$(this).attr("data"); system.get_metric_stat(function(stat){ self.edit.process(stat,function(edit_option){ }); },stat_id); } ); $('.download_file').click( function(){ let type=$(this).attr("type"); let firm_id=$(this).attr("firm_id"); let project_id=$(this).attr("project_id"); let journal_id=$(this).attr("journal_id"); let params=encodeURI(JSON.stringify({'project_id':project_id,'journal_id':journal_id,'firm_id':firm_id})); document.location.href=getDownloadUrl()+'func=download_'+type+'¶ms='+params; } ); } } s__admin_metric_stats_table.prototype=_table_display.prototype; var s__admin_metrics_table=function(root){ var self=this; this.root=root; this.edit= new k__metric_edit_form('.panel_content'); this.table_tpl=function(){ var html='
'; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
DateTypeNameProgress#Ground TruthsAbs %Avg %
'; return html; } this.row_tpl=function(data){ var html=''; html +=''; html +=''+sec_to_date(data['D01_creation_date'] )+''; html +=''+(data['D01_type'] ||'')+''; html +=''+(data['D01_name'] ||'')+''; html +=''+((data['D01_status'] !='complete')?data['D01_progress']:'complete')+''; html +=''+(data['D01_sample_truth'] ||'')+''; html +=''+(data['D01_correctness'] ||'0')+''; html +=''+(data['D01_avg_correctness'] ||'0')+''; 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_metrics,''); } this.process=function(){ self.load_table(1); } this.row_callback=function(){ $('.edit_button').click( function(){ var run_id=$(this).attr("data"); system.get_metric(function(metric){ self.edit.process(metric,function(edit_option){ var r={}; for(var col in edit_option){ r[col]=edit_option[col]; } if(Object.keys(r).length>0){ system.update_metric(function(data){ self.load_table(-1); },run_id,r); } }); },run_id); } ); } } s__admin_metrics_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='
'; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
DateProductionUserActivity
'; 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='
'; html +=''; html +=''; html +=''; html +=''; html +=''; // html +=''; // html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
NameEmailPhoneT / C / P
'; 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; var firm=0; this.menu_tpl=function(branch,item,hide_arrow){ var html=''; html+='
  • '; html+=' '+item.display_name+' '; html+=' '; html+=' '; html+='
  • '; return html; } this.submenu_tpl=function(link,name){ var html=''; html+='
    '; html+=name; 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; let new_firm=( user_profile)?user_profile.A05_firm:0; if(self.priv !=new_priv || self.firm != new_firm){ $(root).html(''); self.process(); } } this.process=function(){ var urls=''; self.priv=( user_profile)?user_profile.A05_priv:0; self.firm=( user_profile)?user_profile.A05_firm: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] || user_profile.A05_firm==-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='
    '; html +=''; html +=''; html +=''; if(global_params.activity_id) html +=''; else html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
    DateDestinedCreatorProductionActivityEmailed
    '; 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='
    '; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
    DateProductionDepartmentPositionDays
    '; 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='
    '; html+='
    '; html+='
    '; html+='
    Last Login'+((!user.A05_last_login)?'':sec_to_date(user.A05_last_login))+'
    '; html+='
    '; html+='
    '; html+='
    '; html+='
    '; if(user.A05_signature){ html+=''; } html+='
    '; html+='
    '; html+='
    '; html+='
    First Name:'; html+=user.A05_firstname; html+='
    '; html+='
    '; html+='
    '; html+='
    Last Name:'; html+=user.A05_lastname; html+='
    '; html+='
    '; html+='
    '; html+='
    '; html+='
    Email:'; html+=((user.A05_email.indexOf('@')>=0)?user.A05_email:''); html+='
    '; html+='
    '; html+='
    '; html+='
    Phone:'; html+=(user.A05_phone || ''); html+='
    '; html+='
    '; html+=' '; html+='
    '; html+='
    Department:'; html+=(user.A02_name || ''); html+='
    '; html+='
    '; html+='
    '; html+='
    Position:'; html+=(user.A03_name || ''); html+='
    '; html+='
    '; html+='
    '; html+='
    Privilege:'; html+=get_upriv(user.A05_priv); html+='
    '; html+='
    '; html+='
    Status:'; html+=user.A05_status; html+='
    '; html+='
    '; html+= '
    '; html+=''; return html; } this.process=function(user){ $(self.root).html(self.view_tpl(user)); } } var k__activity_details_form=function(root){ var self=this; this.html_parse=function(inputs){ let h=''; for(var k in inputs){ if(typeof(inputs[k])=="object") h+=self.html_parse(inputs[k]); else h+='
    '+k+': '+inputs[k]+'
    '; } return h; } this.tmpl_content=function(sys){ var html=''; html+='
    '; html+='
    Date
    '; html+=sec_to_date(sys.Y00_timestamp); html+='
    '; html+='
    '; html+='
    Project
    '; html+=(sys.A04_name || ''); html+='
    '; html+='
    '; html+='
    Name
    '; html+=sys.A05_firstname+' '+sys.A05_lastname; html+='
    '; html+='
    '; html+='
    Activity
    '; html+=sys.Y00_function; html+='
    '; html+='
    '; html+='
    Data
    '; var inputs=JSON.parse(sys.Y00_inputs); html+=self.html_parse(inputs); html+='
    '; html+=' '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, parseInt(user_profile.privs[0]) ,'Activity Details',self.tmpl_content(sys),sys,__callback,function(){ $('.action-button').hide(); }); } } k__activity_details_form.prototype=_action_form.prototype; var k__activity_filter_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(setup){ var html=''; html+='
    '; html+='
    User
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Start date
    '; html+=' '; html+='
    '; html+='
    '; html+='
    End date
    '; html+=' '; html+='
    '; let projects=setup['projects']; html+='
    '; html+='
    Which Project?
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(filter,__callback){ system.get_firm_setup(function(setup){ self.__process(root,user_profile.A05_priv,'Filter',self.tmpl_content(setup),filter,function(r){ if(__callback) __callback(r); },function(cb){ if(cb) cb(); }); }); } } k__activity_filter_form.prototype=_action_form.prototype; var k__firm_edit_form=function(root){ var self=this; var name="Submit"; this.process=function(sys,__callback){ self.__process(root,user_profile.A05_priv,false,firm_form_html(),sys,__callback, function(cb){ if(typeof(cb)=="function") cb(); all_modules_change(); core_modules_change(); all_features_change(); $('#A00_all_modules').change(all_modules_change); $('#core_modules').change(core_modules_change); $('#A00_all_features').change(all_features_change); } ); } } k__firm_edit_form.prototype=_action_form.prototype; var k__firm_register_form=function(root){ var self=this; this._check_email=function(data){ if(data==1){ $('#password').hide(); $('#firstname').hide(); $('#lastname').hide(); }else{ $('#password').show(); $('#firstname').show(); $('#lastname').show(); } let email_ok=false; if($('#email').val() !=''){ email_ok=true; } if(email_ok){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this._check=function(type){ if(type=='email' && $('#email').val() !=''){ system.check_email(self._check_email, $('#email').val()); } else self._check_email(-1); } this.process=function(__callback){ self.__process(root,user_profile.A05_priv,true,firm_form_html(true),{},function(r){ if(! $('.action-button').prop('disabled')){ __callback(r); }else return false; },function(){ all_modules_change(); core_modules_change(); all_features_change(); $('#A00_all_modules').change(all_modules_change); $('#core_modules').change(core_modules_change); $('#A00_all_features').change(all_features_change); $('#email').change(function(){self._check('email')}); }); } } k__firm_register_form.prototype=_action_form.prototype; var firm_form_html=function(add){ var html=''; html+=' '; html+='
    '; html+='
    Domain
    '; html+=' '; html+='
    '; if(add){ html+='
    '; html+='
    Admin Email
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Password
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Admin First Name
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Last Name
    '; html+=' '; html+='
    '; } html+='
    '; html+='
    Firm Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Address
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    City
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    State
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Country
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Zip
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Phone
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Email
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Website
    '; html+=' '; html+='
    '; html+=''; if(user_profile.A05_firm ==-1){ html+='
    '; html+='
    Ground Metric
    '; html+=' '; html+='

    '; html+='
    '; html+='
    All Modules
    '; html+=' '; html+='

    '; html+='
    '; html+='
    Core Modules
    '; html+=' '; html+='
    '; html+='
    Production Modules
    '; html+=' '; html+='
    '; html+='
    '; html+='
    '; html+='
    '; html+='
    All Features
    '; html+=' '; html+='

    '; html+='
    '; html+='
    PR Features
    '; html+=' '; html+='
    '; html+='
    '; } html+='
    '; html+='
    Copyright
    '; html+=' '; html+='
    '; html+=''; return html; } var all_modules_change=function(){ let all_modules=$('#A00_all_modules').val(); if(all_modules=='0') $('#core_modules_1').show(); else $('#core_modules_1').hide(); all_features_change(); } var core_modules_change=function(){ let include_pr=$('#core_modules').val()?.includes('pr'); if(include_pr) $('#pr_modules_1').show(); else $('#pr_modules_1').hide(); all_features_change(); } var all_features_change=function(){ let all_features=$('#A00_all_features').val(); let include_pr=($('#A00_all_modules').val()=='1') || ($('#core_modules').val()?.includes('pr')); if(include_pr){ $('#firm_features_block').show(); if(all_features=='0') $('#pr_features_1').show(); else $('#pr_features_1').hide(); }else{ $('#firm_features_block').hide(); } } var ground_truth_form_html=function(add){ var html=''; html+=' '; html += ' '; return html; } var k__ground_truth_edit_form=function(root){ var self=this; var name="Submit"; this.process=function(sys,__callback){ self.__process(root,user_profile.A05_priv,false,ground_truth_form_html(),sys,__callback, function(cb){ if(typeof(cb)=="function") cb(); } ); } } k__ground_truth_edit_form.prototype=_action_form.prototype; var k__metric_add_form=function(root){ var self=this; var name="Submit"; this.process=function(__callback){ self.__process(root,user_profile.A05_priv,true,metric_form_html(),{},__callback, function(cb){ if(typeof(cb)=="function") cb(); } ); } } k__metric_add_form.prototype=_action_form.prototype; var k__metric_edit_form=function(root){ var self=this; var name="Submit"; this.process=function(sys,__callback){ self.__process(root,user_profile.A05_priv,false,metric_form_html(),sys,__callback, function(cb){ if(typeof(cb)=="function") cb(); } ); } } k__metric_edit_form.prototype=_action_form.prototype; var metric_stat_form_html=function(add){ var html=''; html+=' '; html += ' GROUND
    '; html += ' RESULT
    '; html += ' DIFF
    '; html +='
    '; html +='
    '; return html; } var k__metric_stat_edit_form=function(root){ var self=this; var name="Submit"; this.process=function(sys,__callback){ self.__process(root,user_profile.A05_priv,false,metric_stat_form_html(),sys,__callback, function(cb){ if(typeof(cb)=="function") cb(); $('#result_diff').html(''+JSON.stringify(diffJSON(JSON.parse( $('#D02_ground_data').val(),),JSON.parse($('#D02_result_data').val())))+''); $('.action-button').hide(); $('.delete-button').hide(); } ); } } k__metric_stat_edit_form.prototype=_action_form.prototype; var metric_form_html=function(add){ var html=''; html+=' '; html+='
    '; html+='
    Name
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Description
    '; html+=' '; html+='
    '; return html; } var k__notification_details_form=function(root){ var self=this; this.tmpl_content=function(sys){ var html=''; html+='
    '; html+='
    Email
    '; html+=sys.email; html+='
    '; html+='
    '; html+='
    Date
    '; html+=sys.date; html+='
    '; html+='
    '; html+='
    Project
    '; html+=sys.project; html+='
    '; html+='
    '; html+='
    Activity
    '; html+=sys.title; html+='
    '; html+='
    '; html+='
    Subject
    '; html+=sys.subject; html+='
    '; html+='
    '; html+='
    '; html+=sys.body; html+='
    '; if(user_profile.privs[0]>=15) html+=''; html+=' '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, parseInt(user_profile.privs[0]) ,sys.title+' Notification',self.tmpl_content(sys),sys,__callback,function(cb){ if(typeof(cb)=="function") cb(); $('.action-button').hide(); $('.email_button').click( function(){ system.email_notification(function(){ alert('This notification has been setup to email'); },sys['id']); } ); }); } } k__notification_details_form.prototype=_action_form.prototype; var k__notification_filter_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(setup){ var html=''; html+='
    '; html+='
    Start date
    '; html+=' '; html+='
    '; html+='
    '; html+='
    End date
    '; html+=' '; html+='
    '; let projects=setup['projects']; html+='
    '; html+='
    Which Project?
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(filter,__callback){ system.get_firm_setup(function(setup){ self.__process(root,user_profile.A05_priv,'Filter',self.tmpl_content(setup),filter,function(r){ if(__callback) __callback(r); },function(cb){ if(cb) cb(); }); }); } } k__notification_filter_form.prototype=_action_form.prototype; var k__user_edit_form=function(root){ var self=this; var name="Submit"; var setup; var sys; this.tmpl_content=function(setup,email_edit){ var html=''; html+=' '; html+='
    '; html+='
    '; html+='
    Last Login'+((!self.sys.A05_last_login)?'':sec_to_date(self.sys.A05_last_login))+'
    '; html+='
    '; if(self.sys.A05_id==user_profile.A05_id){ html+='
    Signature
    '; html+= '
    Clear
    '; } if(!self.sys.A05_signature && self.sys.A05_id==user_profile.A05_id) html+='
    Signature is required to proceed
    '; html+='
    '; html+='
    '; html+='
    '; if(self.sys.A05_signature){ html+=''; } html+='
    '; html+='
    '; html+='
    '; html+='
    First Name
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Last Name
    '; html+=' '; html+='
    '; if(email_edit){ html+='
    '; html+='
    '; html+='
    Email
    '; html+=' '; html+='
    '; } if(self.sys.A05_id==user_profile.A05_id){ html+='
    '; html+='
    Phone
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Password
    '; html+=' '; html+='
    '; } if(self.sys.A05_id !=user_profile.A05_id){ if(user_profile.A05_firm>0){ html+='
    '; html+='
    Privilege
    '; html+=' '; html+='
    '; } html+='
    '; html+='
    Status
    '; html+=' '; html+='
    '; html+='
    '; } return html; } this.process=function(sys,__callback){ system.get_firm_setup(function(setup){ self.setup=setup; self.sys=sys; self.__process(root,user_profile.A05_priv,false,self.tmpl_content(setup,true),sys,__callback, function(cb){ if(typeof(cb)=="function") cb(); if(sys.A05_id ==user_profile.A05_id) $('.delete-button').hide(); $('.password_reset').click(function(event){ event.preventDefault(); system.reset_email_password(function(r){ if(r>0) alert('email sent'); },sys.A05_id,0); }); if(sys.A05_id ==user_profile.A05_id){ $('#draw_signature').hide(); var signaturePad = new SignaturePad(document.getElementById('signature-pad'), { backgroundColor: 'rgba(255, 255, 255, 0)', penColor: 'rgb(0, 0, 0)' }); var saveButton = document.getElementById('save'); var cancelButton = document.getElementById('clear'); saveButton.addEventListener('click', function (event) { var signature = signaturePad.toDataURL('image/png'); // Send data to server instead... system.user_signature_update(function(){ load_url((location.pathname+location.search).substr(1),[]); },sys.A05_id,signature); }); cancelButton.addEventListener('click', function (event) { signaturePad.clear(); return false; }); $('.draw_button').click(function(){ $('#draw_signature').show(); }); } } ); }); } } k__user_edit_form.prototype=_action_form.prototype; var k__user_filter_form=function(root){ var self=this; var name="Filter"; var setup; this.tmpl_content=function(setup){ var html=''; html+='
    '; html+='
    Name
    '; html+=' '; html+=' '; html+='
    '; html+='
    '; html+='
    Production
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Department
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Position
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Start date
    '; html+=' '; html+='
    '; html+='
    '; html+='
    End date
    '; html+=' '; html+='
    '; return html; } this.set_positions=function(){ let positions={}; let position=$('#position').val(); $('#position').empty(); $.each(self.setup['positions'], function (i, item) { $('#position').append($('
    '; } // html +=''+(data['pr'] || '0')+''; html += ''; if ((parseInt(user_profile.privs[0]) >= 5 || parseInt(user_profile.privs[data['B04_project']]) >= 5)) html += ''; html += ''; return html; } this.foot_tpl = function (rows) { var showHc = false; var totals = { contract: 0, actual: 0, hc: 0 }; for (var i in rows) { var row = rows[i]; if (!row || !row['B04_id']) continue; if (!user_has_feature(row['B04_project'], 'hotcost')) continue; showHc = true; totals.contract += parseFloat(row['budget']) || 0; totals.actual += parseFloat(row['actual']) || 0; totals.hc += get_journal_hc_remain(row); } var hasHcCol = global_params.project_id ? user_has_feature(global_params.project_id, 'hotcost') : user_has_any_feature('hotcost'); var colCount = (global_params.type == 'work') ? 14 : 10; if (!hasHcCol) colCount -= 1; var labelColspan = (global_params.type == 'work') ? 4 : 3; var tailColspan = colCount - labelColspan - (hasHcCol ? 1 : 0); var html = ''; if (showHc && hasHcCol && (totals.contract || totals.actual || totals.hc)) { var totalColor = get_budget_remain_color(totals.hc); html += ''; html += 'Total Hot Cost'; html += '' + format_hot_cost(totals.hc) + ''; html += ''; html += ''; } html += '
    T=Total, S=Submitted, P=Pending
    '; return html; } this.load_table = function (page_num) { self._load_table(self.root, pr.get_journals, global_params.project_id || 0, global_params.type || '', global_params.closed || -1, global_params.collection_id || 0); } this.process = function () { self.project_id = 0; self.load_table(1); if (global_params['action'] == 'edit' && !global_params.back) self.__edit(global_params.project_id, global_params.journal_id); } this.__edit = function (project_id, journal_id) { var x = function () { pr.get_journal(function (journal) { self.edit.process(journal, function (edit_option) { var r = {}; for (var col in edit_option) { if (journal[col] != edit_option[col]) r[col] = edit_option[col]; } if (Object.keys(r).length > 0) { pr.journal_update(function (data) { self.project_id = 0; self.load_table(-1); }, project_id || 0, journal['B04_id'], r); } }, function () { x(); self.load_table(-1); }); }, project_id || 0, journal_id); } x(); } this.row_callback = function () { $('.journal_hotcost').click(function () { self.hotcost.process({ project_id: $(this).attr('data-project'), journal_id: $(this).attr('data-journal'), title: $(this).attr('data-title'), date: $(this).attr('data-date'), contract: $(this).attr('data-contract'), actual: $(this).attr('data-actual'), hc: $(this).attr('data-hc') }, function () { self.load_table(-1); }); }); $('.edit_button').click( function () { var journal_id = $(this).attr("data"); var project_id = $(this).attr("project"); self.__edit(project_id, journal_id); } ); } } s__project_journals_table.prototype = _table_display.prototype; var s__project_members_table=function(root){ var self=this; this.root=root; this.edit= new k__pmember_edit_form('.panel_content'); this.hotcost= new k__pmember_hotcost_form('.panel_content'); this.table_tpl=function(){ var html='
    '; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; if (user_has_feature(global_params.project_id, 'hotcost')) html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html +=''; html+=''; html+= '
    NameDepartmentPositionShoot Hrs/DayShoot Rate/HrHCEmailPrivilegeT / S / PO/CDTRTS
    '; return html; } this.row_tpl=function(data){ var html=''; html +=''; html +=''+data['A05_firstname']+' '+data['A05_lastname']+''; html +=''+(data['A02_name'] || '')+''; html +=''+(data['A03_name'] || '')+''; html +=''+(data['B01_shoot_hours_per_day'] || '')+''; html +=''+(data['B01_shoot_rate_per_hour'] || '')+''; if (user_has_feature(data['B01_project'] || global_params.project_id, 'hotcost')) { let hcRemain = data['hot_cost_remain'] || 0; let hcTitle = 'Remaining = Hot Cost - Actual\nHot Cost: ' + format_hot_cost(data['hot_cost_budget'] || 0) + '\nActual: ' + format_hot_cost(data['hot_cost_actual'] || 0); let hcColor = get_budget_remain_color(hcRemain); html +=''+format_hot_cost(hcRemain)+''; } html +=''+((data['A05_email'].indexOf('@')>=0)?data['A05_email']:'' )+''; html +=''; let priv=parseInt(data['B01_priv']); html+=get_priv_html(priv); html+=''; html +=''; html+='
    '+(data['tr'] || '0')+'
    '; html+='
    /
    '; html+='
    '+(data['approved_tr'] || '0')+'
    '; html+='
    /
    '; html+='
    '+(data['pending_tr'] || '0')+'
    '; html+=''; html +=''; html+=(data['B01_owncall']=='1')?'':''; html+=''; html +=''; if( global_params['project_id'] && (parseInt(user_profile.privs[0])>=5 || parseInt(user_profile.privs[global_params['project_id']])>=5) ) html+=''; html+=''; html +=''; if( global_params['project_id'] && (parseInt(user_profile.privs[0])>=5 || parseInt(user_profile.privs[global_params['project_id']])>=5) ) html+=''; html+=''; html +=''; // Only show edit when the actor's band is at least the member's current role // (backend refuses priv_exceeded for higher-ranked members). var actorPriv=(parseInt(user_profile.privs[0])==15)?15:((user_profile.privs[global_params['project_id']])?parseInt(user_profile.privs[global_params['project_id']]):parseInt(user_profile.privs[0])); if( data['A04_status']=='active' && global_params['project_id'] && actorPriv>=5 && actorPriv>=priv ) html+=''; html+=''; html +=''; html +=''; return html; } this.foot_tpl=function(summary){ var html=''; html+='
    '; return html; } this.load_table=function(page_num){ self._load_table(self.root, pr.get_pmembers, global_params.project_id || 0); } this.process=function(){ self.load_table(1); } this.row_callback=function(){ $('.pm_hotcost').click(function(){ self.hotcost.process({ user_id: $(this).attr('data-user'), project_id: $(this).attr('data-project'), name: $(this).attr('data-name') }, function() { self.load_table(-1); }); }); if( global_params['project_id'] && (parseInt(user_profile.privs[0])>=5 || parseInt(user_profile.privs[global_params['project_id']])>=5) ){ $('.email_link').click(function(){ let x=this; var user_id=$(this).attr("data"); var project_id=$(this).attr("project"); var name=$(this).attr("name"); if(confirm('A link will be sent to '+name)){ pr.pmember_sendlink(function(data){ alert('Link email has been sent to '+name); },project_id,user_id); } }); $('.linkdtr_button').click(function(){ let x=this; var token=$(this).attr("data"); var project_id=$(this).attr("project"); navigator.clipboard.writeText(location.protocol + '//' + location.host +'/journal_trs?type=crew&project_id='+project_id+'&token='+token); $(x).attr('src',"/icons/copy.svg"); setTimeout(function(){ $(x).attr('src',"/icons/link.png"); },1000); }); $('.linkts_button').click(function(){ let x=this; var token=$(this).attr("data"); var project_id=$(this).attr("project"); navigator.clipboard.writeText(location.protocol + '//' + location.host +'/collection_sheets?project_id='+project_id+'&token='+token); $(x).attr('src',"/icons/copy.svg"); setTimeout(function(){ $(x).attr('src',"/icons/link.png"); },1000); }); $('.edit_button').click( function(){ var pmember_id=$(this).attr("data"); pr.get_pmember(function(pmember){ self.edit.process(pmember,function(edit_option){ var r={}; for(var col in edit_option){ r[col]=edit_option[col]; } if(Object.keys(r).length>0){ pr.pmember_update(function(data){ if(data && data.success===false){ alert(data.error==='priv_exceeded' ? 'You cannot assign or edit a privilege above your own.' : (data.error || 'Update refused')); return; } self.load_table(-1); },global_params.project_id||0,pmember['B01_id'],r); } }); },global_params.project_id||0,pmember_id); } ); } } } s__project_members_table.prototype=_table_display.prototype; var k__comment_add_form=function(root){ var self=this; var username_ok=false; var email_ok=false; var name="Add"; this.tmpl_content=function(){ var html=''; html+='
    '; html+='
    Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Comment
    '; html+=' '; html+='
    '; html+=''; return html; } this.save_test=function(){ if($('#C04_name').val() !='' && $('#C04_comment').val() !=''){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this.process=function(__callback){ self.__process(root, (global_params['project_id'] && user_profile.privs[global_params['project_id']] )?parseInt(user_profile.privs[global_params['project_id']]): parseInt(user_profile.privs[0]) ,true,self.tmpl_content(),{},function(r){ if(! $('.action-button').prop('disabled')){ __callback(r); }else return false; },function(){ self.save_test(); $('#C04_comment').change(self.save_test); $('#C04_name').change(self.save_test); }); } } k__comment_add_form.prototype=_action_form.prototype; var k__comment_edit_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(){ var html=''; html+=' '; html+='
    '; html+='
    Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Comment
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, (user_profile.privs[sys['C04_project']])? parseInt(user_profile.privs[sys['C04_project']]):parseInt(user_profile.privs[0]) ,false,self.tmpl_content(),sys,__callback); } } k__comment_edit_form.prototype=_action_form.prototype; var k__department_add_form=function(root){ var self=this; var name="Add"; this.tmpl_content=function(){ var html=''; html+='
    '; html+='
    Name
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Sort # (0-100)
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Type
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Extra Features
    '; html+=' '; html+='
    '; html+=''; return html; } this.save_test=function(){ if($('#A02_name').val() !=''){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this.process=function(__callback){ self.__process(root,user_profile.A05_priv,true,self.tmpl_content(),{},function(r){ if(! $('.action-button').prop('disabled')){ __callback(r); }else return false; },function(){ $('#A02_name').change(self.save_test); }); } } k__department_add_form.prototype=_action_form.prototype; var k__department_edit_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(sys){ var html=''; html+=' '; html+='
    '; html+='
    Name
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Sort # (0-100)
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Type
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Extra Features
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root,user_profile.A05_priv,false,self.tmpl_content(sys),sys,__callback); } } k__department_edit_form.prototype=_action_form.prototype; var k__journal_add_form=function(root){ var self=this; var username_ok=false; var email_ok=false; var name="Add"; this.tmpl_content=function(){ var html=journal_form_html(); return html; } this.save_test=function(){ if($('#B04_date').val() !=''){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this.process=function(__callback){ self.__process(root,(global_params['project_id'] && user_profile.privs[global_params['project_id']] )?parseInt(user_profile.privs[global_params['project_id']]):parseInt(user_profile.privs[0]) ,true,self.tmpl_content(),{},function(r){ if(! $('.action-button').prop('disabled')){ __callback(r); }else return false; },function(){ $('#B04_date').change(self.save_test); $('#B04_type').val(global_params.type); }); } } k__journal_add_form.prototype=_action_form.prototype; var k__journal_edit_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(project_id,journal_id,priv){ var html=''; if( self.sys['B04_type']=='wd') html+='
    Download
    '; if(self.sys['B04_closed']=='1' && self.sys['A04_status']=='active' && self.sys['status']=='none') html+='
    Approve
    '; if(priv>=15 && self.sys['A04_status']=='active' && self.sys['status']=='approved') html+='
    Unapprove
    '; if(self.sys['B04_closed']=='0' && self.sys['A04_status']=='active' && self.sys['B04_type']=='wd') html+='
    Upload
    '; if(self.sys['B04_closed']=='0' && self.sys['A04_status']=='active') html+='
    '; html+='


    '; if(self.sys['status']=='approved') { html+='
    Approved By:  
    '+self.sys['approvedby']+'
    '; html+='
    '+sec_to_date(self.sys['B04_approval_time'])+'


    '; html+='
    '; } html+=' '; html+=journal_form_html(self.sys); return html; } this.process=function(sys,__callback,reload){ self.sys=sys; var priv=(parseInt(user_profile.privs[0])>=15)?user_profile.privs[0]:((user_profile.privs[sys['B04_project']])? parseInt((user_profile.privs[sys['B04_project']])):0); self.__process(root,priv,false,self.tmpl_content(sys['B04_project'],sys['B04_id'],priv),sys,__callback,function(cb){ let params=encodeURI(JSON.stringify({'project_id':sys['B04_project'],'journal_id':sys['B04_id']})); $('.link_button').click(function(){ var token=sys['B04_token']; var project_id=sys['B04_project']; var journal_id=sys['B04_id']; navigator.clipboard.writeText(location.protocol + '//' + location.host +'/journal_trs?action=add&project_id='+project_id+'&journal_id='+journal_id+'&token='+token); let x=this; $(x).attr('src',"/icons/copy.svg"); setTimeout(function(){ $(x).attr('src',"/icons/link.png"); },1000); }); if(sys.A04_status !='active' || sys.status=='approved') { $('.action-button').prop('disabled',true); $('.delete-button').hide(); } if(priv<10) $('.delete-button').hide(); // Create file input for base64 encoding $("#journal-upload-file").remove(); let fileInput = $(''); $('body').append(fileInput); // Handle file selection and base64 conversion $('#journal-upload-file').on('change', function(e) { const file = e.target.files[0]; if (file && file.type.indexOf('pdf') !== -1) { const reader = new FileReader(); reader.onloadend = function() { // Convert to base64 and submit const base64Data = reader.result.split(',')[1]; // Remove data:application/pdf;base64, prefix submitProductionUpload(base64Data, file.name); }; reader.readAsDataURL(file); } else { alert('pdf only please'); } }); // Function to submit base64 data function submitProductionUpload(base64Data, filename) { pr.process_upload(function(data) { reload(); }, sys['B04_project'], sys['B04_id'], base64Data, filename); } // Upload button click handler $('.upload_button').click(function() { $('#journal-upload-file').click(); }); $('.approve_button').click( function(){ var project_id=sys['B04_project']; var journal_id=sys['B04_id']; pr.journal_approve(reload,project_id,journal_id); } ); $('.unapprove_button').click( function(){ var project_id=sys['B04_project']; var journal_id=sys['B04_id']; pr.journal_unapprove(reload,project_id,journal_id); } ); $('.download_button').click( function(){ document.location.href=getDownloadUrl()+'func=download_dpr¶ms='+params; } ); $('#download_sr').click( function(){ document.location.href=getDownloadUrl()+'func=download_sr¶ms='+params; } ); $('#download_cs').click( function(){ document.location.href=getDownloadUrl()+'func=download_cs¶ms='+params; } ); $('#add_cs_gt').click( function(){ var project_id=sys['B04_project']; var journal_id=sys['B04_id']; pr.add_ground_truth(reload,project_id,journal_id,'cs'); } ); if(cb) cb(); }); } } k__journal_edit_form.prototype=_action_form.prototype; var k__journal_hotcost_form = function(root) { var self = this; this.trs = []; this.trs_all = []; this.filter_opts = { members: {}, departments: {}, positions: {} }; this.build_filter_options = function(trs) { var members = {}, departments = {}, positions = {}; for (var i in trs) { var tr = trs[i]; if (tr['C00_user']) { members[tr['C00_user']] = ((tr['A05_firstname'] || '') + ' ' + (tr['A05_lastname'] || '')).trim(); } if (tr['C00_department'] && tr['A02_name'] && tr['A02_name'] != 'ZZZ') { departments[tr['C00_department']] = tr['A02_name']; } if (tr['C00_position'] && tr['A03_name']) { positions[tr['C00_position']] = { name: tr['A03_name'], dept: tr['C00_department'] }; } } return { members: members, departments: departments, positions: positions }; }; this.get_excluded_calls = function() { var exclude = []; if (!$('#jhc_show_owncall').prop('checked')) exclude.push('owncall'); if (!$('#jhc_show_nocall').prop('checked')) exclude.push('nocall'); return exclude; }; this.get_tr_filter = function() { var filter = { project_id: self.journal.project_id, journal_id: self.journal.journal_id }; var user = parseInt($('#jhc_filter_member').val()) || 0; var dept = parseInt($('#jhc_filter_department').val()) || 0; var pos = parseInt($('#jhc_filter_position').val()) || 0; var trType = $('#jhc_filter_type').val(); if (user > 0) filter.user_id = user; if (dept > 0) filter.department_id = dept; if (pos > 0) filter.position_id = pos; if (trType && trType != '0') filter.type = trType; var exclude = self.get_excluded_calls(); if (exclude.indexOf('owncall') >= 0) filter.owncall = '0'; if (exclude.indexOf('nocall') >= 0) filter.nocall = '0'; return filter; }; this.has_active_filters = function() { return $('#jhc_filter_member').val() != '0' || $('#jhc_filter_department').val() != '0' || $('#jhc_filter_position').val() != '0' || $('#jhc_filter_type').val() != '0' || self.get_excluded_calls().length > 0; }; this.find_tr = function(tr_id) { tr_id = parseInt(tr_id) || 0; for (var i = 0; i < self.trs_all.length; i++) { if (parseInt(self.trs_all[i]['C00_id']) === tr_id) return self.trs_all[i]; } return null; }; this.merge_tr = function(updated) { if (!updated || !updated['C00_id']) return; var tr_id = parseInt(updated['C00_id']); var lists = [self.trs_all, self.trs]; for (var l = 0; l < lists.length; l++) { for (var i = 0; i < lists[l].length; i++) { if (parseInt(lists[l][i]['C00_id']) === tr_id) { for (var key in updated) { lists[l][i][key] = updated[key]; } break; } } } }; this.refresh_day_summary = function() { var contract = 0; var actual = 0; for (var i = 0; i < self.trs_all.length; i++) { var tr = self.trs_all[i]; if (tr['C00_approved'] != '1' || is_tr_zero_hc(tr)) continue; var cols = get_tr_hc_columns(tr); contract += cols.contract; actual += cols.actual; } self.journal.contract = contract; self.journal.actual = actual; self.journal.hc = contract - actual; $('.jhc_day_summary').html(self.day_summary_html(self.journal)); }; this.rate_inputs_html = function(tr) { if (is_tr_zero_hc(tr) || tr['C00_approved'] != '1') { return ''; } var rates = get_tr_hc_rates(tr); var rateVal = format_tr_hc_rate_value(rates.rate_per_hour); var hoursVal = format_tr_hc_rate_value(rates.hours_per_day); var revert = has_tr_hc_override(tr) ? ' ' : ''; var html = ''; html += ''; html += ''; html += ''; html += '' + revert; html += ''; return html; }; this.reload_parent = null; this.sync_tr_after_rates = function(tr_id, callback) { tr_id = parseInt(tr_id) || 0; pr.get_trs(function(trs) { var fresh = null; for (var i = 0; i < (trs || []).length; i++) { if (parseInt(trs[i]['C00_id']) === tr_id) { fresh = trs[i]; break; } } if (fresh) { self.merge_tr(fresh); } else if (tr_id) { self.clear_tr_hc_override(tr_id); } if (typeof callback === 'function') callback(fresh); }, { project_id: self.journal.project_id, journal_id: self.journal.journal_id }); }; this.after_rates_saved = function(tr_id) { self.sync_tr_after_rates(tr_id, function() { self.refresh_table(); self.refresh_day_summary(); if (typeof self.reload_parent === 'function') { self.reload_parent(); } }); }; this.save_tr_rates = function($row) { var tr_id = parseInt($row.attr('data-tr-id')) || 0; var tr = self.find_tr(tr_id); if (!tr || self._saving_rates) return; var parsed = parse_tr_hc_row_inputs(tr, $row); if (has_tr_hc_override(tr) && tr_hc_input_matches_member(tr, parsed.rateRaw, parsed.hoursRaw)) { self.revert_tr_rates($row); return; } if (!tr_hc_row_changed(tr, parsed.rate, parsed.hours)) return; if (isNaN(parsed.rate) || parsed.rate <= 0 || isNaN(parsed.hours) || parsed.hours <= 0) return; self._saving_rates = true; pr.tr_update_hc_rates(function(updated) { self._saving_rates = false; if (!updated) return; self.after_rates_saved(tr_id); }, self.journal.project_id, self.journal.journal_id, tr_id, parsed.rate, parsed.hours, 0); }; this.clear_tr_hc_override = function(tr_id) { tr_id = parseInt(tr_id) || 0; var lists = [self.trs_all, self.trs]; for (var l = 0; l < lists.length; l++) { for (var i = 0; i < lists[l].length; i++) { if (parseInt(lists[l][i]['C00_id']) === tr_id) { lists[l][i]['C00_rate_per_hour'] = null; lists[l][i]['C00_hours_per_day'] = null; } } } }; this.revert_tr_rates = function($row) { var tr_id = parseInt($row.attr('data-tr-id')) || 0; if (!tr_id || self._saving_rates) return; self._saving_rates = true; pr.tr_update_hc_rates(function(updated) { self._saving_rates = false; if (!updated) return; self.after_rates_saved(tr_id); }, self.journal.project_id, self.journal.journal_id, tr_id, null, null, 1); }; this.bind_rate_inputs = function() { var $wrap = $('#jhc_table_wrap'); var $form = $wrap.closest('.action_form'); $wrap.off('change.jhc_rate', '.jhc_rate_input'); $wrap.on('change.jhc_rate', '.jhc_rate_input', function() { self.save_tr_rates($(this).closest('tr')); }); $wrap.off('keydown.jhc_rate', '.jhc_rate_input'); $wrap.on('keydown.jhc_rate', '.jhc_rate_input', function(e) { if (e.which === 13 || e.keyCode === 13) { e.preventDefault(); e.stopPropagation(); self.save_tr_rates($(this).closest('tr')); return false; } }); $form.off('keydown.jhc_form').on('keydown.jhc_form', function(e) { if ((e.which === 13 || e.keyCode === 13) && $(e.target).closest('#jhc_table_wrap').length) { e.preventDefault(); e.stopPropagation(); return false; } }); $wrap.off('click.jhc_revert', '.jhc_revert_link'); $wrap.on('click.jhc_revert', '.jhc_revert_link', function(e) { e.preventDefault(); self.revert_tr_rates($(this).closest('tr')); }); }; this.unbind_rate_inputs = function() { var $wrap = $('#jhc_table_wrap'); $wrap.off('change.jhc_rate', '.jhc_rate_input'); $wrap.off('keydown.jhc_rate', '.jhc_rate_input'); $wrap.off('click.jhc_revert', '.jhc_revert_link'); $wrap.closest('.action_form').off('keydown.jhc_form'); }; this.day_summary_html = function(journal) { var contract = parseFloat(journal.contract) || 0; var actual = parseFloat(journal.actual) || 0; var hc = parseFloat(journal.hc); if (isNaN(hc)) hc = contract - actual; var color = hc < 0 ? '#cc0000' : (hc > 0 ? '#1a7a1a' : '#222'); var weight = hc !== 0 ? 'font-weight:600;' : ''; var html = '
    '; html += 'Hot Cost'; html += '' + format_hot_cost(hc) + ''; html += '
    '; return html; }; this.export_dropdown_html = function() { var html = '
    '; html += ''; html += '
    '; html += ''; html += ''; html += ''; html += '
    '; return html; }; this.render_table = function(trs, journal) { var selType = $('#jhc_filter_type').length ? $('#jhc_filter_type').val() : 'crew'; var show_dept_pos = (selType != 'cast' && selType != 'background'); var col_count = show_dept_pos ? 11 : 9; var html = ''; html += ''; if (show_dept_pos) html += ''; html += ''; html += ''; html += ''; html += ''; var totals = { budget: 0, actual: 0, remain: 0 }; if (!trs || !trs.length) { html += ''; } for (var i in trs) { var tr = trs[i]; var cols = get_tr_hc_columns(tr); totals.budget += cols.contract; totals.actual += cols.actual; var remainColor = get_budget_remain_color(cols.hc); var rates = get_tr_hc_rates(tr); var has_cost = !is_tr_zero_hc(tr) && tr['C00_approved'] == '1' && rates.rate_per_hour > 0 && rates.hours_per_day > 0; var rowClasses = []; if (has_tr_hc_override(tr)) rowClasses.push('jhc_rate_override'); if (!has_cost) rowClasses.push('jhc_nocost'); html += ''; html += ''; html += ''; if (show_dept_pos) { html += ''; html += ''; } html += ''; var work_hours = get_tr_work_hours(tr); html += ''; html += self.rate_inputs_html(tr); html += ''; var tooltip = get_tr_actual_tooltip(tr); html += ''; var hcStyle = remainColor ? ' style="color:' + remainColor + '"' : ''; html += ''; html += ''; } html += ''; html += ''; html += ''; html += ''; totals.remain = totals.budget - totals.actual; var totalColor = get_budget_remain_color(totals.remain); html += ''; html += '
    NameTypeDepartmentPositionDTRHrs WkdHr/DayRate/HrContractActualHot Cost
    No DTR entries
    ' + (tr['A05_firstname'] || '') + ' ' + (tr['A05_lastname'] || '') + '' + capitalizeFirstLetter(tr['C00_type'] || '') + '' + ((tr['A02_name'] && tr['A02_name'] != 'ZZZ') ? tr['A02_name'] : '') + '' + (tr['A03_name'] || '') + '' + get_tr_time_label(tr) + '' + (!is_tr_zero_hc(tr) && work_hours > 0 ? work_hours.toFixed(2) : '—') + '' + (has_cost ? format_hot_cost(cols.contract) : '—') + '' + (has_cost ? format_hot_cost(cols.actual) : '—') + '' + (has_cost ? format_hot_cost(cols.hc) : '—') + '
    Total' + format_hot_cost(totals.budget) + '' + format_hot_cost(totals.actual) + '' + format_hot_cost(totals.remain) + '
    '; if (journal) { if (!self.has_active_filters()) { var contract = parseFloat(journal.contract) || 0; var actual = parseFloat(journal.actual) || 0; var hc = parseFloat(journal.hc); if (isNaN(hc)) hc = contract - actual; var diff = Math.abs(totals.remain - hc); if (diff > 0.01) { html += '
    Breakdown total differs from day HC by ' + format_hot_cost(diff) + '.
    '; } } } return html; }; this.position_options_html = function(positions, department_id, selected) { var html = ''; for (var id in positions) { if (department_id && department_id != '0' && positions[id].dept != department_id) continue; html += ''; } return html; }; this.get_call_counts = function() { var user = parseInt($('#jhc_filter_member').val()) || 0; var dept = parseInt($('#jhc_filter_department').val()) || 0; var pos = parseInt($('#jhc_filter_position').val()) || 0; var trType = $('#jhc_filter_type').length ? $('#jhc_filter_type').val() : 'crew'; var own_n = 0, no_n = 0; for (var i = 0; i < self.trs_all.length; i++) { var tr = self.trs_all[i]; if (user > 0 && parseInt(tr['C00_user']) != user) continue; if (dept > 0 && parseInt(tr['C00_department']) != dept) continue; if (pos > 0 && parseInt(tr['C00_position']) != pos) continue; if (trType && trType != '0' && (tr['C00_type'] || 'crew') != trType) continue; if (is_tr_owncall(tr)) own_n++; else if (is_tr_nocall(tr)) no_n++; } return { own: own_n, no: no_n }; }; this.update_call_counts = function() { var counts = self.get_call_counts(); $('#jhc_owncall_count').text('(' + counts.own + ')'); $('#jhc_nocall_count').text('(' + counts.no + ')'); }; this.filters_html = function(opts) { var html = '
    '; html += ''; html += ''; html += '
    '; html += ''; html += ''; html += '
    '; html += '
    '; html += ''; html += ''; var counts = self.get_call_counts(); html += '
    '; html += 'Include:'; html += ''; html += ''; html += '
    '; html += '
    '; html += '' + self.day_summary_html(self.journal) + ''; html += self.export_dropdown_html(); html += '
    '; return html; }; this.bind_member_combo = function() { var $combo = $('#jhc_member_combo'); var $menu = $('#jhc_combo_menu'); if (!$combo.length || !$menu.length) return; var src = []; for (var uid in self.filter_opts.members) { src.push({ label: self.filter_opts.members[uid], value: '' + uid }); } src.sort(function(a, b) { return a.label.localeCompare(b.label); }); var $clear = $('#jhc_combo_clear'); var toggle_clear = function() { $clear.toggle($.trim($combo.val()) !== ''); }; var apply_member = function(id) { toggle_clear(); if ($('#jhc_filter_member').val() === '' + id) return; $('#jhc_filter_member').val('' + id); self.refresh_table(); }; var render_menu = function(term) { term = (term || '').toLowerCase(); var html = '
    Member: All
    '; var n = 0; for (var i = 0; i < src.length; i++) { if (!term || src[i].label.toLowerCase().indexOf(term) >= 0) { html += '
    ' + src[i].label + '
    '; n++; } } if (!n) html += '
    No matches
    '; $menu.html(html).show(); }; $combo.on('focus.jhc_combo click.jhc_combo', function() { this.select(); render_menu(''); }); $combo.on('input.jhc_combo', function() { toggle_clear(); render_menu($.trim($combo.val())); }); $clear.on('click.jhc_combo', function(e) { e.preventDefault(); $combo.val(''); $menu.hide(); apply_member(0); }); $combo.on('keydown.jhc_combo', function(e) { if (e.which === 27) { $menu.hide(); } if (e.which === 13) { e.preventDefault(); $combo.blur(); } }); $menu.on('mousedown.jhc_combo', '.jhc_combo_item', function(e) { e.preventDefault(); var val = $(this).attr('data-value'); $combo.val(val === '0' ? '' : $(this).text()); $menu.hide(); apply_member(val); }); $combo.on('blur.jhc_combo', function() { setTimeout(function() { $menu.hide(); }, 150); var txt = $.trim($combo.val()); if (txt === '') { apply_member(0); return; } var matched = null; for (var i = 0; i < src.length; i++) { if (src[i].label.toLowerCase() === txt.toLowerCase()) { matched = src[i]; break; } } if (matched) { $combo.val(matched.label); apply_member(matched.value); } else { $combo.val(''); apply_member(0); } }); }; this.load_trs = function(callback) { if (!self.has_active_filters()) { self.trs = self.trs_all.slice(0); if (typeof callback == 'function') callback(); return; } pr.get_trs(function(trs) { self.trs = trs || []; if (typeof callback == 'function') callback(); }, self.get_tr_filter()); }; this.refresh_table = function() { self.load_trs(function() { $('#jhc_table_wrap').html(self.render_table(self.trs, self.journal)); self.bind_rate_inputs(); self.update_call_counts(); }); }; this.export_hotcost = function(format) { $('.jhc_export_dropdown').removeClass('open'); var params = encodeURIComponent(JSON.stringify([ self.journal.project_id, self.journal.journal_id, format, self.get_tr_filter() ])); document.location.href = getDownloadUrl() + 'func=download_journal_hotcost¶ms=' + params; }; this.refresh_positions = function(keep_selection) { var dept = $('#jhc_filter_department').val(); var pos = keep_selection ? $('#jhc_filter_position').val() : '0'; $('#jhc_filter_position').html(self.position_options_html(self.filter_opts.positions, dept, pos)); if (!$('#jhc_filter_position option[value="' + pos + '"]').length) { $('#jhc_filter_position').val('0'); } }; this.bind_filters = function() { $('#jhc_filter_department').change(function() { self.refresh_positions(false); self.refresh_table(); }); self.bind_member_combo(); $('#jhc_filter_type').change(self.refresh_table); $('#jhc_filter_position').change(self.refresh_table); $('#jhc_show_owncall, #jhc_show_nocall').change(self.refresh_table); $('.jhc_export_btn').click(function(e) { e.stopPropagation(); $('.jhc_export_dropdown').toggleClass('open'); }); $('.jhc_export_csv').click(function() { self.export_hotcost('csv'); }); $('.jhc_export_excel').click(function() { self.export_hotcost('excel'); }); $('.jhc_export_pdf').click(function() { self.export_hotcost('pdf'); }); $(document).off('click.jhc_export').on('click.jhc_export', function() { $('.jhc_export_dropdown').removeClass('open'); }); $('.jhc_export_dropdown').click(function(e) { e.stopPropagation(); }); }; this.unbind_filters = function() { $(document).off('click.jhc_export'); $('#jhc_member_combo').off('.jhc_combo'); $('#jhc_combo_menu').off('.jhc_combo'); $('#jhc_combo_clear').off('.jhc_combo'); self.unbind_rate_inputs(); }; this.tmpl_content = function(trs) { self.filter_opts = self.build_filter_options(self.trs_all); var html = self.filters_html(self.filter_opts); html += '
    ' + self.render_table(trs, self.journal) + '
    '; return html; }; this.open_fullscreen = function() { $('.panel_container').addClass('panel_fullscreen'); }; this.process = function(journal, reload_parent) { self.journal = journal; self.reload_parent = reload_parent || null; pr.get_trs(function(trs) { self.trs_all = trs || []; self.trs = $.grep(self.trs_all, function(tr) { return !is_tr_zero_hc(tr) && (tr['C00_type'] || 'crew') == 'crew'; }); var title = journal.title + ' (' + journal.date + ') Hot Cost'; self.__process(root, 0, title, self.tmpl_content(self.trs), {}, function() { self.unbind_filters(); }, function(cb) { $('.action-button').hide(); self.open_fullscreen(); self.bind_filters(); self.bind_rate_inputs(); if (typeof(cb) == 'function') cb(); }); }, { project_id: journal.project_id, journal_id: journal.journal_id }); }; }; k__journal_hotcost_form.prototype = _action_form.prototype; var journal_form_html = function (sys) { let html = ''; var journal_input_cols = { 'title': 'Title', 'date': 'Date' } var journal_sr_cols = { 'production_project': 'Production', 'time_call': 'Call', 'time_1shot': '1st Shot', 'time_lunch_out': 'Lunch Out', 'time_lunch_in': 'Lunch In', 'time_1shot_after_lunch': '1st Shot After Lunch', 'time_dinner_out': 'Dinner Out', 'time_dinner_in': 'Dinner In', 'time_1shot_after_dinner': '1st Shot After Dinner', 'time_wrap_camera': 'Wrap Camera', 'time_2wrap': '2nd Wrap', 'time_wrap_script': 'Wrap Script', 'scenes_completed': 'Scenes Completed', 'scenes_partially_shot': 'Scenes Partially Shot', 'scenes_plus': '(+) Scenes', 'scenes_minus': '(-) Scenes', 'scenes_reshoot': 'Reshoot Scenes', 'scenes_wild_tracks': 'Wild Tracks Scenes', 'scenes_cam_rolls': 'Cam Rolls Scenes', 'scenes_sound': 'Sound Scenes', 'script_total_scenes': 'Total Scenes', 'script_total_pages': 'Total Pages', 'script_total_minutes': 'Total Minutes', 'today_plus_scenes': 'Today (+) Scenes', 'today_plus_pages': 'Today (+) Pages', 'today_plus': 'Today (+)', 'today_minus_scenes': 'Today (-) Scenes', 'today_minus_pages': 'Today (-) Pages', 'today_minus': 'Today (-) ', 'today_plus_scenes': 'Today (+) Scenes', 'today_plus_pages': 'Today (+) Pages', 'today_minus_scenes': 'Today (-) Scenes', 'today_minus_pages': 'Today (-) Pages', 'today_wilds': 'Today Wilds', 'current_total_scenes': 'Current Total Scenes', 'current_total_pages': 'Current Total Pages', 'current_total_minutes': 'Current Total Minutes', 'current_total_setups': 'Current Total Setups', 'previous_scenes': 'Previous Scenes', 'previous_pages': 'Previous Pages', 'previous_minutes': 'Previous Minutes', 'previous_setups': 'Previous Setups', 'previous_wilds': 'Previous Wilds', 'previous_plus_scenes': 'Previous (+) Scenes', 'previous_plus_pages': 'Previous (+) Pages', 'previous_minus_scenes': 'Previous (-) Scenes', 'previous_minus_pages': 'Previous (-) Pages', 'today_scenes': 'Today Scenes', 'today_pages': 'Today Pages', 'today_minutes': 'Today Minutes', 'today_setups': 'Today Setups', 'total_scenes': 'Total Scenes', 'total_pages': 'Total Pages', 'total_minutes': 'Total Minutes', 'total_setups': 'Total Setups', 'remaining_scenes': 'Remaining Scenes', 'remaining_pages': 'Remaining Pages', 'previous_ert': 'Previous ERT', 'previous_art': 'Previous ART', 'previous_plus': 'Previous (+)', 'previous_minus': 'Previous (-) ', 'today_ert': 'Today ERT', 'today_art': 'Today ART', 'total_ert': 'Total ERT', 'total_art': 'total ART', 'total_plus': 'Total (+)', 'total_minus': 'Total (-)', 'total_wilds ': 'Total Wilds', 'total_plus_scenes': 'Total (+) Scenes', 'total_plus_pages': 'Total (+) Pages', 'total_minus_scenes': 'Total (-) Scenes', 'total_minus_pages': 'Total (-) Pages', 'remaining_ert': 'Remaining ERT', 'projected_ert': 'projected ERT', 'projected_art': 'projected ART', 'projected_plus': 'Projected (+)', 'projected_minus': 'Projected (-) ' } var journal_cs_cols = { 'script_version': 'Script Version', 'time_call2': 'Shoot Call', 'nearest_hospital': 'Nearest Hospital', 'travel_in_time': 'Travel In Time', 'travel_out_time': 'Travel Out Time', 'travel_in_distance': 'Travel In Distance', 'travel_out_distance': 'Travel Out Distance', 'production_company': 'Production Company', 'office_address': 'Office Address', 'office_phone': 'Office Phone', 'office_email': 'Office Email', 'executive_producers': 'Executive Producers', 'producers': 'Producers', 'directors': 'Directors', 'production_managers': 'Production Managers', '1st_ads': '1st ADs', 'co_producers': 'Co-Producers' } var journal_page_cols = ['script_total_pages', 'today_plus_pages', 'today_minus_pages', 'current_total_pages', 'previous_pages', 'today_pages', 'total_pages', 'remaining_pages', 'today_plus_pages', 'today_minus_pages', 'total_plus_pages', 'total_minus_pages', 'previous_plus_pages', 'previous_minus_pages']; var journal_time_cols = ['time_call', 'time_call2', 'time_1shot', 'time_lunch_out', 'time_lunch_in', 'time_1shot_after_lunch', 'time_dinner_out', 'time_dinner_in', 'time_1shot_after_dinner', 'time_wrap_camera', 'time_2wrap', 'time_wrap_script', 'script_total_minutes', 'today_plus', 'today_minus', 'current_total_minutes', 'previous_minutes', 'today_minutes', 'total_minutes', 'previous_ert', 'previous_art', 'previous_plus', 'previous_minus', 'today_ert', 'today_art', 'total_ert', 'total_art', 'total_plus', 'total_minus', 'remaining_ert', 'projected_ert', 'projected_art', 'projected_plus', 'projected_minus']; if (!sys) { html += '
    '; html += '
    Type
    '; html += ' '; html += '
    '; } else { html += '
    '; html += '
    Type
    '; html += ' '; html += '
    '; } html += '
    '; html += '
    Status
    '; html += ' '; html += '
    '; for (var col in journal_input_cols) { let colname = col; let display = journal_input_cols[col]; if (journal_page_cols.indexOf(col) == -1 && journal_time_cols.indexOf(col) == -1) { colname = 'B04_' + col; } html += '
    '; html += '
    ' + display + '
    '; html += ' '; html += '
    '; html += ' '; } if (sys && sys.B04_type == 'wd') { html += '

    Call Sheet

    '; html += '
    ' + sys.B04_cs + '
    '; if((parseInt(user_profile.privs[0])>=15) && sys.B04_cs && sys.B04_cs.indexOf('.pdf')>=0 && sys.A00_ground_metric=='1'){ html += '
    Add Ground Truth
    '; } html += '
    '; for (var col in journal_cs_cols) { let colname = col; let display = journal_cs_cols[col]; if (journal_page_cols.indexOf(col) == -1 && journal_time_cols.indexOf(col) == -1) { colname = 'B04_' + col; } html += '
    '; html += '
    ' + display + '
    '; html += ' '; html += '
    '; html += ' '; } html += '

    Script Report

    '; html += '
    ' + sys.B04_sr + '
    '; html += '
    '; for (var col in journal_sr_cols) { let colname = col; let display = journal_sr_cols[col]; if (journal_page_cols.indexOf(col) == -1 && journal_time_cols.indexOf(col) == -1) { colname = 'B04_' + col; } html += '
    '; html += '
    ' + display + '
    '; html += ' '; html += '
    '; html += ' '; } html += '
    '; html += '
    Script Notes
    '; html += ' '; html += '
    '; html += ' '; html += '
    '; html += '
    Notes
    '; html += ' '; html += '
    '; html += ' '; } return html; } var k__location_add_form=function(root){ var self=this; var username_ok=false; var email_ok=false; var name="Add"; this.tmpl_content=function(){ var html=''; html+='
    '; html+='
    Location Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Field 1
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Field 2
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Sort#
    '; html+=' '; html+='
    '; html+=''; return html; } this.save_test=function(){ if($('#C02_name').val() !=''){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this.process=function(__callback){ self.__process(root, (global_params['project_id'] && user_profile.privs[global_params['project_id']] )?parseInt(user_profile.privs[global_params['project_id']]): parseInt(user_profile.privs[0]) ,true,self.tmpl_content(),{},function(r){ if(! $('.action-button').prop('disabled')){ __callback(r); }else return false; },function(){ $('#C02_name').change(self.save_test); }); } } k__location_add_form.prototype=_action_form.prototype; var k__location_edit_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(){ var html=''; html+=' '; html+='
    '; html+='
    Location Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Field 1
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Field 2
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Sort#
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, (user_profile.privs[sys['C02_project']])? parseInt(user_profile.privs[sys['C02_project']]):parseInt(user_profile.privs[0]) ,false,self.tmpl_content(),sys,__callback); } } k__location_edit_form.prototype=_action_form.prototype; var k__pcharacter_add_form=function(root){ var self=this; var username_ok=false; var email_ok=false; var name="Add"; this.tmpl_content=function(){ var html=''; html+='
    '; html+='
    First Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Last Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Bio
    '; html+=' '; html+='
    '; html+=' '; return html; } this.save_test=function(){ if($('#B00_firstname').val() !=''){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this.process=function(__callback){ self.__process(root,(global_params['project_id'] && user_profile.privs[global_params['project_id']] )?parseInt(user_profile.privs[global_params['project_id']]):parseInt(user_profile.privs[0]) ,true,self.tmpl_content(),{},function(r){ if(! $('.action-button').prop('disabled')){ __callback(r); }else return false; },function(){ $('#B00_firstname').change(self.save_test); }); } } k__pcharacter_add_form.prototype=_action_form.prototype; var k__pcharacter_edit_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(){ var html=''; html+=' '; html+='
    '; html+='
    First Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Last Name
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Bio
    '; html+=' '; html+='
    '; html+=' '; return html; } this.process=function(sys,__callback){ self.__process(root,(user_profile.privs[sys['B00_project']])? parseInt((user_profile.privs[sys['B00_project']])):parseInt(user_profile.privs[0]),false,self.tmpl_content(),sys,__callback); } } k__pcharacter_edit_form.prototype=_action_form.prototype; var k__pmember_add_form=function(root){ var self=this; var name="Add"; var setup; this.user_exists=function(id,pusers){ let exists=false; for(var i in pusers){ if(pusers[i]['B01_user']==id) exists=true; } return exists; } this.change_type=function(){ $('#cast_1').hide(); $('#background_1').hide(); if( $('#B01_type').val()=='cast') $('#cast_1').show(); if( $('#B01_type').val()=='background') $('#background_1').show(); } this.tmpl_content=function(setup,priv){ var html=''; html+='
    '; html+='
    Name
    '; html+=' '; html+=' '; html+='
    '; html+='
    '; html+='
    Email
    '; html+=' '; html+='
    '; html+='
    '; html+='
    '; html+='
    '; html+='
    Department
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Position
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Feature Departments
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Type
    '; html+=' '; html+='


    '; html+='
    '; html+='
    Privilege
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Coordinator
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Own Call
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Past DTR
    '; html+=' '; html+='


    '; if(parseInt(setup['A04_prep_days'])>0){ html+='
    '; html+='
    Prep Days (a=all, 0=none)
    '; html+=' '; html+='
    '; if(setup['A04_prep_weekends']=='1'){ html+='
    '; html+='
    Prep Weekends
    '; html+=' '; html+='


    '; } html+='
    '; html+='
    Prep Rate per Hour
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Prep Hours per Day
    '; html+=' '; html+='


    '; } if(parseInt(setup['A04_scheduled_days'])>0){ html+='
    '; html+='
    Shoot Days (a=all, 0=none)
    '; html+=' '; html+='
    '; if(setup['A04_scheduled_weekends']=='1'){ html+='
    '; html+='
    Shoot Weekends
    '; html+=' '; html+='
    '; } html+='
    '; html+='
    Shoot Rate per Hour
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Shoot Hours per Day
    '; html+=' '; html+='


    '; } html+='
    '; html+='
    Cast Character
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Rate
    '; html+=' '; html+='
    '; html+='
    '; return html; } this.email_ok=true; this.setup=null; this._check_email=function(data){ if(data==0) self.email_ok=true; else self.email_ok=false; if(!self.email_ok && data==1) $('#register_email_error').html('email exists'); else $('#register_email_error').html(''); self.save_test(); } this.save_test=function(){ let setup=self.setup; if(self.email_ok ){ $('#email_l').show(); let name=$('#fullname').val(); let users=self.setup['users']; let zuser=null; for(var i in users){ let user=users[i]; let name2=user['A05_firstname']+' '+user['A05_lastname']; if(name2.toUpperCase()==name.toUpperCase()) zuser=user; } if(zuser){ $('#email_l').hide(); $('#email_2').html(zuser['A05_email']) } $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this.check=function(){ if( $('#email').val() !=''){ system.check_email(self._check_email, $('#email').val()); } } this.set_positions=function(){ let positions={}; $('#B01_position').empty(); $.each(self.setup['positions'], function (i, item) { $('#B01_position').append($('
    '; } $('#collection_f').html(html); $('#user_f').empty(); $('#add-timesheet').hide(); if(html){ self.generate_users(); $('#collection_id').change(self.generate_users); } } this.generate_users=function(){ let project_id=$('#project_id').val(); let collection_id=$('#collection_id').val(); var html=''; if(project_id>0 && collection_id>0){ let users=self.projects[project_id]['collections'][collection_id]['users']; html += '
    For whom?
    '; html += ' '; html += '
    '; } $('#user_f').html(html); $('#add-timesheet').hide(); if(html){ $('#user_id').change(function(){ let user_id=$('#user_id').val(); if(user_id>0) $('#add-timesheet').show(); else $('#add-timesheet').hide(); }); } } this.add_timesheet=function(){ let project_id=$('#project_id').val(); let collection_id=$('#collection_id').val(); let user_id=$('#user_id').val(); if(project_id && collection_id && user_id){ ts.sheet_add(function(sheet_id) { load_url('collection_sheets?action=edit&sheet_id='+sheet_id+'&collection_id='+collection_id+'&project_id='+project_id); },project_id, collection_id, user_id); } } this.process = function(__callback) { ts.get_unsheets(function(projects) { self.projects=projects; self.__process(root, parseInt(user_profile.privs[0]), true, self.tmpl_content(projects), {}, __callback, function(cb) { if (cb) cb(); $('#add-timesheet').hide(); self.generate_collections(); $('#project_id').change(self.generate_collections); $('#add-timesheet').click(self.add_timesheet); $('.action-button').hide(); }); }); } } k__sheet_add_form.prototype = _action_form.prototype; var k__sheet_edit_form=function(root){ var self=this; this.tmpl_content=function(sys){ var weekdays=['SUN','MON','TUE','WED','THU','FRI','SAT']; var html=''; html+='
    '; html+='
    First Name
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Last Name
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Position
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Department Head
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Production
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Company
    '; html+=' '; html+='
    '; html+='


    '; for(var j in weekdays){ if(sys[weekdays[j]+"__date"]){ html+='
    '; html+='
    '+weekdays[j]+' ' +sys[weekdays[j]+"__date"]+'
    '; html+='
    '; html+='
    CALL IN
    '; html+='
    '; html+=' '; html+=':'; html+=''; html+='
    '; html+='
    '; html+='
    '; html+='
    LUNCH
    '; html+=' '; html+=':'; html+=''; html+=' TO '; html+=':'; html+=''; html+='
    '; html+='
    '; html+='
    WRAP OUT
    '; html+=' '; html+=':'; html+=''; html+='
    '; html+=' '; html+='


    '; } } html+='
    '; html+='
    Note:
    '; html+=''; html+='
    '; html+=' '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, (user_profile.privs[sys['B03_project']])? parseInt(user_profile.privs[sys['B03_project']]):parseInt(user_profile.privs[0]) ,'Edit TS',self.tmpl_content(sys),sys,__callback,function(cb){ if(cb) cb(); $('.delete-button').hide(); } ); } } k__sheet_edit_form.prototype=_action_form.prototype; var k__sheet_filter_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(){ var html=''; html+='
    '; html+='
    Own Call
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(filter,__callback){ console.log(filter); self.__process(root,user_profile.A05_priv,'Filter',self.tmpl_content(),filter,function(r){ if(__callback) __callback(r); },function(cb){ if(cb) cb(); }); } } k__sheet_filter_form.prototype=_action_form.prototype; var k__sheet_note_form=function(root){ var self=this; var name="Submit"; this.tmpl_content=function(sys){ var html=''; let notes=(sys['B03_notes'])?JSON.parse(sys['B03_notes']):[]; for(var i in notes){ html+='
    '; html+='
    '+sec_to_date(notes[i]['time'])+' '+notes[i]['by']+':
    '; html+=notes[i]['message']; html+='
    '; } html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, (user_profile.privs[sys['B03_project']])? parseInt(user_profile.privs[sys['B03_project']]):parseInt(user_profile.privs[0]) ,"Notes",self.tmpl_content(sys),sys,__callback,function(cb){ if(cb()) cb(); $('.action-button').hide(); $('.delete-button').hide(); }); } } k__sheet_note_form.prototype=_action_form.prototype; var k__sheet_update_form=function(root,name,message){ var self=this; this.tmpl_content=function(sys){ var html=''; html+='
    '; html+='
    Message:
    '; html+=''; html+='
    '; html+=' '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root, (user_profile.privs[sys['B03_project']])? parseInt(user_profile.privs[sys['B03_project']]):parseInt(user_profile.privs[0]) ,name,self.tmpl_content(sys),sys,__callback,function(cb){ if(cb) cb(); // $('.delete-button').hide(); if(message) $('#message').val(message); } ); } } k__sheet_update_form.prototype=_action_form.prototype;