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 ********************************************************************************/
41 CAL.records_openable = true;
42 CAL.moved_from_cell = "";
44 CAL.deleted_module = "";
46 CAL.disable_creating = false;
47 CAL.record_editable = false;
48 CAL.shared_users = {};
49 CAL.shared_users_count = 0;
50 CAL.script_evaled = false;
51 CAL.editDialog = false;
52 CAL.settingsDialog = false;
53 CAL.sharedDialog = false;
56 CAL.update_dd = new YAHOO.util.CustomEvent("update_dd");
57 CAL.dd_registry = new Object();
58 CAL.resize_registry = new Object();
61 CAL.dom = YAHOO.util.Dom;
62 CAL.get = YAHOO.util.Dom.get;
63 CAL.query = YAHOO.util.Selector.query;
65 CAL.arrange_slot = function (cell_id){
68 cellElm = document.getElementById(cell_id);
76 var child_cnt = cellElm.childNodes.length;
77 for(var i = 0; i < child_cnt; i++){
78 var width_p = (92 / child_cnt);
79 width = width_p.toString() + "%";
80 if(cellElm.childNodes[i].tagName == "DIV"){
81 cellElm.childNodes[i].style.top = "-1px";
82 cellElm.childNodes[i].style.left = "-" + (cnt + 1) + "px";
83 cellElm.childNodes[i].style.width = width
91 // prevent item overlapping
92 CAL.arrange_column = function(column){
94 for(var i = 0; i < column.childNodes.length; i++){
95 for(var j = 0; j < column.childNodes[i].childNodes.length; j++){
96 var el = column.childNodes[i].childNodes[j];
97 if(YAHOO.util.Dom.hasClass(el,"empty")){
98 el.parentNode.removeChild(el);
104 var slots = column.childNodes;
107 var end = slots.length;
108 var slot_count = end;
111 var affected_slots = new Array();
112 var affected_items = Array();
113 var ol = new Array();
115 // fill ol array with groups of overlapping items to fit them bit later
116 find_overlapping(null,start,end,level,null);
118 // add transparent empty blocks to the left
119 for(var i = 0; i < ol.length; i++){
120 var ol_group = ol[i];
121 var depth = ol_group.depth;
122 for(var j = 0; j < ol_group.items.length; j++){
123 var el_id = ol_group.items[j]['id'];
124 var level = ol_group.items[j]['level'];
125 var el = CAL.get(el_id);
128 while(node.previousSibling){
130 node = node.previousSibling;
132 insert_empty_items(el,level - 1 - pos,false);
136 // add transparent empty blocks to the right
137 for(var i = 0; i < ol.length; i++){
138 var ol_group = ol[i];
139 var depth = ol_group.depth;
140 for(var j = 0; j < ol_group.items.length; j++){
141 var el_id = ol_group.items[j]['id'];
143 var el = CAL.get(el_id);
144 var cnt = el.parentNode.childNodes.length;
145 insert_empty_items(el,depth - cnt,true);
149 CAL.each(affected_slots,function(i,v){
150 CAL.arrange_slot(affected_slots[i]);
154 function find_overlapping(el,start,end,level,ol_group){
164 ol_group.items = new Array();
166 ol_group.items.push({
170 affected_items.push(el.id);
173 for(var i = start; i < end; i++){
177 if(typeof slots[i].childNodes != 'undefined' && typeof slots[i].childNodes[0] != 'undefined'){
181 var node = slots[i].childNodes[0];
182 while(node.nextSibling && CAL.contains(affected_items,node.id)){
183 node = node.nextSibling;
188 var current = slots[i].childNodes[pos];
189 var slots_takes = parseInt(current.getAttribute('duration_coef'));
191 if(CAL.contains(affected_items,current.id))
195 var slot_id = current.parentNode.id;
196 if(!CAL.contains(affected_slots,slot_id))
197 affected_slots.push(slot_id);
201 var k = find_overlapping(current, i, i + slots_takes, level + 1,ol_group);
209 ol_group.depth = depth;
216 function insert_empty_items(el,count,to_end){
217 var slot = el.parentNode;
218 for(var i = 0; i < count; i++){
219 var empty = document.createElement("div");
220 empty.className = "act_item empty";
221 empty.style.zIndex = "-1";
222 empty.style.width = "1px";
224 slot.appendChild(empty);
226 slot.insertBefore(empty,slot.firstChild);
233 CAL.arrange_advanced = function (){
234 var nodes = CAL.query("#cal-grid #cal-scrollable .col");
235 for(var i = 0; i < nodes.length; i++){
236 CAL.arrange_column(nodes[i]);
238 CAL.update_dd.fire();
242 CAL.create_item = function (params){
243 var item = params.item;
245 var id = params.id + params.id_suffix;
248 //if(params.type == "advanced"){
249 //content = "<div class='content' " + params.content_style + ">" + params.item_text + "</div>";
252 //var el = document.createElement("div");
253 //el.innerHTML = "<div class='head'><div class='adicon' onmouseover='return CAL.show_additional_details(" + '"' + id + '"' + ");' onmouseout='nd(400); SUGAR.util.clearAdditionalDetailsCall();' > </div><div>" + params.head_text + "</div>" + "</div>" + content;
255 var el = document.createElement("div");
256 var elHead = document.createElement("div");
257 elHead.setAttribute("class","head");
259 var elHeadInfo = document.createElement("div");
260 elHeadInfo.setAttribute("class","adicon");
261 elHeadInfo.setAttribute("id","div_"+id);
263 var params_click = new Object();
264 params_click.id = id;
265 YAHOO.util.Event.on(elHeadInfo,"click",function(e){
266 YAHOO.util.Event.stopPropagation(e);
267 CAL.show_additional_details(params_click.id);
272 var head_text = document.createElement("div");
273 head_text.innerHTML = params.head_text;
276 elHead.appendChild(elHeadInfo);
277 elHead.appendChild(head_text);
279 el.appendChild(elHead);
282 if(params.type == "advanced"){
283 var elContent = document.createElement("div");
284 elContent.setAttribute("class","content");
285 if(params.content_style != "") {
286 elContent.style[params.content_style] = params.content_style_value;
288 elContent.innerHTML = params.item_text;
289 el.appendChild(elContent);
296 el.setAttribute("id",id);
297 el.className = "act_item" + " " + item.type+"_item";
298 el.style.backgroundColor = CAL.activity_colors[item.module_name]['body'];
299 el.style.borderColor = CAL.activity_colors[item.module_name]['border'];
301 el.setAttribute("record",params.id);
302 el.setAttribute("module_name",item.module_name);
303 el.setAttribute("record",item.record);
304 el.setAttribute("status",item.status);
305 el.setAttribute("detail",item.detail);
306 el.setAttribute("edit",item.edit);
307 if(typeof item.repeat_parent_id != "undefined" && item.repeat_parent_id != "")
308 el.setAttribute("repeat_parent_id",item.repeat_parent_id);
309 if(params.type == "basic"){
310 el.style.left = "-1px";
311 el.style.display = "block";
312 el.setAttribute("days",params.days);
313 el.style.width = ((params.days)*100) + "%";
314 el.style.top = parseInt(params.position * CAL.slot_height - params.slot.childNodes.length * (CAL.slot_height + 1)) + "px";
317 el.style.height = parseInt((CAL.slot_height + 1) * params.duration_coef - 1) + "px";
318 el.setAttribute("duration_coef",params.duration_coef);
321 YAHOO.util.Event.on(el,"mouseover",function(){
322 if(!CAL.records_openable)
324 CAL.disable_creating = true;
326 if(e = CAL.get(el.id))
329 YAHOO.util.Event.on(el,"mouseout",function(event){
330 if(!CAL.records_openable)
332 var node = event.toElement || event.relatedTarget;
338 node = node.parentNode;
341 CAL.get(el.id).style.zIndex = '';
342 CAL.disable_creating = false;
345 CAL.clear_additional_details(params.id);
350 CAL.make_draggable = function (id,type){
358 if(CAL.view != "month" && CAL.view != "shared")
359 border = "cal-multiday-bar";
363 if(CAL.view != "month")
364 border = "cal-scrollable";
369 var dd = new YAHOO.util.DDCAL(id,prefix+"cal",{isTarget: false,cont: border});
371 CAL.dd_registry[id] = dd;
373 dd.onInvalidDrop = function(e){
375 CAL.basic.populate_grid();
378 CAL.arrange_slot(this.el.parentNode.getAttribute("id"));
379 if(CAL.dropped == 0){
380 this.el.childNodes[0].innerHTML = CAL.tmp_header;
383 CAL.records_openable = true;
384 CAL.disable_creating = false;
387 dd.onMouseDown = function(e){
388 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
389 YAHOO.util.DDM.clickPixelThresh = 20;
392 dd.onMouseUp = function(e){
393 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
394 YAHOO.util.DDM.clickPixelThresh = 3;
397 dd.startDrag = function(x,y){
399 this.el = document.getElementById(this.id);
400 this.el.style.zIndex = 5;
402 CAL.records_openable = false;
403 CAL.disable_creating = true;
404 CAL.tmp_header = this.el.childNodes[0].innerHTML;
405 CAL.moved_from_cell = this.el.parentNode.id;
410 dd.endDrag = function(x,y){
411 this.el = document.getElementById(this.id);
412 this.el.style.zIndex = "";
414 var nodes = CAL.query("#cal-grid div."+prefix+"slot");
415 CAL.each(nodes,function(i,v){
416 YAHOO.util.Dom.removeClass(nodes[i],"slot_active");
420 dd.onDragDrop = function(e,id){
422 var slot = document.getElementById(id);
423 YAHOO.util.Dom.removeClass(slot,"slot_active");
424 if(CAL.dropped) // prevent dropping on two slots in same time
428 this.el.style.position = "relative";
429 this.el.style.cssFloat = "none";
431 if(type == "advanced"){
432 if(CAL.view != 'shared'){
433 var box_id = this.id;
435 var ex_slot_id = CAL.moved_from_cell;
436 CAL.move_activity(box_id,slot_id,ex_slot_id);
438 var record = this.el.getAttribute("record");
440 var tar = tid.split("_");
441 var timestamp = tar[1];
442 var tid = CAL.moved_from_cell;
443 var tar = tid.split("_");
444 var ex_timestamp = tar[1];
446 for(i = 0; i < CAL.shared_users_count; i++){
447 var box_id = record + "____" + i;
448 var slot_id = id_prefix + timestamp + "_" + i;
449 var ex_slot_id = id_prefix + ex_timestamp + "_" + i;
450 CAL.move_activity(box_id,slot_id,ex_slot_id);
456 success: function(o){
458 res = eval("("+o.responseText+")");
460 alert(CAL.lbl_error_saving);
461 ajaxStatus.hideStatus();
464 if(res.access == 'yes'){
466 CAL.disable_creating = false;
467 CAL.records_openable = true;
469 ajaxStatus.hideStatus();
472 if (res.errorMessage != 'undefined') {
473 alert(res.errorMessage);
476 ajaxStatus.hideStatus();
481 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
482 var url = "index.php?module=Calendar&action=Reschedule&sugar_body_only=true";
484 "current_module" : this.el.getAttribute("module_name"),
485 "record" : this.el.getAttribute("record"),
486 "datetime" : slot.getAttribute("datetime"),
487 "calendar_style" : type
489 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
491 YAHOO.util.Dom.removeClass(slot,"slot_active");
495 dd.onDragOver = function(e,id){
496 var slot = document.getElementById(id);
497 if(!YAHOO.util.Dom.hasClass(slot,"slot_active"))
498 YAHOO.util.Dom.addClass(slot,"slot_active");
499 if(type == "advanced")
500 this.el.childNodes[0].childNodes[1].childNodes[0].innerHTML = slot.getAttribute('time');
503 dd.onDragOut = function(e,id){
504 var slot = document.getElementById(id);
505 YAHOO.util.Dom.removeClass(slot,"slot_active");
509 CAL.make_resizable = function (id,slot){
511 var pos = 0, e = slot;
512 while(e = e.previousSibling){
515 var max_height = (CAL.cells_per_day - pos) * (CAL.slot_height + 1) - 1;
517 var resize = new YAHOO.util.Resize(id,{
519 maxHeight : max_height
522 CAL.resize_registry[id] = resize;
524 resize.on('startResize', function(e){
525 var el = CAL.get(id);
529 CAL.records_openable = false;
530 CAL.disable_creating = true;
532 resize.on('endResize', function(e){
536 var duration = e.height / (CAL.slot_height + 1) * CAL.t_step;
537 var remainder = duration % 15;
539 remainder = (-1) * (15 - remainder);
540 duration = duration - remainder;
541 var duration_hours = parseInt(duration / 60);
542 var duration_minutes = duration % 60;
544 var new_size = (duration / CAL.t_step) * (CAL.slot_height + 1) - 1;
546 var el = CAL.get(elm_id);
548 el.style.zIndex = '';
549 el.style.height = new_size + "px";
550 CAL.arrange_slot(slot.id);
552 var nodes = CAL.query("#cal-grid div.act_item");
553 CAL.each(nodes,function(i,v){
554 nodes[i].style.zIndex = '';
557 var duration_coef = duration / CAL.t_step;
558 el.setAttribute("duration_coef",duration_coef);
559 if(duration_coef < 1.75)
560 el.childNodes[1].style.display = "none";
562 el.childNodes[1].style.display = "";
565 success: function(o){
567 res = eval("("+o.responseText+")");
569 alert(CAL.lbl_error_saving);
570 ajaxStatus.hideStatus();
573 if(res.access == 'yes'){
575 CAL.clear_additional_details(el.getAttribute("record"));
576 CAL.arrange_column(slot.parentNode);
577 CAL.update_dd.fire();
578 ajaxStatus.hideStatus();
579 CAL.disable_creating = false;
580 CAL.records_openable = true;
584 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
585 var url = "index.php?module=Calendar&action=Resize&sugar_body_only=true";
587 "current_module" : el.getAttribute("module_name"),
588 "record" : el.getAttribute("record"),
589 "duration_hours" : duration_hours,
590 "duration_minutes" : duration_minutes
592 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
597 CAL.destroy_ui = function (id){
598 if(CAL.items_resizable && typeof CAL.resize_registry[id] != "undefined"){
599 CAL.resize_registry[id].destroy();
600 delete CAL.resize_registry[id];
602 if(CAL.items_draggable && typeof CAL.dd_registry[id] != "undefined")
603 CAL.dd_registry[id].unreg();
604 delete CAL.dd_registry[id];
607 CAL.basic.remove = function (item){
608 if(typeof CAL.basic.items[item.user_id] == 'undefined')
609 CAL.basic.items[item.user_id] = new Object();
610 delete CAL.basic.items[item.user_id][item.record];
613 CAL.basic.add = function (item){
614 if(typeof CAL.basic.items[item.user_id] == 'undefined')
615 CAL.basic.items[item.user_id] = new Object();
616 CAL.basic.items[item.user_id][item.record] = item;
619 CAL.basic.populate_grid = function(){
621 var nodes = CAL.query("#cal-grid .cal-basic .col .act_item");
622 CAL.each(nodes,function(i,v){
623 nodes[i].parentNode.removeChild(nodes[i]);
626 var users_arr = new Array();
627 if(CAL.view != "shared"){
628 users_arr.push(CAL.current_user_id);
630 CAL.each(CAL.shared_users,function(i,v){
635 for(ui = 0; ui < users_arr.length; ui++){
637 var user_id = users_arr[ui];
640 if(CAL.view == 'shared'){
641 suffix = "_" + CAL.shared_users[user_id];
642 id_suffix = '____' + CAL.shared_users[user_id];
646 if(CAL.view == "day")
649 var portions_count = 1;
650 if(CAL.view == "month"){
651 var e = CAL.get("b_" + CAL.grid_start_ts + suffix);
653 portions_count = e.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes.length;
658 var start = CAL.grid_start_ts;
660 for(w = 0; w < portions_count; w++){
662 var end = start + step * 3600 * 24;
663 var portion = Array();
665 CAL.each(CAL.basic.items[user_id],function(id,item){
667 var c = !((item.ts_start < start && item.ts_end <= start) || (end <= item.ts_start && end <= item.ts_end));
669 if(item.ts_start < start)
672 var from = item.ts_start;
673 if(end <= item.ts_end)
676 var to = item.ts_end;
687 portion.sort(function(a,b){
688 return a.offset - b.offset;
691 var equalizer = Array();
692 for(i = 0; i < step; i++){
696 CAL.each(portion,function(i,v){
697 var from = (portion[i].from - start) / (3600 * 24);
698 var to = (portion[i].to - start) / (3600 * 24);
701 for(d = from; d < to; d++){
702 if(equalizer[d] > pos)
705 for(d = from; d < to; d++){
706 equalizer[d] = pos + 1;
709 portion[i].position = pos;
710 portion[i].days = to - from;
715 var item = CAL.basic.items[user_id][portion[i].id];
717 var slot = CAL.get("b_" + portion[i].from + suffix);
719 var time_start = item.time_start;
720 if(item.ts_start < start)
721 time_start = "... ";
723 var head_text = CAL.get_header_text(item.type,time_start,item.name,item.record);
725 var el = CAL.create_item({
728 head_text: head_text,
730 position: portion[i].position,
732 id_suffix: id_suffix,
733 days: portion[i].days
736 YAHOO.util.Event.on(el,"click",function(){
737 if(this.getAttribute('detail') == "1")
738 CAL.load_form(this.getAttribute('module_name'),this.getAttribute('record'),false);
741 slot.appendChild(el);
743 if(CAL.items_draggable && item.edit == 1){
744 CAL.make_draggable(el.getAttribute("id"),"basic");
749 h = parseInt((max_pos + 1) * CAL.slot_height + (CAL.slot_height + 1));
750 if(h < CAL.basic.min_height)
751 h = CAL.basic.min_height;
754 var height_string = h + "px";
755 var row = CAL.get("b_" + start + suffix).parentNode.parentNode;
758 row.parentNode.childNodes[0].childNodes[0].style.height = height_string;
759 CAL.each(row.childNodes,function(i,v){
760 if(typeof row.childNodes[i] == 'object')
761 row.childNodes[i].childNodes[0].style.height = height_string;
764 start = start + step * 3600 * 24;
771 CAL.add_item_to_grid = function (item){
776 if( item.user_id != "" && CAL.view == 'shared'){
777 suffix = "_" + CAL.shared_users[item.user_id];
778 id_suffix = '____' + CAL.shared_users[item.user_id];
781 var e = CAL.get(item.record + id_suffix);
783 e.parentNode.removeChild(e);
784 CAL.destroy_ui(item.record + id_suffix);
787 CAL.basic.remove(item);
788 //Add item to top grid if items have a duration > 1 day and view style is basic
789 if(CAL.style == "basic" || item.days > 1){
794 var head_text = CAL.get_header_text(item.type,item.time_start,item.name,item.record);
795 var time_cell = item.timestamp - item.timestamp % (CAL.t_step * 60);
797 if(item.module_name == 'Tasks'){
800 if((item.duration_minutes < CAL.t_step) && (item.duration_hours == 0))
803 duration_coef = (parseInt(item.duration_hours) * 60 + parseInt(item.duration_minutes)) / CAL.t_step;
806 var item_text = SUGAR.language.languages.app_list_strings[item.type +'_status_dom'][item.status];
808 var content_style = "";
809 var content_style_value = "";
810 if(duration_coef < 1.75) {
811 content_style = "display";
812 content_style_value = "none";
815 var elm_id = item.record + id_suffix;
817 var el = CAL.create_item({
820 head_text: head_text,
821 duration_coef: duration_coef,
823 id_suffix: id_suffix,
824 item_text: item_text,
825 content_style: content_style,
826 content_style_value: content_style_value
829 YAHOO.util.Event.on(el,"click",function(){
830 if(this.getAttribute('detail') == "1")
831 CAL.load_form(this.getAttribute('module_name'),this.getAttribute('record'),false);
834 if(slot = CAL.get("t_" + time_cell + suffix)){
836 slot.appendChild(el);
839 if(CAL.items_draggable)
840 CAL.make_draggable(elm_id,"advanced");
841 if(item.module_name != "Tasks" && CAL.items_resizable)
842 CAL.make_resizable(elm_id,slot);
845 CAL.cut_record(item.record + id_suffix);
846 //CAL.arrange_slot("t_" + time_cell + suffix);
851 CAL.get_header_text = function (type,time_start,text,record){
852 var start_text = "<span class='start_time'>" + time_start + "</span> " + text;
856 CAL.cut_record = function (id){
857 var el = CAL.get(id);
860 var duration_coef = el.getAttribute("duration_coef");
861 real_celcount = CAL.cells_per_day;
863 var s = el.parentNode;
864 while(s.previousSibling){
866 s = s.previousSibling;
869 if(real_celcount - celpos - duration_coef < 0)
870 duration_coef = real_celcount - celpos + 1;
871 el.style.height = parseInt((CAL.slot_height + 1) * duration_coef - 1) + "px";
874 CAL.init_edit_dialog = function (params){
875 CAL.editDialog = false;
877 var rd = CAL.get("cal-edit");
878 var content = CAL.get("edit-dialog-content");
880 if(CAL.dashlet && rd){
881 document.getElementById("content").appendChild(rd);
884 rd.style.width = params.width + "px";
885 content.style.height = params.height + "px";
886 content.style.overflow = "auto";
887 content.style.padding = "0";
889 CAL.editDialog = new YAHOO.widget.Dialog("cal-edit",{
896 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
897 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
899 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){
900 CAL.close_edit_dialog();
903 rd.style.display = "block";
904 CAL.editDialog.render();
906 rd.style.overflow = "auto";
907 rd.style.overflowX = "hidden";
908 rd.style.outline = "0 none";
909 rd.style.height = "auto";
913 CAL.open_edit_dialog = function (params){
915 document.getElementById("form_content").innerHTML = "";
917 CAL.editDialog.center();
918 CAL.editDialog.show();
920 var nodes = CAL.query("#cal-tabs li a");
921 CAL.each(nodes,function(i,v){
922 YAHOO.util.Event.on(nodes[i], 'click', function(){
923 CAL.select_tab(this.getAttribute("tabname"));
928 if(typeof params != "undefined" && typeof params.stay_on_tab != "undefined" && params.stay_on_tab)
932 var nodes_li = CAL.query("#cal-tabs li");
933 CAL.each(nodes_li,function(j,v){
934 CAL.dom.removeClass(nodes_li[j],"selected");
936 CAL.dom.addClass(nodes_li[j],"selected");
939 var nodes = CAL.query(".yui-nav");
940 CAL.each(nodes,function(i,v){
941 nodes[i].style.overflowX = "visible";
947 CAL.close_edit_dialog = function (){
948 CAL.reset_edit_dialog();
951 CAL.remove_edit_dialog = function(){
952 var rd_c = CAL.get("cal-edit_c");
954 rd_c.parentNode.removeChild(rd_c);
958 CAL.reset_edit_dialog = function (){
961 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
963 CAL.get("radio_call").removeAttribute("disabled");
964 CAL.get("radio_meeting").removeAttribute("disabled");
965 CAL.get("radio_call").checked = false;
966 CAL.get("radio_meeting").checked = true;
968 CAL.get("send_invites").value = "";
970 if(e = CAL.get("record"))
973 if(e = CAL.get("list_div_win"))
974 e.style.display = "none";
976 if(typeof SugarWidgetSchedulerSearch.hideCreateForm != 'undefined')
977 SugarWidgetSchedulerSearch.hideCreateForm();
979 $("#scheduler .schedulerInvitees").css("display", "");
980 $("#create-invitees-title").css("display", "");
981 $("#create-invitees-buttons").css("display", "");
983 if(CAL.enable_repeat){
984 CAL.reset_repeat_form();
987 CAL.GR_update_focus("Meetings","");
988 CAL.select_tab("cal-tab-1");
990 QSFieldsArray = new Array();
991 QSProcessedFieldsArray = new Array();
994 CAL.reset_repeat_form = function (){
995 document.forms['CalendarRepeatForm'].reset();
996 var fields = ['type','interval','count','until','dow'];
997 CAL.each(fields,function(i,field){
998 CAL.get('repeat_' + field).value = "";
1000 toggle_repeat_type();
1001 CAL.get("repeat_parent_id").value = "";
1002 CAL.get("edit_all_recurrences").value = "";
1003 CAL.get("edit_all_recurrences_block").style.display = "none";
1004 CAL.get("cal-repeat-block").style.display = "none";
1007 CAL.select_tab = function (tid){
1008 var nodes_li = CAL.query("#cal-tabs li");
1009 CAL.each(nodes_li,function(j,v){
1010 CAL.dom.removeClass(nodes_li[j],"selected");
1013 CAL.dom.addClass(CAL.get(tid + "-link").parentNode,"selected");
1015 var nodes = CAL.query("#cal-tabs .yui-content");
1016 CAL.each(nodes,function(i,v){
1017 nodes[i].style.display = "none";
1019 var nodes = CAL.query("#cal-tabs #"+tid);
1020 CAL.each(nodes,function(i,v){
1021 nodes[i].style.display = "block";
1025 CAL.fill_repeat_data = function (){
1027 if (CAL.enable_repeat && (CAL.get("current_module").value == "Meetings" || CAL.get("current_module").value == "Calls")) {
1028 if(repeat_type = document.forms['CalendarRepeatForm'].repeat_type.value){
1029 document.forms['CalendarEditView'].repeat_type.value = repeat_type;
1030 document.forms['CalendarEditView'].repeat_interval.value = document.forms['CalendarRepeatForm'].repeat_interval.value;
1031 if(document.getElementById("repeat_count_radio").checked){
1032 document.forms['CalendarEditView'].repeat_count.value = document.forms['CalendarRepeatForm'].repeat_count.value;
1033 document.forms['CalendarEditView'].repeat_until.value = "";
1035 document.forms['CalendarEditView'].repeat_until.value = document.forms['CalendarRepeatForm'].repeat_until.value;
1036 document.forms['CalendarEditView'].repeat_count.value = "";
1038 if(repeat_type == 'Weekly'){
1039 var repeat_dow = "";
1040 for(var i = 0; i < 7; i++)
1041 if(CAL.get("repeat_dow_" + i).checked)
1042 repeat_dow += i.toString();
1043 CAL.get("repeat_dow").value = repeat_dow;
1049 CAL.fill_repeat_tab = function(data){
1051 if(!CAL.enable_repeat)
1054 if(typeof data.repeat_parent_id != "undefined"){
1055 CAL.get("cal-repeat-block").style.display = "none";
1056 CAL.get("edit_all_recurrences_block").style.display = "";
1057 CAL.get("edit_all_recurrences").value = "";
1058 CAL.get("repeat_parent_id").value = data.repeat_parent_id;
1062 CAL.get("cal-repeat-block").style.display = "";
1064 var repeat_type = "";
1065 var set_default_repeat_until = true;
1066 if(typeof data.repeat_type != "undefined"){
1067 repeat_type = data.repeat_type;
1069 document.forms['CalendarRepeatForm'].repeat_type.value = data.repeat_type;
1070 document.forms['CalendarRepeatForm'].repeat_interval.value = data.repeat_interval;
1071 if(data.repeat_count != '' && data.repeat_count != 0){
1072 document.forms['CalendarRepeatForm'].repeat_count.value = data.repeat_count;
1073 CAL.get("repeat_count_radio").checked = true;
1074 CAL.get("repeat_until_radio").checked = false;
1076 document.forms['CalendarRepeatForm'].repeat_until.value = data.repeat_until;
1077 CAL.get("repeat_until_radio").checked = true;
1078 CAL.get("repeat_count_radio").checked = false;
1079 set_default_repeat_until = false;
1081 if(data.repeat_type == "Weekly"){
1082 var arr = data.repeat_dow.split("");
1083 CAL.each(arr,function(i,d){
1084 CAL.get("repeat_dow_" + d).checked = true;
1088 CAL.get("cal-repeat-block").style.display = "";
1089 CAL.get("edit_all_recurrences_block").style.display = "none";
1090 toggle_repeat_type();
1093 CAL.get("edit_all_recurrences").value = "true";
1095 if(typeof data.current_dow != "undefined" && repeat_type != "Weekly")
1096 CAL.get("repeat_dow_" + data.current_dow).checked = true;
1098 if(typeof data.default_repeat_until != "undefined" && set_default_repeat_until)
1099 CAL.get("repeat_until_input").value = data.default_repeat_until;
1104 CAL.repeat_tab_handle = function (module_name){
1105 if(!CAL.enable_repeat)
1107 CAL.reset_repeat_form();
1108 if(module_name == "Meetings" || module_name == "Calls"){
1109 CAL.get("tab_repeat").style.display = "";
1111 CAL.get("tab_repeat").style.display = "none";
1114 toggle_repeat_type();
1118 CAL.GR_update_user = function (user_id){
1120 success: function(o){
1121 res = eval(o.responseText);
1122 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;
1123 //SugarWidgetScheduler.update_time();
1129 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";
1130 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1134 CAL.GR_update_focus = function (module,record){
1136 GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
1137 SugarWidgetScheduler.update_time();
1140 success: function(o){
1141 res = eval(o.responseText);
1142 SugarWidgetScheduler.update_time();
1143 if(CAL.record_editable){
1144 CAL.enable_buttons();
1149 var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;
1150 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1154 CAL.toggle_settings = function (){
1155 var sd = CAL.get("settings_dialog");
1158 if(!CAL.settingsDialog){
1159 CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{
1166 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
1167 CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
1169 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
1170 CAL.get("form_settings").reset();
1172 sd.style.display = "block";
1173 CAL.settingsDialog.render();
1174 CAL.settingsDialog.show();
1178 CAL.fill_invitees = function (){
1180 CAL.get("user_invitees").value = "";
1181 CAL.get("contact_invitees").value = "";
1182 CAL.get("lead_invitees").value = "";
1184 CAL.each( GLOBAL_REGISTRY['focus'].users_arr, function(i,v){
1185 var field_name = "";
1186 if(v.module == "User")
1187 field_name = "user_invitees";
1188 if(v.module == "Contact")
1189 field_name = "contact_invitees";
1190 if(v.module == "Lead")
1191 field_name = "lead_invitees";
1192 var str = CAL.get(field_name).value;
1193 CAL.get(field_name).value = str + v.fields.id + ",";
1199 CAL.repeat_type_selected = function (){
1201 if(rt = CAL.get("repeat_type")){
1202 if(rt.value == 'Weekly'){
1203 var nodes = CAL.query(".weeks_checks_div");
1204 CAL.each(nodes,function (i,v){
1205 nodes[i].style.display = "block";
1208 var nodes = CAL.query(".weeks_checks_div");
1209 CAL.each(nodes,function (i,v){
1210 nodes[i].style.display = "none";
1215 CAL.get("repeat_interval").setAttribute("disabled","disabled");
1216 CAL.get("repeat_end_date").setAttribute("disabled","disabled");
1218 CAL.get("repeat_interval").removeAttribute("disabled");
1219 CAL.get("repeat_end_date").removeAttribute("disabled");
1224 CAL.load_form = function (module_name, record, edit_all_recurrences){
1226 CAL.disable_creating = true;
1230 if(module_name == "Tasks")
1233 if(to_open && CAL.records_openable){
1234 CAL.get("form_content").style.display = "none";
1236 CAL.disable_buttons();
1238 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1240 CAL.repeat_tab_handle(module_name);
1242 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
1245 if(edit_all_recurrences)
1246 params = {stay_on_tab: true};
1248 CAL.open_edit_dialog(params);
1249 CAL.get("record").value = "";
1251 if(!edit_all_recurrences)
1252 edit_all_recurrences = "";
1256 success: function(o){
1258 res = eval("("+o.responseText+")");
1260 alert(CAL.lbl_error_loading);
1261 CAL.editDialog.cancel();
1262 ajaxStatus.hideStatus();
1265 if(res.access == 'yes'){
1267 var fc = document.getElementById("form_content");
1268 CAL.script_evaled = false;
1269 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
1270 if(!CAL.script_evaled){
1271 SUGAR.util.evalScript(res.html);
1274 CAL.get("record").value = res.record;
1275 CAL.get("current_module").value = res.module_name;
1277 var mod_name = res.module_name;
1279 if(mod_name == "Meetings")
1280 CAL.get("radio_meeting").checked = true;
1281 if(mod_name == "Calls")
1282 CAL.get("radio_call").checked = true;
1285 CAL.record_editable = true;
1287 CAL.record_editable = false;
1290 CAL.get("radio_call").setAttribute("disabled","disabled");
1291 CAL.get("radio_meeting").setAttribute("disabled","disabled");
1295 SugarWidgetScheduler.update_time();
1296 if(CAL.record_editable){
1297 CAL.enable_buttons();
1300 CAL.get("form_content").style.display = "";
1302 if(typeof res.repeat != "undefined"){
1303 CAL.fill_repeat_tab(res.repeat);
1306 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1307 ajaxStatus.hideStatus();
1308 CAL.get("btn-save").focus();
1310 setTimeout(function(){
1312 $("#scheduler .schedulerInvitees").css("display", "none");
1313 $("#create-invitees-buttons").css("display", "none");
1314 $("#create-invitees-title").css("display", "none");
1317 disableOnUnloadEditView();
1320 alert(CAL.lbl_error_loading);
1323 failure: function(){
1324 alert(CAL.lbl_error_loading);
1327 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1329 "current_module" : module_name,
1331 "edit_all_recurrences" : edit_all_recurrences
1333 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1340 CAL.edit_all_recurrences = function (){
1341 var record = CAL.get("record").value;
1342 if(CAL.get("repeat_parent_id").value != ""){
1343 record = CAL.get("repeat_parent_id").value;
1344 CAL.get("repeat_parent_id").value = "";
1346 var module = CAL.get("current_module").value;
1348 CAL.load_form(module, record, true);
1353 CAL.remove_shared = function (record_id, edit_all_recurrences){
1354 if(typeof edit_all_recurrences == "undefined")
1355 edit_all_recurrences = false;
1358 var arr = new Array();
1359 if(CAL.enable_repeat && edit_all_recurrences){
1360 var nodes = CAL.query("div.act_item[repeat_parent_id='" + record_id + "']");
1361 CAL.each(nodes,function (i,v){
1362 var record = nodes[i].getAttribute("record");
1363 if(!CAL.contains(arr,record))
1365 nodes[i].parentNode.removeChild(nodes[i]);
1366 CAL.destroy_ui(nodes[i].id);
1370 CAL.each(CAL.shared_users,function(user_id,v){
1371 if(e = CAL.get(record_id + '____' + v)){
1372 CAL.destroy_ui(e.id);
1373 e.parentNode.removeChild(e);
1379 CAL.each(arr,function(i,id){
1388 CAL.add_item = function (item){
1390 var edit_all_recurrences = false;
1391 if(typeof item.edit_all_recurrences != "undefined" && item.edit_all_recurrences == 'true')
1392 edit_all_recurrences = true;
1394 if(CAL.view != 'shared'){
1395 var arr = new Array();
1396 if(CAL.enable_repeat && edit_all_recurrences){
1397 var nodes = CAL.query("div.act_item[repeat_parent_id='" + item.record + "']");
1398 CAL.each(nodes,function (i,v){
1399 var record = nodes[i].getAttribute("record");
1400 if(!CAL.contains(arr,record))
1402 nodes[i].parentNode.removeChild(nodes[i]);
1405 CAL.each(arr,function(i,id){
1408 user_id: CAL.current_user_id
1411 CAL.add_item_to_grid(item);
1412 var record_id = item.record;
1413 if(CAL.enable_repeat && typeof item.repeat != "undefined"){
1414 CAL.each(item.repeat,function(j,r){
1415 var clone = CAL.clone(item);
1416 clone.record = r.id;
1417 clone.timestamp = r.timestamp;
1418 clone.ts_start = r.ts_start;
1419 clone.ts_end = r.ts_end;
1420 clone.repeat_parent_id = record_id;
1421 CAL.add_item_to_grid(clone);
1425 CAL.remove_shared(item.record, edit_all_recurrences);
1426 record_id = item.record;
1427 CAL.each(item.users, function (i,user_id){
1428 item.user_id = user_id;
1429 CAL.add_item_to_grid(item);
1430 if(CAL.enable_repeat && typeof item.repeat != "undefined"){
1431 CAL.each(item.repeat,function(j,r){
1432 var clone = CAL.clone(item);
1433 clone.record = r.id;
1434 clone.timestamp = r.timestamp;
1435 clone.ts_start = r.ts_start;
1436 clone.ts_end = r.ts_end;
1437 clone.repeat_parent_id = record_id;
1438 CAL.add_item_to_grid(clone);
1444 CAL.arrange_advanced();
1445 CAL.basic.populate_grid();
1449 CAL.move_activity = function (box_id,slot_id,ex_slot_id){
1451 if(u = CAL.get(box_id)){
1452 if(s = CAL.get(slot_id)){
1455 CAL.destroy_ui(box_id);
1457 CAL.arrange_column(document.getElementById(slot_id).parentNode);
1458 CAL.arrange_column(document.getElementById(ex_slot_id).parentNode);
1459 CAL.update_dd.fire();
1461 CAL.cut_record(box_id);
1462 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),' ... ',u.getAttribute('record'));
1463 var date_field = "date_start";
1464 if(u.getAttribute('module_name') == "Tasks")
1465 date_field = "date_due";
1466 u.setAttribute(date_field,s.getAttribute("datetime"));
1467 u.childNodes[0].childNodes[1].innerHTML = start_text;
1473 CAL.change_activity_type = function (mod_name){
1474 if(typeof CAL.current_params.module_name != "undefined" )
1475 if(CAL.current_params.module_name == mod_name)
1478 var e, user_name, user_id, date_start;
1479 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1480 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;
1481 CAL.current_params.module_name = mod_name;
1482 QSFieldsArray = new Array();
1483 QSProcessedFieldsArray = new Array();
1485 CAL.load_create_form(CAL.current_params);
1490 CAL.load_create_form = function (params){
1492 CAL.disable_buttons();
1494 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
1496 CAL.repeat_tab_handle(CAL.current_params.module_name);
1500 success: function(o){
1502 res = eval("("+o.responseText+")");
1504 alert(CAL.lbl_error_loading);
1505 CAL.editDialog.cancel();
1506 ajaxStatus.hideStatus();
1509 if(res.access == 'yes'){
1510 var fc = document.getElementById("form_content");
1511 CAL.script_evaled = false;
1512 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
1514 if(!CAL.script_evaled){
1515 SUGAR.util.evalScript(res.html);
1518 CAL.get("record").value = "";
1519 CAL.get("current_module").value = res.module_name;
1520 var mod_name = res.module_name;
1523 CAL.record_editable = true;
1525 CAL.record_editable = false;
1528 CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
1530 if(typeof res.repeat != "undefined"){
1531 CAL.fill_repeat_tab(res.repeat);
1534 CAL.enable_buttons();
1536 setTimeout(function(){
1537 SugarWidgetScheduler.update_time();
1539 disableOnUnloadEditView();
1542 ajaxStatus.hideStatus();
1544 alert(CAL.lbl_error_loading);
1545 ajaxStatus.hideStatus();
1548 failure: function() {
1549 alert(CAL.lbl_error_loading);
1550 ajaxStatus.hideStatus();
1554 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1556 "current_module" : params.module_name,
1557 "assigned_user_id" : params.user_id,
1558 "assigned_user_name" : params.user_name,
1559 "date_start" : params.date_start
1561 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1564 CAL.full_form = function() {
1565 var e = document.createElement('input');
1566 e.setAttribute('type', 'hidden');
1567 e.setAttribute('name', 'module');
1568 e.value = CAL.get('current_module').value;
1569 CAL.get('form_content').parentNode.appendChild(e);
1571 var e = document.createElement('input');
1572 e.setAttribute('type', 'hidden');
1573 e.setAttribute('name', 'action');
1574 e.value = 'EditView';
1575 CAL.get('form_content').parentNode.appendChild(e);
1577 document.forms['CalendarEditView'].action = "index.php";
1578 document.forms['CalendarEditView'].full_form = "true";
1579 document.forms['CalendarEditView'].submit();
1583 CAL.disable_buttons = function() {
1584 CAL.get("btn-save").setAttribute("disabled","disabled");
1585 CAL.get("btn-send-invites").setAttribute("disabled","disabled");
1586 CAL.get("btn-delete").setAttribute("disabled","disabled");
1587 CAL.get("btn-full-form").setAttribute("disabled","disabled");
1588 if (CAL.enable_repeat) {
1589 CAL.get("btn-edit-all-recurrences").setAttribute("disabled","disabled");
1590 CAL.get("btn-remove-all-recurrences").setAttribute("disabled","disabled");
1594 CAL.enable_buttons = function() {
1595 CAL.get("btn-save").removeAttribute("disabled");
1596 CAL.get("btn-send-invites").removeAttribute("disabled");
1597 if (CAL.get("record").value != "")
1598 CAL.get("btn-delete").removeAttribute("disabled");
1599 CAL.get("btn-full-form").removeAttribute("disabled");
1600 if (CAL.enable_repeat) {
1601 CAL.get("btn-edit-all-recurrences").removeAttribute("disabled");
1602 CAL.get("btn-remove-all-recurrences").removeAttribute("disabled");
1607 CAL.dialog_create = function (cell){
1609 var e,user_id,user_name;
1610 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1611 CAL.open_edit_dialog();
1613 CAL.disable_buttons();
1615 var module_name = CAL.get("current_module").value;
1617 if(CAL.view == 'shared'){
1618 user_name = cell.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("user_name");
1619 user_id = cell.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("user_id");
1620 CAL.GR_update_user(user_id);
1622 user_id = CAL.current_user_id;
1623 user_name = CAL.current_user_name;
1624 CAL.GR_update_user(CAL.current_user_id);
1628 'module_name': module_name,
1630 'user_name': user_name,
1631 'date_start': cell.getAttribute("datetime")
1633 CAL.current_params = params;
1634 CAL.load_create_form(CAL.current_params);
1638 CAL.dialog_save = function(){
1640 CAL.disable_buttons();
1642 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1644 if (CAL.get("send_invites").value == "1") {
1645 CAL.get("title-cal-edit").innerHTML = CAL.lbl_sending;
1647 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
1650 CAL.fill_invitees();
1651 CAL.fill_repeat_data();
1654 success: function(o){
1656 res = eval("("+o.responseText+")");
1658 alert(CAL.lbl_error_saving);
1659 CAL.editDialog.cancel();
1660 ajaxStatus.hideStatus();
1663 if(res.access == 'yes'){
1665 if(typeof res.limit_error != "undefined"){
1666 var alert_msg = CAL.lbl_repeat_limit_error;
1667 alert(alert_msg.replace("\$limit",res.limit));
1668 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1669 ajaxStatus.hideStatus();
1670 CAL.enable_buttons();
1675 CAL.editDialog.cancel();
1677 ajaxStatus.hideStatus();
1679 alert(CAL.lbl_error_saving);
1680 ajaxStatus.hideStatus();
1683 failure: function(){
1684 alert(CAL.lbl_error_saving);
1685 ajaxStatus.hideStatus();
1688 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
1689 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1690 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1693 CAL.remove_all_recurrences = function(){
1695 if(confirm(CAL.lbl_confirm_remove_all_recurring)){
1696 if(CAL.get("repeat_parent_id").value != ''){
1697 CAL.get("record").value = CAL.get("repeat_parent_id").value;
1699 CAL.get("edit_all_recurrences").value = true;
1700 CAL.dialog_remove();
1705 CAL.dialog_remove = function(){
1706 CAL.deleted_id = CAL.get("record").value;
1707 CAL.deleted_module = CAL.get("current_module").value;
1709 var remove_all_recurrences = CAL.get("edit_all_recurrences").value;
1711 var isRecurrence = false;
1712 if (CAL.enable_repeat) {
1713 if (CAL.get("repeat_parent_id").value != '') {
1714 var isRecurrence = true;
1716 if (document.CalendarRepeatForm.repeat_type.value != '') {
1717 var isRecurrence = true;
1723 success: function(o){
1725 res = eval("("+o.responseText+")");
1727 alert(CAL.lbl_error_saving);
1728 CAL.editDialog.cancel();
1729 ajaxStatus.hideStatus();
1734 if(e = CAL.get(CAL.deleted_id))
1735 cell_id = e.parentNode.id;
1737 if(CAL.view == 'shared'){
1738 if (remove_all_recurrences && isRecurrence) {
1741 CAL.remove_shared(CAL.deleted_id, remove_all_recurrences);
1745 if(e = CAL.get(CAL.deleted_id)){
1746 e.parentNode.removeChild(e);
1747 CAL.destroy_ui(CAL.deleted_id);
1751 record: CAL.deleted_id,
1752 user_id: CAL.current_user_id
1755 if(CAL.enable_repeat && remove_all_recurrences && isRecurrence){
1760 CAL.records_openable = true;
1761 CAL.disable_creating = false;
1763 CAL.arrange_advanced();
1764 CAL.basic.populate_grid();
1768 failure: function(){
1769 alert(CAL.lbl_error_saving);
1774 "current_module" : CAL.deleted_module,
1775 "record" : CAL.deleted_id,
1776 "remove_all_recurrences": remove_all_recurrences
1778 var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";
1779 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1781 CAL.editDialog.cancel();
1784 CAL.refresh = function () {
1787 success: function(o) {
1790 var activities = eval("("+o.responseText+")");
1792 alert(CAL.lbl_error_saving);
1793 ajaxStatus.hideStatus();
1797 CAL.each(activities, function(i, v) {
1798 CAL.add_item_to_grid(activities[i]);
1801 CAL.arrange_advanced();
1802 CAL.basic.populate_grid();
1804 CAL.update_dd.fire();
1814 var url = "index.php?module=Calendar&action=getActivities&sugar_body_only=true";
1815 YAHOO.util.Connect.asyncRequest('POST', url, callback, CAL.toURI(data));
1820 CAL.clear = function () {
1821 CAL.basic.items = {};
1822 var nodes = CAL.query("#cal-grid div.act_item");
1823 CAL.each(nodes, function(i,v) {
1824 nodes[i].parentNode.removeChild(nodes[i]);
1828 CAL.show_additional_details = function (id){
1830 var obj = CAL.get(id);
1831 var record = obj.getAttribute("record");
1832 var module_name = obj.getAttribute("module_name");
1833 SUGAR.util.getAdditionalDetails(module_name, record, 'div_'+id, true);
1837 CAL.clear_additional_details = function (id){
1838 if(typeof SUGAR.util.additionalDetailsCache[id] != "undefined")
1839 SUGAR.util.additionalDetailsCache[id] = undefined;
1840 if(typeof SUGAR.util.additionalDetailsCalls[id] != "undefined")
1841 SUGAR.util.additionalDetailsCalls[id] = undefined;
1844 CAL.toggle_shared_edit = function (){
1846 var sd = CAL.get("shared_cal_edit");
1847 if(!CAL.sharedDialog){
1848 CAL.sharedDialog = new YAHOO.widget.Dialog("shared_cal_edit",{
1855 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.sharedDialog.cancel();} } );
1856 CAL.sharedDialog.cfg.queueProperty("keylisteners", listeners);
1858 CAL.sharedDialog.cancelEvent.subscribe(function(e, a, o){
1859 //CAL.get("form_settings").reset();
1861 sd.style.display = "block";
1862 CAL.sharedDialog.render();
1863 CAL.sharedDialog.show();
1866 CAL.goto_date_call = function (){
1867 var date_string = CAL.get("goto_date").value;
1869 date_arr = date_string.split("/");
1871 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];
1874 CAL.check_forms = function (){
1875 if(!(check_form('CalendarEditView') && cal_isValidDuration())){
1876 CAL.select_tab("cal-tab-1");
1879 if(CAL.enable_repeat && CAL.get("edit_all_recurrences").value != ""){
1880 lastSubmitTime = lastSubmitTime - 2001; // allow to run check second time
1881 if(!check_form('CalendarRepeatForm')){
1882 CAL.select_tab("cal-tab-3");
1889 CAL.toURI = function (a){
1892 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1894 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1896 t.push(x+"="+encodeURIComponent(a[x]));
1901 CAL.each = function (object, callback) {
1903 if(typeof object == "undefined")
1906 length = object.length,
1907 isObj = (length === undefined) || (typeof (object) === "function");
1909 for (name in object) {
1910 if (callback.call(object[name], name, object[name]) === false) {
1915 for (; i < length;) {
1916 if (callback.call(object[i], i, object[i++]) === false) {
1924 CAL.clone = function (o) {
1925 var c = new Object();
1931 CAL.contains = function(a, obj){
1939 CAL.update_vcal = function(){
1941 var v = CAL.current_user_id;
1943 success: function(result){
1944 if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
1945 GLOBAL_REGISTRY.freebusy = new Object();
1947 if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
1948 GLOBAL_REGISTRY.freebusy_adjusted = new Object();
1950 // parse vCal and put it in the registry using the user_id as a key:
1951 GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);
1952 // parse for current user adjusted vCal
1953 GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
1954 SugarWidgetScheduler.update_time();
1958 var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;
1959 YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
1962 CAL.fit_grid = function(control_call){
1964 if (CAL.view == 'year') {
1969 var cal_width = document.getElementById("cal-width-helper").offsetWidth;
1975 var left_width = 80;
1976 if(CAL.style == "basic"){
1977 if(CAL.view != "month"){
1983 if(CAL.view == "day"){
1984 day_width = parseInt((cal_width - left_width - 10));
1985 if(typeof control_call == "undefined" || !control_call){
1986 setTimeout(function(){
1988 setTimeout(function(){
1994 day_width = parseInt((cal_width - left_width) / 7);
1997 var nodes = CAL.query("#cal-grid div.col");
1998 CAL.each(nodes, function(i,v){
1999 nodes[i].style.width = day_width + "px";
2002 var nodes = CAL.query("#cal-grid .cal-basic .act_item");
2003 CAL.each(nodes, function(i,v){
2004 var days = nodes[i].getAttribute('days');
2005 nodes[i].style.width = (day_width * days - 1) + "px";
2007 document.getElementById("cal-grid").style.visibility = "";
2012 YAHOO.util.DDCAL = function(id, sGroup, config){
2013 this.cont = config.cont;
2014 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
2016 YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, {
2019 YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
2020 this.initConstraints();
2021 CAL.update_dd.subscribe(function(type, args, dd){
2022 dd.resetConstraints();
2023 dd.initConstraints();
2026 initConstraints: function() {
2027 var region = YAHOO.util.Dom.getRegion(this.cont);
2028 var el = this.getEl();
2030 var xy = YAHOO.util.Dom.getXY(el);
2031 var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
2032 var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10);
2033 var left = xy[0] - region.left;
2034 var right = region.right - xy[0] - width;
2035 var top = xy[1] - region.top;
2036 var bottom = region.bottom - xy[1] - height;
2039 this.setXConstraint(left, right);
2040 this.setYConstraint(top, bottom);
2045 CAL.remove_edit_dialog();
2047 var cal_loaded = true;