1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 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);
291 var related_to = document.createElement("div");
292 related_to.setAttribute("class","content");
293 if(params.content_style != "") {
294 related_to.style[params.content_style] = params.content_style_value;
296 if (params.related_to){
297 related_to.innerHTML = params.related_to;
299 el.appendChild(related_to);
306 el.setAttribute("id",id);
307 el.className = "act_item" + " " + item.type+"_item";
308 el.style.backgroundColor = CAL.activity_colors[item.module_name]['body'];
309 el.style.borderColor = CAL.activity_colors[item.module_name]['border'];
311 el.setAttribute("record",params.id);
312 el.setAttribute("module_name",item.module_name);
313 el.setAttribute("record",item.record);
314 el.setAttribute("status",item.status);
315 el.setAttribute("detail",item.detail);
316 el.setAttribute("edit",item.edit);
317 if(typeof item.repeat_parent_id != "undefined" && item.repeat_parent_id != "")
318 el.setAttribute("repeat_parent_id",item.repeat_parent_id);
319 if(params.type == "basic"){
320 el.style.left = "-1px";
321 el.style.display = "block";
322 el.setAttribute("days",params.days);
323 el.style.width = ((params.days)*100) + "%";
324 el.style.top = parseInt(params.position * CAL.slot_height - params.slot.childNodes.length * (CAL.slot_height + 1)) + "px";
327 el.style.height = parseInt((CAL.slot_height + 1) * params.duration_coef - 1) + "px";
328 el.setAttribute("duration_coef",params.duration_coef);
331 YAHOO.util.Event.on(el,"mouseover",function(){
332 if(!CAL.records_openable)
334 CAL.disable_creating = true;
336 if(e = CAL.get(el.id))
339 YAHOO.util.Event.on(el,"mouseout",function(event){
340 if(!CAL.records_openable)
342 var node = event.toElement || event.relatedTarget;
348 node = node.parentNode;
351 CAL.get(el.id).style.zIndex = '';
352 CAL.disable_creating = false;
355 CAL.clear_additional_details(params.id);
360 CAL.make_draggable = function (id,type){
368 if(CAL.view != "month" && CAL.view != "shared")
369 border = "cal-multiday-bar";
373 if(CAL.view != "month")
374 border = "cal-scrollable";
379 var dd = new YAHOO.util.DDCAL(id,prefix+"cal",{isTarget: false,cont: border});
381 CAL.dd_registry[id] = dd;
383 dd.onInvalidDrop = function(e){
385 CAL.basic.populate_grid();
388 CAL.arrange_slot(this.el.parentNode.getAttribute("id"));
389 if(CAL.dropped == 0){
390 this.el.childNodes[0].innerHTML = CAL.tmp_header;
393 CAL.records_openable = true;
394 CAL.disable_creating = false;
397 dd.onMouseDown = function(e){
398 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
399 YAHOO.util.DDM.clickPixelThresh = 20;
402 dd.onMouseUp = function(e){
403 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
404 YAHOO.util.DDM.clickPixelThresh = 3;
407 dd.startDrag = function(x,y){
409 this.el = document.getElementById(this.id);
410 this.el.style.zIndex = 5;
412 CAL.records_openable = false;
413 CAL.disable_creating = true;
414 CAL.tmp_header = this.el.childNodes[0].innerHTML;
415 CAL.moved_from_cell = this.el.parentNode.id;
420 dd.endDrag = function(x,y){
421 this.el = document.getElementById(this.id);
422 this.el.style.zIndex = "";
424 var nodes = CAL.query("#cal-grid div."+prefix+"slot");
425 CAL.each(nodes,function(i,v){
426 YAHOO.util.Dom.removeClass(nodes[i],"slot_active");
430 dd.onDragDrop = function(e,id){
432 var slot = document.getElementById(id);
433 YAHOO.util.Dom.removeClass(slot,"slot_active");
434 if(CAL.dropped) // prevent dropping on two slots in same time
438 this.el.style.position = "relative";
439 this.el.style.cssFloat = "none";
441 if(type == "advanced"){
442 if(CAL.view != 'shared'){
443 var box_id = this.id;
445 var ex_slot_id = CAL.moved_from_cell;
446 CAL.move_activity(box_id,slot_id,ex_slot_id);
448 var record = this.el.getAttribute("record");
450 var tar = tid.split("_");
451 var timestamp = tar[1];
452 var tid = CAL.moved_from_cell;
453 var tar = tid.split("_");
454 var ex_timestamp = tar[1];
456 for(i = 0; i < CAL.shared_users_count; i++){
457 var box_id = record + "____" + i;
458 var slot_id = id_prefix + timestamp + "_" + i;
459 var ex_slot_id = id_prefix + ex_timestamp + "_" + i;
460 CAL.move_activity(box_id,slot_id,ex_slot_id);
466 success: function(o){
468 res = eval("("+o.responseText+")");
470 alert(CAL.lbl_error_saving);
471 ajaxStatus.hideStatus();
474 if(res.access == 'yes'){
476 CAL.disable_creating = false;
477 CAL.records_openable = true;
479 ajaxStatus.hideStatus();
482 if (res.errorMessage != 'undefined') {
483 alert(res.errorMessage);
486 ajaxStatus.hideStatus();
491 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
492 var url = "index.php?module=Calendar&action=Reschedule&sugar_body_only=true";
494 "current_module" : this.el.getAttribute("module_name"),
495 "record" : this.el.getAttribute("record"),
496 "datetime" : slot.getAttribute("datetime"),
497 "calendar_style" : type
499 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
501 YAHOO.util.Dom.removeClass(slot,"slot_active");
505 dd.onDragOver = function(e,id){
506 var slot = document.getElementById(id);
507 if(!YAHOO.util.Dom.hasClass(slot,"slot_active"))
508 YAHOO.util.Dom.addClass(slot,"slot_active");
509 if(type == "advanced")
510 this.el.childNodes[0].childNodes[1].childNodes[0].innerHTML = slot.getAttribute('time');
513 dd.onDragOut = function(e,id){
514 var slot = document.getElementById(id);
515 YAHOO.util.Dom.removeClass(slot,"slot_active");
519 CAL.make_resizable = function (id,slot){
521 var pos = 0, e = slot;
522 while(e = e.previousSibling){
525 var max_height = (CAL.cells_per_day - pos) * (CAL.slot_height + 1) - 1;
527 var resize = new YAHOO.util.Resize(id,{
529 maxHeight : max_height
532 CAL.resize_registry[id] = resize;
534 resize.on('startResize', function(e){
535 var el = CAL.get(id);
539 CAL.records_openable = false;
540 CAL.disable_creating = true;
542 resize.on('endResize', function(e){
546 var duration = e.height / (CAL.slot_height + 1) * CAL.t_step;
547 var remainder = duration % 15;
549 remainder = (-1) * (15 - remainder);
550 duration = duration - remainder;
551 var duration_hours = parseInt(duration / 60);
552 var duration_minutes = duration % 60;
554 var new_size = (duration / CAL.t_step) * (CAL.slot_height + 1) - 1;
556 var el = CAL.get(elm_id);
558 el.style.zIndex = '';
559 el.style.height = new_size + "px";
560 CAL.arrange_slot(slot.id);
562 var nodes = CAL.query("#cal-grid div.act_item");
563 CAL.each(nodes,function(i,v){
564 nodes[i].style.zIndex = '';
567 var duration_coef = duration / CAL.t_step;
568 el.setAttribute("duration_coef",duration_coef);
569 if(duration_coef < 1.75){
570 el.childNodes[1].style.display = "none";
571 if (el.childNodes[2]){
572 el.childNodes[2].style.display = "none";
576 el.childNodes[1].style.display = "";
577 if (el.childNodes[2]){
578 el.childNodes[2].style.display = "";
583 success: function(o){
585 res = eval("("+o.responseText+")");
587 alert(CAL.lbl_error_saving);
588 ajaxStatus.hideStatus();
591 if(res.access == 'yes'){
593 CAL.clear_additional_details(el.getAttribute("record"));
594 CAL.arrange_column(slot.parentNode);
595 CAL.update_dd.fire();
596 ajaxStatus.hideStatus();
597 CAL.disable_creating = false;
598 CAL.records_openable = true;
602 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
603 var url = "index.php?module=Calendar&action=Resize&sugar_body_only=true";
605 "current_module" : el.getAttribute("module_name"),
606 "record" : el.getAttribute("record"),
607 "duration_hours" : duration_hours,
608 "duration_minutes" : duration_minutes
610 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
615 CAL.destroy_ui = function (id){
616 if(CAL.items_resizable && typeof CAL.resize_registry[id] != "undefined"){
617 CAL.resize_registry[id].destroy();
618 delete CAL.resize_registry[id];
620 if(CAL.items_draggable && typeof CAL.dd_registry[id] != "undefined")
621 CAL.dd_registry[id].unreg();
622 delete CAL.dd_registry[id];
625 CAL.basic.remove = function (item){
626 if(typeof CAL.basic.items[item.user_id] == 'undefined')
627 CAL.basic.items[item.user_id] = new Object();
628 delete CAL.basic.items[item.user_id][item.record];
631 CAL.basic.add = function (item){
632 if(typeof CAL.basic.items[item.user_id] == 'undefined')
633 CAL.basic.items[item.user_id] = new Object();
634 CAL.basic.items[item.user_id][item.record] = item;
637 CAL.basic.populate_grid = function(){
639 var nodes = CAL.query("#cal-grid .cal-basic .col .act_item");
640 CAL.each(nodes,function(i,v){
641 nodes[i].parentNode.removeChild(nodes[i]);
644 var users_arr = new Array();
645 if(CAL.view != "shared"){
646 users_arr.push(CAL.current_user_id);
648 CAL.each(CAL.shared_users,function(i,v){
653 for(ui = 0; ui < users_arr.length; ui++){
655 var user_id = users_arr[ui];
658 if(CAL.view == 'shared'){
659 suffix = "_" + CAL.shared_users[user_id];
660 id_suffix = '____' + CAL.shared_users[user_id];
664 if(CAL.view == "day")
667 var portions_count = 1;
668 if(CAL.view == "month"){
669 var e = CAL.get("b_" + CAL.grid_start_ts + suffix);
671 portions_count = e.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes.length;
676 var start = CAL.grid_start_ts;
678 for(w = 0; w < portions_count; w++){
680 var end = start + step * 3600 * 24;
681 var portion = Array();
683 CAL.each(CAL.basic.items[user_id],function(id,item){
685 var c = !((item.ts_start < start && item.ts_end <= start) || (end <= item.ts_start && end <= item.ts_end));
687 if(item.ts_start < start)
690 var from = item.ts_start;
691 if(end <= item.ts_end)
694 var to = item.ts_end;
705 portion.sort(function(a,b){
706 return a.offset - b.offset;
709 var equalizer = Array();
710 for(i = 0; i < step; i++){
714 CAL.each(portion,function(i,v){
715 var from = (portion[i].from - start) / (3600 * 24);
716 var to = (portion[i].to - start) / (3600 * 24);
719 for(d = from; d < to; d++){
720 if(equalizer[d] > pos)
723 for(d = from; d < to; d++){
724 equalizer[d] = pos + 1;
727 portion[i].position = pos;
728 portion[i].days = to - from;
733 var item = CAL.basic.items[user_id][portion[i].id];
735 var slot = CAL.get("b_" + portion[i].from + suffix);
737 var time_start = item.time_start;
738 if(item.ts_start < start)
739 time_start = "... ";
741 var head_text = CAL.get_header_text(item.type,time_start,item.name,item.record);
743 var el = CAL.create_item({
746 head_text: head_text,
748 position: portion[i].position,
750 id_suffix: id_suffix,
751 days: portion[i].days
754 YAHOO.util.Event.on(el,"click",function(){
755 if(this.getAttribute('detail') == "1")
756 CAL.load_form(this.getAttribute('module_name'),this.getAttribute('record'),false);
759 slot.appendChild(el);
761 if(CAL.items_draggable && item.edit == 1){
762 CAL.make_draggable(el.getAttribute("id"),"basic");
767 h = parseInt((max_pos + 1) * CAL.slot_height + (CAL.slot_height + 1));
768 if(h < CAL.basic.min_height)
769 h = CAL.basic.min_height;
772 var height_string = h + "px";
773 var row = CAL.get("b_" + start + suffix).parentNode.parentNode;
776 row.parentNode.childNodes[0].childNodes[0].style.height = height_string;
777 CAL.each(row.childNodes,function(i,v){
778 if(typeof row.childNodes[i] == 'object')
779 row.childNodes[i].childNodes[0].style.height = height_string;
782 start = start + step * 3600 * 24;
789 CAL.add_item_to_grid = function (item){
794 if( item.user_id != "" && CAL.view == 'shared'){
795 suffix = "_" + CAL.shared_users[item.user_id];
796 id_suffix = '____' + CAL.shared_users[item.user_id];
799 var e = CAL.get(item.record + id_suffix);
801 e.parentNode.removeChild(e);
802 CAL.destroy_ui(item.record + id_suffix);
805 CAL.basic.remove(item);
806 //Add item to top grid if items have a duration > 1 day and view style is basic
807 if(CAL.style == "basic" || item.days > 1){
812 var head_text = CAL.get_header_text(item.type,item.time_start,item.name,item.record);
813 var time_cell = item.timestamp - item.timestamp % (CAL.t_step * 60);
815 if(item.module_name == 'Tasks'){
818 if((item.duration_minutes < CAL.t_step) && (item.duration_hours == 0))
821 duration_coef = (parseInt(item.duration_hours) * 60 + parseInt(item.duration_minutes)) / CAL.t_step;
824 var item_text = SUGAR.language.languages.app_list_strings[item.type +'_status_dom'][item.status];
825 var related_to = item.related_to;
827 var content_style = "";
828 var content_style_value = "";
829 if(duration_coef < 1.75) {
830 content_style = "display";
831 content_style_value = "none";
834 var elm_id = item.record + id_suffix;
836 var el = CAL.create_item({
839 head_text: head_text,
840 duration_coef: duration_coef,
842 id_suffix: id_suffix,
843 item_text: item_text,
844 content_style: content_style,
845 content_style_value: content_style_value,
846 related_to: related_to
849 YAHOO.util.Event.on(el,"click",function(){
850 if(this.getAttribute('detail') == "1")
851 CAL.load_form(this.getAttribute('module_name'),this.getAttribute('record'),false);
854 if(slot = CAL.get("t_" + time_cell + suffix)){
856 slot.appendChild(el);
859 if(CAL.items_draggable)
860 CAL.make_draggable(elm_id,"advanced");
861 if(item.module_name != "Tasks" && CAL.items_resizable)
862 CAL.make_resizable(elm_id,slot);
865 CAL.cut_record(item.record + id_suffix);
866 //CAL.arrange_slot("t_" + time_cell + suffix);
868 // Bug59353 - fix of appointment overlaps to another user on shared Calendar
869 if (CAL.view == "shared"){
870 var end_time = $("#"+slot.id).parents("div:first").children("div:last").attr("time");
871 var end_time_id = $("#"+slot.id).parents("div:first").children("div:last").attr("id");
872 if (end_time && end_time_id){
873 var end_timestamp = parseInt(end_time_id.match(/t_([0-9]+)_.*/)[1]) + 1800;
874 var share_coef = (end_timestamp - parseInt(item.timestamp)) / 1800;
875 if (share_coef < duration_coef)
876 el.style.height = parseInt((CAL.slot_height + 1) * share_coef - 1) + "px";
883 CAL.get_header_text = function (type,time_start,text,record){
884 var start_text = (CAL.view=='month')?("<span class='start_time'>" + time_start + "</span> " + text) : text;
888 CAL.cut_record = function (id){
889 var el = CAL.get(id);
892 var duration_coef = el.getAttribute("duration_coef");
893 real_celcount = CAL.cells_per_day;
895 var s = el.parentNode;
896 while(s.previousSibling){
898 s = s.previousSibling;
901 if(real_celcount - celpos - duration_coef < 0)
902 duration_coef = real_celcount - celpos + 1;
903 el.style.height = parseInt((CAL.slot_height + 1) * duration_coef - 1) + "px";
906 CAL.init_edit_dialog = function (params){
907 CAL.editDialog = false;
909 var rd = CAL.get("cal-edit");
910 var content = CAL.get("edit-dialog-content");
912 if(CAL.dashlet && rd){
913 document.getElementById("content").appendChild(rd);
916 rd.style.width = params.width + "px";
917 content.style.height = params.height + "px";
918 content.style.overflow = "auto";
919 content.style.padding = "0";
921 CAL.editDialog = new YAHOO.widget.Dialog("cal-edit",{
929 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
930 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
932 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){
933 CAL.close_edit_dialog();
936 rd.style.display = "block";
937 CAL.editDialog.render();
939 rd.style.overflow = "auto";
940 rd.style.overflowX = "hidden";
941 rd.style.outline = "0 none";
942 rd.style.height = "auto";
946 CAL.open_edit_dialog = function (params){
948 document.getElementById("form_content").innerHTML = "";
950 CAL.editDialog.center();
951 CAL.editDialog.show();
953 var nodes = CAL.query("#cal-tabs li a");
954 CAL.each(nodes,function(i,v){
955 YAHOO.util.Event.on(nodes[i], 'click', function(){
956 CAL.select_tab(this.getAttribute("tabname"));
961 if(typeof params != "undefined" && typeof params.stay_on_tab != "undefined" && params.stay_on_tab)
965 var nodes_li = CAL.query("#cal-tabs li");
966 CAL.each(nodes_li,function(j,v){
967 CAL.dom.removeClass(nodes_li[j],"selected");
969 CAL.dom.addClass(nodes_li[j],"selected");
972 var nodes = CAL.query(".yui-nav");
973 CAL.each(nodes,function(i,v){
974 nodes[i].style.overflowX = "visible";
980 CAL.close_edit_dialog = function (){
981 CAL.reset_edit_dialog();
984 CAL.remove_edit_dialog = function(){
985 var rd_c = CAL.get("cal-edit_c");
987 rd_c.parentNode.removeChild(rd_c);
991 CAL.reset_edit_dialog = function (){
994 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
996 CAL.get("radio_call").removeAttribute("disabled");
997 CAL.get("radio_meeting").removeAttribute("disabled");
998 CAL.get("radio_call").checked = false;
999 CAL.get("radio_meeting").checked = true;
1001 CAL.get("send_invites").value = "";
1003 if(e = CAL.get("record"))
1006 if(e = CAL.get("list_div_win"))
1007 e.style.display = "none";
1009 if(typeof SugarWidgetSchedulerSearch.hideCreateForm != 'undefined')
1010 SugarWidgetSchedulerSearch.hideCreateForm();
1012 $("#scheduler .schedulerInvitees").css("display", "");
1013 $("#create-invitees-title").css("display", "");
1014 $("#create-invitees-buttons").css("display", "");
1016 if(CAL.enable_repeat){
1017 CAL.reset_repeat_form();
1020 CAL.GR_update_focus("Meetings","");
1021 CAL.select_tab("cal-tab-1");
1023 QSFieldsArray = new Array();
1024 QSProcessedFieldsArray = new Array();
1027 CAL.reset_repeat_form = function (){
1028 document.forms['CalendarRepeatForm'].reset();
1029 var fields = ['type','interval','count','until','dow'];
1030 CAL.each(fields,function(i,field){
1031 CAL.get('repeat_' + field).value = "";
1033 toggle_repeat_type();
1034 CAL.get("repeat_parent_id").value = "";
1035 CAL.get("edit_all_recurrences").value = "";
1036 CAL.get("edit_all_recurrences_block").style.display = "none";
1037 CAL.get("cal-repeat-block").style.display = "none";
1040 CAL.select_tab = function (tid){
1041 var nodes_li = CAL.query("#cal-tabs li");
1042 CAL.each(nodes_li,function(j,v){
1043 CAL.dom.removeClass(nodes_li[j],"selected");
1046 CAL.dom.addClass(CAL.get(tid + "-link").parentNode,"selected");
1048 var nodes = CAL.query("#cal-tabs .yui-content");
1049 CAL.each(nodes,function(i,v){
1050 nodes[i].style.display = "none";
1052 var nodes = CAL.query("#cal-tabs #"+tid);
1053 CAL.each(nodes,function(i,v){
1054 nodes[i].style.display = "block";
1058 CAL.fill_repeat_data = function (){
1060 if (CAL.enable_repeat && (CAL.get("current_module").value == "Meetings" || CAL.get("current_module").value == "Calls")) {
1061 if(repeat_type = document.forms['CalendarRepeatForm'].repeat_type.value){
1062 document.forms['CalendarEditView'].repeat_type.value = repeat_type;
1063 document.forms['CalendarEditView'].repeat_interval.value = document.forms['CalendarRepeatForm'].repeat_interval.value;
1064 if(document.getElementById("repeat_count_radio").checked){
1065 document.forms['CalendarEditView'].repeat_count.value = document.forms['CalendarRepeatForm'].repeat_count.value;
1066 document.forms['CalendarEditView'].repeat_until.value = "";
1068 document.forms['CalendarEditView'].repeat_until.value = document.forms['CalendarRepeatForm'].repeat_until.value;
1069 document.forms['CalendarEditView'].repeat_count.value = "";
1071 if(repeat_type == 'Weekly'){
1072 var repeat_dow = "";
1073 for(var i = 0; i < 7; i++)
1074 if(CAL.get("repeat_dow_" + i).checked)
1075 repeat_dow += i.toString();
1076 CAL.get("repeat_dow").value = repeat_dow;
1082 CAL.fill_repeat_tab = function(data){
1084 if(!CAL.enable_repeat)
1087 if(typeof data.repeat_parent_id != "undefined"){
1088 CAL.get("cal-repeat-block").style.display = "none";
1089 CAL.get("edit_all_recurrences_block").style.display = "";
1090 CAL.get("edit_all_recurrences").value = "";
1091 CAL.get("repeat_parent_id").value = data.repeat_parent_id;
1095 CAL.get("cal-repeat-block").style.display = "";
1097 var repeat_type = "";
1098 var set_default_repeat_until = true;
1099 if(typeof data.repeat_type != "undefined"){
1100 repeat_type = data.repeat_type;
1102 document.forms['CalendarRepeatForm'].repeat_type.value = data.repeat_type;
1103 document.forms['CalendarRepeatForm'].repeat_interval.value = data.repeat_interval;
1104 if(data.repeat_count != '' && data.repeat_count != 0){
1105 document.forms['CalendarRepeatForm'].repeat_count.value = data.repeat_count;
1106 CAL.get("repeat_count_radio").checked = true;
1107 CAL.get("repeat_until_radio").checked = false;
1109 document.forms['CalendarRepeatForm'].repeat_until.value = data.repeat_until;
1110 CAL.get("repeat_until_radio").checked = true;
1111 CAL.get("repeat_count_radio").checked = false;
1112 set_default_repeat_until = false;
1114 if(data.repeat_type == "Weekly"){
1115 var arr = data.repeat_dow.split("");
1116 CAL.each(arr,function(i,d){
1117 CAL.get("repeat_dow_" + d).checked = true;
1121 CAL.get("cal-repeat-block").style.display = "";
1122 CAL.get("edit_all_recurrences_block").style.display = "none";
1123 toggle_repeat_type();
1126 CAL.get("edit_all_recurrences").value = "true";
1128 if(typeof data.current_dow != "undefined" && repeat_type != "Weekly")
1129 CAL.get("repeat_dow_" + data.current_dow).checked = true;
1131 if(typeof data.default_repeat_until != "undefined" && set_default_repeat_until)
1132 CAL.get("repeat_until_input").value = data.default_repeat_until;
1137 CAL.repeat_tab_handle = function (module_name){
1138 if(!CAL.enable_repeat)
1140 CAL.reset_repeat_form();
1141 if(module_name == "Meetings" || module_name == "Calls"){
1142 CAL.get("tab_repeat").style.display = "";
1144 CAL.get("tab_repeat").style.display = "none";
1147 toggle_repeat_type();
1151 CAL.GR_update_user = function (user_id){
1153 success: function(o){
1154 res = eval(o.responseText);
1155 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;
1156 //SugarWidgetScheduler.update_time();
1162 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";
1163 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1167 CAL.GR_update_focus = function (module,record){
1169 GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
1170 SugarWidgetScheduler.update_time();
1173 success: function(o){
1174 res = eval(o.responseText);
1175 SugarWidgetScheduler.update_time();
1176 if(CAL.record_editable){
1177 CAL.enable_buttons();
1182 var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;
1183 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1187 CAL.toggle_settings = function (){
1188 var sd = CAL.get("settings_dialog");
1191 if(!CAL.settingsDialog){
1192 CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{
1199 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
1200 CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
1202 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
1203 CAL.get("form_settings").reset();
1205 sd.style.display = "block";
1206 CAL.settingsDialog.render();
1207 CAL.settingsDialog.show();
1211 CAL.fill_invitees = function (){
1213 CAL.get("user_invitees").value = "";
1214 CAL.get("contact_invitees").value = "";
1215 CAL.get("lead_invitees").value = "";
1217 CAL.each( GLOBAL_REGISTRY['focus'].users_arr, function(i,v){
1218 var field_name = "";
1219 if(v.module == "User")
1220 field_name = "user_invitees";
1221 if(v.module == "Contact")
1222 field_name = "contact_invitees";
1223 if(v.module == "Lead")
1224 field_name = "lead_invitees";
1225 var str = CAL.get(field_name).value;
1226 CAL.get(field_name).value = str + v.fields.id + ",";
1232 CAL.repeat_type_selected = function (){
1234 if(rt = CAL.get("repeat_type")){
1235 if(rt.value == 'Weekly'){
1236 var nodes = CAL.query(".weeks_checks_div");
1237 CAL.each(nodes,function (i,v){
1238 nodes[i].style.display = "block";
1241 var nodes = CAL.query(".weeks_checks_div");
1242 CAL.each(nodes,function (i,v){
1243 nodes[i].style.display = "none";
1248 CAL.get("repeat_interval").setAttribute("disabled","disabled");
1249 CAL.get("repeat_end_date").setAttribute("disabled","disabled");
1251 CAL.get("repeat_interval").removeAttribute("disabled");
1252 CAL.get("repeat_end_date").removeAttribute("disabled");
1257 CAL.load_form = function (module_name, record, edit_all_recurrences){
1259 CAL.disable_creating = true;
1263 if(module_name == "Tasks")
1266 if(to_open && CAL.records_openable){
1267 CAL.get("form_content").style.display = "none";
1269 CAL.disable_buttons();
1271 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1273 CAL.repeat_tab_handle(module_name);
1275 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
1278 if(edit_all_recurrences)
1279 params = {stay_on_tab: true};
1281 CAL.open_edit_dialog(params);
1282 CAL.get("record").value = "";
1284 if(!edit_all_recurrences)
1285 edit_all_recurrences = "";
1289 success: function(o){
1291 res = eval("("+o.responseText+")");
1293 alert(CAL.lbl_error_loading);
1294 CAL.editDialog.cancel();
1295 ajaxStatus.hideStatus();
1298 if(res.access == 'yes'){
1300 var fc = document.getElementById("form_content");
1301 CAL.script_evaled = false;
1302 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
1303 if(!CAL.script_evaled){
1304 SUGAR.util.evalScript(res.html);
1307 CAL.get("record").value = res.record;
1308 CAL.get("current_module").value = res.module_name;
1310 var mod_name = res.module_name;
1312 if(mod_name == "Meetings")
1313 CAL.get("radio_meeting").checked = true;
1314 if(mod_name == "Calls")
1315 CAL.get("radio_call").checked = true;
1318 CAL.record_editable = true;
1320 CAL.record_editable = false;
1323 CAL.get("radio_call").setAttribute("disabled","disabled");
1324 CAL.get("radio_meeting").setAttribute("disabled","disabled");
1328 SugarWidgetScheduler.update_time();
1329 if(CAL.record_editable){
1330 CAL.enable_buttons();
1333 CAL.get("form_content").style.display = "";
1335 if(typeof res.repeat != "undefined"){
1336 CAL.fill_repeat_tab(res.repeat);
1339 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1340 ajaxStatus.hideStatus();
1341 CAL.get("btn-save").focus();
1343 setTimeout(function(){
1345 $("#scheduler .schedulerInvitees").css("display", "none");
1346 $("#create-invitees-buttons").css("display", "none");
1347 $("#create-invitees-title").css("display", "none");
1350 disableOnUnloadEditView();
1353 alert(CAL.lbl_error_loading);
1356 failure: function(){
1357 alert(CAL.lbl_error_loading);
1360 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1362 "current_module" : module_name,
1364 "edit_all_recurrences" : edit_all_recurrences
1366 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1373 CAL.edit_all_recurrences = function (){
1374 var record = CAL.get("record").value;
1375 if(CAL.get("repeat_parent_id").value != ""){
1376 record = CAL.get("repeat_parent_id").value;
1377 CAL.get("repeat_parent_id").value = "";
1379 var module = CAL.get("current_module").value;
1381 CAL.load_form(module, record, true);
1386 CAL.remove_shared = function (record_id, edit_all_recurrences){
1387 if(typeof edit_all_recurrences == "undefined")
1388 edit_all_recurrences = false;
1391 var arr = new Array();
1392 if(CAL.enable_repeat && edit_all_recurrences){
1393 var nodes = CAL.query("div.act_item[repeat_parent_id='" + record_id + "']");
1394 CAL.each(nodes,function (i,v){
1395 var record = nodes[i].getAttribute("record");
1396 if(!CAL.contains(arr,record))
1398 nodes[i].parentNode.removeChild(nodes[i]);
1399 CAL.destroy_ui(nodes[i].id);
1403 CAL.each(CAL.shared_users,function(user_id,v){
1404 if(e = CAL.get(record_id + '____' + v)){
1405 CAL.destroy_ui(e.id);
1406 e.parentNode.removeChild(e);
1412 CAL.each(arr,function(i,id){
1421 CAL.add_item = function (item){
1423 var edit_all_recurrences = false;
1424 if(typeof item.edit_all_recurrences != "undefined" && item.edit_all_recurrences == 'true')
1425 edit_all_recurrences = true;
1427 if(CAL.view != 'shared'){
1428 var arr = new Array();
1429 if(CAL.enable_repeat && edit_all_recurrences){
1430 var nodes = CAL.query("div.act_item[repeat_parent_id='" + item.record + "']");
1431 CAL.each(nodes,function (i,v){
1432 var record = nodes[i].getAttribute("record");
1433 if(!CAL.contains(arr,record))
1435 nodes[i].parentNode.removeChild(nodes[i]);
1438 CAL.each(arr,function(i,id){
1441 user_id: CAL.current_user_id
1444 CAL.add_item_to_grid(item);
1445 var record_id = item.record;
1446 if(CAL.enable_repeat && typeof item.repeat != "undefined"){
1447 CAL.each(item.repeat,function(j,r){
1448 var clone = CAL.clone(item);
1449 clone.record = r.id;
1450 clone.timestamp = r.timestamp;
1451 clone.ts_start = r.ts_start;
1452 clone.ts_end = r.ts_end;
1453 clone.repeat_parent_id = record_id;
1454 CAL.add_item_to_grid(clone);
1458 CAL.remove_shared(item.record, edit_all_recurrences);
1459 record_id = item.record;
1460 CAL.each(item.users, function (i,user_id){
1461 item.user_id = user_id;
1462 CAL.add_item_to_grid(item);
1463 if(CAL.enable_repeat && typeof item.repeat != "undefined"){
1464 CAL.each(item.repeat,function(j,r){
1465 var clone = CAL.clone(item);
1466 clone.record = r.id;
1467 clone.timestamp = r.timestamp;
1468 clone.ts_start = r.ts_start;
1469 clone.ts_end = r.ts_end;
1470 clone.repeat_parent_id = record_id;
1471 CAL.add_item_to_grid(clone);
1477 CAL.arrange_advanced();
1478 CAL.basic.populate_grid();
1482 CAL.move_activity = function (box_id,slot_id,ex_slot_id){
1484 if(u = CAL.get(box_id)){
1485 if(s = CAL.get(slot_id)){
1488 CAL.destroy_ui(box_id);
1490 CAL.arrange_column(document.getElementById(slot_id).parentNode);
1491 CAL.arrange_column(document.getElementById(ex_slot_id).parentNode);
1492 CAL.update_dd.fire();
1494 CAL.cut_record(box_id);
1495 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),' ... ',u.getAttribute('record'));
1496 var date_field = "date_start";
1497 if(u.getAttribute('module_name') == "Tasks")
1498 date_field = "date_due";
1499 u.setAttribute(date_field,s.getAttribute("datetime"));
1500 u.childNodes[0].childNodes[1].innerHTML = start_text;
1506 CAL.change_activity_type = function (mod_name){
1507 if(typeof CAL.current_params.module_name != "undefined" )
1508 if(CAL.current_params.module_name == mod_name)
1511 var e, user_name, user_id, date_start;
1512 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1513 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;
1514 CAL.current_params.module_name = mod_name;
1515 QSFieldsArray = new Array();
1516 QSProcessedFieldsArray = new Array();
1518 CAL.load_create_form(CAL.current_params);
1523 CAL.load_create_form = function (params){
1525 CAL.disable_buttons();
1527 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
1529 CAL.repeat_tab_handle(CAL.current_params.module_name);
1533 success: function(o){
1535 res = eval("("+o.responseText+")");
1537 alert(CAL.lbl_error_loading);
1538 CAL.editDialog.cancel();
1539 ajaxStatus.hideStatus();
1542 if(res.access == 'yes'){
1543 var fc = document.getElementById("form_content");
1544 CAL.script_evaled = false;
1545 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
1547 if(!CAL.script_evaled){
1548 SUGAR.util.evalScript(res.html);
1551 CAL.get("record").value = "";
1552 CAL.get("current_module").value = res.module_name;
1553 var mod_name = res.module_name;
1556 CAL.record_editable = true;
1558 CAL.record_editable = false;
1561 CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
1563 if(typeof res.repeat != "undefined"){
1564 CAL.fill_repeat_tab(res.repeat);
1567 CAL.enable_buttons();
1569 setTimeout(function(){
1570 SugarWidgetScheduler.update_time();
1572 disableOnUnloadEditView();
1575 ajaxStatus.hideStatus();
1577 alert(CAL.lbl_error_loading);
1578 ajaxStatus.hideStatus();
1581 failure: function() {
1582 alert(CAL.lbl_error_loading);
1583 ajaxStatus.hideStatus();
1587 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1589 "current_module" : params.module_name,
1590 "assigned_user_id" : params.user_id,
1591 "assigned_user_name" : params.user_name,
1592 "date_start" : params.date_start
1594 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1597 CAL.full_form = function() {
1598 var e = document.createElement('input');
1599 e.setAttribute('type', 'hidden');
1600 e.setAttribute('name', 'module');
1601 e.value = CAL.get('current_module').value;
1602 CAL.get('form_content').parentNode.appendChild(e);
1604 var e = document.createElement('input');
1605 e.setAttribute('type', 'hidden');
1606 e.setAttribute('name', 'action');
1607 e.value = 'EditView';
1608 CAL.get('form_content').parentNode.appendChild(e);
1610 document.forms['CalendarEditView'].action = "index.php";
1611 document.forms['CalendarEditView'].full_form = "true";
1612 document.forms['CalendarEditView'].submit();
1616 CAL.disable_buttons = function() {
1617 CAL.get("btn-save").setAttribute("disabled","disabled");
1618 CAL.get("btn-send-invites").setAttribute("disabled","disabled");
1619 CAL.get("btn-delete").setAttribute("disabled","disabled");
1620 CAL.get("btn-full-form").setAttribute("disabled","disabled");
1621 if (CAL.enable_repeat) {
1622 CAL.get("btn-edit-all-recurrences").setAttribute("disabled","disabled");
1623 CAL.get("btn-remove-all-recurrences").setAttribute("disabled","disabled");
1627 CAL.enable_buttons = function() {
1628 CAL.get("btn-save").removeAttribute("disabled");
1629 CAL.get("btn-send-invites").removeAttribute("disabled");
1630 if (CAL.get("record").value != "")
1631 CAL.get("btn-delete").removeAttribute("disabled");
1632 CAL.get("btn-full-form").removeAttribute("disabled");
1633 if (CAL.enable_repeat) {
1634 CAL.get("btn-edit-all-recurrences").removeAttribute("disabled");
1635 CAL.get("btn-remove-all-recurrences").removeAttribute("disabled");
1640 CAL.dialog_create = function (cell){
1642 var e,user_id,user_name;
1643 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
1644 CAL.open_edit_dialog();
1646 CAL.disable_buttons();
1648 var module_name = CAL.get("current_module").value;
1650 if(CAL.view == 'shared'){
1651 // Pick the div that contains 2 custom attributes we
1652 // use for storing values in case of 'shared' view
1653 parentWithUserValues = $('div[user_id][user_name]');
1654 // Pull out the values
1655 user_name = parentWithUserValues.attr('user_name');
1656 user_id = parentWithUserValues.attr('user_id');
1658 // Shared by multiple users, need to get attributes from user whom is clicked
1659 if (parentWithUserValues.length > 1) {
1660 var theUserName, theUserId;
1661 var theUser = cell.parentNode;
1663 if (theUser.getAttribute("user_name") && theUser.getAttribute("user_id")) {
1664 theUserName = theUser.getAttribute("user_name");
1665 theUserId = theUser.getAttribute("user_id");
1669 theUser = theUser.parentNode;
1672 // Found user in the parentNode iteration, use it
1673 if (theUserName && theUserId) {
1674 user_name = theUserName;
1675 user_id = theUserId;
1679 CAL.GR_update_user(user_id);
1681 user_id = CAL.current_user_id;
1682 user_name = CAL.current_user_name;
1683 CAL.GR_update_user(CAL.current_user_id);
1687 'module_name': module_name,
1689 'user_name': user_name,
1690 'date_start': cell.getAttribute("datetime")
1692 CAL.current_params = params;
1693 CAL.load_create_form(CAL.current_params);
1697 CAL.dialog_save = function(){
1699 CAL.disable_buttons();
1701 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1703 if (CAL.get("send_invites").value == "1") {
1704 CAL.get("title-cal-edit").innerHTML = CAL.lbl_sending;
1706 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
1709 CAL.fill_invitees();
1710 CAL.fill_repeat_data();
1713 success: function(o){
1715 res = eval("("+o.responseText+")");
1717 alert(CAL.lbl_error_saving);
1718 CAL.editDialog.cancel();
1719 ajaxStatus.hideStatus();
1722 if(res.access == 'yes'){
1724 if(typeof res.limit_error != "undefined"){
1725 var alert_msg = CAL.lbl_repeat_limit_error;
1726 alert(alert_msg.replace("\$limit",res.limit));
1727 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1728 ajaxStatus.hideStatus();
1729 CAL.enable_buttons();
1734 CAL.editDialog.cancel();
1736 ajaxStatus.hideStatus();
1738 alert(CAL.lbl_error_saving);
1739 ajaxStatus.hideStatus();
1742 failure: function(){
1743 alert(CAL.lbl_error_saving);
1744 ajaxStatus.hideStatus();
1747 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
1748 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1749 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1752 CAL.remove_all_recurrences = function(){
1754 if(confirm(CAL.lbl_confirm_remove_all_recurring)){
1755 if(CAL.get("repeat_parent_id").value != ''){
1756 CAL.get("record").value = CAL.get("repeat_parent_id").value;
1758 CAL.get("edit_all_recurrences").value = true;
1759 CAL.dialog_remove();
1764 CAL.dialog_remove = function(){
1765 CAL.deleted_id = CAL.get("record").value;
1766 CAL.deleted_module = CAL.get("current_module").value;
1768 var remove_all_recurrences = CAL.get("edit_all_recurrences").value;
1770 var isRecurrence = false;
1771 if (CAL.enable_repeat) {
1772 if (CAL.get("repeat_parent_id").value != '') {
1773 var isRecurrence = true;
1775 if (document.CalendarRepeatForm.repeat_type.value != '') {
1776 var isRecurrence = true;
1782 success: function(o){
1784 res = eval("("+o.responseText+")");
1786 alert(CAL.lbl_error_saving);
1787 CAL.editDialog.cancel();
1788 ajaxStatus.hideStatus();
1793 if(e = CAL.get(CAL.deleted_id))
1794 cell_id = e.parentNode.id;
1796 if(CAL.view == 'shared'){
1797 if (remove_all_recurrences && isRecurrence) {
1800 CAL.remove_shared(CAL.deleted_id, remove_all_recurrences);
1804 if(e = CAL.get(CAL.deleted_id)){
1805 e.parentNode.removeChild(e);
1806 CAL.destroy_ui(CAL.deleted_id);
1810 record: CAL.deleted_id,
1811 user_id: CAL.current_user_id
1814 if(CAL.enable_repeat && remove_all_recurrences && isRecurrence){
1819 CAL.records_openable = true;
1820 CAL.disable_creating = false;
1822 CAL.arrange_advanced();
1823 CAL.basic.populate_grid();
1827 failure: function(){
1828 alert(CAL.lbl_error_saving);
1833 "current_module" : CAL.deleted_module,
1834 "record" : CAL.deleted_id,
1835 "remove_all_recurrences": remove_all_recurrences
1837 var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";
1838 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1840 CAL.editDialog.cancel();
1843 CAL.refresh = function () {
1846 success: function(o) {
1849 var activities = eval("("+o.responseText+")");
1851 alert(CAL.lbl_error_saving);
1852 ajaxStatus.hideStatus();
1856 CAL.each(activities, function(i, v) {
1857 CAL.add_item_to_grid(activities[i]);
1860 CAL.arrange_advanced();
1861 CAL.basic.populate_grid();
1863 CAL.update_dd.fire();
1873 var url = "index.php?module=Calendar&action=getActivities&sugar_body_only=true";
1874 YAHOO.util.Connect.asyncRequest('POST', url, callback, CAL.toURI(data));
1879 CAL.clear = function () {
1880 CAL.basic.items = {};
1881 var nodes = CAL.query("#cal-grid div.act_item");
1882 CAL.each(nodes, function(i,v) {
1883 nodes[i].parentNode.removeChild(nodes[i]);
1887 CAL.show_additional_details = function (id){
1889 var obj = CAL.get(id);
1890 var record = obj.getAttribute("record");
1891 var module_name = obj.getAttribute("module_name");
1892 SUGAR.util.getAdditionalDetails(module_name, record, 'div_'+id, true);
1896 CAL.clear_additional_details = function (id){
1897 if(typeof SUGAR.util.additionalDetailsCache[id] != "undefined")
1898 SUGAR.util.additionalDetailsCache[id] = undefined;
1899 if(typeof SUGAR.util.additionalDetailsCalls[id] != "undefined")
1900 SUGAR.util.additionalDetailsCalls[id] = undefined;
1903 CAL.toggle_shared_edit = function (){
1905 var sd = CAL.get("shared_cal_edit");
1906 if(!CAL.sharedDialog){
1907 CAL.sharedDialog = new YAHOO.widget.Dialog("shared_cal_edit",{
1914 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.sharedDialog.cancel();} } );
1915 CAL.sharedDialog.cfg.queueProperty("keylisteners", listeners);
1917 CAL.sharedDialog.cancelEvent.subscribe(function(e, a, o){
1918 //CAL.get("form_settings").reset();
1920 sd.style.display = "block";
1921 CAL.sharedDialog.render();
1922 CAL.sharedDialog.show();
1925 CAL.goto_date_call = function (){
1926 var date_string = CAL.get("goto_date").value;
1928 date_arr = date_string.split("/");
1930 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];
1933 CAL.check_forms = function (){
1934 if(!(check_form('CalendarEditView') && cal_isValidDuration())){
1935 CAL.select_tab("cal-tab-1");
1938 if(CAL.enable_repeat && CAL.get("edit_all_recurrences").value != ""){
1939 lastSubmitTime = lastSubmitTime - 2001; // allow to run check second time
1940 if(!check_form('CalendarRepeatForm')){
1941 CAL.select_tab("cal-tab-3");
1948 CAL.toURI = function (a){
1951 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1953 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1955 t.push(x+"="+encodeURIComponent(a[x]));
1960 CAL.each = function (object, callback) {
1962 if(typeof object == "undefined")
1965 length = object.length,
1966 isObj = (length === undefined) || (typeof (object) === "function");
1968 for (name in object) {
1969 if (callback.call(object[name], name, object[name]) === false) {
1974 for (; i < length;) {
1975 if (callback.call(object[i], i, object[i++]) === false) {
1983 CAL.clone = function (o) {
1984 var c = new Object();
1990 CAL.contains = function(a, obj){
1998 CAL.update_vcal = function(){
2000 var v = CAL.current_user_id;
2002 success: function(result){
2003 if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
2004 GLOBAL_REGISTRY.freebusy = new Object();
2006 if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
2007 GLOBAL_REGISTRY.freebusy_adjusted = new Object();
2009 // parse vCal and put it in the registry using the user_id as a key:
2010 GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);
2011 // parse for current user adjusted vCal
2012 GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
2013 SugarWidgetScheduler.update_time();
2017 var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;
2018 YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
2021 CAL.fit_grid = function(control_call){
2023 if (CAL.view == 'year') {
2027 var container_width = document.getElementById("cal-width-helper").offsetWidth;
2028 var left_column_width = 53;
2029 var scroll_padding = 0;
2032 if (CAL.view == "day")
2033 container_width = 720;
2035 container_width = 800;
2038 var is_scrollable = document.getElementById("cal-scrollable");
2039 if (is_scrollable) {
2040 scroll_padding = 30;
2044 var data_width = container_width - left_column_width - scroll_padding;
2047 if(CAL.view == "day"){
2049 if(typeof control_call == "undefined" || !control_call){
2050 setTimeout(function(){
2052 setTimeout(function(){
2061 var columns_width = CAL.calculate_columns_width(data_width, num_columns);
2062 var cell_nodes = CAL.query("#cal-grid div.col");
2063 CAL.each(cell_nodes, function(i)
2065 cell_nodes[i].style.width = columns_width[i % num_columns] + "px";
2068 document.getElementById("cal-grid").style.visibility = "";
2071 CAL.calculate_columns_width = function(width, count)
2074 var integer = Math.floor(width / count);
2075 var remainder = width - count * integer;
2077 for (var i = 1, value; i <= count; i++)
2080 if (dispensed * count < i * remainder) {
2089 YAHOO.util.DDCAL = function(id, sGroup, config){
2090 this.cont = config.cont;
2091 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
2093 YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, {
2096 YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
2097 this.initConstraints();
2098 CAL.update_dd.subscribe(function(type, args, dd){
2099 dd.resetConstraints();
2100 dd.initConstraints();
2103 initConstraints: function() {
2104 var region = YAHOO.util.Dom.getRegion(this.cont);
2105 var el = this.getEl();
2107 var xy = YAHOO.util.Dom.getXY(el);
2108 var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
2109 var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10);
2110 var left = xy[0] - region.left;
2111 var right = region.right - xy[0] - width;
2112 var top = xy[1] - region.top;
2113 var bottom = region.bottom - xy[1] - height;
2116 this.setXConstraint(left, right);
2117 this.setYConstraint(top, bottom);
2122 CAL.remove_edit_dialog();
2124 var cal_loaded = true;