Custom view recurring events - Detect master event

How can you detect if an event is the master recurring event or not?

I would like to change all other recurring events normally (by inserting it), but if you delete the master event – then delete all the recurring events with its event_pid.

Master event has not event_pid value

if (!scheduler.getEvent(id).event_pid) do_some();

Also there is a getRecDates API, which will give dates of all events occurrences based on master id ( so you can get list of dates on which events need to be inserted in DB before deleting master event )

I tried this back-end in PHP and the event_pid was showing up as the primary_key ID, even for the master event.

When I viewed the ‘ev’ object it still showed the event_pid as 5, even though in the database for the master event it was 0 because it is the master event…

Fields exists in DB, so all events will have it, but master event will contain empty value as event_pid

When I viewed the ‘ev’ object it still showed the event_pid as 5
Can you provide a snippet of code which you are using to check properties of master event?

function alertObj(obj){
		alert(JSON.stringify(obj));
}
	scheduler.showLightbox = function(id) {    
	  var mode = scheduler.getState().mode;   
    var new_event = scheduler.getState().new_event;  
		var ev = scheduler.getEvent(id);  
    var type = EVENT_TYPE[ev.event_type]; 
		scheduler.startLightbox(id, html("event_form"));    
		html("text").focus();
		var id = ev.id;  
		if(id.length>0){
      var recTime = id.split("#");   
  		if(recTime[1]){
  		  var date = new Date(recTime[1]*1000);
        var formattedTime = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
  		}       
		} 
    if(ev.issue_id){            
        html("accountIssue").style.display = '';      
        html("issue_id").value = ev.issue_id;
        html("issue_idText").innerHTML = "#"+ev.issue_id;
        html("issue_idText").setAttribute('class','link'); 
        html("issue_idText").href="?module=iss&do=view&id="+ev.issue_id;  
        html("accountClear").style.display = ''; 
        html("accountText").style.display = 'none';   
        html("accountText1").style.display = 'none';   
        html("accountText2").style.display = 'none';  
        html("accountText3").style.display = 'none'; 
        html("acc_search_result").style.border = 'none'; 
    } else {	
      if(type=='Onsite' || type=='Remote'){    
        html("accountClear").style.display = ''; 
        html("accountText").style.display = '';   
        html("acc_search_result").style.border = 'none';      
        html("accountIssue").style.display = 'none'; 
      } else {               
        html("acc_search").value = '';  
        html("accountClear").style.display = 'none'; 
        html("accountText").style.display = 'none';   
        html("accountText1").style.display = 'none';   
        html("accountText2").style.display = 'none';  
        html("accountText3").style.display = 'none'; 
        html("acc_search_result").style.border = 'none';       
        html("accountIssue").style.display = 'none'; 
      }
    }
		html("text").value = ev.text || "";     
		  selectOption("start_time",timeFormat(ev.start_date));  
		  selectOption("end_time",timeFormat(ev.end_date));	  
		  slider_start.setValue(timeFormat(ev.start_date).replace(':',''));  
		  slider_end.setValue(timeFormat(ev.end_date).replace(':',''));
		html("start_date").value = dateFormat(ev.start_date);   
		html("end_date").value = dateFormat(ev.end_date);     
		html("description").value = ev.descr || "Enter a description here";  
		combo.setComboValue((ev.user_id) || "");   
		if(scheduler.getState().new_event){
      html('rec_dateText').style.display='';  
      html('rec_dateBody').style.display='';  
      html('rec_dateClear').style.display='';
    } else {
      html('rec_box').style.display='none';     
      html('rec_dateText').style.display='none';  
      html('rec_dateBody').style.display='none'; 
      html('rec_dateClear').style.display='none';
    }   
		selectOption("event_type",(ev.event_type||0)); 
		switch(ev.event_type){
      case "0":      
        html("event_form").className=EVENT_FORM[ev.event_type];
        break; 
      default:
        html("event_form").className=EVENT_FORM[html("event_type").selectedIndex];  
        break;
    }	  
    
	}; 

It seems that you are using custom form, in such case built-in logic of recurring events will not work. For already existing event ( created by built-in lightbox ) you can check ev.event_pid, but if event was created by custom lightbox - it will not have such mark.

I figured out a solution!

Turns out this is all you need. If you delete the master event client side, it will delete all the events. Everything else is normal.

function beforeProcessing($action){ 
  define('ORIG_ID', $action->get_value("timesheet_id"));  
  ....
} 
function afterProcessing($action){
  if($action->get_value("event_pid")==intval(ORIG_ID)){
    if($action->get_value("rec_type")==""){}
    if($action->get_value("rec_type")=="none"){       
      mysql_query("DELETE FROM timesheets WHERE timesheet_id='".$action->get_value("event_pid")."' || event_pid='".$action->get_value("event_pid")."'");   
      $action->set_response_attribute("result","MASTER_EVENT_DELETED");
    }
  }
}

And if you want to load it properly client side

  dataProcessor.defineAction("inserted",function(response){
    if(response.getAttribute("result")=="MASTER_EVENT_DELETED")location.reload();
    return true;
  }); 

Still thinking of a way to prevent you from editing the master event. Right now if the master event start & end date is edited it must be deleted twice, because the timesheet_id changed.