]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Meetings/jsclass_scheduler.js
Release 6.2.0
[Github/sugarcrm.git] / jssource / src_files / modules / Meetings / jsclass_scheduler.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
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.
11  * 
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
15  * details.
16  * 
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
20  * 02110-1301 USA.
21  * 
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.
24  * 
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.
28  * 
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  ********************************************************************************/
35
36
37
38 //////////////////////////////////////////////////
39 // class: SugarWidgetListView
40 // widget to display a list view
41 //
42 //////////////////////////////////////////////////
43
44 SugarClass.inherit("SugarWidgetListView","SugarClass");
45
46 function SugarWidgetListView() {
47         this.init();
48 }
49
50 SugarWidgetListView.prototype.init = function() {
51
52 }
53
54 SugarWidgetListView.prototype.load = function(parentNode) {
55         this.parentNode = parentNode;
56         this.display();
57 }
58
59 SugarWidgetListView.prototype.display = function() {
60         if(typeof GLOBAL_REGISTRY['result_list'] == 'undefined') {
61                 this.display_loading();
62                 return;
63         }
64
65         var div = document.getElementById('list_div_win');
66         div.style.display = 'block';
67         //div.style.height='125px';
68         var html = '<table width="100%" cellpadding="0" cellspacing="0" border="0" class="list view">';
69         html += '<tr>';
70         html += '<th width="2%" nowrap="nowrap">&nbsp;</th>';
71         html += '<th width="20%" nowrap="nowrap">'+GLOBAL_REGISTRY['meeting_strings']['LBL_NAME']+'</th>';
72         html += '<th width="20%" nowrap="nowrap">'+GLOBAL_REGISTRY['meeting_strings']['LBL_EMAIL']+'</th>';
73         html += '<th width="20%" nowrap="nowrap">'+GLOBAL_REGISTRY['meeting_strings']['LBL_PHONE']+'</th>';
74         html += '<th width="18%" nowrap="nowrap">&nbsp;</th>';
75         html += '</tr>';
76         //var html = '<table width="100%" cellpadding="0" cellspacing="0">';
77         for(var i=0;i<GLOBAL_REGISTRY['result_list'].length;i++) {
78                 var bean = GLOBAL_REGISTRY['result_list'][i];
79                 var disabled = false;
80                 var className='evenListRowS1';
81
82                 if(typeof(GLOBAL_REGISTRY.focus.users_arr_hash[ bean.fields.id]) != 'undefined') {
83                         disabled = true;
84                 }
85                 if((i%2) == 0) {
86                         className='oddListRowS1';
87                 } else {
88                         className='evenListRowS1';
89                 }
90                 if(typeof (bean.fields.first_name) == 'undefined') {
91                         bean.fields.first_name = '';
92                 }
93                 if(typeof (bean.fields.email1) == 'undefined' || bean.fields.email1 == "") {
94                         bean.fields.email1 = '&nbsp;';
95                 }
96                 if(typeof (bean.fields.phone_work) == 'undefined' || bean.fields.phone_work == "") {
97                         bean.fields.phone_work = '&nbsp;';
98                 }
99
100                 html += '<tr class="'+className+'">';
101                 html += '<td><img src="'+GLOBAL_REGISTRY.config['site_url']+'/index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName='+bean.module+'s.gif"/></td>';
102                 html += '<td>'+bean.fields.full_name+'</td>';
103                 html += '<td>'+bean.fields.email1+'</td>';
104                 html += '<td>'+bean.fields.phone_work+'</td>';
105                 html += '<td align="right">';
106                 //      hidden = 'hidden';
107                 hidden = 'visible';
108                 if(!disabled) {
109                         //      hidden = 'visible';
110                 }
111                 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+'"/>';
112                 html += '</td>';
113
114                 html += '</tr>';
115         }
116         html += '</table>';
117         this.parentNode.innerHTML = html;
118 }
119
120 SugarWidgetListView.prototype.display_loading = function() {
121
122 }
123
124 //////////////////////////////////////////////////
125 // class: SugarWidgetSchedulerSearch
126 // widget to display the meeting scheduler search box
127 //
128 //////////////////////////////////////////////////
129
130 SugarClass.inherit("SugarWidgetSchedulerSearch","SugarClass");
131
132 function SugarWidgetSchedulerSearch() {
133         this.init();
134 }
135
136 SugarWidgetSchedulerSearch.prototype.init = function() {
137         this.form_id = 'scheduler_search';
138         GLOBAL_REGISTRY['widget_element_map'] = new Object();
139         GLOBAL_REGISTRY['widget_element_map'][this.form_id] = this;
140 }
141
142 SugarWidgetSchedulerSearch.prototype.load = function(parentNode) {
143         this.parentNode = parentNode;
144         this.display();
145 }
146
147 SugarWidgetSchedulerSearch.submit = function(form) {
148         //construct query obj:
149         var conditions  = new Array();
150
151         if(form.search_first_name.value != '') {
152                 conditions[conditions.length] = {"name":"first_name","op":"starts_with","value":form.search_first_name.value}
153         }
154         if(form.search_last_name.value != '') {
155                 conditions[conditions.length] = {"name":"last_name","op":"starts_with","value":form.search_last_name.value}
156         }
157         if(form.search_email.value != '') {
158                 conditions[conditions.length] = {"name":"email1","op":"starts_with","value":form.search_email.value}
159         }
160
161         var query = {"modules":["Users","Contacts"
162         ,"Leads"
163         ],"group":"and","field_list":['id','full_name','email1','phone_work'],"conditions":conditions};
164         global_request_registry[req_count] = [this,'display'];
165         req_id = global_rpcClient.call_method('query',query);
166         global_request_registry[req_id] = [ GLOBAL_REGISTRY['widget_element_map'][form.id],'refresh_list'];
167 }
168
169 SugarWidgetSchedulerSearch.prototype.refresh_list = function(rslt) {
170         GLOBAL_REGISTRY['result_list'] = rslt['list'];
171         this.list_view.display();
172 }
173
174 SugarWidgetSchedulerSearch.prototype.display = function() {
175         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">';
176         html +='<tr><td>';                  
177         html += '<form name="schedulerwidget" id="'+this.form_id+'" onsubmit="SugarWidgetSchedulerSearch.submit(this);return false;">';
178
179         html += '<table width="100%" cellpadding="0" cellspacing="0" width="100%" >'
180         html += '<tr>';
181         //html += '<form id="'+this.form_id+'"><table width="100%"><tbody><tr>';
182         html += '<td scope="row" nowrap>'+GLOBAL_REGISTRY['meeting_strings']['LBL_FIRST_NAME']+':&nbsp;&nbsp;<input  name="search_first_name" value="" type="text" size="10"></td>';
183         html += '<td scope="row" nowrap>'+GLOBAL_REGISTRY['meeting_strings']['LBL_LAST_NAME']+':&nbsp;&nbsp;<input  name="search_last_name" value="" type="text" size="10"></td>';
184         html += '<td scope="row" nowrap>'+GLOBAL_REGISTRY['meeting_strings']['LBL_EMAIL']+':&nbsp;&nbsp;<input  name="search_email" type="text" value="" size="15"></td>';
185         //html += '<td valign="center"><input type="submit" onclick="SugarWidgetSchedulerSearch.submit(this.form);" value="Search" ></td></tr></tbody></table></form>';
186         html += '<td valign="center"><input type="submit" class="button" value="'+GLOBAL_REGISTRY['meeting_strings']['LBL_SEARCH_BUTTON']+'" ></td></tr>';
187         html += '</table>';
188         html += '</form>';
189         html += '</td></tr></table></div>';
190
191         // append the list_view as the third row of the outside table
192         this.parentNode.innerHTML += html;
193
194         var div = document.createElement('div');
195         div.setAttribute('id','list_div_win');
196         div.style.overflow = 'auto';
197         div.style.width = '100%';
198         div.style.height= '125px';
199         div.style.display = 'none';
200     this.parentNode.appendChild(div);
201         
202     this.list_view = new SugarWidgetListView();
203         this.list_view.load(div);
204 }
205
206 //////////////////////////////////////////////////
207 // class: SugarWidgetScheduler
208 // widget to display the meeting scheduler
209 //
210 //////////////////////////////////////////////////
211
212 SugarClass.inherit("SugarWidgetScheduler","SugarClass");
213
214 function SugarWidgetScheduler() {
215         this.init();
216 }
217
218 SugarWidgetScheduler.prototype.init = function() {
219         //var row = new SugarWidgetScheduleAttendees();
220         //row.load(this);
221 }
222
223 SugarWidgetScheduler.prototype.load = function(parentNode) {
224         this.parentNode = parentNode;
225         this.display();
226 }
227
228 SugarWidgetScheduler.fill_invitees = function(form) {
229         for(var i=0;i<GLOBAL_REGISTRY.focus.users_arr.length;i++) {
230                 if(GLOBAL_REGISTRY.focus.users_arr[i].module == 'User') {
231                         form.user_invitees.value += GLOBAL_REGISTRY.focus.users_arr[i].fields.id + ",";
232                 } else if(GLOBAL_REGISTRY.focus.users_arr[i].module == 'Contact') {
233                         form.contact_invitees.value += GLOBAL_REGISTRY.focus.users_arr[i].fields.id + ",";
234                 } else if(GLOBAL_REGISTRY.focus.users_arr[i].module == 'Lead') {
235                         form.lead_invitees.value += GLOBAL_REGISTRY.focus.users_arr[i].fields.id + ",";
236                 }
237         }
238 }
239
240 SugarWidgetScheduler.update_time = function() {
241
242     //For quick creates do nothing.
243     if( typeof(document.EditView) == 'undefined')
244         return;
245
246         var date_start = document.EditView.date_start.value;
247         if(date_start.length < 16) {
248                 return;
249         }       
250         var hour_start = parseInt(date_start.substring(11,13), 10);
251         var minute_start = parseInt(date_start.substring(14,16), 10);
252         var has_meridiem = /am|pm/i.test(date_start);
253         if(has_meridiem) {
254         var meridiem = trim(date_start.substring(16));
255         }
256
257         GLOBAL_REGISTRY.focus.fields.date_start = date_start;
258
259         if(has_meridiem) {
260                 GLOBAL_REGISTRY.focus.fields.time_start = hour_start + time_separator + minute_start + meridiem;
261         } else {
262                 GLOBAL_REGISTRY.focus.fields.time_start = hour_start + time_separator + minute_start;
263         }
264
265         GLOBAL_REGISTRY.focus.fields.duration_hours = document.EditView.duration_hours.value;
266         GLOBAL_REGISTRY.focus.fields.duration_minutes = document.EditView.duration_minutes.value;
267         GLOBAL_REGISTRY.focus.fields.datetime_start = SugarDateTime.mysql2jsDateTime(GLOBAL_REGISTRY.focus.fields.date_start,GLOBAL_REGISTRY.focus.fields.time_start);
268
269         GLOBAL_REGISTRY.scheduler_attendees_obj.init();
270         GLOBAL_REGISTRY.scheduler_attendees_obj.display();
271 }
272
273 SugarWidgetScheduler.prototype.display = function() {
274     this.parentNode.innerHTML = '';
275     
276         var attendees = new SugarWidgetSchedulerAttendees();
277         attendees.load(this.parentNode);
278
279         var search = new SugarWidgetSchedulerSearch();
280         search.load(this.parentNode);
281 }
282
283
284 //////////////////////////////////////////////////
285 // class: SugarWidgetSchedulerAttendees
286 // widget to display the meeting attendees and availability
287 //
288 //////////////////////////////////////////////////
289
290 SugarClass.inherit("SugarWidgetSchedulerAttendees","SugarClass");
291
292 function SugarWidgetSchedulerAttendees() {
293         this.init();
294 }
295
296 SugarWidgetSchedulerAttendees.prototype.init = function() {
297         // this.datetime = new SugarDateTime();
298         GLOBAL_REGISTRY.scheduler_attendees_obj = this;
299         var date_start = document.EditView.date_start.value;
300         var hour_start = parseInt(date_start.substring(11,13), 10);
301         var minute_start = parseInt(date_start.substring(14,16), 10);
302         var has_meridiem = /am|pm/i.test(date_start);
303         if(has_meridiem) {
304         var meridiem = trim(date_start.substring(16));
305         }
306
307         if(has_meridiem) {
308                 GLOBAL_REGISTRY.focus.fields.time_start = hour_start + time_separator + minute_start + meridiem;
309         } else {
310                 GLOBAL_REGISTRY.focus.fields.time_start = hour_start+time_separator+minute_start;
311                 //GLOBAL_REGISTRY.focus.fields.time_start = document.EditView.time_hour_start.value+time_separator+minute_start;
312         }
313
314         GLOBAL_REGISTRY.focus.fields.date_start = document.EditView.date_start.value;
315         GLOBAL_REGISTRY.focus.fields.duration_hours = document.EditView.duration_hours.value;
316         GLOBAL_REGISTRY.focus.fields.duration_minutes = document.EditView.duration_minutes.value;
317         GLOBAL_REGISTRY.focus.fields.datetime_start = SugarDateTime.mysql2jsDateTime(GLOBAL_REGISTRY.focus.fields.date_start,GLOBAL_REGISTRY.focus.fields.time_start);
318
319         this.timeslots = new Array();
320         this.hours = 9;
321         this.segments = 4;
322         this.start_hours_before = 4;
323
324         var minute_interval = 15;
325         var dtstart = GLOBAL_REGISTRY.focus.fields.datetime_start;
326
327         // initialize first date in timeslots
328         var curdate = new Date(dtstart.getFullYear(),dtstart.getMonth(),dtstart.getDate(),dtstart.getHours()-this.start_hours_before,0);
329
330         if(typeof(GLOBAL_REGISTRY.focus.fields.duration_minutes) == 'undefined') {
331                 GLOBAL_REGISTRY.focus.fields.duration_minutes = 0;
332         }
333         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);
334
335         var has_start = false;
336         var has_end = false;
337
338         for(i=0;i < this.hours*this.segments; i++) {
339                 var hash = SugarDateTime.getUTCHash(curdate);
340                 var obj = {"hash":hash,"date_obj":curdate};
341                 if(has_start == false && GLOBAL_REGISTRY.focus.fields.datetime_start.getTime() <= curdate.getTime()) {
342                         obj.is_start = true;
343                         has_start = true;
344                 }
345                 if(has_end == false && GLOBAL_REGISTRY.focus.fields.datetime_end.getTime() <= curdate.getTime()) {
346                         obj.is_end = true;
347                         has_end = true;
348                 }
349                 this.timeslots.push(obj);
350
351                 curdate = new Date(curdate.getFullYear(),curdate.getMonth(),curdate.getDate(),curdate.getHours(),curdate.getMinutes()+minute_interval);
352         }
353 }
354
355 SugarWidgetSchedulerAttendees.prototype.load = function (parentNode) {
356         this.parentNode = parentNode;
357         this.display();
358 }
359
360 SugarWidgetSchedulerAttendees.prototype.display = function() {
361         var dtstart = GLOBAL_REGISTRY.focus.fields.datetime_start;
362         var top_date = SugarDateTime.getFormattedDate(dtstart);
363         var html = '<h3>'+GLOBAL_REGISTRY['meeting_strings']['LBL_SCHEDULING_FORM_TITLE']+'</h3><table id ="schedulerTable">';
364         html += '<tr class="schedulerTopRow">';
365         html += '<th colspan="'+((this.hours*this.segments)+2)+'"><h4>'+ top_date +'</h4></th>';
366         html += '</tr>';
367         html += '<tr class="schedulerTimeRow">';
368         html += '<td>&nbsp;</td>';
369
370         for(var i=0;i < (this.timeslots.length/this.segments); i++) {
371                 var hours = this.timeslots[i*this.segments].date_obj.getHours();
372                 var am_pm = '';
373
374                 if(time_reg_format.indexOf('A') >= 0 || time_reg_format.indexOf('a') >= 0) {
375                         am_pm = "AM";
376
377                         if(hours > 12) {
378                                 am_pm = "PM";
379                                 hours -= 12;
380                         }
381                         if(hours == 12) {
382                                 am_pm = "PM";
383                         }
384                         if(hours == 0) {
385                                 hours = 12;
386                                 am_pm = "AM";
387                         }
388                         if(time_reg_format.indexOf('a') >= 0) {
389                                 am_pm = am_pm.toLowerCase();
390                         }
391                         if(hours != 0 && hours != 12 && i != 0) {
392                                 am_pm = "";
393                         }
394
395                 }
396
397                 var form_hours = hours+time_separator+"00";
398                 html += '<td scope="col" colspan="'+this.segments+'">'+form_hours+am_pm+'</td>';
399         }
400
401         html += '<td>&nbsp;</td>';
402         html += '</tr>';
403         html += '</table>';
404     if ( this.parentNode.childNodes.length < 1 )
405         this.parentNode.innerHTML += '<div class="schedulerDiv">' + html + '</div>';
406     else
407         this.parentNode.childNodes[0].innerHTML = html;
408         
409         var thetable = "schedulerTable";
410
411         if(typeof (GLOBAL_REGISTRY) == 'undefined') {
412                 return;
413         }
414
415         //set the current user (as event-coordinator) so that they can be added to invitee list 
416         //only IF the first removed flag has not been set AND this is a new record
417         if((typeof (GLOBAL_REGISTRY.focus.users_arr) == 'undefined' || GLOBAL_REGISTRY.focus.users_arr.length == 0)
418       && document.EditView.record.value =='' && typeof(GLOBAL_REGISTRY.FIRST_REMOVE)=='undefined') {
419                 GLOBAL_REGISTRY.focus.users_arr = [ GLOBAL_REGISTRY.current_user ];
420         }
421         
422         if(typeof GLOBAL_REGISTRY.focus.users_arr_hash == 'undefined') {
423                 GLOBAL_REGISTRY.focus.users_arr_hash = new Object();
424         }
425
426         // append attendee rows
427         for(var i=0;i < GLOBAL_REGISTRY.focus.users_arr.length;i++) {
428                 var row = new SugarWidgetScheduleRow(this.timeslots);
429                 row.focus_bean = GLOBAL_REGISTRY.focus.users_arr[i];
430                 GLOBAL_REGISTRY.focus.users_arr_hash[ GLOBAL_REGISTRY.focus.users_arr[i]['fields']['id']] =     GLOBAL_REGISTRY.focus.users_arr[i];
431                 row.load(thetable);
432         }
433 }
434
435 SugarWidgetSchedulerAttendees.form_add_attendee = function (list_row) {
436         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') {
437                 GLOBAL_REGISTRY.focus.users_arr[ GLOBAL_REGISTRY.focus.users_arr.length ] = GLOBAL_REGISTRY.result_list[list_row];
438         }
439         GLOBAL_REGISTRY.scheduler_attendees_obj.display();
440 }
441
442
443 //////////////////////////////////////////////////
444 // class: SugarWidgetScheduleRow
445 // widget to display each row in the scheduler
446 //
447 //////////////////////////////////////////////////
448 SugarClass.inherit("SugarWidgetScheduleRow","SugarClass");
449
450 function SugarWidgetScheduleRow(timeslots) {
451         this.init(timeslots);
452 }
453
454 SugarWidgetScheduleRow.prototype.init = function(timeslots) {
455         this.timeslots = timeslots;
456 }
457
458 SugarWidgetScheduleRow.prototype.load = function (thetableid) {
459         this.thetableid = thetableid;
460         var self = this;
461
462         vcalClient = new SugarVCalClient();
463         if(typeof (GLOBAL_REGISTRY['freebusy_adjusted']) == 'undefined' ||      typeof (GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id]) == 'undefined') {
464                 global_request_registry[req_count] = [this,'display'];
465                 vcalClient.load(this.focus_bean.fields.id,req_count);
466                 req_count++;
467         } else {
468                 this.display();
469         }
470 }
471
472 SugarWidgetScheduleRow.prototype.display = function() {
473         var self = this;
474         var tr;
475         this.thetable = document.getElementById(this.thetableid);
476         
477         if(typeof (this.element) != 'undefined') {
478             if (this.element.parentNode != null)
479                         this.thetable.deleteRow(this.element.rowIndex);
480
481                 tr = document.createElement('tr'); 
482                 this.thetable.appendChild(tr);
483         } else {
484                 tr = this.thetable.insertRow(this.thetable.rows.length);
485         }
486         tr.className = "schedulerAttendeeRow";
487
488         td = document.createElement('td');
489         tr.appendChild(td);
490         //insertCell(tr.cells.length);
491
492         // icon + full name
493         td.scope = 'row';
494         var img = '<img align="absmiddle" src="index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName='+self.focus_bean.module+'s.gif"/>&nbsp;';
495         td.innerHTML = img;
496
497         td.innerHTML = td.innerHTML;
498
499         if (self.focus_bean.fields.full_name)
500                 td.innerHTML += ' ' + self.focus_bean.fields.full_name;
501         else
502                 td.innerHTML += ' ' + self.focus_bean.fields.name;
503
504         // add freebusy tds here:
505         this.add_freebusy_nodes(tr);
506
507         // delete button
508         var td = document.createElement('td');
509         tr.appendChild(td);
510         //var td = tr.insertCell(tr.cells.length);
511         td.className = 'schedulerAttendeeDeleteCell';
512         td.noWrap = true;
513         //CCL - Remove check to disallow removal of assigned user or current user
514         //if ( GLOBAL_REGISTRY.focus.fields.assigned_user_id != self.focus_bean.fields.id && GLOBAL_REGISTRY.current_user.fields.id != self.focus_bean.fields.id) {
515        td.innerHTML = '<a title="'+ GLOBAL_REGISTRY['meeting_strings']['LBL_REMOVE'] +'" class="listViewTdToolsS1" style="text-decoration:none;" href="javascript:SugarWidgetScheduleRow.deleteRow(\''+self.focus_bean.fields.id+'\');">&nbsp;<img src="index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=delete_inline.gif" align="absmiddle" alt="'+ GLOBAL_REGISTRY['meeting_strings']['LBL_REMOVE'] +'" border="0"> '+ GLOBAL_REGISTRY['meeting_strings']['LBL_REMOVE'] +'</a>';
516         //}
517         this.element = tr;
518         this.element_index = this.thetable.rows.length - 1;
519 }
520
521 SugarWidgetScheduleRow.deleteRow = function(bean_id) {
522         // can't delete organizer
523         /*
524         if(GLOBAL_REGISTRY.focus.users_arr.length == 1 || GLOBAL_REGISTRY.focus.fields.assigned_user_id == bean_id) {
525                 return;
526         }
527     */
528         for(var i=0;i<GLOBAL_REGISTRY.focus.users_arr.length;i++) {
529                 if(GLOBAL_REGISTRY.focus.users_arr[i]['fields']['id']==bean_id) {
530                         delete GLOBAL_REGISTRY.focus.users_arr_hash[GLOBAL_REGISTRY.focus.users_arr[i]['fields']['id']];
531                         GLOBAL_REGISTRY.focus.users_arr.splice(i,1);
532                 //set first remove flag to true for processing in display() function
533                         GLOBAL_REGISTRY.FIRST_REMOVE = true;
534                         GLOBAL_REGISTRY.container.root_widget.display();
535                 }
536         }
537 }
538
539
540 function DL_GetElementLeft(eElement) {
541         /*
542          * ifargument is invalid
543          * (not specified, is null or is 0)
544          * and function is a method
545          * identify the element as the method owner
546          */
547         if(!eElement && this) {
548                 eElement = this;
549         }
550
551         /*
552          * initialize var to store calculations
553          * identify first offset parent element
554          * move up through element hierarchy
555          * appending left offset of each parent
556          * until no more offset parents exist
557          */
558         var nLeftPos = eElement.offsetLeft;
559         var eParElement = eElement.offsetParent;
560         while (eParElement != null) {
561                 nLeftPos += eParElement.offsetLeft;
562                 eParElement = eParElement.offsetParent;
563         }
564         return nLeftPos; // return the number calculated
565 }
566
567
568 function DL_GetElementTop(eElement) {
569         if(!eElement && this) {
570                 eElement = this;
571         }
572
573         var nTopPos = eElement.offsetTop;
574         var eParElement = eElement.offsetParent;
575         while (eParElement != null) {
576                 nTopPos += eParElement.offsetTop;
577                 eParElement = eParElement.offsetParent;
578         }
579         return nTopPos;
580 }
581
582
583 //////////////////////////////////////////
584 // adds the <td>s for freebusy display within a row
585 SugarWidgetScheduleRow.prototype.add_freebusy_nodes = function(tr,attendee) {
586         var hours = 9;
587         var segments = 4;
588         var html = '';
589         var is_loaded = false;
590
591         if(typeof GLOBAL_REGISTRY['freebusy_adjusted'] != 'undefined' && typeof GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id] != 'undefined') {
592                 is_loaded = true;
593         }
594
595         for(var i=0;i < this.timeslots.length; i++) {
596                 var td = document.createElement('td');
597                 tr.appendChild(td);
598                 //var td = tr.insertCell(tr.cells.length);
599         td.innerHTML = '&nbsp;';
600                 if(typeof(this.timeslots[i]['is_start']) != 'undefined') {
601                         td.className = 'schedulerSlotCellStartTime';
602                 }
603                 if(typeof(this.timeslots[i]['is_end']) != 'undefined') {
604                         td.className = 'schedulerSlotCellEndTime';
605                 }
606
607                 if(is_loaded) {
608                         // iftheres a freebusy stack in this slice
609                         if(     typeof(GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id][this.timeslots[i].hash]) != 'undefined') {
610                                 td.style.backgroundColor="#4D5EAA";
611
612                                 if(td.className == 'schedulerSlotCellStartTime') {
613                                         fb_limit = 1;
614                                         if(typeof(GLOBAL_REGISTRY.focus.orig_users_arr_hash) != 'undefined' && typeof(GLOBAL_REGISTRY.focus.orig_users_arr_hash[this.focus_bean.fields.id]) != 'undefined') {
615                                                 fb_limit = 2;
616                                         }
617
618                                         if(     GLOBAL_REGISTRY['freebusy_adjusted'][this.focus_bean.fields.id][this.timeslots[i].hash] >= fb_limit) {
619                                                 td.style.backgroundColor="#AA4D4D";
620                                         } else {
621                                                 td.style.backgroundColor="#4D5EAA";
622                                         }
623                                 }
624                         }
625                 }
626         }
627 }