var System=function(){ this.login=function(callback,email,password,firm_id){ server_call(callback,"__login",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.logout=function(callback){ server_call(callback,"__logout",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_login=function(callback,token){ server_call(callback,"get_login",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_dashboard=function(callback){ server_call(callback,"get_dashboard",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_firms=function(callback){ server_call(callback,"get_firms",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_domains=function(callback){ server_call(callback,"get_domains",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_firm=function(callback,firm_id){ server_call(callback,"get_firm",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.firm_update=function(callback,firm_id,r){ server_call(callback,"__update_firm",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.user_update=function(callback,user_id,r){ server_call(callback,"__user_update",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.user_signature_update=function(callback,user_id,signature){ server_call(callback,"__signature_update",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_activity=function(callback,activity_id){ server_call(callback,"get_activity",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_activities=function(callback,filter,sort){ server_call(callback,"get_activities",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_notification=function(callback,notification_id){ server_call(callback,"get_notification",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.email_notification=function(callback,notification_id){ server_call(callback,"__email_notification",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.email_notifications=function(callback,activity_id){ server_call(callback,"__email_notifications",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_notifications=function(callback,filter,sort,clear_view,_skip_rotator_){ server_call(callback,"get_notifications",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.firm_register=function(callback,r){ server_call(callback,"__firm_register",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.user_register=function(callback,r){ server_call(callback,"__user_register",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_users=function(callback,filter){ server_call(callback,"get_users",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_user=function(callback,user_id){ server_call(callback,"get_user",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_firm_setup=function(callback){ server_call(callback,"get_firm_setup",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.reset_email_passwords=function(callback,project_id){ server_call(callback,"__reset_email_passwords",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.reset_email_password=function(callback,user_id,project_id){ server_call(callback,"__reset_email_password",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } } var system= new System(); var get_login=system.get_login; var login=system.login; var get_dashboard=system.get_dashboard; var __page_widgets=[]; var page_widgets=[]; var login_status='__public__'; var vpage_name_register={}; var urls=[]; var p_url=''; var c_url=''; var global_params={}; var pageTimeout=''; function update_vpage_name(vpage,name){ if(name) name=vpages_setup[vpage][0]+' - '+name; else name=vpages_setup[vpage][0]; for(var page in vpage_name_register) { vpage_name_register[page](name); } } function set_load_vpage(vpage,params,go_back,name){ if(typeof(params) !="undefined"){ for(var i in params) global_params[i]=params[i]; } load_vpage(vpage,go_back,name); } function set_load_vpage_r(vpage,query_str,go_back,name){ set_load_vpage(vpage,set_params(query_str),go_back,name); } var set_params = function(query_str) { // This function is anonymous, is executed immediately and // the return value is assigned to QueryString! let params = {}; if (query_str ) { query_str = query_str.replace(/^\/|\?/g, ""); var vars = query_str.split("&"); for (var i = 0; i < vars.length; i++) { if (vars[i] != "") { var pair = vars[i].split("="); var var_name = pair.shift(); var var_data = pair.join("="); // If first entry with this name if (typeof params[var_name] === "undefined") { params[var_name] = decodeURIComponent(var_data); // If second entry with this name } else if (typeof params[var_name] === "string") { var arr = [ params[var_name], decodeURIComponent(var_data) ]; params[var_name] = arr; // If third or later entry with this name } else { params[var_name].push(decodeURIComponent(var_data)); } } } } return params; }; function go_back(){ if(urls.length>0){ let url=urls.pop(); let hurl=(url &&url.indexOf('?back=')==-1 && url.indexOf('&back=')==-1)?(((url.indexOf('?')==-1)?(url+'?'):(url+'&'))+'back=1'):url; load_url(hurl,undefined,true); } } function get_page_path(page) { return page.replace(/\.*$/,'').replace(/^\//,''); } function load_url(url,_profile,go_back,name){ if(typeof(_profile)=="undefined") _profile=user_profile; else user_profile=_profile if(typeof(_profile) !="undefined" && Object.keys(_profile).length>0 ) login_status='_login__'; else login_status='__public__'; let p=_profile || user_profile; //if( p &&!p.A05_signature && !p.token && p.A05_id) url='firm_users?action=edit&user_id='+p.A05_id; if( url != (location.pathname+location.search).substr(1)) { var History = window.history; // Note: We are using a capital H instead of a lowe History.pushState(null, '', url); } c_url=url; if(c_url !=p_url) { global_params={}; if(p_url !='' && !go_back) urls.push(p_url); p_url=url; } var w=url.split('?'); var x=(vpages_setup[w[0]] && vpages_setup[w[0]][3])?vpages_setup[w[0]][3]:w[0]; var a=x.split('?'); var vpage=(vpages_setup[w[0]] && vpages_setup[w[0]][3])?w[0]:a[0]; var query_str=a[1]; if(w[1] && query_str) query_str+='&'+w[1]; else if(w[1]) query_str=w[1]; set_load_vpage_r(vpage,query_str,go_back,name); } function get_rpage(vpage){ var x=(vpages_setup[vpage] && vpages_setup[vpage][3])?vpages_setup[vpage][3]:vpage; var a=x.split('?'); var rpage=a[0]; return rpage; } function load_vpage( vpage,go_back,name) { if(vpage=='') vpage='dashboard'; var x=function(lstatus){ login_status=lstatus; __page_widgets=page_widgets; page_widgets = get_page_widgets(get_rpage(vpage), login_status); ajaxRender.run(1, function() { if(login_status=="__public__" || !vpages_setup[vpage] || ((user_profile.modules.indexOf('all')>=0 ||vpages_setup[vpage][2]=='' || user_profile.modules.indexOf(vpages_setup[vpage][2])>=0 ) && user_profile && user_profile.A05_priv>=vpages_setup[vpage][1])){ _previousData=''; sync_widgets(page_widgets,__page_widgets); if(pageTimeout !=''){ clearTimeout(pageTimeout); pageTimeout=''; } update_vpage_name(vpage,name); } },page_widgets); } if(login_status=='__public__'){ get_login(function(data){ if(data){ user_profile=data; x('__login__'); }else x('__public__'); },global_params['token']); }else x('__login__'); } var sync_widgets = function(active_widgets,inactive_widgets) { for (var i = 0; i < active_widgets.length; i++) { show_widget(active_widgets[i]); } for (var i = 0; i < inactive_widgets.length; i++) { if (active_widgets.indexOf(inactive_widgets[i]) == -1) { hide_widget(inactive_widgets[i]); } } } var hide_widget = function(widget) { set_widget_state(widget, 'none'); } var show_widget = function(widget) { set_widget_state(widget, 'block'); } var widget_state={}; var widget_pstate={}; var set_widget_state = function(widget, state) { var widget_current_state = $('#' + widget).css('display'); var callpre = window["_" + widget + "__callpre"]; widget_state[widget]=state; widget_pstate[widget]=widget_current_state; set_state(widget, callpre); } var set_state = function(widget, callpre) { if (typeof (callpre) == "function") { callpre(widget_state[widget], widget_pstate[widget], function() { var real_state = widget_state[widget] === 'block' ? '' : widget_state[widget]; if (widget_pstate[widget] != real_state) $('#' + widget).css('display', real_state); }); } else { var real_state = widget_state[widget] === 'block' ? '' : widget_state[widget]; if (widget_pstate[widget] != real_state) $('#' + widget).css('display', real_state); } } var get_page_widgets = function(vpage, login) { var _page_ = clone_obj(__page__[login]); var pagePath = vpage.split('/'); var _page_widgets_ = []; var set_wp=function(parr){ _page_widgets_ = _page_widgets_.concat(parr); } for (var i = 0; i <= pagePath.length; i++) { _page_widgets_ = _page_widgets_.concat(_page_['0']); if (typeof (_page_[pagePath[i]]) == "undefined" || pagePath[i] == "index") { set_wp(_page_['404']); break; } else { if (Array.isArray(_page_[pagePath[i]])) { set_wp(_page_[pagePath[i]]); break; } else { if (typeof (_page_[pagePath[i]]) == 'object'){ _page_ = _page_[pagePath[i]]; }else { set_wp(_page_['404']); break; } } } } _page_widgets_ = unique(_page_widgets_); return _page_widgets_; } function p__body(){ var self=this; this.root="p__body"; this.to_login; this.processed=false; this.navigation; this.go_back=function(){ go_back(); } this.temp=function(){ var html=''; html+=''; html+='
'; html+='
'; html+='
'; html+='
'; html+=''; html+='
'; html+='
'; html+='
'; html+=''; html+=''; html+='
'; html+='
'; html+='
'; html+=' '; 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').hide(); }); } $("#firm_name").html((user_profile)?user_profile.A00_name:''); $(".copyright").html((user_profile)?user_profile.A00_copyright:''); if( !$("#rear_menu").hasClass('hide_menu')) $("#rear_menu").addClass('hide_menu'); if(urls.length==0) $('.back_button').hide(); else $('.back_button').show(); self.navigation.refresh(); self.navigation.set_url(c_url); $("#main_content_top_right_bar").empty(); } this.set_navigation_pending=function(menu_item,count){ self.navigation[menu_item].set_pending_count(count); } this.set_menu_title=function(menu_title){ $(".menu_title").html(menu_title); } this.callpre=function(state,pstate,callback){ if(user_profile.A05_priv<3) $(".menu_notification").hide(); else $(".menu_notification").show(); $('.profile_name').text(user_profile.A05_firstname+" "+user_profile.A05_lastname); if(self.to_login) clearInterval(self.to_login); self.to_login=setInterval(function(){ $('.profile_time').text( formatDuration(Math.round(Date.now() / 1000) -user_profile.A05_last_login)); },1000); //$('.main_content').empty(); if(typeof(callback)=="function") callback(); } } var __p__body=new p__body(); function _p__body__data( callback ) { __p__body.process(); callback(); } var _p__body__callpre=__p__body.callpre; ajaxRender.addCall(_p__body__data); function p__login(){ var self=this; this.root="p__login"; this.tmpl=function(domains){ var html=''; html+=''; html+='
'; 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__dashboard(){ var self=this; this.root="c__dashboard"; this.processed=false; this.main_area=function(data){ var html=''; html+='
'; html+='
Setup Signature
'; html+='
'; html+='
Change Password
'; if( user_profile && user_profile.modules &&(user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf('pr')>=0) ){ html+='

'; html+='
My Pending DTR
'; html+='
'; html+='
My Approved DTR
'; } if( user_profile && user_profile.modules && (user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf('ts')>=0) ){ html+='

'; html+='
Pending Time Sheets
'; html+='
'; html+='
Approved Time Sheets
'; html+='
'; // html+='
Add Timesheet
'; } if(user_profile && user_profile.modules && (user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf('pc')>=0 )){ html+='

'; html+='
Add Receipt
'; html+='
'; html+='
My Pending Receipts
'; html+='
'; html+='
My Pending Petty Cash Envelopes
'; } /* html+='
'; if(parseInt(data['project_all'])>0){ html+='

Production

'; html+='
Total: '+data['project_all']+'
'; html+='
Active: '+data['project_active']+'
'; html+='
Wrapped: '+data['project_wrapped']+'
'; html+='
Inactive: '+data['project_inactive']+'
'; html+='
'; } if(parseInt(data['production_all'])>0){ html+='
'; html+='

DPR

'; html+='
Total: '+data['production_all']+'
'; html+='
Closed: '+data['production_closed']+'
'; html+='
Open: '+data['production_open']+'
'; html+='
'; } if(parseInt(data['dtr_all'])>0 && data['dtr_all'] !=data['my_dtr_all']){ html+='
'; html+='

DTR

'; html+='
Total: '+data['dtr_all']+'
'; html+='
Closed: '+data['dtr_approved']+'
'; html+='
Open: '+data['dtr_open']+'
'; html+='
'; } if(parseInt(data['my_dtr_all'])>0){ html+='
'; html+='

My DTR

'; html+='
Total: '+data['my_dtr_all']+'
'; html+='
Closed: '+data['my_dtr_approved']+'
'; html+='
Open: '+data['my_dtr_open']+'
'; html+='
'; } */ html+='
'; html+=''; return html; } this.process=function(data){ if(!self.processed){ $(".main_content").append(""); self.processed=true; } $('#'+self.root).html(self.main_area(data)); } this.callpre=function(state,pstate,callback){ if(typeof(callback)=="function") callback(); } } var __c__dashboard=new c__dashboard(); function _c__dashboard__data( callback ) { get_dashboard(function(data){ __c__dashboard.process(data); callback(); }); } var _c__dashboard__callpre=__c__dashboard.callpre; ajaxRender.addCall(_c__dashboard__data,"_p__body__data"); function c__firm_activities(){ var self=this; this.root="c__firm_activities"; this.processed=false; this.table; this.filter; this.filter_options={}; this.top_bar; this.columns={ } this.process=function(){ if(!self.processed){ $(".main_content").append(""); self.table=new s__firm_activities_table('#'+self.root); self.filter= new k__activity_filter_form('.panel_content'); self.top_bar= new _top_bar(); self.processed=true; } } this.create_filter=function(){ self.top_bar.add_top_bar_button('filter','Filter','filter','green','filter', function(){ self.filter.process( self.filter_options, function(filter_options){ self.filter_options=filter_options; self.table.process(filter_options); } ); } ); } this.callpre=function(state,pstate,callback){ if(state !='none'){ self.table.init(); self.create_filter(); //self.create_panel(); self.filter_options={}; self.table.process(self.filter_options); } if(typeof(callback)=="function") callback(); } } var __c__firm_activities=new c__firm_activities(); function _c__firm_activities__data( callback ) { __c__firm_activities.process(); callback(); } var _c__firm_activities__callpre=__c__firm_activities.callpre; ajaxRender.addCall(_c__firm_activities__data,"_p__body__data"); function c__firm_users(){ var self=this; this.root="c__firm_users"; this.processed=false; this.table; this.users={}; this.filter={}; this.register_form; this.filter_form; this.top_bar; this.columns={ } this.process=function(){ if(!self.processed){ $(".main_content").append(""); self.table=new s__firm_users_table('#'+self.root,self.reload); self.register_form= new k__user_register_form('.panel_content'); self.filter_form = new k__user_filter_form('.panel_content'); self.top_bar= new _top_bar(); self.processed=true; } } this.register_button=function(){ self.top_bar.add_top_bar_button('register','Register','register','green','pencil-square', function(){ self.register_form.process( function(register_options){ if(Object.keys(register_options).length>0){ system.user_register(function(data){ self.reload(); },register_options); } } ); } ); } this.reset_emails_button=function(){ self.top_bar.add_top_bar_button('send_reset_emails','Send Everyone Reset Email','reset_password','green','envelope', function(){ if(confirm('Are you sure?')){ system.reset_email_passwords(function(r){ if(r) alert('email sent'); },0); } } ); } this.filter_button=function(){ self.top_bar.add_top_bar_button('filter','Filter','filter','gray','filter', function(){ self.filter_form.process( self.filter, function(filter_options){ let lfilter=self.filter; self.filter = filter_options; if(lfilter.activity_start || lfilter.activity_end ||self.filter.activity_start || self.filter.activity_end) self.reload(); else self.refresh(); } ); } ); /* self.top_bar.add_top_bar_button('clear_filter','Clear Filter','clear_filter','white','refresh', function(){ let lfilter=self.filter; self.filter = {}; if(lfilter.activity_start || lfilter.activity_end) self.reload(); else self.refresh(); } ); */ } this.reload=function(){ system.get_users(function(users){ self.users=users; self.table.process(users,self.filter); },self.filter); } this.refresh=function(){ self.table.process(self.users,self.filter); } this.callpre=function(state,pstate,callback){ if(state !='none'){ self.filter={}; self.table.init(); if(parseInt(user_profile.A05_priv)>=5) self.register_button(); if(parseInt(user_profile.A05_priv)>=5) self.reset_emails_button(); //self.create_panel(); self.filter_button(); self.reload(); } if(typeof(callback)=="function") callback(); } } var __c__firm_users=new c__firm_users(); function _c__firm_users__data( callback ) { __c__firm_users.process(); callback(); } var _c__firm_users__callpre=__c__firm_users.callpre; ajaxRender.addCall(_c__firm_users__data,"_p__body__data"); function c__notifications(){ var self=this; this.root="c__notifications"; this.processed=false; this.table; this.filter; this.filter_options={}; this.top_bar; this.columns={ } this.process=function(){ if(!self.processed){ $(".main_content").append(""); self.table=new s__notifications_table('#'+self.root); self.filter= new k__notification_filter_form('.panel_content'); self.top_bar= new _top_bar(); self.processed=true; } } this.create_filter=function(){ self.top_bar.add_top_bar_button('filter','Filter','filter','green','filter', function(){ self.filter.process( self.filter_options, function(filter_options){ // filter_options['user_id']=global_params.user_id || -1; // filter_options['activity_id']=global_params.activity_id || 0; self.filter_options=filter_options; self.table.process(filter_options,''); } ); } ); } this.create_email_notifications=function(){ self.top_bar.add_top_bar_button('email_notifications','Email Notifications','email_notifications','blue','envelope-square', function(){ if(confirm('Are you sure you want to send email to all members listed in this page?')){ system.email_notifications(function(){ alert('Notification reminder has been submitted to the listed members'); },global_params.activity_id ||0); } } ); } this.callpre=function(state,pstate,callback){ if(state !='none'){ self.table.init(); self.create_filter(); if(global_params.activity_id && user_profile.privs[0]>=15) self.create_email_notifications(); //self.create_panel(); self.table.process({'user_id':global_params.user_id || -1,'activity_id':global_params.activity_id || 0},''); } if(typeof(callback)=="function") callback(); } } var __c__notifications=new c__notifications(); function _c__notifications__data( callback ) { __c__notifications.process(); callback(); } var _c__notifications__callpre=__c__notifications.callpre; ajaxRender.addCall(_c__notifications__data,"_p__body__data"); function c__user_profile(){ var self=this; this.root="c__user_profile"; this.processed=false; this.profile; this.top_bar; this.setup; this.edit_form; this.process=function(){ if(!self.processed){ $(".main_content").append(""); self.top_bar= new _top_bar(); self.edit_form= new k__user_edit_form('.panel_content'); self.profile=new s__user_profile('#'+self.root+'_top'); self.processed=true; } } this.edit=function(user_id){ system.get_user(function(user){ self.edit_form.process(user,function(edit_option){ var r={}; for(var col in edit_option){ if(user[col] !=edit_option[col]) r[col]=edit_option[col]; } if(Object.keys(r).length>0){ system.user_update(function(data){ refresh(); },user['A05_id'],r); } }); },user_id); } this.edit_button=function(){ self.top_bar.add_top_bar_button('edit','Edit Profile','edit','blue','pencil-square', function(){ let user_id=global_params.user_id; self.edit(user_id); } ); } this.refresh=function(){ let user_id=global_params['user_id'] || 0; system.get_user(function(user){ if(user){ self.profile.process(user); self.association_table=new s__user_association_table('#'+self.root+'_bottom',self.setup); self.association_table.process(user.projects); } },user_id); } this.callpre=function(state,pstate,callback){ if(state !='none'){ system.get_firm_setup(function(setup){ self.setup=setup; self.refresh(); }); } if(typeof(callback)=="function") callback(); } } var __c__user_profile=new c__user_profile(); function _c__user_profile__data( callback ) { __c__user_profile.process(); callback(); } var _c__user_profile__callpre=__c__user_profile.callpre; ajaxRender.addCall(_c__user_profile__data,"_p__body__data"); var s__admin_firms_table=function(root){ var self=this; this.root=root; this.edit= new k__firm_edit_form('.panel_content'); this.table_tpl=function(){ var html='
'; 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__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; 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; if(self.priv !=new_priv){ $(root).html(''); self.process(); } } this.process=function(){ var urls=''; self.priv=( user_profile)?user_profile.A05_priv:0; for(var branch in navigation_menu){ if(!vpages_setup[branch] || (user_profile && user_profile.modules && ( user_profile.modules.indexOf('all')>=0 || user_profile.modules.indexOf(vpages_setup[branch][2])>=0 ) && user_profile.A05_priv>=vpages_setup[branch][1])){ var item=navigation_menu[branch]; $(root).append(self.menu_tpl(branch,item,typeof(item.submenu)=="undefined")); self.set_menu_hover(branch); if(typeof(item.submenu) !="undefined"){ urls+=self.build_menu(branch,item); } self.set_menu_click(branch,item); } } //console.log(urls); } this.set_pending_count=function(count){ if(!count) count=0; if(count==0) $('#'+branch+"__pending_count").hide(); else $('#'+branch+"__pending_count").show(); $('#'+branch+"__pending_count").text(count); } self.process(); } var s__notifications_table=function(root){ var self=this; this.root=root; this.sort; this.users; this.filter; this.details= new k__notification_details_form('.panel_content'); this.table_tpl=function(){ var html='
    '; 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(); $('#A00_all_modules').change(all_modules_change); $('#core_modules').change(core_modules_change); } ); } } k__firm_edit_form.prototype=_action_form.prototype; var k__firm_register_form=function(root){ var self=this; var username_ok=false; var email_ok=false; var name="Register"; 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(){ if(self.email_ok){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } this._check=function(type){ var x=function(data){ if(self.email_ok){ $('.action-button').prop('disabled',false); }else { $('.action-button').prop('disabled',true); } } 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(); $('#A00_all_modules').change(all_modules_change); $('#core_modules').change(core_modules_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+='
    All Modules
    '; html+=' '; html+='

    '; html+='
    '; html+='
    Core Modules
    '; html+=' '; html+='
    '; html+='
    Production 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(); } 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(); } 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(){ $('.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+='
    '; html+='
    Signature
    '; html+='
    Signature
    '; html+= '
    Clear
    '; if(!self.sys.A05_signature) 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+='
    '; } html+='
    '; html+='
    Phone
    '; html+=' '; html+='
    '; html+=' '; html+='
    '; html+='
    Password
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Privilege
    '; html+=' '; html+='
    '; html+='
    '; html+='
    Status
    '; html+=' '; html+='
    '; html+='
    '; return html; } this.set_positions=function(){ let positions={}; let position=$('#A05_position').val(); $('#A05_position').empty(); $.each(self.setup['positions'], function (i, item) { $('#A05_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(summary){ var html=''; html+='
    T=Total,S=Submitted,P=Pending
    '; html+='
    '; return html; } this.load_table=function(page_num){ self._load_table(root, pr.get_productions,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.production_id); } this.__edit=function(project_id,production_id){ var x=function(){ pr.get_production(function(production){ self.edit.process(production,function(edit_option){ var r={}; for(var col in edit_option){ if(production[col] !=edit_option[col]) r[col]=edit_option[col]; } if(Object.keys(r).length>0){ pr.production_update(function(data){ self.project_id=0; self.load_table(-1); },project_id||0,production['B04_id'],r); } },function(){ x(); self.load_table(-1); }); },project_id||0,production_id); } x(); } this.row_callback=function(){ $('.edit_button').click( function(){ var production_id=$(this).attr("data"); var project_id=$(this).attr("project"); self.__edit(project_id,production_id); } ); } } s__project_productions_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+=''; 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(){ var html=''; html+=' '; html+='
    '; html+='
    Name
    '; html+=' '; html+='
    '; html+=''; html+='
    '; html+='
    Sort # (0-100)
    '; html+=' '; html+='
    '; html+=''; return html; } this.process=function(sys,__callback){ self.__process(root,user_profile.A05_priv,false,self.tmpl_content(),sys,__callback); } } k__department_edit_form.prototype=_action_form.prototype; 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+='
    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+='


    '; } } 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+='
    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; var Sa=function(){ this.process_add_script=function(callback, project_id, scriptBase64, filename) { server_call(callback,"__process_add_script",get_param_names(arguments.callee).slice(1),([].slice.call(arguments)).slice(1)); } this.get_script = function(callback, project_id, script_id) {server_call(callback, "get_script", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scripts = function(callback, filter) {server_call(callback, "get_scripts", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_script = function(callback, project_id, r) {server_call(callback, "add_script", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_script = function(callback, project_id, script_id, r) {server_call(callback, "update_script", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_script = function(callback, project_id, script_id) {server_call(callback, "delete_script", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene = function(callback, project_id, script_id, scene_id) {server_call(callback, "get_scene", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scenes = function(callback, filter) {server_call(callback, "get_scenes", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_scene = function(callback, project_id, script_id, r) {server_call(callback, "add_scene", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_scene = function(callback, project_id, script_id, scene_id, r) {server_call(callback, "update_scene", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_scene = function(callback, project_id, script_id, scene_id) {server_call(callback, "delete_scene", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_character = function(callback, project_id, scene_id, character_id) {server_call(callback, "get_scene_character", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_characters = function(callback, filter) {server_call(callback, "get_scene_characters", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_scene_character = function(callback, project_id, scene_id, r) {server_call(callback, "add_scene_character", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_scene_character = function(callback, project_id, scene_id, character_id, r) {server_call(callback, "update_scene_character", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_scene_character = function(callback, project_id, scene_id, character_id) {server_call(callback, "delete_scene_character", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_dood = function(callback, project_id, scene_id, dood_id) {server_call(callback, "get_dood", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_doods = function(callback, filter) {server_call(callback, "get_doods", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_dood = function(callback, project_id, scene_id, r) {server_call(callback, "add_dood", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_dood = function(callback, project_id, scene_id, dood_id, r) {server_call(callback, "update_dood", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_dood = function(callback, project_id, scene_id, dood_id) {server_call(callback, "delete_dood", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_item = function(callback, project_id, scene_id, item_id) {server_call(callback, "get_scene_item", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_items = function(callback, filter) {server_call(callback, "get_scene_items", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_scene_item = function(callback, project_id, scene_id, r) {server_call(callback, "add_scene_item", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_scene_item = function(callback, project_id, scene_id, item_id, r) {server_call(callback, "update_scene_item", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_scene_item = function(callback, project_id, scene_id, item_id) {server_call(callback, "delete_scene_item", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_animal = function(callback, project_id, scene_id, animal_id) {server_call(callback, "get_scene_animal", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_animals = function(callback, filter) {server_call(callback, "get_scene_animals", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_scene_animal = function(callback, project_id, scene_id, r) {server_call(callback, "add_scene_animal", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_scene_animal = function(callback, project_id, scene_id, animal_id, r) {server_call(callback, "update_scene_animal", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_scene_animal = function(callback, project_id, scene_id, animal_id) {server_call(callback, "delete_scene_animal", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_vehicle = function(callback, project_id, scene_id, vehicle_id) {server_call(callback, "get_scene_vehicle", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.get_scene_vehicles = function(callback, filter) {server_call(callback, "get_scene_vehicles", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.add_scene_vehicle = function(callback, project_id, scene_id, r) {server_call(callback, "add_scene_vehicle", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.update_scene_vehicle = function(callback, project_id, scene_id, vehicle_id, r) {server_call(callback, "update_scene_vehicle", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; this.delete_scene_vehicle = function(callback, project_id, scene_id, vehicle_id) {server_call(callback, "delete_scene_vehicle", get_param_names(arguments.callee).slice(1), ([].slice.call(arguments)).slice(1));}; } var sa=new Sa(); function c__firm_script(){ var self=this; this.root="c__firm_script"; this.processed=false; this.script; this.top_bar; this.setup; this.process=function(){ if(!self.processed){ $(".main_content").append(""); self.top_bar= new _top_bar(); self.script=new s__firm_script('#'+self.root+'_top'); self.processed=true; } } this.refresh=function(){ let project_id=global_params['project_id'] || 0; let script_id=global_params['script_id'] || 0; sa.get_script(function(script){ if(script){ self.script.process(script); } },project_id,script_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__firm_script=new c__firm_script(); function _c__firm_script__data( callback ) { __c__firm_script.process(); callback(); } var _c__firm_script__callpre=__c__firm_script.callpre; ajaxRender.addCall(_c__firm_script__data,"_p__body__data"); function c__firm_scripts() { var self = this; this.root = "c__firm_scripts"; this.processed = false; this.table; this.filter = {}; this.top_bar; this.columns = {}; // Process method: Initialize UI components this.process = function () { if (!self.processed) { if (!$(".main_content").length) { console.error("Error: .main_content element not found."); return; } $(".main_content").append(""); self.table = new s__firm_scripts_table('#' + self.root); self.top_bar = new _top_bar(); self.processed = true; } }; // Create Add button and handle file uploads this.create_add = function () { if (typeof self.top_bar.add_top_bar_button !== "function") { console.error("Error: add_top_bar_button is not a function."); return; } self.top_bar.add_top_bar_button('script_upload', 'Add', 'upload', 'green', 'pencil-square', function (e) { if (!e.target.files || e.target.files.length === 0) { alert('No file selected.'); return; } const fileInput = e.target; // Reference to the file input const reader = new FileReader(); reader.onloadend = () => { let base64pdf = reader.result; let filename = e.target.files[0].name; let type = e.target.files[0].type; if (type !== 'application/pdf') { alert('PDF format only'); fileInput.value = ''; // Clear the file input return; } if (typeof sa.process_add_script !== "function") { console.error("Error: sa.process_add_script is not a function."); fileInput.value = ''; // Clear the file input return; } // Disable the Add button during processing (Optional) const addButton = e.target.closest('button'); // Assuming the button wraps the input if (addButton) addButton.disabled = true; sa.process_add_script(function (res) { console.log("Script processed successfully:", res); // Refresh the table to show the new script self.refresh(); // Clear the file input fileInput.value = ''; // Re-enable the Add button if (addButton) addButton.disabled = false; }, 0, base64pdf, filename); }; reader.onerror = () => { console.error("Error reading the file."); alert("Failed to read the file."); fileInput.value = ''; // Clear the file input }; reader.readAsDataURL(e.target.files[0]); }); }; // Refresh method: Updates the table dynamically this.refresh = function () { if (self.table) { self.table.process(); // Ensure the table updates dynamically } else { console.error("Error: Table is not initialized."); } }; // Callpre method: Prepares the state before rendering this.callpre = function (state, pstate, callback) { if (state !== 'none') { if (!self.table) { console.error("Error: Table is not initialized."); return; } self.table.init(); self.create_add(); self.table.process(); } if (typeof callback === "function") callback(); }; } // Create an instance of c__firm_scripts var __c__firm_scripts = new c__firm_scripts(); // Initialize the data and process the scripts function _c__firm_scripts__data(callback) { __c__firm_scripts.process(); callback(); } // Register the callpre method for ajax rendering var _c__firm_scripts__callpre = __c__firm_scripts.callpre; ajaxRender.addCall(_c__firm_scripts__data, "_p__body__data"); function c__script_scene() { var self = this; this.root = "c__script_scene"; this.processed = false; this.scene; this.top_bar; // Process method: sets up the DOM structure this.process = function() { if (!self.processed) { $(".main_content").append( "" ); self.top_bar = new _top_bar(); self.scene = new s__script_scene('#' + self.root + '_top'); self.processed = true; } }; // Refresh method: fetches and processes the scene data this.refresh = function() { let project_id = global_params?.['project_id'] || 0; let script_id = global_params?.['script_id'] || 0; let scene_id = global_params?.['scene_id'] || 0; // Fetch the scene data sa.get_scene( function(scene) { if (scene) { self.scene.process(scene); } else { console.error('No scene found.'); } }, project_id, script_id, scene_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(); }; } // Global instance of c__script_scene var __c__script_scene = new c__script_scene(); // Function to process data and execute callback function _c__script_scene__data(callback) { __c__script_scene.process(); callback(); } // Register the callpre method var _c__script_scene__callpre = __c__script_scene.callpre; ajaxRender.addCall(_c__script_scene__data, "_p__body__data"); function c__script_scenes() { var self = this; this.root = "c__script_scenes"; this.processed = false; this.table; this.filter = {}; this.top_bar; this.columns = {}; this.process = function () { if (!self.processed) { if (!$(".main_content").length) { console.error("Error: .main_content element not found."); return; } $(".main_content").append(""); self.table = new s__script_scenes_table('#' + self.root); self.top_bar = new _top_bar(); self.processed = true; } }; this.create_add = function () { if (typeof self.top_bar.add_top_bar_button !== "function") { console.error("Error: add_top_bar_button is not a function."); return; } /*self.top_bar.add_top_bar_button('script_upload', 'Add', 'upload', 'green', 'pencil-square', function (e) { if (!e.target.files || e.target.files.length === 0) { alert('No file selected.'); return; } const reader = new FileReader(); reader.onloadend = () => { let base64pdf = reader.result; let filename = e.target.files[0].name; let type = e.target.files[0].type; if (type !== 'application/pdf') { alert('PDF format only'); return; } if (typeof sa.process_add_script !== "function") { console.error("Error: sa.process_add_script is not a function."); return; } sa.process_add_script(function (res) { console.log("Script processed successfully:", res); }, 0, base64pdf, filename); }; reader.onerror = () => { console.error("Error reading the file."); alert("Failed to read the file."); }; reader.readAsDataURL(e.target.files[0]); });*/ }; this.callpre = function (state, pstate, callback) { if (state !== 'none') { if (!self.table) { console.error("Error: Table is not initialized."); return; } self.table.init(); self.create_add(); self.table.process(); } if (typeof callback === "function") callback(); }; } var __c__script_scenes = new c__script_scenes(); function _c__script_scenes__data(callback) { __c__script_scenes.process(); callback(); } var _c__script_scenes__callpre = __c__script_scenes.callpre; ajaxRender.addCall(_c__script_scenes__data, "_p__body__data"); var s__firm_script = function (root) { var self = this; this.root = root; this.view_tpl = function (script) { var html = '
    '; html += '
    '; html += '
    Title: ' + script.F00_title + '
    '; html += '
    '; html += '
    '; // Add a newline between fields html += '
    '; html += ' Synopsis: ' + script.F00_synopsis; html += '
    '; html += '
    '; // Add a newline between fields html += '
    '; html += ' Summary: ' + script.F00_summary; html += '
    '; html += '
    '; // Add a newline between fields // Display Number of Characters var characters = script.F00_characters ? script.F00_characters .replace(/[\{\}\[\]"]/g, '') // Remove brackets and quotes .replace(/\d+:\s*/g, '') // Remove numeric indices and the colon .split(',') // Split by commas .map(function(character) { return character.trim(); // Trim whitespace from each character name }) : []; console.log(characters); html += '
    '; html += '
    Number of Characters: ' + characters.length + '
    '; html += '
    '; html += '
    '; // Add a newline between fields // Display List of Characters if (characters.length > 0) { html += '
    '; html += '
    Characters:
    '; html += '
      '; characters.forEach(function(character) { html += '
    • ' + character.trim() + '
    • '; }); html += '
    '; html += '
    '; } html += '
    '; // Add a newline between fields html += '
    '; html += '
    Number of Scenes: ' + ((script.F00_scene_count >= 0) ? script.F00_scene_count : 0) + '
    '; html += '
    '; html += '
    '; // Add a newline between fields html += ' '; html += '
    '; return html; }; this.process = function (script) { $(self.root).html(self.view_tpl(script)); }; }; var s__firm_scripts_table = function(root) { var self = this; this.root = root; this.refreshPage=false; //this.edit = new k__script_edit_form('.panel_content'); // Helper function for word truncation function truncateWords(text, maxWords) { if (!text) return ''; const words = text.split(/\s+/); return words.length > maxWords ? words.slice(0, maxWords).join(' ') + '...' : text; } this.table_tpl = function() { var html = `
    `; if (user_profile.A05_firm == -1) html += ' '; html += `
    FirmTitle Synosis Summary User Icon Scenes
    `; return html; }; this.row_tpl = function(data) { let priv = Math.max(parseInt(user_profile.privs[0]), (user_profile.privs[data['A04_id']] || 0)); if(data['F00_status']=='pending') self.refreshPage=true; var html = ` `; if (user_profile.A05_firm == -1) html += ' ' + data['A00_name'] + ''; html += `
    ${data['F00_title']}
    ${truncateWords(data['F00_synopsis'], 10)} ${truncateWords(data['F00_summary'], 10)} ${data['F00_characters'] ? data['F00_characters'].split(',').length : 0}
    ${data['F00_scene_count']}
    `; html += ''; return html; }; this.foot_tpl = function(summary) { var html = '
    '; return html; }; this.load_table = function(page_num) { self._load_table(root, sa.get_scripts, {'project_id':global_params.project_id || 0}); }; this.process = function() { self.load_table(1); if (global_params['action'] === 'edit' && !global_params.back) self.__edit(global_params.script_id); }; this.__edit = function(script_id) { sa.get_script(function(script) { self.edit.process(script, function(edit_option) { var r = {}; for (var col in edit_option) { if (script[col] != edit_option[col]) r[col] = edit_option[col]; } if (Object.keys(r).length > 0) { sa.script_update(function(data) { self.load_table(-1); }, script['A04_id'], r); } }); }, script_id); }; this.row_callback = function() { clearInterval(pageTimeout); if(self.refreshPage){ pageTimeout=setInterval(self.load_table,30000); self.refreshPage=false; } $('.link_button').click(function() { let x = this; var token = $(this).attr("data"); var script_id = $(this).attr("script"); navigator.clipboard.writeText(location.protocol + '//' + location.host + '/production_trs?action=add&script_id=' + script_id + '&token=' + token); $(x).attr('src', "/icons/copy.svg"); setTimeout(function() { $(x).attr('src', "/icons/link.png"); }, 1000); }); $('.edit_button').click(function() { var script_id = $(this).attr("data"); self.__edit(script_id); }); }; }; s__firm_scripts_table.prototype = _table_display.prototype; var s__script_scene = function(root) { var self = this; this.root = root; this.view_tpl = function(scene) { var html = '
    '; html += '
    '; html += '
    Number: ' + (scene.F01_number || 'N/A') + '
    '; html += '
    '; html += '
    '; // Add a newline between fields html += '
    '; html += '
    Title: ' + (scene.F01_title || 'N/A') + '
    '; html += '
    '; html += '
    '; // Add a newline between fields html += '
    '; html += ' Description: ' + (scene.F01_description || 'N/A'); html += '
    '; html += '
    '; // Add a newline between fields // html += '
    '; html += '
    Pages: ' + (scene.F01_pages || 'N/A') + '
    '; html += '
    '; html += '
    '; html += '
    '; html += '
    Environment: ' + (scene.F01_enviroment || 'N/A') + '
    '; html += '
    '; html += '
    '; html += '
    '; html += '
    Setting: ' + (scene.F01_setting || 'N/A') + '
    '; html += '
    '; html += '
    '; html += '
    '; html += '
    Time: ' + (scene.F01_time || 'N/A') + '
    '; html += '
    '; html += '
    '; html += '
    '; html += '
    Weather: ' + (scene.F01_weather || 'N/A') + '
    '; html += '
    '; html += '
    '; html += '
    '; html += '
    Lightning: ' + (scene.F01_ligthning || 'N/A') + '
    '; html += '
    '; html += '
    '; // Number of Characters html += '
    '; html += '
    Number of Characters: ' + (scene.characters?.length || 0) + '
    '; html += '
    '; html += '
    '; // List of Characters if (scene.characters?.length > 0) { html += '
    '; html += '
    Characters:
    '; html += '
      '; scene.characters.forEach(function(character) { html += '
    • ' + (character.F02_name || 'Unnamed Character') + '
    • '; }); html += '
    '; html += '
    '; } html += '
    '; // Number of Doods html += '
    '; html += '
    Number of Doods: ' + (scene.doods?.length || 0) + '
    '; html += '
    '; html += '
    '; if (scene.doods?.length > 0) { html += '
    '; html += '
    Doods:
    '; html += '
    User/ Role/ Commitment:
    '; html += '
      '; scene.doods.forEach(function(dood) { html += '
    • ' + (dood.F03_user || 'Unknown User') + ' / ' + (dood.F03_role || 'Unknown Role') + ' / ' + (dood.F03_commitment || 'No Commitment') + '
    • '; }); html += '
    '; html += '
    '; } html += '
    '; // Number of Items html += '
    '; html += '
    Number of Items: ' + (scene.items?.length || 0) + '
    '; html += '
    '; html += '
    '; // List of Items if (scene.items?.length > 0) { html += '
    '; html += '
    Items:
    '; html += '
      '; scene.items.forEach(function(item) { html += '
    • ' + (item.F04_type || 'Unknown Type') + ' - ' + (item.F04_description || 'No Description') + ' - ' + (item.F04_quantity || '0') + '
    • '; }); html += '
    '; html += '
    '; } html += '
    '; // Number of Animals html += '
    '; html += '
    Number of Animals: ' + (scene.animals?.length || 0) + '
    '; html += '
    '; html += '
    '; // List of Animals if (scene.animals?.length > 0) { html += '
    '; html += '
    Animals:
    '; html += '
      '; scene.animals.forEach(function(animal) { html += '
    • ' + (animal.F05_type || 'Unknown Type') + ' - ' + (animal.F05_role || 'Unknown Role') + ' - ' + (animal.F05_handler || 'No Handler') + '
    • '; }); html += '
    '; html += '
    '; } html += '
    '; // Number of Vehicles html += '
    '; html += '
    Number of Vehicles: ' + (scene.vehicles?.length || 0) + '
    '; html += '
    '; html += '
    '; // List of Vehicles if (scene.vehicles?.length > 0) { html += '
    '; html += '
    Vehicles:
    '; html += '
      '; scene.vehicles.forEach(function(vehicle) { html += '
    • ' + (vehicle.F06_type || 'Unknown Type') + ' - ' + (vehicle.F06_description || 'No Description') + '
    • '; }); html += '
    '; html += '
    '; } html += '
    '; html += ' '; html += '
    '; return html; }; this.process = function(scene) { $(self.root).html(self.view_tpl(scene)); }; }; var s__script_scenes_table = function(root) { var self = this; this.root = root; //this.edit = new k__script_edit_form('.panel_content'); // Helper function for word truncation function truncateWords(text, maxWords) { if (!text) return ''; const words = text.split(/\s+/); return words.length > maxWords ? words.slice(0, maxWords).join(' ') + '...' : text; } this.table_tpl = function() { var html = `
    `; if (user_profile.A05_firm == -1) html += ' '; html += `
    Firm# Title Pages Environment Setting Lightning Description Set Changes
    `; return html; }; this.row_tpl = function(data) { let priv = Math.max(parseInt(user_profile.privs[0]), (user_profile.privs[data['A04_id']] || 0)); let script_id = global_params.script_id || 0; var html = ` `; if (user_profile.A05_firm == -1) html += ' ' + data['A00_name'] + ''; html += `
    ${data['F01_number']}
    ${data['F01_title']} ${data['F01_pages']} ${(data['F01_enviroment']=='I')?'INT':'EXT'} ${(data['F01_setting']=='D')?'DAY':((data['F01_setting']=='N')?'NIGHT':data['F01_setting'])} ${data['F01_lightling']??'N/A'} ${truncateWords(data['F01_description'], 10)} ${data['F01_set_changes']??'N/A'} `; return html; }; this.foot_tpl = function(summary) { var html = '
    '; return html; }; this.load_table = function(page_num) { self._load_table(root, sa.get_scenes, {'project_id':global_params.project_id || 0,'script_id':global_params.script_id || 0}); //self._load_table(root, sa.get_scene_characters, {'project_id':global_params.project_id || 0}); }; this.process = function() { self.load_table(1); if (global_params['action'] === 'edit' && !global_params.back) self.__edit(global_params.scene_id); }; this.__edit = function(scene_id) { sa.get_scene(function(scene) { self.edit.process(scene, function(edit_option) { var r = {}; for (var col in edit_option) { if (scene[col] != edit_option[col]) r[col] = edit_option[col]; } if (Object.keys(r).length > 0) { sa.update_scene(function(data) { self.load_table(-1); }, scene['F01_id'], r); } }); }, scene_id); }; this.row_callback = function() { $('.link_button').click(function() { let x = this; var token = $(this).attr("data"); var scene_id = $(this).attr("scene"); navigator.clipboard.writeText(location.protocol + '//' + location.host + '/production_trs?action=add&script_id=' + scene_id + '&token=' + token); $(x).attr('src', "/icons/copy.svg"); setTimeout(function() { $(x).attr('src', "/icons/link.png"); }, 1000); }); $('.edit_button').click(function() { var scene_id = $(this).attr("data"); self.__edit(scene_id); }); }; }; s__script_scenes_table.prototype = _table_display.prototype;