1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
40 CAL.records_openable = true;
41 CAL.moved_from_cell = "";
43 CAL.deleted_module = "";
45 CAL.disable_creating = false;
46 CAL.record_editable = false;
49 CAL.shared_users = {};
50 CAL.shared_users_count = 0;
51 CAL.script_evaled = false;
52 CAL.editDialog = false;
53 CAL.settingsDialog = false;
55 CAL.update_dd = new YAHOO.util.CustomEvent("update_dd");
57 CAL.dom = YAHOO.util.Dom;
58 CAL.get = YAHOO.util.Dom.get;
59 CAL.query = YAHOO.util.Selector.query;
61 CAL.arrange_slot = function (cell_id){
64 cellElm = document.getElementById(cell_id);
72 var child_cnt = cellElm.childNodes.length;
73 for(var i = 0; i < child_cnt; i++){
74 var width_p = (92 / child_cnt);
75 width = width_p.toString() + "%";
76 if(cellElm.childNodes[i].tagName == "DIV"){
77 cellElm.childNodes[i].style.top = "-1px";
78 cellElm.childNodes[i].style.left = "-"+(cnt+1)+"px";
79 cellElm.childNodes[i].style.width = width
87 // prevent item overlapping
88 CAL.arrange_column = function(column){
90 for(var i = 0; i < column.childNodes.length; i++){
91 for(var j = 0; j < column.childNodes[i].childNodes.length; j++){
92 var el = column.childNodes[i].childNodes[j];
93 if(YAHOO.util.Dom.hasClass(el,"empty")){
94 el.parentNode.removeChild(el);
100 var slots = column.childNodes;
103 var end = slots.length;
104 var slot_count = end;
107 var affected_slots = new Array();
108 var affected_items = Array();
109 var ol = new Array();
111 // fill ol array with groups of overlapping items to fit them bit later
112 find_overlapping(null,start,end,level,null);
114 // add transparent empty blocks to the left
115 for(var i = 0; i < ol.length; i++){
116 var ol_group = ol[i];
117 var depth = ol_group.depth;
118 for(var j = 0; j < ol_group.items.length; j++){
119 var el_id = ol_group.items[j]['id'];
120 var level = ol_group.items[j]['level'];
121 var el = CAL.get(el_id);
124 while(node.previousSibling){
126 node = node.previousSibling;
128 insert_empty_items(el,level - 1 - pos,false);
132 // add transparent empty blocks to the right
133 for(var i = 0; i < ol.length; i++){
134 var ol_group = ol[i];
135 var depth = ol_group.depth;
136 for(var j = 0; j < ol_group.items.length; j++){
137 var el_id = ol_group.items[j]['id'];
139 var el = CAL.get(el_id);
140 var cnt = el.parentNode.childNodes.length;
141 insert_empty_items(el,depth - cnt,true);
145 CAL.each(affected_slots,function(i,v){
146 CAL.arrange_slot(affected_slots[i]);
150 function find_overlapping(el,start,end,level,ol_group){
160 ol_group.items = new Array();
162 ol_group.items.push({
166 affected_items.push(el.id);
169 for(var i = start; i < end; i++){
173 if(typeof slots[i].childNodes != 'undefined' && typeof slots[i].childNodes[0] != 'undefined'){
177 var node = slots[i].childNodes[0];
178 while(node.nextSibling && contains(affected_items,node.id)){
179 node = node.nextSibling;
184 var current = slots[i].childNodes[pos];
185 var slots_takes = parseInt(current.getAttribute('duration_coef'));
187 if(contains(affected_items,current.id))
191 var slot_id = current.parentNode.id;
192 if(!contains(affected_slots,slot_id))
193 affected_slots.push(slot_id);
197 var k = find_overlapping(current, i, i + slots_takes, level + 1,ol_group);
205 ol_group.depth = depth;
212 function insert_empty_items(el,count,to_end){
213 var slot = el.parentNode;
214 for(var i = 0; i < count; i++){
215 var empty = document.createElement("div");
216 empty.className = "act_item empty";
217 empty.style.zIndex = "-1";
218 empty.style.width = "1px";
220 slot.appendChild(empty);
222 slot.insertBefore(empty,slot.firstChild);
227 function contains(a, obj){
236 CAL.arrange_advanced = function (){
237 var nodes = CAL.query("#cal-grid .day_col");
238 for(var i = 0; i < nodes.length; i++){
239 CAL.arrange_column(nodes[i]);
241 CAL.update_dd.fire();
244 CAL.add_item_to_grid = function (item){
249 if( item.user_id != "" && CAL.view == 'shared'){
250 suffix = "_" + CAL.shared_users[item.user_id];
251 id_suffix = '____' + CAL.shared_users[item.user_id];
254 var e = CAL.get(item.record + id_suffix);
256 e.parentNode.removeChild(e);
259 var duration_text = item.duration_hours + CAL.lbl_hours_abbrev;
260 if(item.duration_minutes > 0)
261 duration_text += item.duration_minutes + CAL.lbl_mins_abbrev;
262 var start_text = CAL.get_header_text(item.type,item.time_start,item.status,item.record);
264 var time_cell = item.timestamp - item.timestamp % (CAL.t_step * 60);
267 if(item.module_name == 'Tasks'){
271 if((item.duration_minutes < CAL.t_step) && (item.duration_hours == 0))
274 duration_coef = (parseInt(item.duration_hours) * 60 + parseInt(item.duration_minutes)) / CAL.t_step;
278 if(CAL.item_text && (typeof item[CAL.item_text] != "undefined") )
279 item_text = item[CAL.item_text];
281 var contain_style = "";
282 if(duration_coef < 1.75)
283 contain_style = "style='display: none;'";
285 var elm_id = item.record + id_suffix;
287 var el = document.createElement("div");
288 el.innerHTML = "<div class='head'><div class='adicon' onmouseover='return CAL.show_additional_details(" + '"' + item.record + id_suffix + '"' + ");' onmouseout='return nd(400);' > </div><div>" + start_text + "</div>" + "" + "</div><div class='contain' "+contain_style+">" + item_text + "</div>";
289 el.className = "act_item" + " " + item.type+"_item";
290 el.setAttribute("id",elm_id);
291 el.setAttribute("module_name",item.module_name);
292 el.setAttribute("record",item.record);
293 el.setAttribute("dur",duration_text);
294 el.setAttribute("subj",item.record_name);
295 el.setAttribute("date_start",item.date_start);
296 el.setAttribute("desc",item.description);
297 el.setAttribute("parent_name",item.parent_name);
298 el.setAttribute("parent_type",item.parent_type);
299 el.setAttribute("parent_id",item.parent_id);
300 el.setAttribute("status",item.status);
301 el.setAttribute("detail",item.detail);
302 el.setAttribute("edit",item.edit);
303 el.setAttribute("duration_coef",duration_coef);
304 el.style.backgroundColor = CAL.activity_colors[item.module_name]['body'];
305 el.style.borderColor = CAL.activity_colors[item.module_name]['border'];
306 el.style.height = parseInt(15 * duration_coef - 1) + "px";
307 if(item.module_name == "Tasks")
308 el.setAttribute("date_due",item.date_due);
310 YAHOO.util.Event.on(el,"click",function(){
311 if(this.getAttribute('detail') == "1")
312 CAL.load_form(this.getAttribute('module_name'),this.getAttribute('record'),false);
314 YAHOO.util.Event.on(el,"mouseover",function(){
315 if(!CAL.records_openable)
317 CAL.disable_creating = true;
321 if(e = CAL.get(elm_id))
327 YAHOO.util.Event.on(el,"mouseout",function(){
328 if(!CAL.records_openable)
330 clearTimeout(CAL.tp);
331 CAL.get(elm_id).style.zIndex = '';
332 CAL.disable_creating = false;
336 if(slot = CAL.get("t_" + time_cell + suffix)){
337 slot.appendChild(el);
339 CAL.cut_record(item.record + id_suffix);
341 if(duration_coef < 1.75 && CAL.mouseover_expand){
342 YAHOO.util.Event.on(elm_id,"mouseover",function(){
343 if(CAL.records_openable)
344 CAL.expand_record(this.getAttribute("id"));
346 YAHOO.util.Event.on(elm_id,"mouseout",function(){
347 CAL.unexpand_record(this.getAttribute("id"));
349 YAHOO.util.Event.on(elm_id,"click",function(){
350 CAL.unexpand_record(this.getAttribute("id"));
354 if(CAL.items_draggable && item.edit == 1){
356 var border = 'cal-grid';
357 if(CAL.view != "shared" && CAL.view != "month")
358 border = 'cal-scrollable';
360 var dd = new YAHOO.util.DDCAL(elm_id,"cal",{isTarget: false,cont: border});
362 dd.onInvalidDrop = function(e){
363 CAL.arrange_slot(this.el.parentNode.getAttribute("id"));
364 if(CAL.dropped == 0){
365 this.el.childNodes[0].innerHTML = CAL.old_caption;
367 CAL.records_openable = true;
368 CAL.disable_creating = false;
371 dd.onMouseDown = function(e){
372 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
373 YAHOO.util.DDM.clickPixelThresh = 20;
376 dd.onMouseUp = function(e){
377 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
378 YAHOO.util.DDM.clickPixelThresh = 3;
381 dd.startDrag = function(x,y){
382 this.el = document.getElementById(this.id);
383 this.el.style.zIndex = 5;
385 CAL.records_openable = false;
386 CAL.disable_creating = true;
387 CAL.old_caption = this.el.childNodes[0].innerHTML;
388 CAL.moved_from_cell = this.el.parentNode.id;
393 dd.endDrag = function(x,y){
394 this.el = document.getElementById(this.id);
395 this.el.style.zIndex = "";
397 var nodes = CAL.query("#cal-grid .slot");
398 CAL.each(nodes,function(i,v){
399 YAHOO.util.Dom.removeClass(nodes[i],"slot_active");
403 dd.onDragDrop = function(e,id){
405 var slot = document.getElementById(id);
406 YAHOO.util.Dom.removeClass(slot,"slot_active");
407 if(CAL.dropped) // prevent dropping on two slots in same time
411 this.el.style.position = "relative";
412 this.el.style.cssFloat = "none";
414 if(CAL.view != 'shared'){
415 var box_id = this.id;
417 var ex_slot_id = CAL.moved_from_cell;
418 CAL.move_activity(box_id,slot_id,ex_slot_id);
420 var record = this.el.getAttribute("record");
422 var tar = tid.split("_");
423 var timestamp = tar[1];
424 var tid = CAL.moved_from_cell;
425 var tar = tid.split("_");
426 var ex_timestamp = tar[1];
428 for(i = 0; i < CAL.shared_users_count; i++){
429 var box_id = ""+record+"____"+i;
430 var slot_id = "t_"+timestamp+"_"+i;
431 var ex_slot_id = "t_"+ex_timestamp+"_"+i;
432 CAL.move_activity(box_id,slot_id,ex_slot_id);
437 success: function(o){
439 res = eval("("+o.responseText+")");
441 alert(CAL.lbl_error_saving);
442 ajaxStatus.hideStatus();
445 CAL.records_openable = true;
446 CAL.disable_creating = false;
448 ajaxStatus.hideStatus();
451 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
452 var url = "index.php?module=Calendar&action=Reschedule&sugar_body_only=true";
454 "current_module" : this.el.getAttribute("module_name"),
455 "record" : this.el.getAttribute("record"),
456 "datetime" : slot.getAttribute("datetime")
458 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
460 YAHOO.util.Dom.removeClass(slot,"slot_active");
463 dd.onDragOver = function(e,id){
464 var slot = document.getElementById(id);
465 if(!YAHOO.util.Dom.hasClass(slot,"slot_active"))
466 YAHOO.util.Dom.addClass(slot,"slot_active");
467 this.el.childNodes[0].childNodes[1].childNodes[0].innerHTML = slot.getAttribute('time');
470 dd.onDragOut = function(e,id){
471 var slot = document.getElementById(id);
472 YAHOO.util.Dom.removeClass(slot,"slot_active");
476 CAL.arrange_slot("t_" + time_cell + suffix);
481 CAL.expand_record = function (id){
482 CAL.tp1 = setTimeout(
484 var el = CAL.get(id);
486 el.style.height = parseInt(15 * 2 - 1) + "px";
487 el.childNodes[1].style.display = "block";
494 CAL.unexpand_record = function (id){
495 clearTimeout(CAL.tp1);
496 var el = CAL.get(id);
497 el.style.height = parseInt(15 * CAL.get(id).getAttribute("duration_coef") - 2) + "px";
498 el.childNodes[1].style.display = "none"; //innerHTML = "";
502 CAL.get_header_text = function (type,time_start,status,record){
503 var start_text = "<span class='start_time'>" + time_start + "</span> " + SUGAR.language.languages.app_list_strings[type +'_status_dom'][status];
507 CAL.cut_record = function (id){
509 var el = CAL.get(id);
513 var duration_coef = el.getAttribute("duration_coef");
514 var real_celcount = CAL.celcount;
516 if(CAL.view == 'day' || CAL.view == 'week')
517 real_celcount = CAL.cells_per_day;
520 var s = el.parentNode;
521 while(s.previousSibling){
523 s = s.previousSibling;
526 if(CAL.view == 'week')
529 if(real_celcount - celpos - duration_coef < 0)
530 duration_coef = real_celcount - celpos + 1;
531 el.style.height = parseInt(15 * duration_coef - 1) + "px";
535 CAL.init_edit_dialog = function (params){
536 CAL.editDialog = false;
538 var rd = CAL.get("cal-edit");
539 var content = CAL.get("edit-dialog-content");
541 if(CAL.dashlet && rd){
542 document.getElementById("content").appendChild(rd);
545 rd.style.width = params.width+"px";
546 content.style.height = params.height+"px";
547 content.style.overflow = "auto";
548 content.style.padding = "0";
550 CAL.editDialog = new YAHOO.widget.Dialog("cal-edit",{
557 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
558 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
562 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){
563 CAL.close_edit_dialog();
566 rd.style.display = "block";
567 CAL.editDialog.render();
569 rd.style.overflow = "auto";
570 rd.style.overflowX = "hidden";
571 rd.style.outline = "0 none";
572 rd.style.height = "auto";
577 CAL.open_edit_dialog = function (params){
578 // Reset display parameter, if the delete button was hidden
579 CAL.get("btn-delete").style.display = "";
581 CAL.editDialog.center();
582 CAL.editDialog.show();
584 var nodes = CAL.query("#cal-tabs li a");
585 CAL.each(nodes,function(i,v){
586 YAHOO.util.Event.on(nodes[i], 'click', function(){
587 CAL.select_tab(this.getAttribute("tabname"));
591 var nodes_li = CAL.query("#cal-tabs li");
592 CAL.each(nodes_li,function(j,v){
593 CAL.dom.removeClass(nodes_li[j],"selected");
595 CAL.dom.addClass(nodes_li[j],"selected");
598 var nodes = CAL.query(".yui-nav");
599 CAL.each(nodes,function(i,v){
600 nodes[i].style.overflowX = "visible";
605 CAL.close_edit_dialog = function (){
606 CAL.reset_edit_dialog();
609 CAL.remove_edit_dialog = function(){
610 var rd_c = CAL.get("cal-edit_c");
612 rd_c.parentNode.removeChild(rd_c);
616 CAL.reset_edit_dialog = function (){
619 document.getElementById("form_content").innerHTML = "";
620 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
622 CAL.get("radio_call").removeAttribute("disabled");
623 CAL.get("radio_meeting").removeAttribute("disabled");
624 CAL.get("radio_call").checked = false;
625 CAL.get("radio_meeting").checked = true;
627 CAL.get("send_invites").value = "";
629 if(e = CAL.get("record"))
632 if(e = CAL.get("list_div_win"))
633 e.style.display = "none";
635 CAL.GR_update_focus("Meetings","");
636 CAL.select_tab("cal-tab-1");
638 QSFieldsArray = new Array();
639 QSProcessedFieldsArray = new Array();
642 CAL.select_tab = function (tid){
644 var nodes_li = CAL.query("#cal-tabs li");
645 CAL.each(nodes_li,function(j,v){
646 CAL.dom.removeClass(nodes_li[j],"selected");
649 CAL.dom.addClass(CAL.get(tid + "-link").parentNode,"selected");
652 var nodes = CAL.query("#cal-tabs .yui-content");
653 CAL.each(nodes,function(i,v){
654 nodes[i].style.display = "none";
656 var nodes = CAL.query("#cal-tabs #"+tid);
657 CAL.each(nodes,function(i,v){
658 nodes[i].style.display = "block";
662 CAL.GR_update_user = function (user_id){
665 success: function(o){
666 res = eval(o.responseText);
667 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;
668 //SugarWidgetScheduler.update_time();
675 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";
676 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
680 CAL.GR_update_focus = function (module,record){
682 GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
683 SugarWidgetScheduler.update_time();
686 success: function(o){
687 res = eval(o.responseText);
688 SugarWidgetScheduler.update_time();
689 if(CAL.record_editable){
690 CAL.get("btn-save").removeAttribute("disabled");
691 CAL.get("btn-delete").removeAttribute("disabled");
692 CAL.get("btn-apply").removeAttribute("disabled");
693 CAL.get("btn-send-invites").removeAttribute("disabled");
698 var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;
699 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
703 CAL.toggle_settings = function (){
704 var sd = CAL.get("settings_dialog");
707 if(!CAL.settingsDialog){
708 CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{
715 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
716 CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
718 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
719 CAL.get("form_settings").reset();
721 sd.style.display = "block";
722 CAL.settingsDialog.render();
723 CAL.settingsDialog.show();
726 CAL.toggle_whole_day = function (){
727 var wd = CAL.get("whole_day");
735 var nodes = CAL.query("#cal-grid .owt");
736 CAL.each(nodes,function(i,v){
737 nodes[i].style.display = "block";
740 var nodes = CAL.query("#cal-grid .owt");
741 CAL.each(nodes,function(i,v){
742 nodes[i].style.display = "none";
750 CAL.fill_invitees = function (){
752 CAL.get("user_invitees").value = "";
753 CAL.get("contact_invitees").value = "";
754 CAL.get("lead_invitees").value = "";
756 CAL.each( GLOBAL_REGISTRY['focus'].users_arr, function(i,v){
758 if(v.module == "User")
759 field_name = "user_invitees";
760 if(v.module == "Contact")
761 field_name = "contact_invitees";
762 if(v.module == "Lead")
763 field_name = "lead_invitees";
764 var str = CAL.get(field_name).value;
765 CAL.get(field_name).value = str + v.fields.id + ",";
771 CAL.load_form = function (module_name,record,run_one_time){
775 if(module_name == "Tasks")
778 if(to_open && CAL.records_openable){
779 CAL.get("form_content").style.display = "none";
781 CAL.get("btn-delete").setAttribute("disabled","disabled");
782 CAL.get("btn-apply").setAttribute("disabled","disabled");
783 CAL.get("btn-save").setAttribute("disabled","disabled");
784 CAL.get("btn-send-invites").setAttribute("disabled","disabled");
786 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
788 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
790 CAL.open_edit_dialog();
791 CAL.get("record").value = "";
796 success: function(o){
798 res = eval("("+o.responseText+")");
800 alert(CAL.lbl_error_loading);
801 CAL.editDialog.cancel();
802 ajaxStatus.hideStatus();
805 if(res.success == 'yes'){
806 var fc = document.getElementById("form_content");
807 CAL.script_evaled = false;
808 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
809 if(!CAL.script_evaled){
810 SUGAR.util.evalScript(res.html);
813 CAL.get("record").value = res.record;
814 CAL.get("current_module").value = res.module_name;
816 var mod_name = res.module_name;
818 if(mod_name == "Meetings")
819 CAL.get("radio_meeting").checked = true;
820 if(mod_name == "Calls")
821 CAL.get("radio_call").checked = true;
824 CAL.record_editable = true;
826 CAL.record_editable = false;
829 CAL.get("radio_call").setAttribute("disabled","disabled");
830 CAL.get("radio_meeting").setAttribute("disabled","disabled");
833 SugarWidgetScheduler.update_time();
835 if(CAL.record_editable){
836 CAL.get("btn-save").removeAttribute("disabled");
837 CAL.get("btn-delete").removeAttribute("disabled");
838 CAL.get("btn-apply").removeAttribute("disabled");
839 CAL.get("btn-send-invites").removeAttribute("disabled");
842 CAL.get("form_content").style.display = "";
843 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
844 ajaxStatus.hideStatus();
846 setTimeout(function(){
848 disableOnUnloadEditView();
852 alert(CAL.lbl_error_loading);
856 alert(CAL.lbl_error_loading);
859 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
861 "current_module" : module_name,
864 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
867 CAL.records_openable = true;
871 CAL.remove_shared = function (record_id){
874 if(e = CAL.get(record_id + '____' + "0"))
875 cell_id = e.parentNode.id;
877 if(typeof cell_id != "undefined"){
878 var cell_id_arr = cell_id.split("_");
879 cell_id = "t_" + cell_id_arr[1];
881 CAL.each(CAL.shared_users,function(i,v){
882 if(e = CAL.get(record_id + '____' + v))
883 e.parentNode.removeChild(e);
884 CAL.arrange_slot(cell_id + '_' + v);
889 CAL.add_item = function (item){
891 if(CAL.view != 'shared'){
892 CAL.add_item_to_grid(item);
894 CAL.remove_shared(item.record);
895 record_id = item.record;
896 //var rec_id = item.rec_id;
897 var timestamp = item.timestamp;
902 //rec.rec_id = rec_id;
903 rec.timestamp = timestamp;
905 rec.record = record_id;
906 CAL.add_item_to_grid(rec);
911 rec.record = r.record;
912 rec.timestamp = r.timestamp;
913 //rec.rec_id = record_id;
914 CAL.add_item_to_grid(rec);
921 CAL.arrange_advanced();
924 CAL.move_activity = function (box_id,slot_id,ex_slot_id){
926 if(u = CAL.get(box_id)){
927 if(s = CAL.get(slot_id)){
930 CAL.arrange_column(document.getElementById(slot_id).parentNode);
931 CAL.arrange_column(document.getElementById(ex_slot_id).parentNode);
932 CAL.update_dd.fire();
934 CAL.cut_record(box_id);
935 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),u.getAttribute('status'),u.getAttribute('record'));
936 var date_field = "date_start";
937 if(u.getAttribute('module_name') == "Tasks")
938 date_field = "date_due";
939 u.setAttribute(date_field,s.getAttribute("datetime"));
940 u.childNodes[0].childNodes[1].innerHTML = start_text;
945 CAL.change_activity_type = function (mod_name){
946 if(typeof CAL.current_params.module_name != "undefined" )
947 if(CAL.current_params.module_name == mod_name)
950 var e,user_name,user_id,date_start;
952 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
954 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;
956 CAL.current_params.module_name = mod_name;
958 QSFieldsArray = new Array();
959 QSProcessedFieldsArray = new Array();
961 CAL.load_create_form(CAL.current_params);
966 CAL.load_create_form = function (params){
968 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
972 success: function(o){
974 res = eval("("+o.responseText+")");
976 alert(CAL.lbl_error_loading);
977 CAL.editDialog.cancel();
978 ajaxStatus.hideStatus();
981 if(res.success == 'yes'){
982 var fc = document.getElementById("form_content");
983 CAL.script_evaled = false;
984 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
986 if(!CAL.script_evaled){
987 SUGAR.util.evalScript(res.html);
990 CAL.get("record").value = "";
991 CAL.get("current_module").value = res.module_name;
992 var mod_name = res.module_name;
995 CAL.record_editable = true;
997 CAL.record_editable = false;
1000 CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
1002 setTimeout(function(){
1003 SugarWidgetScheduler.update_time();
1005 disableOnUnloadEditView();
1008 ajaxStatus.hideStatus();
1011 alert(CAL.lbl_error_loading);
1012 ajaxStatus.hideStatus();
1015 failure: function() {
1016 alert(CAL.lbl_error_loading);
1017 ajaxStatus.hideStatus();
1021 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1023 "current_module" : params.module_name,
1024 "assigned_user_id" : params.user_id,
1025 "assigned_user_name" : params.user_name,
1026 "date_start" : params.date_start
1028 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1032 CAL.dialog_create = function (cell){
1034 var e,user_id,user_name;
1035 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1036 CAL.open_edit_dialog();
1038 // Hide and disable delete button when creating a new record
1039 CAL.get("btn-delete").setAttribute("disabled","disabled");
1040 CAL.get("btn-delete").style.display = "none";
1043 var module_name = CAL.get("current_module").value;
1045 if(CAL.view == 'shared'){
1046 user_name = cell.parentNode.parentNode.parentNode.getAttribute("user_name");
1047 user_id = cell.parentNode.parentNode.parentNode.getAttribute("user_id");
1048 CAL.GR_update_user(user_id);
1050 user_id = CAL.current_user_id;
1051 user_name = CAL.current_user_name;
1052 CAL.GR_update_user(CAL.current_user_id);
1056 'module_name': module_name,
1058 'user_name': user_name,
1059 'date_start': cell.getAttribute("datetime")
1061 CAL.current_params = params;
1062 CAL.load_create_form(CAL.current_params);
1066 CAL.dialog_save = function(){
1067 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1069 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
1070 CAL.fill_invitees();
1071 //CAL.fill_recurrence();
1074 success: function(o){
1076 res = eval("("+o.responseText+")");
1078 alert(CAL.lbl_error_saving);
1079 CAL.editDialog.cancel();
1080 ajaxStatus.hideStatus();
1083 if(res.success == 'yes'){
1085 CAL.editDialog.cancel();
1087 ajaxStatus.hideStatus();
1089 alert(CAL.lbl_error_saving);
1090 ajaxStatus.hideStatus();
1093 failure: function(){
1094 alert(CAL.lbl_error_saving);
1095 ajaxStatus.hideStatus();
1098 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
1099 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1100 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1103 CAL.dialog_apply = function(){
1104 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1106 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
1107 CAL.fill_invitees();
1108 //CAL.fill_recurrence();
1111 if(e = CAL.get("radio_call"))
1112 e.setAttribute("disabled","disabled");
1113 if(e = CAL.get("radio_meeting"))
1114 e.setAttribute("disabled","disabled");
1119 success: function(o){
1121 res = eval("("+o.responseText+")");
1123 alert(CAL.lbl_error_saving);
1124 CAL.editDialog.cancel();
1125 ajaxStatus.hideStatus();
1128 if(res.success == 'yes'){
1130 CAL.get("record").value = res.record;
1131 //SugarWidgetScheduler.update_time();
1132 //CAL.GR_update_focus(CAL.get("current_module").value,res.record);
1135 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1136 if(e = CAL.get("send_invites"))
1137 e.removeAttribute("checked");
1139 ajaxStatus.hideStatus();
1141 // If new data is added with Apply, show the Delete button
1142 CAL.get("btn-delete").removeAttribute("disabled");
1143 CAL.get("btn-delete").style.display = "";
1145 alert(CAL.lbl_error_saving);
1146 ajaxStatus.hideStatus();
1149 failure: function(){
1150 alert(CAL.lbl_error_saving);
1151 ajaxStatus.hideStatus();
1154 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
1155 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1156 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1159 CAL.dialog_remove = function(){
1160 CAL.deleted_id = CAL.get("record").value;
1161 CAL.deleted_module = CAL.get("current_module").value;
1162 var delete_recurring = false;
1165 success: function(o){
1167 res = eval("("+o.responseText+")");
1169 alert(CAL.lbl_error_saving);
1170 CAL.editDialog.cancel();
1171 ajaxStatus.hideStatus();
1176 if(e = CAL.get(CAL.deleted_id))
1177 cell_id = e.parentNode.id;
1178 if(CAL.view == 'shared')
1179 CAL.remove_shared(CAL.deleted_id);
1181 if(e = CAL.get(CAL.deleted_id))
1182 e.parentNode.removeChild(e);
1185 CAL.arrange_advanced();
1188 failure: function(){
1189 alert(CAL.lbl_error_saving);
1194 "current_module" : CAL.deleted_module,
1195 "record" : CAL.deleted_id,
1196 "delete_recurring": delete_recurring
1198 var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";
1199 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1201 CAL.editDialog.cancel();
1204 CAL.show_additional_details = function (id){
1205 var obj = CAL.get(id);
1207 var record = obj.getAttribute("record");
1208 mod = obj.getAttribute("module_name");
1209 var atype = CAL.act_types[mod];
1211 var subj = obj.getAttribute("subj");
1212 var date_start = obj.getAttribute("date_start");
1213 var duration = obj.getAttribute("dur");
1214 var desc = obj.getAttribute("desc");
1215 var detail = parseInt(obj.getAttribute("detail"));
1216 var edit = parseInt(obj.getAttribute("edit"));
1219 if(date_start != "")
1220 date_str += '<b>'+CAL.lbl_start+':</b> ' + date_start;
1222 var date_due = obj.getAttribute("date_due");
1226 date_str += '<b>'+CAL.lbl_due+':</b> ' + date_due;
1231 if(obj.getAttribute("parent_id") != '' && obj.getAttribute("parent_name") != '')
1232 related = "<b>" + CAL.lbl_related + ":</b> <a href='index.php?module="+obj.getAttribute("parent_type")+"&action=DetailView&record="+obj.getAttribute("parent_id")+"'>"+obj.getAttribute("parent_name")+"</a>" + "<br>";
1235 desc = '<b>'+ CAL.lbl_desc + ':</b><br> ' + desc +'<br>';
1239 var date_lbl = CAL.lbl_start;
1241 var duration_text = '<b>'+CAL.lbl_duration+':</b> ' + duration + '<br>';
1243 date_lbl = CAL.lbl_due;
1249 var caption = "<div style='float: left;'>"+CAL.lbl_title+"</div><div style='float: right;'>";
1251 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_EDIT_BUTTON')+"\' href=\'index.php?module="+mod+"&action=EditView&record="+record+"\'><img border=0 src=\'"+CAL.img_edit_inline+"\'></a>";
1254 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_VIEW_BUTTON')+"\' href=\'index.php?module="+mod+"&action=DetailView&record="+record+"\'><img border=0 style=\'margin-left:2px;\' src=\'"+CAL.img_view_inline+"\'></a>";
1256 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_ADDITIONAL_DETAILS_CLOSE_TITLE')+"\' href=\'javascript:return cClick();\' onclick=\'javascript:return cClick();\'><img border=0 style=\'margin-left:2px;margin-right:2px;\' src=\'"+CAL.img_close+"\'></a></div>";
1259 var body = '<b>'+CAL.lbl_name+':</b> ' + subj + '<br>' + date_str + '<br>' + duration_text + related + desc;
1260 return overlib(body, CAPTION, caption, DELAY, 200, STICKY, MOUSEOFF, 200, WIDTH, 300, CLOSETEXT, '', CLOSETITLE, SUGAR.language.get('app_strings','LBL_ADDITIONAL_DETAILS_CLOSE_TITLE'), CLOSECLICK, FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass ecCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass');
1263 CAL.toggle_shared_edit = function (id){
1264 if(document.getElementById(id).style.display == 'none'){
1265 document.getElementById(id).style.display = 'inline'
1266 if(document.getElementById(id+"link") != undefined){
1267 document.getElementById(id+"link").style.display='none';
1270 document.getElementById(id).style.display = 'none'
1271 if(document.getElementById(id+"link") != undefined){
1272 document.getElementById(id+"link").style.display = 'inline';
1277 CAL.goto_date_call = function (){
1278 var date_string = CAL.get("goto_date").value;
1280 date_arr = date_string.split("/");
1282 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];
1285 CAL.toURI = function (a){
1288 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1290 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1292 t.push(x+"="+encodeURIComponent(a[x]));
1297 CAL.each = function (object, callback) {
1299 if(typeof object == "undefined")
1302 length = object.length,
1303 isObj = (length === undefined) || (typeof (object) === "function");
1305 for (name in object) {
1306 if (callback.call(object[name], name, object[name]) === false) {
1311 for (; i < length;) {
1312 if (callback.call(object[i], i, object[i++]) === false) {
1320 CAL.update_vcal = function(){
1322 var v = CAL.current_user_id;
1324 success: function(result){
1325 if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
1326 GLOBAL_REGISTRY.freebusy = new Object();
1328 if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
1329 GLOBAL_REGISTRY.freebusy_adjusted = new Object();
1331 // parse vCal and put it in the registry using the user_id as a key:
1332 GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);
1333 // parse for current user adjusted vCal
1334 GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
1335 SugarWidgetScheduler.update_time();
1339 var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;
1340 YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
1343 CAL.fit_grid = function(){
1345 var cal_width = document.getElementById("cal-grid").parentNode.parentNode.offsetWidth;
1346 var left_width = 80;
1349 if(CAL.view == "day")
1350 day_width = parseInt((cal_width - left_width));
1352 day_width = parseInt((cal_width - left_width) / 7 );
1354 var nodes = CAL.query("#cal-grid div.day_col");
1355 CAL.each(nodes, function(i,v){
1356 nodes[i].style.width = day_width + "px";
1359 document.getElementById("cal-grid").style.visibility = "";
1363 YAHOO.util.DDCAL = function(id, sGroup, config){
1364 this.cont = config.cont;
1365 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
1367 YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, {
1370 YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
1371 this.initConstraints();
1372 CAL.update_dd.subscribe(function(type, args, dd){
1373 dd.resetConstraints();
1374 dd.initConstraints();
1377 initConstraints: function() {
1378 var region = YAHOO.util.Dom.getRegion(this.cont);
1379 var el = this.getEl();
1380 var xy = YAHOO.util.Dom.getXY(el);
1381 var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
1382 var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10);
1383 var left = xy[0] - region.left;
1384 var right = region.right - xy[0] - width;
1385 var top = xy[1] - region.top;
1386 var bottom = region.bottom - xy[1] - height;
1387 this.setXConstraint(left, right);
1388 this.setYConstraint(top, bottom);
1392 CAL.remove_edit_dialog();
1394 var cal_loaded = true;