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",{
897 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
898 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
900 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){
901 CAL.close_edit_dialog();
904 rd.style.display = "block";
905 CAL.editDialog.render();
907 rd.style.overflow = "auto";
908 rd.style.overflowX = "hidden";
909 rd.style.outline = "0 none";
910 rd.style.height = "auto";
914 CAL.open_edit_dialog = function (params){
916 document.getElementById("form_content").innerHTML = "";
918 CAL.editDialog.center();
919 CAL.editDialog.show();
921 var nodes = CAL.query("#cal-tabs li a");
922 CAL.each(nodes,function(i,v){
923 YAHOO.util.Event.on(nodes[i], 'click', function(){
924 CAL.select_tab(this.getAttribute("tabname"));
929 if(typeof params != "undefined" && typeof params.stay_on_tab != "undefined" && params.stay_on_tab)
933 var nodes_li = CAL.query("#cal-tabs li");
934 CAL.each(nodes_li,function(j,v){
935 CAL.dom.removeClass(nodes_li[j],"selected");
937 CAL.dom.addClass(nodes_li[j],"selected");
940 var nodes = CAL.query(".yui-nav");
941 CAL.each(nodes,function(i,v){
942 nodes[i].style.overflowX = "visible";
948 CAL.close_edit_dialog = function (){
949 CAL.reset_edit_dialog();
952 CAL.remove_edit_dialog = function(){
953 var rd_c = CAL.get("cal-edit_c");
955 rd_c.parentNode.removeChild(rd_c);
959 CAL.reset_edit_dialog = function (){
962 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
964 CAL.get("radio_call").removeAttribute("disabled");
965 CAL.get("radio_meeting").removeAttribute("disabled");
966 CAL.get("radio_call").checked = false;
967 CAL.get("radio_meeting").checked = true;
969 CAL.get("send_invites").value = "";
971 if(e = CAL.get("record"))
974 if(e = CAL.get("list_div_win"))
975 e.style.display = "none";
977 if(typeof SugarWidgetSchedulerSearch.hideCreateForm != 'undefined')
978 SugarWidgetSchedulerSearch.hideCreateForm();
980 $("#scheduler .schedulerInvitees").css("display", "");
981 $("#create-invitees-title").css("display", "");
982 $("#create-invitees-buttons").css("display", "");
984 if(CAL.enable_repeat){
985 CAL.reset_repeat_form();
988 CAL.GR_update_focus("Meetings","");
989 CAL.select_tab("cal-tab-1");
991 QSFieldsArray = new Array();
992 QSProcessedFieldsArray = new Array();
995 CAL.reset_repeat_form = function (){
996 document.forms['CalendarRepeatForm'].reset();
997 var fields = ['type','interval','count','until','dow'];
998 CAL.each(fields,function(i,field){
999 CAL.get('repeat_' + field).value = "";
1001 toggle_repeat_type();
1002 CAL.get("repeat_parent_id").value = "";
1003 CAL.get("edit_all_recurrences").value = "";
1004 CAL.get("edit_all_recurrences_block").style.display = "none";
1005 CAL.get("cal-repeat-block").style.display = "none";
1008 CAL.select_tab = function (tid){
1009 var nodes_li = CAL.query("#cal-tabs li");
1010 CAL.each(nodes_li,function(j,v){
1011 CAL.dom.removeClass(nodes_li[j],"selected");
1014 CAL.dom.addClass(CAL.get(tid + "-link").parentNode,"selected");
1016 var nodes = CAL.query("#cal-tabs .yui-content");
1017 CAL.each(nodes,function(i,v){
1018 nodes[i].style.display = "none";
1020 var nodes = CAL.query("#cal-tabs #"+tid);
1021 CAL.each(nodes,function(i,v){
1022 nodes[i].style.display = "block";
1026 CAL.fill_repeat_data = function (){
1028 if (CAL.enable_repeat && (CAL.get("current_module").value == "Meetings" || CAL.get("current_module").value == "Calls")) {
1029 if(repeat_type = document.forms['CalendarRepeatForm'].repeat_type.value){
1030 document.forms['CalendarEditView'].repeat_type.value = repeat_type;
1031 document.forms['CalendarEditView'].repeat_interval.value = document.forms['CalendarRepeatForm'].repeat_interval.value;
1032 if(document.getElementById("repeat_count_radio").checked){
1033 document.forms['CalendarEditView'].repeat_count.value = document.forms['CalendarRepeatForm'].repeat_count.value;
1034 document.forms['CalendarEditView'].repeat_until.value = "";
1036 document.forms['CalendarEditView'].repeat_until.value = document.forms['CalendarRepeatForm'].repeat_until.value;
1037 document.forms['CalendarEditView'].repeat_count.value = "";
1039 if(repeat_type == 'Weekly'){
1040 var repeat_dow = "";
1041 for(var i = 0; i < 7; i++)
1042 if(CAL.get("repeat_dow_" + i).checked)
1043 repeat_dow += i.toString();
1044 CAL.get("repeat_dow").value = repeat_dow;
1050 CAL.fill_repeat_tab = function(data){
1052 if(!CAL.enable_repeat)
1055 if(typeof data.repeat_parent_id != "undefined"){
1056 CAL.get("cal-repeat-block").style.display = "none";
1057 CAL.get("edit_all_recurrences_block").style.display = "";
1058 CAL.get("edit_all_recurrences").value = "";
1059 CAL.get("repeat_parent_id").value = data.repeat_parent_id;
1063 CAL.get("cal-repeat-block").style.display = "";
1065 var repeat_type = "";
1066 var set_default_repeat_until = true;
1067 if(typeof data.repeat_type != "undefined"){
1068 repeat_type = data.repeat_type;
1070 document.forms['CalendarRepeatForm'].repeat_type.value = data.repeat_type;
1071 document.forms['CalendarRepeatForm'].repeat_interval.value = data.repeat_interval;
1072 if(data.repeat_count != '' && data.repeat_count != 0){
1073 document.forms['CalendarRepeatForm'].repeat_count.value = data.repeat_count;
1074 CAL.get("repeat_count_radio").checked = true;
1075 CAL.get("repeat_until_radio").checked = false;
1077 document.forms['CalendarRepeatForm'].repeat_until.value = data.repeat_until;
1078 CAL.get("repeat_until_radio").checked = true;
1079 CAL.get("repeat_count_radio").checked = false;
1080 set_default_repeat_until = false;
1082 if(data.repeat_type == "Weekly"){
1083 var arr = data.repeat_dow.split("");
1084 CAL.each(arr,function(i,d){
1085 CAL.get("repeat_dow_" + d).checked = true;
1089 CAL.get("cal-repeat-block").style.display = "";
1090 CAL.get("edit_all_recurrences_block").style.display = "none";
1091 toggle_repeat_type();
1094 CAL.get("edit_all_recurrences").value = "true";
1096 if(typeof data.current_dow != "undefined" && repeat_type != "Weekly")
1097 CAL.get("repeat_dow_" + data.current_dow).checked = true;
1099 if(typeof data.default_repeat_until != "undefined" && set_default_repeat_until)
1100 CAL.get("repeat_until_input").value = data.default_repeat_until;
1105 CAL.repeat_tab_handle = function (module_name){
1106 if(!CAL.enable_repeat)
1108 CAL.reset_repeat_form();
1109 if(module_name == "Meetings" || module_name == "Calls"){
1110 CAL.get("tab_repeat").style.display = "";
1112 CAL.get("tab_repeat").style.display = "none";
1115 toggle_repeat_type();
1119 CAL.GR_update_user = function (user_id){
1121 success: function(o){
1122 res = eval(o.responseText);
1123 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;
1124 //SugarWidgetScheduler.update_time();
1130 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";
1131 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1135 CAL.GR_update_focus = function (module,record){
1137 GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
1138 SugarWidgetScheduler.update_time();
1141 success: function(o){
1142 res = eval(o.responseText);
1143 SugarWidgetScheduler.update_time();
1144 if(CAL.record_editable){
1145 CAL.enable_buttons();
1150 var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;
1151 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1155 CAL.toggle_settings = function (){
1156 var sd = CAL.get("settings_dialog");
1159 if(!CAL.settingsDialog){
1160 CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{
1167 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
1168 CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
1170 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
1171 CAL.get("form_settings").reset();
1173 sd.style.display = "block";
1174 CAL.settingsDialog.render();
1175 CAL.settingsDialog.show();
1179 CAL.fill_invitees = function (){
1181 CAL.get("user_invitees").value = "";
1182 CAL.get("contact_invitees").value = "";
1183 CAL.get("lead_invitees").value = "";
1185 CAL.each( GLOBAL_REGISTRY['focus'].users_arr, function(i,v){
1186 var field_name = "";
1187 if(v.module == "User")
1188 field_name = "user_invitees";
1189 if(v.module == "Contact")
1190 field_name = "contact_invitees";
1191 if(v.module == "Lead")
1192 field_name = "lead_invitees";
1193 var str = CAL.get(field_name).value;
1194 CAL.get(field_name).value = str + v.fields.id + ",";
1200 CAL.repeat_type_selected = function (){
1202 if(rt = CAL.get("repeat_type")){
1203 if(rt.value == 'Weekly'){
1204 var nodes = CAL.query(".weeks_checks_div");
1205 CAL.each(nodes,function (i,v){
1206 nodes[i].style.display = "block";
1209 var nodes = CAL.query(".weeks_checks_div");
1210 CAL.each(nodes,function (i,v){
1211 nodes[i].style.display = "none";
1216 CAL.get("repeat_interval").setAttribute("disabled","disabled");
1217 CAL.get("repeat_end_date").setAttribute("disabled","disabled");
1219 CAL.get("repeat_interval").removeAttribute("disabled");
1220 CAL.get("repeat_end_date").removeAttribute("disabled");
1225 CAL.load_form = function (module_name, record, edit_all_recurrences){
1227 CAL.disable_creating = true;
1231 if(module_name == "Tasks")
1234 if(to_open && CAL.records_openable){
1235 CAL.get("form_content").style.display = "none";
1237 CAL.disable_buttons();
1239 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1241 CAL.repeat_tab_handle(module_name);
1243 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
1246 if(edit_all_recurrences)
1247 params = {stay_on_tab: true};
1249 CAL.open_edit_dialog(params);
1250 CAL.get("record").value = "";
1252 if(!edit_all_recurrences)
1253 edit_all_recurrences = "";
1257 success: function(o){
1259 res = eval("("+o.responseText+")");
1261 alert(CAL.lbl_error_loading);
1262 CAL.editDialog.cancel();
1263 ajaxStatus.hideStatus();
1266 if(res.access == 'yes'){
1268 var fc = document.getElementById("form_content");
1269 CAL.script_evaled = false;
1270 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
1271 if(!CAL.script_evaled){
1272 SUGAR.util.evalScript(res.html);
1275 CAL.get("record").value = res.record;
1276 CAL.get("current_module").value = res.module_name;
1278 var mod_name = res.module_name;
1280 if(mod_name == "Meetings")
1281 CAL.get("radio_meeting").checked = true;
1282 if(mod_name == "Calls")
1283 CAL.get("radio_call").checked = true;
1286 CAL.record_editable = true;
1288 CAL.record_editable = false;
1291 CAL.get("radio_call").setAttribute("disabled","disabled");
1292 CAL.get("radio_meeting").setAttribute("disabled","disabled");
1296 SugarWidgetScheduler.update_time();
1297 if(CAL.record_editable){
1298 CAL.enable_buttons();
1301 CAL.get("form_content").style.display = "";
1303 if(typeof res.repeat != "undefined"){
1304 CAL.fill_repeat_tab(res.repeat);
1307 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1308 ajaxStatus.hideStatus();
1309 CAL.get("btn-save").focus();
1311 setTimeout(function(){
1313 $("#scheduler .schedulerInvitees").css("display", "none");
1314 $("#create-invitees-buttons").css("display", "none");
1315 $("#create-invitees-title").css("display", "none");
1318 disableOnUnloadEditView();
1321 alert(CAL.lbl_error_loading);
1324 failure: function(){
1325 alert(CAL.lbl_error_loading);
1328 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1330 "current_module" : module_name,
1332 "edit_all_recurrences" : edit_all_recurrences
1334 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1341 CAL.edit_all_recurrences = function (){
1342 var record = CAL.get("record").value;
1343 if(CAL.get("repeat_parent_id").value != ""){
1344 record = CAL.get("repeat_parent_id").value;
1345 CAL.get("repeat_parent_id").value = "";
1347 var module = CAL.get("current_module").value;
1349 CAL.load_form(module, record, true);
1354 CAL.remove_shared = function (record_id, edit_all_recurrences){
1355 if(typeof edit_all_recurrences == "undefined")
1356 edit_all_recurrences = false;
1359 var arr = new Array();
1360 if(CAL.enable_repeat && edit_all_recurrences){
1361 var nodes = CAL.query("div.act_item[repeat_parent_id='" + record_id + "']");
1362 CAL.each(nodes,function (i,v){
1363 var record = nodes[i].getAttribute("record");
1364 if(!CAL.contains(arr,record))
1366 nodes[i].parentNode.removeChild(nodes[i]);
1367 CAL.destroy_ui(nodes[i].id);
1371 CAL.each(CAL.shared_users,function(user_id,v){
1372 if(e = CAL.get(record_id + '____' + v)){
1373 CAL.destroy_ui(e.id);
1374 e.parentNode.removeChild(e);
1380 CAL.each(arr,function(i,id){
1389 CAL.add_item = function (item){
1391 var edit_all_recurrences = false;
1392 if(typeof item.edit_all_recurrences != "undefined" && item.edit_all_recurrences == 'true')
1393 edit_all_recurrences = true;
1395 if(CAL.view != 'shared'){
1396 var arr = new Array();
1397 if(CAL.enable_repeat && edit_all_recurrences){
1398 var nodes = CAL.query("div.act_item[repeat_parent_id='" + item.record + "']");
1399 CAL.each(nodes,function (i,v){
1400 var record = nodes[i].getAttribute("record");
1401 if(!CAL.contains(arr,record))
1403 nodes[i].parentNode.removeChild(nodes[i]);
1406 CAL.each(arr,function(i,id){
1409 user_id: CAL.current_user_id
1412 CAL.add_item_to_grid(item);
1413 var record_id = item.record;
1414 if(CAL.enable_repeat && typeof item.repeat != "undefined"){
1415 CAL.each(item.repeat,function(j,r){
1416 var clone = CAL.clone(item);
1417 clone.record = r.id;
1418 clone.timestamp = r.timestamp;
1419 clone.ts_start = r.ts_start;
1420 clone.ts_end = r.ts_end;
1421 clone.repeat_parent_id = record_id;
1422 CAL.add_item_to_grid(clone);
1426 CAL.remove_shared(item.record, edit_all_recurrences);
1427 record_id = item.record;
1428 CAL.each(item.users, function (i,user_id){
1429 item.user_id = user_id;
1430 CAL.add_item_to_grid(item);
1431 if(CAL.enable_repeat && typeof item.repeat != "undefined"){
1432 CAL.each(item.repeat,function(j,r){
1433 var clone = CAL.clone(item);
1434 clone.record = r.id;
1435 clone.timestamp = r.timestamp;
1436 clone.ts_start = r.ts_start;
1437 clone.ts_end = r.ts_end;
1438 clone.repeat_parent_id = record_id;
1439 CAL.add_item_to_grid(clone);
1445 CAL.arrange_advanced();
1446 CAL.basic.populate_grid();
1450 CAL.move_activity = function (box_id,slot_id,ex_slot_id){
1452 if(u = CAL.get(box_id)){
1453 if(s = CAL.get(slot_id)){
1456 CAL.destroy_ui(box_id);
1458 CAL.arrange_column(document.getElementById(slot_id).parentNode);
1459 CAL.arrange_column(document.getElementById(ex_slot_id).parentNode);
1460 CAL.update_dd.fire();
1462 CAL.cut_record(box_id);
1463 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),' ... ',u.getAttribute('record'));
1464 var date_field = "date_start";
1465 if(u.getAttribute('module_name') == "Tasks")
1466 date_field = "date_due";
1467 u.setAttribute(date_field,s.getAttribute("datetime"));
1468 u.childNodes[0].childNodes[1].innerHTML = start_text;
1474 CAL.change_activity_type = function (mod_name){
1475 if(typeof CAL.current_params.module_name != "undefined" )
1476 if(CAL.current_params.module_name == mod_name)
1479 var e, user_name, user_id, date_start;
1480 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1481 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;
1482 CAL.current_params.module_name = mod_name;
1483 QSFieldsArray = new Array();
1484 QSProcessedFieldsArray = new Array();
1486 CAL.load_create_form(CAL.current_params);
1491 CAL.load_create_form = function (params){
1493 CAL.disable_buttons();
1495 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
1497 CAL.repeat_tab_handle(CAL.current_params.module_name);
1501 success: function(o){
1503 res = eval("("+o.responseText+")");
1505 alert(CAL.lbl_error_loading);
1506 CAL.editDialog.cancel();
1507 ajaxStatus.hideStatus();
1510 if(res.access == 'yes'){
1511 var fc = document.getElementById("form_content");
1512 CAL.script_evaled = false;
1513 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
1515 if(!CAL.script_evaled){
1516 SUGAR.util.evalScript(res.html);
1519 CAL.get("record").value = "";
1520 CAL.get("current_module").value = res.module_name;
1521 var mod_name = res.module_name;
1524 CAL.record_editable = true;
1526 CAL.record_editable = false;
1529 CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
1531 if(typeof res.repeat != "undefined"){
1532 CAL.fill_repeat_tab(res.repeat);
1535 CAL.enable_buttons();
1537 setTimeout(function(){
1538 SugarWidgetScheduler.update_time();
1540 disableOnUnloadEditView();
1543 ajaxStatus.hideStatus();
1545 alert(CAL.lbl_error_loading);
1546 ajaxStatus.hideStatus();
1549 failure: function() {
1550 alert(CAL.lbl_error_loading);
1551 ajaxStatus.hideStatus();
1555 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1557 "current_module" : params.module_name,
1558 "assigned_user_id" : params.user_id,
1559 "assigned_user_name" : params.user_name,
1560 "date_start" : params.date_start
1562 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1565 CAL.full_form = function() {
1566 var e = document.createElement('input');
1567 e.setAttribute('type', 'hidden');
1568 e.setAttribute('name', 'module');
1569 e.value = CAL.get('current_module').value;
1570 CAL.get('form_content').parentNode.appendChild(e);
1572 var e = document.createElement('input');
1573 e.setAttribute('type', 'hidden');
1574 e.setAttribute('name', 'action');
1575 e.value = 'EditView';
1576 CAL.get('form_content').parentNode.appendChild(e);
1578 document.forms['CalendarEditView'].action = "index.php";
1579 document.forms['CalendarEditView'].full_form = "true";
1580 document.forms['CalendarEditView'].submit();
1584 CAL.disable_buttons = function() {
1585 CAL.get("btn-save").setAttribute("disabled","disabled");
1586 CAL.get("btn-send-invites").setAttribute("disabled","disabled");
1587 CAL.get("btn-delete").setAttribute("disabled","disabled");
1588 CAL.get("btn-full-form").setAttribute("disabled","disabled");
1589 if (CAL.enable_repeat) {
1590 CAL.get("btn-edit-all-recurrences").setAttribute("disabled","disabled");
1591 CAL.get("btn-remove-all-recurrences").setAttribute("disabled","disabled");
1595 CAL.enable_buttons = function() {
1596 CAL.get("btn-save").removeAttribute("disabled");
1597 CAL.get("btn-send-invites").removeAttribute("disabled");
1598 if (CAL.get("record").value != "")
1599 CAL.get("btn-delete").removeAttribute("disabled");
1600 CAL.get("btn-full-form").removeAttribute("disabled");
1601 if (CAL.enable_repeat) {
1602 CAL.get("btn-edit-all-recurrences").removeAttribute("disabled");
1603 CAL.get("btn-remove-all-recurrences").removeAttribute("disabled");
1608 CAL.dialog_create = function (cell){
1610 var e,user_id,user_name;
1611 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1612 CAL.open_edit_dialog();
1614 CAL.disable_buttons();
1616 var module_name = CAL.get("current_module").value;
1618 if(CAL.view == 'shared'){
1619 // Pick the div that contains 2 custom attributes we
1620 // use for storing values in case of 'shared' view
1621 parentWithUserValues = $('div[user_id][user_name]');
1622 // Pull out the values
1623 user_name = parentWithUserValues.attr('user_name');
1624 user_id = parentWithUserValues.attr('user_id');
1626 // Shared by multiple users, need to get attributes from user whom is clicked
1627 if (parentWithUserValues.length > 1) {
1628 var theUserName, theUserId;
1629 var theUser = cell.parentNode;
1631 if (theUser.getAttribute("user_name") && theUser.getAttribute("user_id")) {
1632 theUserName = theUser.getAttribute("user_name");
1633 theUserId = theUser.getAttribute("user_id");
1637 theUser = theUser.parentNode;
1640 // Found user in the parentNode iteration, use it
1641 if (theUserName && theUserId) {
1642 user_name = theUserName;
1643 user_id = theUserId;
1647 CAL.GR_update_user(user_id);
1649 user_id = CAL.current_user_id;
1650 user_name = CAL.current_user_name;
1651 CAL.GR_update_user(CAL.current_user_id);
1655 'module_name': module_name,
1657 'user_name': user_name,
1658 'date_start': cell.getAttribute("datetime")
1660 CAL.current_params = params;
1661 CAL.load_create_form(CAL.current_params);
1665 CAL.dialog_save = function(){
1667 CAL.disable_buttons();
1669 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1671 if (CAL.get("send_invites").value == "1") {
1672 CAL.get("title-cal-edit").innerHTML = CAL.lbl_sending;
1674 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
1677 CAL.fill_invitees();
1678 CAL.fill_repeat_data();
1681 success: function(o){
1683 res = eval("("+o.responseText+")");
1685 alert(CAL.lbl_error_saving);
1686 CAL.editDialog.cancel();
1687 ajaxStatus.hideStatus();
1690 if(res.access == 'yes'){
1692 if(typeof res.limit_error != "undefined"){
1693 var alert_msg = CAL.lbl_repeat_limit_error;
1694 alert(alert_msg.replace("\$limit",res.limit));
1695 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1696 ajaxStatus.hideStatus();
1697 CAL.enable_buttons();
1702 CAL.editDialog.cancel();
1704 ajaxStatus.hideStatus();
1706 alert(CAL.lbl_error_saving);
1707 ajaxStatus.hideStatus();
1710 failure: function(){
1711 alert(CAL.lbl_error_saving);
1712 ajaxStatus.hideStatus();
1715 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
1716 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1717 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1720 CAL.remove_all_recurrences = function(){
1722 if(confirm(CAL.lbl_confirm_remove_all_recurring)){
1723 if(CAL.get("repeat_parent_id").value != ''){
1724 CAL.get("record").value = CAL.get("repeat_parent_id").value;
1726 CAL.get("edit_all_recurrences").value = true;
1727 CAL.dialog_remove();
1732 CAL.dialog_remove = function(){
1733 CAL.deleted_id = CAL.get("record").value;
1734 CAL.deleted_module = CAL.get("current_module").value;
1736 var remove_all_recurrences = CAL.get("edit_all_recurrences").value;
1738 var isRecurrence = false;
1739 if (CAL.enable_repeat) {
1740 if (CAL.get("repeat_parent_id").value != '') {
1741 var isRecurrence = true;
1743 if (document.CalendarRepeatForm.repeat_type.value != '') {
1744 var isRecurrence = true;
1750 success: function(o){
1752 res = eval("("+o.responseText+")");
1754 alert(CAL.lbl_error_saving);
1755 CAL.editDialog.cancel();
1756 ajaxStatus.hideStatus();
1761 if(e = CAL.get(CAL.deleted_id))
1762 cell_id = e.parentNode.id;
1764 if(CAL.view == 'shared'){
1765 if (remove_all_recurrences && isRecurrence) {
1768 CAL.remove_shared(CAL.deleted_id, remove_all_recurrences);
1772 if(e = CAL.get(CAL.deleted_id)){
1773 e.parentNode.removeChild(e);
1774 CAL.destroy_ui(CAL.deleted_id);
1778 record: CAL.deleted_id,
1779 user_id: CAL.current_user_id
1782 if(CAL.enable_repeat && remove_all_recurrences && isRecurrence){
1787 CAL.records_openable = true;
1788 CAL.disable_creating = false;
1790 CAL.arrange_advanced();
1791 CAL.basic.populate_grid();
1795 failure: function(){
1796 alert(CAL.lbl_error_saving);
1801 "current_module" : CAL.deleted_module,
1802 "record" : CAL.deleted_id,
1803 "remove_all_recurrences": remove_all_recurrences
1805 var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";
1806 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1808 CAL.editDialog.cancel();
1811 CAL.refresh = function () {
1814 success: function(o) {
1817 var activities = eval("("+o.responseText+")");
1819 alert(CAL.lbl_error_saving);
1820 ajaxStatus.hideStatus();
1824 CAL.each(activities, function(i, v) {
1825 CAL.add_item_to_grid(activities[i]);
1828 CAL.arrange_advanced();
1829 CAL.basic.populate_grid();
1831 CAL.update_dd.fire();
1841 var url = "index.php?module=Calendar&action=getActivities&sugar_body_only=true";
1842 YAHOO.util.Connect.asyncRequest('POST', url, callback, CAL.toURI(data));
1847 CAL.clear = function () {
1848 CAL.basic.items = {};
1849 var nodes = CAL.query("#cal-grid div.act_item");
1850 CAL.each(nodes, function(i,v) {
1851 nodes[i].parentNode.removeChild(nodes[i]);
1855 CAL.show_additional_details = function (id){
1857 var obj = CAL.get(id);
1858 var record = obj.getAttribute("record");
1859 var module_name = obj.getAttribute("module_name");
1860 SUGAR.util.getAdditionalDetails(module_name, record, 'div_'+id, true);
1864 CAL.clear_additional_details = function (id){
1865 if(typeof SUGAR.util.additionalDetailsCache[id] != "undefined")
1866 SUGAR.util.additionalDetailsCache[id] = undefined;
1867 if(typeof SUGAR.util.additionalDetailsCalls[id] != "undefined")
1868 SUGAR.util.additionalDetailsCalls[id] = undefined;
1871 CAL.toggle_shared_edit = function (){
1873 var sd = CAL.get("shared_cal_edit");
1874 if(!CAL.sharedDialog){
1875 CAL.sharedDialog = new YAHOO.widget.Dialog("shared_cal_edit",{
1882 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.sharedDialog.cancel();} } );
1883 CAL.sharedDialog.cfg.queueProperty("keylisteners", listeners);
1885 CAL.sharedDialog.cancelEvent.subscribe(function(e, a, o){
1886 //CAL.get("form_settings").reset();
1888 sd.style.display = "block";
1889 CAL.sharedDialog.render();
1890 CAL.sharedDialog.show();
1893 CAL.goto_date_call = function (){
1894 var date_string = CAL.get("goto_date").value;
1896 date_arr = date_string.split("/");
1898 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];
1901 CAL.check_forms = function (){
1902 if(!(check_form('CalendarEditView') && cal_isValidDuration())){
1903 CAL.select_tab("cal-tab-1");
1906 if(CAL.enable_repeat && CAL.get("edit_all_recurrences").value != ""){
1907 lastSubmitTime = lastSubmitTime - 2001; // allow to run check second time
1908 if(!check_form('CalendarRepeatForm')){
1909 CAL.select_tab("cal-tab-3");
1916 CAL.toURI = function (a){
1919 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1921 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1923 t.push(x+"="+encodeURIComponent(a[x]));
1928 CAL.each = function (object, callback) {
1930 if(typeof object == "undefined")
1933 length = object.length,
1934 isObj = (length === undefined) || (typeof (object) === "function");
1936 for (name in object) {
1937 if (callback.call(object[name], name, object[name]) === false) {
1942 for (; i < length;) {
1943 if (callback.call(object[i], i, object[i++]) === false) {
1951 CAL.clone = function (o) {
1952 var c = new Object();
1958 CAL.contains = function(a, obj){
1966 CAL.update_vcal = function(){
1968 var v = CAL.current_user_id;
1970 success: function(result){
1971 if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
1972 GLOBAL_REGISTRY.freebusy = new Object();
1974 if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
1975 GLOBAL_REGISTRY.freebusy_adjusted = new Object();
1977 // parse vCal and put it in the registry using the user_id as a key:
1978 GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);
1979 // parse for current user adjusted vCal
1980 GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
1981 SugarWidgetScheduler.update_time();
1985 var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;
1986 YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
1989 CAL.fit_grid = function(control_call){
1991 if (CAL.view == 'year') {
1995 var container_width = document.getElementById("cal-width-helper").offsetWidth;
1996 var left_column_width = 53;
1997 var scroll_padding = 0;
2000 if (CAL.view == "day")
2001 container_width = 720;
2003 container_width = 800;
2006 var is_scrollable = document.getElementById("cal-scrollable");
2007 if (is_scrollable) {
2008 scroll_padding = 30;
2012 var data_width = container_width - left_column_width - scroll_padding;
2015 if(CAL.view == "day"){
2017 if(typeof control_call == "undefined" || !control_call){
2018 setTimeout(function(){
2020 setTimeout(function(){
2029 var columns_width = CAL.calculate_columns_width(data_width, num_columns);
2030 var cell_nodes = CAL.query("#cal-grid div.col");
2031 CAL.each(cell_nodes, function(i)
2033 cell_nodes[i].style.width = columns_width[i % num_columns] + "px";
2036 document.getElementById("cal-grid").style.visibility = "";
2039 CAL.calculate_columns_width = function(width, count)
2042 var integer = Math.floor(width / count);
2043 var remainder = width - count * integer;
2045 for (var i = 1, value; i <= count; i++)
2048 if (dispensed * count < i * remainder) {
2057 YAHOO.util.DDCAL = function(id, sGroup, config){
2058 this.cont = config.cont;
2059 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
2061 YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, {
2064 YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
2065 this.initConstraints();
2066 CAL.update_dd.subscribe(function(type, args, dd){
2067 dd.resetConstraints();
2068 dd.initConstraints();
2071 initConstraints: function() {
2072 var region = YAHOO.util.Dom.getRegion(this.cont);
2073 var el = this.getEl();
2075 var xy = YAHOO.util.Dom.getXY(el);
2076 var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
2077 var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10);
2078 var left = xy[0] - region.left;
2079 var right = region.right - xy[0] - width;
2080 var top = xy[1] - region.top;
2081 var bottom = region.bottom - xy[1] - height;
2084 this.setXConstraint(left, right);
2085 this.setYConstraint(top, bottom);
2090 CAL.remove_edit_dialog();
2092 var cal_loaded = true;