1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
38 //////////////////////////////////////////////////
39 // class: SugarWidgetListView
40 // widget to display a list view
42 //////////////////////////////////////////////////
44 SugarClass.inherit("SugarWidgetListView","SugarClass");
46 function SugarWidgetListView() {
50 SugarWidgetListView.prototype.init = function() {
54 SugarWidgetListView.prototype.load = function(parentNode) {
55 this.parentNode = parentNode;
59 SugarWidgetListView.prototype.display = function() {
61 if(typeof GLOBAL_REGISTRY['result_list'] == 'undefined') {
62 this.display_loading();
66 var div = document.getElementById('list_div_win');
67 div.style.display = 'block';
68 //div.style.height='125px';
69 var html = '<table width="100%" cellpadding="0" cellspacing="0" border="0" class="list view">';
71 html += '<th width="2%" nowrap="nowrap"> </th>';
72 html += '<th width="20%" nowrap="nowrap">'+GLOBAL_REGISTRY['meeting_strings']['LBL_NAME']+'</th>';
73 html += '<th width="20%" nowrap="nowrap">'+GLOBAL_REGISTRY['meeting_strings']['LBL_EMAIL']+'</th>';
74 html += '<th width="20%" nowrap="nowrap">'+GLOBAL_REGISTRY['meeting_strings']['LBL_PHONE']+'</th>';
75 html += '<th width="18%" nowrap="nowrap"> </th>';
77 //var html = '<table width="100%" cellpadding="0" cellspacing="0">';
78 for(var i=0;i<GLOBAL_REGISTRY['result_list'].length;i++) {
79 var bean = GLOBAL_REGISTRY['result_list'][i];
81 var className='evenListRowS1';
83 if(typeof(GLOBAL_REGISTRY.focus.users_arr_hash[ bean.fields.id]) != 'undefined') {
87 className='oddListRowS1';
89 className='evenListRowS1';
91 if(typeof (bean.fields.first_name) == 'undefined') {
92 bean.fields.first_name = '';
94 if(typeof (bean.fields.email1) == 'undefined' || bean.fields.email1 == "") {
95 bean.fields.email1 = ' ';
97 if(typeof (bean.fields.phone_work) == 'undefined' || bean.fields.phone_work == "") {
98 bean.fields.phone_work = ' ';
101 html += '<tr class="'+className+'">';
102 html += '<td><img src="'+GLOBAL_REGISTRY.config['site_url']+'/index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName='+bean.module+'s.gif"/></td>';
103 html += '<td>'+bean.fields.full_name+'</td>';
104 html += '<td>'+bean.fields.email1+'</td>';
105 html += '<td>'+bean.fields.phone_work+'</td>';
106 html += '<td align="right">';
107 // hidden = 'hidden';
110 // hidden = 'visible';
112 html += '<input type="button" class="button" onclick="this.disabled=true;SugarWidgetSchedulerAttendees.form_add_attendee('+i+');" value="'+GLOBAL_REGISTRY['meeting_strings']['LBL_ADD_BUTTON']+'"/ style="visibility: '+hidden+'"/>';
118 //this.parentNode.innerHTML = html;
120 div.innerHTML = html;
123 SugarWidgetListView.prototype.display_loading = function() {
127 //////////////////////////////////////////////////
128 // class: SugarWidgetSchedulerSearch
129 // widget to display the meeting scheduler search box
131 //////////////////////////////////////////////////
133 SugarClass.inherit("SugarWidgetSchedulerSearch","SugarClass");
135 function SugarWidgetSchedulerSearch() {
139 SugarWidgetSchedulerSearch.prototype.init = function() {
140 this.form_id = 'scheduler_search';
141 GLOBAL_REGISTRY['widget_element_map'] = new Object();
142 GLOBAL_REGISTRY['widget_element_map'][this.form_id] = this;
145 SugarWidgetSchedulerSearch.prototype.load = function(parentNode) {
146 this.parentNode = parentNode;
150 SugarWidgetSchedulerSearch.submit = function(form) {
152 SugarWidgetSchedulerSearch.hideCreateForm();
154 //construct query obj:
155 var conditions = new Array();
157 if(form.search_first_name.value != '') {
158 conditions[conditions.length] = {"name":"first_name","op":"starts_with","value":form.search_first_name.value}
160 if(form.search_last_name.value != '') {
161 conditions[conditions.length] = {"name":"last_name","op":"starts_with","value":form.search_last_name.value}
163 if(form.search_email.value != '') {
164 conditions[conditions.length] = {"name":"email1","op":"starts_with","value":form.search_email.value}
167 var query = {"modules":["Users","Contacts"
169 ],"group":"and","field_list":['id','full_name','email1','phone_work'],"conditions":conditions};
170 global_request_registry[req_count] = [this,'display'];
171 req_id = global_rpcClient.call_method('query',query);
172 global_request_registry[req_id] = [ GLOBAL_REGISTRY['widget_element_map'][form.id],'refresh_list'];
175 SugarWidgetSchedulerSearch.prototype.refresh_list = function(rslt) {
177 GLOBAL_REGISTRY['result_list'] = rslt['list'];
179 if (rslt['list'].length > 0) {
180 this.list_view.display();
181 document.getElementById('empty-search-message').style.display = 'none';
183 document.getElementById('list_div_win').style.display = 'none';
184 document.getElementById('empty-search-message').style.display = '';
189 SugarWidgetSchedulerSearch.prototype.display = function() {
190 var html ='<div class="schedulerInvitees"><h3>'+GLOBAL_REGISTRY['meeting_strings']['LBL_ADD_INVITEE']+'</h5><table border="0" cellpadding="0" cellspacing="0" width="100%" class="edit view">';
192 html += '<form name="schedulerwidget" id="'+this.form_id+'" onsubmit="SugarWidgetSchedulerSearch.submit(this);return false;">';
194 html += '<table width="100%" cellpadding="0" cellspacing="0" width="100%" >'
196 //html += '<form id="'+this.form_id+'"><table width="100%"><tbody><tr>';
197 html += '<td scope="col" nowrap><label for="search_first_name">'+GLOBAL_REGISTRY['meeting_strings']['LBL_FIRST_NAME']+':</label> <input name="search_first_name" id="search_first_name" value="" type="text" size="10"></td>';
198 html += '<td scope="col" nowrap><label for="search_last_name">'+GLOBAL_REGISTRY['meeting_strings']['LBL_LAST_NAME']+':</label> <input name="search_last_name" id="search_last_name" value="" type="text" size="10"></td>';
199 html += '<td scope="col" nowrap><label for="search_email">'+GLOBAL_REGISTRY['meeting_strings']['LBL_EMAIL']+':</label> <input name="search_email" id="search_email" type="text" value="" size="15"></td>';
200 //html += '<td valign="center"><input type="submit" onclick="SugarWidgetSchedulerSearch.submit(this.form);" value="Search" ></td></tr></tbody></table></form>';
201 html += '<td valign="center"><input type="submit" class="button" value="'+GLOBAL_REGISTRY['meeting_strings']['LBL_SEARCH_BUTTON']+'" ></td></tr>';
204 html += '</td></tr></table></div>';
206 // append the list_view as the third row of the outside table
207 this.parentNode.innerHTML += html;
210 var div = document.createElement('div');
211 div.setAttribute('id','list_div_win');
212 div.style.overflow = 'auto';
213 div.style.width = '100%';
214 div.style.height= '100%';
215 div.style.display = 'none';
216 this.parentNode.appendChild(div);
220 html += '<div id="create-invitees" style="margin-bottom: 10px;">';
221 html += '<div id="empty-search-message" style="display: none;">' + GLOBAL_REGISTRY['meeting_strings']['LBL_EMPTY_SEARCH_RESULT'] + '</div>';
222 html += '<h3>' + GLOBAL_REGISTRY['meeting_strings']['LBL_CREATE_INVITEE'] + '</h3>';
223 html += '<div id="create-invitees-buttons">';
224 html += '<button type="button" onclick="SugarWidgetSchedulerSearch.showCreateForm(\'Contacts\');">' + GLOBAL_REGISTRY['meeting_strings']['LBL_CREATE_CONTACT'] + '</button> ';
225 html += '<button type="button" onclick="SugarWidgetSchedulerSearch.showCreateForm(\'Leads\');">' + GLOBAL_REGISTRY['meeting_strings']['LBL_CREATE_LEAD'] + '</button> ';
228 html += '<div id="create-invitee-edit" style="display: none;">';
229 html += '<form name="createInviteeForm" id="createInviteeForm" onsubmit="SugarWidgetSchedulerSearch.createInvitee(this); return false;">';
230 html += '<input type="hidden" name="inviteeModule" value="Contacts">';
231 html += '<table class="edit view" cellpadding="0" cellspacing="0" style="width: 330px; margin-top: 2px;">'
233 html += '<td valign="top" width="33%">' + GLOBAL_REGISTRY['meeting_strings']['LBL_FIRST_NAME'] + ': </td><td valign="top"><input name="first_name" type="text" size="19"></td>';
236 html += '<td valign="top" width="33%">' + GLOBAL_REGISTRY['meeting_strings']['LBL_LAST_NAME'] + ': <span class="required">*</span></td><td valign="top"><input name="last_name" type="text" size="19"></td>';
239 html += '<td valign="top" width="33%">' + GLOBAL_REGISTRY['meeting_strings']['LBL_EMAIL'] + ': </td><td valign="top"><input name="email1" type="text" size="19"></td>';
242 html += '<button type="button" id="create-invitee-btn" onclick="SugarWidgetSchedulerSearch.createInvitee(this.form);">' + GLOBAL_REGISTRY['meeting_strings']['LBL_CREATE_AND_ADD'] + '</button> ';
243 html += '<button type="button" id="cancel-create-invitee-btn" onclick="SugarWidgetSchedulerSearch.hideCreateForm();">' + GLOBAL_REGISTRY['meeting_strings']['LBL_CANCEL_CREATE_INVITEE'] + '</button> ';
247 this.parentNode.innerHTML += html;
249 addToValidate('createInviteeForm', 'last_name', 'last_name', true, GLOBAL_REGISTRY['meeting_strings']['LBL_LAST_NAME']);
251 this.list_view = new SugarWidgetListView();
252 this.list_view.load(div);
255 SugarWidgetSchedulerSearch.showCreateForm = function(module){
256 document.getElementById('create-invitee-edit').style.display = '';
257 document.getElementById('create-invitees-buttons').style.display = 'none';
258 document.getElementById('list_div_win').style.display = 'none';
259 document.forms['createInviteeForm'].elements['inviteeModule'].value = module;
261 document.getElementById('empty-search-message').style.display = 'none';
263 if (typeof document.createInviteeForm.first_name != 'undefined' && typeof document.schedulerwidget.search_first_name != 'undefined')
264 document.createInviteeForm.first_name.value = document.schedulerwidget.search_first_name.value;
265 if (typeof document.createInviteeForm.last_name != 'undefined' && typeof document.schedulerwidget.search_last_name != 'undefined')
266 document.createInviteeForm.last_name.value = document.schedulerwidget.search_last_name.value;
267 if (typeof document.createInviteeForm.email1 != 'undefined' && typeof document.schedulerwidget.search_email != 'undefined')
268 document.createInviteeForm.email1.value = document.schedulerwidget.search_email.value;
272 SugarWidgetSchedulerSearch.hideCreateForm = function(module){
273 document.getElementById('create-invitee-edit').style.display = 'none';
274 document.getElementById('create-invitees-buttons').style.display = '';
276 document.forms['createInviteeForm'].reset();
279 SugarWidgetSchedulerSearch.createInvitee = function(form){
280 if(!(check_form('createInviteeForm'))){
284 document.getElementById('create-invitee-btn').setAttribute('disabled', 'disabled');
285 document.getElementById('cancel-create-invitee-btn').setAttribute('disabled', 'disabled');
287 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
290 success: function (response) {
292 var rObj = eval("("+response.responseText+")");
294 ajaxStatus.hideStatus();
296 if (typeof rObj.noAccess != 'undefined') {
297 var alertMsg = GLOBAL_REGISTRY['meeting_strings']['LBL_NO_ACCESS'];
298 alertMsg = alertMsg.replace("\$module", rObj.module);
299 SugarWidgetSchedulerSearch.hideCreateForm();
304 GLOBAL_REGISTRY.focus.users_arr[GLOBAL_REGISTRY.focus.users_arr.length] = rObj;
305 GLOBAL_REGISTRY.scheduler_attendees_obj.display();
306 SugarWidgetSchedulerSearch.hideCreateForm();
308 document.getElementById('create-invitee-btn').removeAttribute('disabled');
309 document.getElementById('cancel-create-invitee-btn').removeAttribute('disabled');
313 var fieldList = ['id', 'full_name', 'email1', 'phone_work'];
316 for (i in fieldList) {
317 t.push("fieldList[]=" + encodeURIComponent(fieldList[i]));
319 var postData = t.join("&");
321 var url = "index.php?module=Calendar&action=CreateInvitee&sugar_body_only=true";
322 YAHOO.util.Connect.setForm(document.forms['createInviteeForm']);
323 YAHOO.util.Connect.asyncRequest('POST', url, callback, postData);
327 //////////////////////////////////////////////////
328 // class: SugarWidgetScheduler
329 // widget to display the meeting scheduler
331 //////////////////////////////////////////////////
333 SugarClass.inherit("SugarWidgetScheduler","SugarClass");
335 function SugarWidgetScheduler() {
339 SugarWidgetScheduler.prototype.init = function() {
340 //var row = new SugarWidgetScheduleAttendees();
344 SugarWidgetScheduler.prototype.load = function(parentNode) {
345 this.parentNode = parentNode;
349 SugarWidgetScheduler.fill_invitees = function(form) {
350 for(var i=0;i<GLOBAL_REGISTRY.focus.users_arr.length;i++) {
351 if(GLOBAL_REGISTRY.focus.users_arr[i].module == 'User') {
352 form.user_invitees.value += GLOBAL_REGISTRY.focus.users_arr[i].fields.id + ",";
353 } else if(GLOBAL_REGISTRY.focus.users_arr[i].module == 'Contact') {
354 form.contact_invitees.value += GLOBAL_REGISTRY.focus.users_arr[i].fields.id + ",";
355 } else if(GLOBAL_REGISTRY.focus.users_arr[i].module == 'Lead') {
356 form.lead_invitees.value += GLOBAL_REGISTRY.focus.users_arr[i].fields.id + ",";
361 SugarWidgetScheduler.update_time = function() {
364 if(typeof document.EditView != 'undefined')
365 form_name = "EditView";
366 else if(typeof document.CalendarEditView != 'undefined')
367 form_name = "CalendarEditView";
371 //check for field value, we can't do anything if it doesnt exist.
372 if(typeof document.forms[form_name].date_start == 'undefined')
375 var date_start = document.forms[form_name].date_start.value;
376 if(date_start.length < 16) {
379 var hour_start = parseInt(date_start.substring(11,13), 10);
380 var minute_start = parseInt(date_start.substring(14,16), 10);
381 var has_meridiem = /am|pm/i.test(date_start);
383 var meridiem = trim(date_start.substring(16));
386 GLOBAL_REGISTRY.focus.fields.date_start = date_start;
389 GLOBAL_REGISTRY.focus.fields.time_start = hour_start + time_separator + minute_start + meridiem;
391 GLOBAL_REGISTRY.focus.fields.time_start = hour_start + time_separator + minute_start;
394 GLOBAL_REGISTRY.focus.fields.duration_hours = document.forms[form_name].duration_hours.value;
395 GLOBAL_REGISTRY.focus.fields.duration_minutes = document.forms[form_name].duration_minutes.value;
396 GLOBAL_REGISTRY.focus.fields.datetime_start = SugarDateTime.mysql2jsDateTime(GLOBAL_REGISTRY.focus.fields.date_start,GLOBAL_REGISTRY.focus.fields.time_start);
398 GLOBAL_REGISTRY.scheduler_attendees_obj.init();
399 GLOBAL_REGISTRY.scheduler_attendees_obj.display();
402 SugarWidgetScheduler.prototype.display = function() {
403 this.parentNode.innerHTML = '';
405 var attendees = new SugarWidgetSchedulerAttendees();
406 attendees.load(this.parentNode);
408 var search = new SugarWidgetSchedulerSearch();
409 search.load(this.parentNode);
413 //////////////////////////////////////////////////
414 // class: SugarWidgetSchedulerAttendees
415 // widget to display the meeting attendees and availability
417 //////////////////////////////////////////////////
419 SugarClass.inherit("SugarWidgetSchedulerAttendees","SugarClass");
421 function SugarWidgetSchedulerAttendees() {
425 SugarWidgetSchedulerAttendees.prototype.init = function() {
428 if(typeof document.EditView != 'undefined')
429 form_name = "EditView";
430 else if(typeof document.CalendarEditView != 'undefined')
431 form_name = "CalendarEditView";
435 // this.datetime = new SugarDateTime();
436 GLOBAL_REGISTRY.scheduler_attendees_obj = this;
437 var date_start = document.forms[form_name].date_start.value;
438 var hour_start = parseInt(date_start.substring(11,13), 10);
439 var minute_start = parseInt(date_start.substring(14,16), 10);
440 var has_meridiem = /am|pm/i.test(date_start);
442 var meridiem = trim(date_start.substring(16));
446 GLOBAL_REGISTRY.focus.fields.time_start = hour_start + time_separator + minute_start + meridiem;
448 GLOBAL_REGISTRY.focus.fields.time_start = hour_start+time_separator+minute_start;
449 //GLOBAL_REGISTRY.focus.fields.time_start = document.forms[form_name].time_hour_start.value+time_separator+minute_start;
452 GLOBAL_REGISTRY.focus.fields.date_start = document.forms[form_name].date_start.value;
453 GLOBAL_REGISTRY.focus.fields.duration_hours = document.forms[form_name].duration_hours.value;
454 GLOBAL_REGISTRY.focus.fields.duration_minutes = document.forms[form_name].duration_minutes.value;
455 GLOBAL_REGISTRY.focus.fields.datetime_start = SugarDateTime.mysql2jsDateTime(GLOBAL_REGISTRY.focus.fields.date_start,GLOBAL_REGISTRY.focus.fields.time_start);
457 this.timeslots = new Array();
460 this.start_hours_before = 4;
462 var minute_interval = 15;
463 var dtstart = GLOBAL_REGISTRY.focus.fields.datetime_start;
465 // initialize first date in timeslots
466 var curdate = new Date(dtstart.getFullYear(),dtstart.getMonth(),dtstart.getDate(),dtstart.getHours()-this.start_hours_before,0);
468 if(typeof(GLOBAL_REGISTRY.focus.fields.duration_minutes) == 'undefined') {
469 GLOBAL_REGISTRY.focus.fields.duration_minutes = 0;
471 GLOBAL_REGISTRY.focus.fields.datetime_end = new Date(dtstart.getFullYear(),dtstart.getMonth(),dtstart.getDate(),dtstart.getHours()+parseInt(GLOBAL_REGISTRY.focus.fields.duration_hours),dtstart.getMinutes()+parseInt(GLOBAL_REGISTRY.focus.fields.duration_minutes),0);
473 var has_start = false;
476 for(i=0;i < this.hours*this.segments; i++) {
477 var hash = SugarDateTime.getUTCHash(curdate);
478 var obj = {"hash":hash,"date_obj":curdate};
479 if(has_start == false && GLOBAL_REGISTRY.focus.fields.datetime_start.getTime() <= curdate.getTime()) {
483 if(has_end == false && GLOBAL_REGISTRY.focus.fields.datetime_end.getTime() <= curdate.getTime()) {
487 this.timeslots.push(obj);
489 curdate = new Date(curdate.getFullYear(),curdate.getMonth(),curdate.getDate(),curdate.getHours(),curdate.getMinutes()+minute_interval);
493 SugarWidgetSchedulerAttendees.prototype.load = function (parentNode) {
494 this.parentNode = parentNode;
498 SugarWidgetSchedulerAttendees.prototype.display = function() {
501 if(typeof document.EditView != 'undefined')
502 form_name = "EditView";
503 else if(typeof document.CalendarEditView != 'undefined')
504 form_name = "CalendarEditView";
508 var dtstart = GLOBAL_REGISTRY.focus.fields.datetime_start;
509 var top_date = SugarDateTime.getFormattedDate(dtstart);
510 var html = '<h3>'+GLOBAL_REGISTRY['meeting_strings']['LBL_SCHEDULING_FORM_TITLE']+'</h3><table id ="schedulerTable">';
511 html += '<tr class="schedulerTopRow">';
512 html += '<th colspan="'+((this.hours*this.segments)+2)+'"><h4>'+ top_date +'</h4></th>';
514 html += '<tr class="schedulerTimeRow">';
515 html += '<td> </td>';
517 for(var i=0;i < (this.timeslots.length/this.segments); i++) {
518 var hours = this.timeslots[i*this.segments].date_obj.getHours();
521 if(time_reg_format.indexOf('A') >= 0 || time_reg_format.indexOf('a') >= 0) {
535 if(time_reg_format.indexOf('a') >= 0) {
536 am_pm = am_pm.toLowerCase();
538 if(hours != 0 && hours != 12 && i != 0) {
544 var form_hours = hours+time_separator+"00";
545 html += '<th scope="col" colspan="'+this.segments+'">'+form_hours+am_pm+'</th>';
548 html += '<td> </td>';
551 if ( this.parentNode.childNodes.length < 1 )
552 this.parentNode.innerHTML += '<div class="schedulerDiv">' + html + '</div>';
554 this.parentNode.childNodes[0].innerHTML = html;
556 var thetable = "schedulerTable";
558 if(typeof (GLOBAL_REGISTRY) == 'undefined') {
562 //set the current user (as event-coordinator) so that they can be added to invitee list
563 //only IF the first removed flag has not been set AND this is a new record
564 if((typeof (GLOBAL_REGISTRY.focus.users_arr) == 'undefined' || GLOBAL_REGISTRY.focus.users_arr.length == 0)
565 && document.forms[form_name].record.value =='' && typeof(GLOBAL_REGISTRY.FIRST_REMOVE)=='undefined') {
566 GLOBAL_REGISTRY.focus.users_arr = [ GLOBAL_REGISTRY.current_user ];
569 if(typeof GLOBAL_REGISTRY.focus.users_arr_hash == 'undefined') {
570 GLOBAL_REGISTRY.focus.users_arr_hash = new Object();
573 // append attendee rows
574 for(var i=0;i < GLOBAL_REGISTRY.focus.users_arr.length;i++) {
575 var row = new SugarWidgetScheduleRow(this.timeslots);
576 row.focus_bean = GLOBAL_REGISTRY.focus.users_arr[i];
577 GLOBAL_REGISTRY.focus.users_arr_hash[ GLOBAL_REGISTRY.focus.users_arr[i]['fields']['id']] = GLOBAL_REGISTRY.focus.users_arr[i];
582 SugarWidgetSchedulerAttendees.form_add_attendee = function (list_row) {
583 if(typeof (GLOBAL_REGISTRY.result_list[list_row]) != 'undefined' && typeof(GLOBAL_REGISTRY.focus.users_arr_hash[ GLOBAL_REGISTRY.result_list[list_row].fields.id]) == 'undefined') {
584 GLOBAL_REGISTRY.focus.users_arr[ GLOBAL_REGISTRY.focus.users_arr.length ] = GLOBAL_REGISTRY.result_list[list_row];
586 GLOBAL_REGISTRY.scheduler_attendees_obj.display();
590 //////////////////////////////////////////////////
591 // class: SugarWidgetScheduleRow
592 // widget to display each row in the scheduler
594 //////////////////////////////////////////////////
595 SugarClass.inherit("SugarWidgetScheduleRow","SugarClass");
597 function SugarWidgetScheduleRow(timeslots) {
598 this.init(timeslots);
601 SugarWidgetScheduleRow.prototype.init = function(timeslots) {
602 this.timeslots = timeslots;
605 SugarWidgetScheduleRow.prototype.load = function (thetableid) {
606 this.thetableid = thetableid;
609 vcalClient = new SugarVCalClient();
610 if(typeof (GLOBAL_REGISTRY['freebusy_adjusted']) == 'undefined' || typeof (GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id]) == 'undefined') {
611 global_request_registry[req_count] = [this,'display'];
612 vcalClient.load(this.focus_bean.fields.id,req_count);
619 SugarWidgetScheduleRow.prototype.display = function() {
620 SUGAR.util.doWhen("document.getElementById('" + this.thetableid + "') != null", function(){
622 this.thetable = document.getElementById(this.thetableid);
624 if(typeof (this.element) != 'undefined') {
625 if (this.element.parentNode != null)
626 this.thetable.deleteRow(this.element.rowIndex);
628 tr = document.createElement('tr');
629 this.thetable.appendChild(tr);
631 tr = this.thetable.insertRow(this.thetable.rows.length);
633 tr.className = "schedulerAttendeeRow";
635 td = document.createElement('td');
637 //insertCell(tr.cells.length);
641 var img = '<img align="absmiddle" src="index.php?entryPoint=getImage&themeName='
642 + SUGAR.themes.theme_name+'&imageName='+this.focus_bean.module+'s.gif"/> ';
645 td.innerHTML = td.innerHTML;
647 if (this.focus_bean.fields.full_name)
648 td.innerHTML += ' ' + this.focus_bean.fields.full_name;
650 td.innerHTML += ' ' + this.focus_bean.fields.name;
652 // add freebusy tds here:
653 this.add_freebusy_nodes(tr);
656 var td = document.createElement('td');
658 //var td = tr.insertCell(tr.cells.length);
659 td.className = 'schedulerAttendeeDeleteCell';
661 //CCL - Remove check to disallow removal of assigned user or current user
662 //if ( GLOBAL_REGISTRY.focus.fields.assigned_user_id != this.focus_bean.fields.id && GLOBAL_REGISTRY.current_user.fields.id != this.focus_bean.fields.id) {
663 td.innerHTML = '<a title="'+ GLOBAL_REGISTRY['meeting_strings']['LBL_REMOVE']
664 + '" class="listViewTdToolsS1" style="text-decoration:none;" '
665 + 'href="javascript:SugarWidgetScheduleRow.deleteRow(\''+this.focus_bean.fields.id+'\');"> '
666 + '<img src="index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=delete_inline.gif" '
667 + 'align="absmiddle" alt="'+ GLOBAL_REGISTRY['meeting_strings']['LBL_REMOVE'] +'" border="0"> '
668 + GLOBAL_REGISTRY['meeting_strings']['LBL_REMOVE'] +'</a>';
671 this.element_index = this.thetable.rows.length - 1;
675 SugarWidgetScheduleRow.deleteRow = function(bean_id) {
676 // can't delete organizer
678 if(GLOBAL_REGISTRY.focus.users_arr.length == 1 || GLOBAL_REGISTRY.focus.fields.assigned_user_id == bean_id) {
682 for(var i=0;i<GLOBAL_REGISTRY.focus.users_arr.length;i++) {
683 if(GLOBAL_REGISTRY.focus.users_arr[i]['fields']['id']==bean_id) {
684 delete GLOBAL_REGISTRY.focus.users_arr_hash[GLOBAL_REGISTRY.focus.users_arr[i]['fields']['id']];
685 GLOBAL_REGISTRY.focus.users_arr.splice(i,1);
686 //set first remove flag to true for processing in display() function
687 GLOBAL_REGISTRY.FIRST_REMOVE = true;
688 GLOBAL_REGISTRY.container.root_widget.display();
694 function DL_GetElementLeft(eElement) {
696 * ifargument is invalid
697 * (not specified, is null or is 0)
698 * and function is a method
699 * identify the element as the method owner
701 if(!eElement && this) {
706 * initialize var to store calculations
707 * identify first offset parent element
708 * move up through element hierarchy
709 * appending left offset of each parent
710 * until no more offset parents exist
712 var nLeftPos = eElement.offsetLeft;
713 var eParElement = eElement.offsetParent;
714 while (eParElement != null) {
715 nLeftPos += eParElement.offsetLeft;
716 eParElement = eParElement.offsetParent;
718 return nLeftPos; // return the number calculated
722 function DL_GetElementTop(eElement) {
723 if(!eElement && this) {
727 var nTopPos = eElement.offsetTop;
728 var eParElement = eElement.offsetParent;
729 while (eParElement != null) {
730 nTopPos += eParElement.offsetTop;
731 eParElement = eParElement.offsetParent;
737 //////////////////////////////////////////
738 // adds the <td>s for freebusy display within a row
739 SugarWidgetScheduleRow.prototype.add_freebusy_nodes = function(tr,attendee) {
743 var is_loaded = false;
745 if(typeof GLOBAL_REGISTRY['freebusy_adjusted'] != 'undefined' && typeof GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id] != 'undefined') {
749 for(var i=0;i < this.timeslots.length; i++) {
750 var td = document.createElement('td');
752 //var td = tr.insertCell(tr.cells.length);
753 td.innerHTML = ' ';
754 if(typeof(this.timeslots[i]['is_start']) != 'undefined') {
755 td.className = 'schedulerSlotCellStartTime';
757 if(typeof(this.timeslots[i]['is_end']) != 'undefined') {
758 td.className = 'schedulerSlotCellEndTime';
762 // iftheres a freebusy stack in this slice
763 if( typeof(GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id][this.timeslots[i].hash]) != 'undefined') {
764 td.style.backgroundColor="#4D5EAA";
767 if(typeof(GLOBAL_REGISTRY.focus.orig_users_arr_hash) != 'undefined' && typeof(GLOBAL_REGISTRY.focus.orig_users_arr_hash[this.focus_bean.fields.id]) != 'undefined') {
771 if( GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id][this.timeslots[i].hash] >= fb_limit) {
772 td.style.backgroundColor="#AA4D4D";