1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
40 CAL.records_openable = true;
41 CAL.moved_from_cell = "";
43 CAL.deleted_module = "";
45 CAL.disable_creating = false;
46 CAL.record_editable = false;
49 CAL.shared_users = {};
50 CAL.shared_users_count = 0;
51 CAL.script_evaled = false;
52 CAL.editDialog = false;
53 CAL.settingsDialog = false;
56 CAL.dom = YAHOO.util.Dom;
57 CAL.get = YAHOO.util.Dom.get;
58 CAL.query = YAHOO.util.Selector.query;
60 CAL.arrange_slot = function (cell_id){
63 cellElm = document.getElementById(cell_id);
71 var child_cnt = cellElm.childNodes.length;
72 for(var i = 0; i < child_cnt; i++){
73 var width_p = (92 / child_cnt);
74 width = width_p.toString() + "%";
75 if(cellElm.childNodes[i].tagName == "DIV"){
76 cellElm.childNodes[i].style.top = "-1px";
77 cellElm.childNodes[i].style.left = "-"+(cnt+1)+"px";
78 cellElm.childNodes[i].style.width = width
86 CAL.add_item_to_grid = function (item){
91 if( item.user_id != "" && CAL.view == 'shared'){
92 suffix = "_" + CAL.shared_users[item.user_id];
93 id_suffix = '____' + CAL.shared_users[item.user_id];
96 var e = CAL.get(item.record + id_suffix);
98 e.parentNode.removeChild(e);
101 var duration_text = item.duration_hours + CAL.lbl_hours_abbrev;
102 if(item.duration_minutes > 0)
103 duration_text += item.duration_minutes + CAL.lbl_mins_abbrev;
104 var start_text = CAL.get_header_text(item.type,item.time_start,item.status,item.record);
106 var time_cell = item.timestamp - item.timestamp % (CAL.t_step * 60);
109 if(item.module_name == 'Tasks'){
113 if((item.duration_minutes < CAL.t_step) && (item.duration_hours == 0))
116 duration_coef = (parseInt(item.duration_hours) * 60 + parseInt(item.duration_minutes)) / CAL.t_step;
120 if(CAL.item_text && (typeof item[CAL.item_text] != "undefined") )
121 item_text = item[CAL.item_text];
123 var contain_style = "";
124 if(duration_coef < 1.75)
125 contain_style = "style='display: none;'";
127 var elm_id = item.record + id_suffix;
129 var el = document.createElement("div");
130 el.innerHTML = "<div class='head'><div class='adicon' onmouseover='return CAL.show_additional_details(" + '"' + item.record + id_suffix + '"' + ");' onmouseout='return nd(400);' > </div><div>" + start_text + "</div>" + "" + "</div><div class='contain' "+contain_style+">" + item_text + "</div>";
131 el.className = "act_item" + " " + item.type+"_item";
132 el.setAttribute("id",elm_id);
133 el.setAttribute("module_name",item.module_name);
134 el.setAttribute("record",item.record);
135 el.setAttribute("dur",duration_text);
136 el.setAttribute("subj",item.record_name);
137 el.setAttribute("date_start",item.date_start);
138 el.setAttribute("desc",item.description);
139 el.setAttribute("parent_name",item.parent_name);
140 el.setAttribute("parent_type",item.parent_type);
141 el.setAttribute("parent_id",item.parent_id);
142 el.setAttribute("status",item.status);
143 el.setAttribute("detail",item.detail);
144 el.setAttribute("edit",item.edit);
145 el.setAttribute("duration_coef",duration_coef);
146 el.style.backgroundColor = CAL.activity_colors[item.module_name]['body'];
147 el.style.borderColor = CAL.activity_colors[item.module_name]['border'];
148 el.style.height = parseInt(15 * duration_coef - 1) + "px";
149 YAHOO.util.Event.on(el,"click",function(){
150 if(this.getAttribute('detail') == "1")
151 CAL.load_from(this.getAttribute('module_name'),this.getAttribute('record'),false);
153 YAHOO.util.Event.on(el,"mouseover",function(){
154 if(!CAL.records_openable)
156 CAL.disable_creating = true;
160 if(e = CAL.get(elm_id))
166 YAHOO.util.Event.on(el,"mouseout",function(){
167 if(!CAL.records_openable)
169 clearTimeout(CAL.tp);
170 CAL.get(elm_id).style.zIndex = '';
171 CAL.disable_creating = false;
175 if(slot = CAL.get("t_" + time_cell + suffix)){
176 slot.appendChild(el);
178 if(duration_coef < 1.75 && CAL.mouseover_expand){
179 YAHOO.util.Event.on(elm_id,"mouseover",function(){
180 if(CAL.records_openable)
181 CAL.expand_record(this.getAttribute("id"));
183 YAHOO.util.Event.on(elm_id,"mouseout",function(){
184 CAL.unexpand_record(this.getAttribute("id"));
186 YAHOO.util.Event.on(elm_id,"click",function(){
187 CAL.unexpand_record(this.getAttribute("id"));
191 if(CAL.items_draggable && item.module_name != "Tasks" && item.edit == 1){
193 var border = 'cal-grid';
194 if(CAL.view != "shared" && CAL.view != "month")
195 border = 'cal-scrollable';
197 var dd = new YAHOO.util.DDCAL(elm_id,"cal",{isTarget: false,cont: border});
199 dd.onInvalidDrop = function(e){
200 this.el.style.left = "-1px";
201 this.el.style.top = "-1px";
202 if(CAL.dropped == 0){
203 this.el.childNodes[0].innerHTML = CAL.old_caption;
207 dd.onMouseDown = function(e){
208 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
209 YAHOO.util.DDM.clickPixelThresh = 20;
212 dd.onMouseUp = function(e){
213 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
214 YAHOO.util.DDM.clickPixelThresh = 3;
217 dd.startDrag = function(x,y){
218 this.el = document.getElementById(this.id);
219 this.el.style.zIndex = 5;
221 CAL.records_openable = false;
222 CAL.old_caption = this.el.childNodes[0].innerHTML;
223 CAL.moved_from_cell = this.el.parentNode.id;
228 dd.endDrag = function(x,y){
229 this.el = document.getElementById(this.id);
230 this.el.style.zIndex = "";
232 var nodes = CAL.query("#cal-grid .slot");
233 CAL.each(nodes,function(i,v){
234 YAHOO.util.Dom.removeClass(nodes[i],"slot_active");
238 dd.onDragDrop = function(e,id){
240 var slot = document.getElementById(id);
241 YAHOO.util.Dom.removeClass(slot,"slot_active");
242 if(CAL.dropped) // prevent dropping on two slots in same time
246 this.el.style.position = "relative";
247 this.el.style.cssFloat = "none";
249 if(CAL.view != 'shared'){
250 var box_id = this.id;
252 var ex_slot_id = CAL.moved_from_cell;
253 CAL.move_activity(box_id,slot_id,ex_slot_id);
255 var record = this.el.getAttribute("record");
257 var tar = tid.split("_");
258 var timestamp = tar[1];
259 var tid = CAL.moved_from_cell;
260 var tar = tid.split("_");
261 var ex_timestamp = tar[1];
263 for(i = 0; i < CAL.shared_users_count; i++){
264 var box_id = ""+record+"____"+i;
265 var slot_id = "t_"+timestamp+"_"+i;
266 var ex_slot_id = "t_"+ex_timestamp+"_"+i;
267 CAL.move_activity(box_id,slot_id,ex_slot_id);
272 success: function(o){
273 CAL.records_openable = true;
275 ajaxStatus.hideStatus();
278 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
279 var url = "index.php?module=Calendar&action=Reschedule&sugar_body_only=true";
281 "current_module" : this.el.getAttribute("module_name"),
282 "record" : this.el.getAttribute("record"),
283 "datetime" : slot.getAttribute("datetime")
285 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
288 YAHOO.util.Dom.removeClass(slot,"slot_active");
289 CAL.disable_creating = false;
290 CAL.records_openable = true;
294 dd.onDragOver = function(e,id){
295 var slot = document.getElementById(id);
296 if(!YAHOO.util.Dom.hasClass(slot,"slot_active"))
297 YAHOO.util.Dom.addClass(slot,"slot_active");
298 this.el.childNodes[0].childNodes[1].childNodes[0].innerHTML = slot.getAttribute('time');
301 dd.onDragOut = function(e,id){
302 var slot = document.getElementById(id);
303 YAHOO.util.Dom.removeClass(slot,"slot_active");
307 CAL.cut_record(item.record + id_suffix);
308 CAL.arrange_slot("t_" + time_cell + suffix);
313 CAL.expand_record = function (id){
314 CAL.tp1 = setTimeout(
316 var el = CAL.get(id);
318 el.style.height = parseInt(15 * 2 - 1) + "px";
319 el.childNodes[1].style.display = "block";
326 CAL.unexpand_record = function (id){
327 clearTimeout(CAL.tp1);
328 var el = CAL.get(id);
329 el.style.height = parseInt(15 * CAL.get(id).getAttribute("duration_coef") - 2) + "px";
330 el.childNodes[1].style.display = "none"; //innerHTML = "";
334 CAL.get_header_text = function (type,time_start,status,record){
335 var start_text = "<span class='start_time'>" + time_start + "</span> " + SUGAR.language.languages.app_list_strings[type +'_status_dom'][status];
339 CAL.cut_record = function (id){
341 var el = CAL.get(id);
345 var duration_coef = el.getAttribute("duration_coef");
346 var real_celcount = CAL.celcount;
348 if(CAL.view == 'day' || CAL.view == 'week')
349 real_celcount = CAL.cells_per_day;
352 var s = el.parentNode;
353 while(s.previousSibling){
355 s = s.previousSibling;
358 if(CAL.view == 'week')
361 if(real_celcount - celpos - duration_coef < 0)
362 duration_coef = real_celcount - celpos + 1;
363 el.style.height = parseInt(15 * duration_coef - 1) + "px";
367 CAL.init_edit_dialog = function (params){
368 CAL.editDialog = false;
370 var rd = CAL.get("cal-edit");
371 var content = CAL.get("edit-dialog-content");
373 if(CAL.dashlet && rd){
374 document.getElementById("content").appendChild(rd);
377 rd.style.width = params.width+"px";
378 content.style.height = params.height+"px";
379 content.style.overflow = "auto";
380 content.style.padding = "0";
382 CAL.editDialog = new YAHOO.widget.Dialog("cal-edit",{
390 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
391 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
395 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){
396 CAL.close_edit_dialog();
399 rd.style.display = "block";
400 CAL.editDialog.render();
402 rd.style.overflow = "auto";
403 rd.style.overflowX = "hidden";
404 rd.style.outline = "0 none";
405 rd.style.height = "auto";
410 CAL.open_edit_dialog = function (params){
412 CAL.editDialog.show();
414 var nodes = CAL.query("#cal-tabs li a");
415 CAL.each(nodes,function(i,v){
416 YAHOO.util.Event.on(nodes[i], 'click', function(){
417 var nodes_li = CAL.query("#cal-tabs li");
418 CAL.each(nodes_li,function(j,v){
419 CAL.dom.removeClass(nodes_li[j],"selected");
422 if(!CAL.dom.hasClass(this.parentNode,"selected"))
423 CAL.dom.addClass(this.parentNode,"selected");
424 CAL.select_tab(this.getAttribute("tabname"));
428 var nodes_li = CAL.query("#cal-tabs li");
429 CAL.each(nodes_li,function(j,v){
430 CAL.dom.removeClass(nodes_li[j],"selected");
432 CAL.dom.addClass(nodes_li[j],"selected");
435 var nodes = CAL.query(".yui-nav");
436 CAL.each(nodes,function(i,v){
437 nodes[i].style.overflowX = "visible";
442 CAL.close_edit_dialog = function (){
443 CAL.reset_edit_dialog();
446 CAL.remove_edit_dialog = function(){
447 var rd_c = CAL.get("cal-edit_c");
449 rd_c.parentNode.removeChild(rd_c);
453 CAL.reset_edit_dialog = function (){
456 document.getElementById("form_content").innerHTML = "";
457 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
459 CAL.get("radio_call").removeAttribute("disabled");
460 CAL.get("radio_meeting").removeAttribute("disabled");
461 CAL.get("radio_call").checked = false;
462 CAL.get("radio_meeting").checked = true;
464 CAL.get("send_invites").value = "";
466 if(e = CAL.get("record"))
469 if(e = CAL.get("list_div_win"))
470 e.style.display = "none";
472 /*if(e = CAL.get("edit_all_recurrences_btn"))
473 e.style.display = "none";
475 var nodes = CAL.query("#repeat_type option[value='']");
476 CAL.each(nodes,function(i,v){
477 nodes[i].setAttribute("selected","selected");
480 //CAL.repeat_type_selected();
482 CAL.GR_update_focus("Meetings","");
483 CAL.select_tab("cal-tab-1");
486 CAL.select_tab = function (tid){
487 var nodes = CAL.query("#cal-tabs .yui-content");
488 CAL.each(nodes,function(i,v){
489 nodes[i].style.display = "none";
491 var nodes = CAL.query("#cal-tabs #"+tid);
492 CAL.each(nodes,function(i,v){
493 nodes[i].style.display = "block";
497 CAL.GR_update_user = function (user_id){
500 success: function(o){
501 res = eval(o.responseText);
502 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;
503 //SugarWidgetScheduler.update_time();
510 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";
511 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
515 CAL.GR_update_focus = function (module,record){
517 GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
518 SugarWidgetScheduler.update_time();
521 success: function(o){
522 res = eval(o.responseText);
523 SugarWidgetScheduler.update_time();
524 if(CAL.record_editable){
525 CAL.get("btn-save").removeAttribute("disabled");
526 CAL.get("btn-delete").removeAttribute("disabled");
527 CAL.get("btn-apply").removeAttribute("disabled");
528 CAL.get("btn-send-invites").removeAttribute("disabled");
533 var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;
534 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
538 CAL.toggle_settings = function (){
539 var sd = CAL.get("settings_dialog");
542 if(!CAL.settingsDialog){
543 CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{
550 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
551 CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
553 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
554 CAL.get("form_settings").reset();
556 sd.style.display = "block";
557 CAL.settingsDialog.render();
558 CAL.settingsDialog.show();
561 CAL.toggle_whole_day = function (){
562 var wd = CAL.get("whole_day");
570 var nodes = CAL.query("#cal-grid .owt");
571 CAL.each(nodes,function(i,v){
572 nodes[i].style.display = "block";
575 var nodes = CAL.query("#cal-grid .owt");
576 CAL.each(nodes,function(i,v){
577 nodes[i].style.display = "none";
585 CAL.fill_invitees = function (){
587 CAL.get("user_invitees").value = "";
588 CAL.get("contact_invitees").value = "";
589 CAL.get("lead_invitees").value = "";
591 CAL.each( GLOBAL_REGISTRY['focus'].users_arr, function(i,v){
593 if(v.module == "User")
594 field_name = "user_invitees";
595 if(v.module == "Contact")
596 field_name = "contact_invitees";
597 if(v.module == "Lead")
598 field_name = "lead_invitees";
599 var str = CAL.get(field_name).value;
600 CAL.get(field_name).value = str + v.fields.id + ",";
606 CAL.repeat_type_selected = function (){
608 if(rt = CAL.get("repeat_type")){
609 if(rt.value == 'Weekly'){
610 var nodes = CAL.query(".weeks_checks_div");
611 CAL.each(nodes,function (i,v){
612 nodes[i].style.display = "block";
615 var nodes = CAL.query(".weeks_checks_div");
616 CAL.each(nodes,function (i,v){
617 nodes[i].style.display = "none";
622 CAL.get("repeat_interval").setAttribute("disabled","disabled");
623 CAL.get("repeat_end_date").setAttribute("disabled","disabled");
625 CAL.get("repeat_interval").removeAttribute("disabled");
626 CAL.get("repeat_end_date").removeAttribute("disabled");
631 CAL.load_from = function (module_name,record,run_one_time){
635 if(module_name == "Tasks")
638 if(to_open && CAL.records_openable){
639 CAL.get("form_content").style.display = "none";
641 CAL.get("btn-delete").setAttribute("disabled","disabled");
642 CAL.get("btn-apply").setAttribute("disabled","disabled");
643 CAL.get("btn-save").setAttribute("disabled","disabled");
644 CAL.get("btn-send-invites").setAttribute("disabled","disabled");
646 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
648 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
650 CAL.open_edit_dialog();
651 CAL.get("record").value = "";
656 success: function(o){
657 res = eval("("+o.responseText+")");
658 if(res.success == 'yes'){
659 var fc = document.getElementById("form_content");
660 CAL.script_evaled = false;
661 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
662 if(!CAL.script_evaled){
663 SUGAR.util.evalScript(res.html);
666 CAL.get("record").value = res.record;
667 CAL.get("current_module").value = res.module_name;
669 var mod_name = res.module_name;
671 if(mod_name == "Meetings")
672 CAL.get("radio_meeting").checked = true;
673 if(mod_name == "Calls")
674 CAL.get("radio_call").checked = true;
677 CAL.record_editable = true;
679 CAL.record_editable = false;
682 CAL.get("radio_call").setAttribute("disabled","disabled");
683 CAL.get("radio_meeting").setAttribute("disabled","disabled");
686 SugarWidgetScheduler.update_time();
687 if(CAL.record_editable){
688 CAL.get("btn-save").removeAttribute("disabled");
689 CAL.get("btn-delete").removeAttribute("disabled");
690 CAL.get("btn-apply").removeAttribute("disabled");
691 CAL.get("btn-send-invites").removeAttribute("disabled");
694 CAL.get("form_content").style.display = "";
695 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
696 ajaxStatus.hideStatus();
698 if(typeof changeParentQS != 'undefined')
699 changeParentQS("parent_name");
701 setTimeout(function(){
703 disableOnUnloadEditView();
707 alert(CAL.lbl_error_loading);
711 alert(CAL.lbl_error_loading);
714 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
716 "current_module" : module_name,
719 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
722 CAL.records_openable = true;
726 CAL.remove_shared = function (record_id){
729 if(e = CAL.get(record_id + '____' + "0"))
730 cell_id = e.parentNode.id;
732 if(typeof cell_id != "undefined"){
733 var cell_id_arr = cell_id.split("_");
734 cell_id = "t_" + cell_id_arr[1];
736 CAL.each(CAL.shared_users,function(i,v){
737 if(e = CAL.get(record_id + '____' + v))
738 e.parentNode.removeChild(e);
739 CAL.arrange_slot(cell_id + '_' + v);
744 CAL.add_item = function (item){
746 if(CAL.view != 'shared'){
747 CAL.add_item_to_grid(item);
749 CAL.remove_shared(item.record);
750 record_id = item.record;
751 //var rec_id = item.rec_id;
752 var timestamp = item.timestamp;
757 //rec.rec_id = rec_id;
758 rec.timestamp = timestamp;
760 rec.record = record_id;
761 CAL.add_item_to_grid(rec);
766 rec.record = r.record;
767 rec.timestamp = r.timestamp;
768 //rec.rec_id = record_id;
769 CAL.add_item_to_grid(rec);
778 CAL.move_activity = function (box_id,slot_id,ex_slot_id){
780 if(u = CAL.get(box_id)){
781 if(s = CAL.get(slot_id)){
783 CAL.arrange_slot(slot_id);
784 CAL.arrange_slot(ex_slot_id);
785 CAL.cut_record(box_id);
786 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),u.getAttribute('status'),u.getAttribute('record'));
787 u.setAttribute("date_start",s.getAttribute("datetime"));
788 u.childNodes[0].childNodes[1].innerHTML = start_text;
793 CAL.change_activity_type = function (mod_name){
794 if(typeof CAL.current_params.module_name != "undefined" )
795 if(CAL.current_params.module_name == mod_name)
798 var e,user_name,user_id,date_start;
800 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
802 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;
804 CAL.current_params.module_name = mod_name;
805 CAL.load_create_form(CAL.current_params);
810 CAL.load_create_form = function (params){
812 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
816 success: function(o){
817 res = eval("("+o.responseText+")");
818 if(res.success == 'yes'){
819 var fc = document.getElementById("form_content");
820 CAL.script_evaled = false;
821 fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html;
823 if(!CAL.script_evaled){
824 SUGAR.util.evalScript(res.html);
827 CAL.get("record").value = "";
828 CAL.get("current_module").value = res.module_name;
829 var mod_name = res.module_name;
832 CAL.record_editable = true;
834 CAL.record_editable = false;
837 CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
839 SugarWidgetScheduler.update_time();
841 setTimeout(function(){
843 disableOnUnloadEditView();
846 ajaxStatus.hideStatus();
849 alert(CAL.lbl_error_loading);
850 ajaxStatus.hideStatus();
853 failure: function() {
854 alert(CAL.lbl_error_loading);
855 ajaxStatus.hideStatus();
859 var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
861 "current_module" : params.module_name,
862 "assigned_user_id" : params.user_id,
863 "assigned_user_name" : params.user_name,
864 "date_start" : params.date_start,
865 "duration_hours" : 1,
866 "duration_minutes" : 0
868 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
872 CAL.dialog_create = function (cell){
874 var e,user_id,user_name;
875 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
876 CAL.open_edit_dialog();
877 CAL.get("btn-delete").setAttribute("disabled","disabled");
879 var module_name = CAL.get("current_module").value;
881 if(CAL.view == 'shared'){
882 user_name = cell.parentNode.parentNode.parentNode.getAttribute("user_name");
883 user_id = cell.parentNode.parentNode.parentNode.getAttribute("user_id");
884 CAL.GR_update_user(user_id);
886 user_id = CAL.current_user_id;
887 user_name = CAL.current_user_name;
888 CAL.GR_update_user(CAL.current_user_id);
892 'module_name': module_name,
894 'user_name': user_name,
895 'date_start': cell.getAttribute("datetime")
897 CAL.current_params = params;
898 CAL.load_create_form(CAL.current_params);
902 CAL.dialog_save = function(){
903 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
905 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
907 //CAL.fill_recurrence();
910 success: function(o){
911 res = eval('('+o.responseText+')');
912 if(res.success == 'yes'){
914 CAL.editDialog.cancel();
916 ajaxStatus.hideStatus();
918 alert(CAL.lbl_error_saving);
919 ajaxStatus.hideStatus();
923 alert(CAL.lbl_error_saving);
924 ajaxStatus.hideStatus();
927 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
928 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
929 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
932 CAL.dialog_apply = function(){
933 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
935 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;
937 //CAL.fill_recurrence();
940 if(e = CAL.get("radio_call"))
941 e.setAttribute("disabled","disabled");
942 if(e = CAL.get("radio_meeting"))
943 e.setAttribute("disabled","disabled");
945 CAL.get("btn-apply").setAttribute("disabled","disabled");
948 success: function(o){
949 res = eval('('+o.responseText+')');
950 if(res.success == 'yes'){
952 CAL.get("record").value = res.record;
953 //SugarWidgetScheduler.update_time();
954 //CAL.GR_update_focus(CAL.get("current_module").value,res.record);
957 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
958 if(e = CAL.get("send_invites"))
959 e.removeAttribute("checked");
960 ajaxStatus.hideStatus();
962 alert(CAL.lbl_error_saving);
963 ajaxStatus.hideStatus();
967 alert(CAL.lbl_error_saving);
968 ajaxStatus.hideStatus();
971 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true";
972 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
973 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
976 CAL.dialog_remove = function(){
977 CAL.deleted_id = CAL.get("record").value;
978 CAL.deleted_module = CAL.get("current_module").value;
979 var delete_recurring = false;
982 success: function(o){
983 res = eval('('+o.responseText+')');
986 if(e = CAL.get(CAL.deleted_id))
987 cell_id = e.parentNode.id;
988 if(CAL.view == 'shared')
989 CAL.remove_shared(CAL.deleted_id);
991 if(e = CAL.get(CAL.deleted_id))
992 e.parentNode.removeChild(e);
994 CAL.arrange_slot(cell_id);
999 alert(CAL.lbl_error_saving);
1004 "current_module" : CAL.deleted_module,
1005 "record" : CAL.deleted_id,
1006 "delete_recurring": delete_recurring
1008 var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";
1009 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1011 CAL.editDialog.cancel();
1014 CAL.show_additional_details = function (id){
1015 var obj = CAL.get(id);
1017 var record = obj.getAttribute("record");
1018 mod = obj.getAttribute("module_name");
1019 var atype = CAL.act_types[mod];
1021 var subj = obj.getAttribute("subj");
1022 var date_start = obj.getAttribute("date_start");
1023 var duration = obj.getAttribute("dur");
1024 var desc = obj.getAttribute("desc");
1025 var detail = parseInt(obj.getAttribute("detail"));
1026 var edit = parseInt(obj.getAttribute("edit"));
1029 if(obj.getAttribute("parent_id") != '')
1030 related = "<b>" + CAL.lbl_related + ":</b> <a href='index.php?module="+obj.getAttribute("parent_type")+"&action=DetailView&record="+obj.getAttribute("parent_id")+"'>"+obj.getAttribute("parent_name")+"</a>" + "<br>";
1033 desc = '<b>'+ CAL.lbl_desc + ':</b><br> ' + desc +'<br>';
1037 var date_lbl = CAL.lbl_start;
1039 var duration_text = '<b>'+CAL.lbl_duration+':</b> ' + duration + '<br>';
1041 date_lbl = CAL.lbl_due;
1047 var caption = "<div style='float: left;'>"+CAL.lbl_title+"</div><div style='float: right;'>";
1049 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_EDIT_BUTTON')+"\' href=\'index.php?module="+mod+"&action=EditView&record="+record+"\'><img border=0 src=\'"+CAL.img_edit_inline+"\'></a>";
1052 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_VIEW_BUTTON')+"\' href=\'index.php?module="+mod+"&action=DetailView&record="+record+"\'><img border=0 style=\'margin-left:2px;\' src=\'"+CAL.img_view_inline+"\'></a>";
1054 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_ADDITIONAL_DETAILS_CLOSE_TITLE')+"\' href=\'javascript:return cClick();\' onclick=\'javascript:return cClick();\'><img border=0 style=\'margin-left:2px;margin-right:2px;\' src=\'"+CAL.img_close+"\'></a></div>";
1057 var body = '<b>'+CAL.lbl_name+':</b> ' + subj + ' <br><b>'+date_lbl+':</b> ' + date_start + '<br>' + duration_text + related + desc;
1058 return overlib(body, CAPTION, caption, DELAY, 200, STICKY, MOUSEOFF, 200, WIDTH, 300, CLOSETEXT, '', CLOSETITLE, SUGAR.language.get('app_strings','LBL_ADDITIONAL_DETAILS_CLOSE_TITLE'), CLOSECLICK, FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass ecCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass');
1061 CAL.toggle_shared_edit = function (id){
1062 if(document.getElementById(id).style.display == 'none'){
1063 document.getElementById(id).style.display = 'inline'
1064 if(document.getElementById(id+"link") != undefined){
1065 document.getElementById(id+"link").style.display='none';
1068 document.getElementById(id).style.display = 'none'
1069 if(document.getElementById(id+"link") != undefined){
1070 document.getElementById(id+"link").style.display = 'inline';
1075 CAL.goto_date_call = function (){
1076 var date_string = CAL.get("goto_date").value;
1078 date_arr = date_string.split("/");
1080 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];
1083 CAL.toURI = function (a){
1086 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1088 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1090 t.push(x+"="+encodeURIComponent(a[x]));
1095 CAL.each = function (object, callback) {
1097 if(typeof object == "undefined")
1100 length = object.length,
1101 isObj = (length === undefined) || (typeof (object) === "function");
1103 for (name in object) {
1104 if (callback.call(object[name], name, object[name]) === false) {
1109 for (; i < length;) {
1110 if (callback.call(object[i], i, object[i++]) === false) {
1118 CAL.update_vcal = function(){
1120 var v = CAL.current_user_id;
1122 success: function(result){
1123 if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
1124 GLOBAL_REGISTRY.freebusy = new Object();
1126 if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
1127 GLOBAL_REGISTRY.freebusy_adjusted = new Object();
1129 // parse vCal and put it in the registry using the user_id as a key:
1130 GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);
1131 // parse for current user adjusted vCal
1132 GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
1133 SugarWidgetScheduler.update_time();
1137 var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;
1138 YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
1141 CAL.fit_grid = function(){
1143 var cal_width = document.getElementById("cal-grid").parentNode.parentNode.offsetWidth;
1144 var left_width = 80;
1147 if(CAL.view == "day")
1148 day_width = parseInt((cal_width - left_width));
1150 day_width = parseInt((cal_width - left_width) / 7 );
1152 var nodes = CAL.query("#cal-grid div.day_col");
1153 CAL.each(nodes, function(i,v){
1154 nodes[i].style.width = day_width + "px";
1157 document.getElementById("cal-grid").style.visibility = "";
1161 YAHOO.util.DDCAL = function(id, sGroup, config){
1162 this.cont = config.cont;
1163 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
1165 YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, {
1168 YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
1169 this.initConstraints();
1170 YAHOO.util.Event.on(window, 'resize', function() {
1171 this.initConstraints();
1174 initConstraints: function() {
1175 var region = YAHOO.util.Dom.getRegion(this.cont);
1176 var el = this.getEl();
1177 var xy = YAHOO.util.Dom.getXY(el);
1178 var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
1179 var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10);
1180 var left = xy[0] - region.left;
1181 var right = region.right - xy[0] - width;
1182 var top = xy[1] - region.top;
1183 var bottom = region.bottom - xy[1] - height;
1184 this.setXConstraint(left, right);
1185 this.setYConstraint(top, bottom);
1189 CAL.remove_edit_dialog();
1191 var cal_loaded = true;