]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/javascript/complexLayout.js
Release 6.5.1
[Github/sugarcrm.git] / modules / Emails / javascript / complexLayout.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
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.
11  * 
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
15  * details.
16  * 
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
20  * 02110-1301 USA.
21  * 
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.
24  * 
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.
28  * 
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  ********************************************************************************/
35
36 /**
37   Complex layout init
38  */
39 function complexLayoutInit() {
40         var se = SUGAR.email2;
41         var Dom = YAHOO.util.Dom;
42         se.e2Layout = {
43         getInnerLayout : function(rows) {
44                 se.listViewLayout = new YAHOO.widget.Layout('listViewDiv', {
45                 parent: se.complexLayout,  
46                         border:true,
47                     hideOnLayout: true,
48                     height: 400,
49                                 units: [{
50                                         position: "center",
51                                     scroll:false, // grid should autoScroll itself
52                                     split:true,
53                                     body: "<div id='emailGrid'></div><div id='dt-pag-nav'></div> "
54                                 },{
55                                         position: "bottom",
56                                     scroll:true,
57                                     collapse: false,
58                                     resize: true,
59                                     useShim:true,
60                                     height:'250',
61                                     body: "<div id='listBottom' />"
62                                 },{
63                                     position: "right",
64                                     scroll:true,
65                                     collapse: false,
66                                     resize: true,
67                                     useShim:true,
68                                     width:'250',
69                                     body: "<div id='listRight' />",
70                                     titlebar: false //,header: "right"
71                                 }]
72             });
73                 se.complexLayout.on("render", function(){
74                         var height = SUGAR.email2.innerLayout.get("element").clientHeight - 30;
75                                 SUGAR.email2.innerLayout.get("activeTab").get("contentEl").parentNode.style.height = height + "px";
76                                 SUGAR.email2.listViewLayout.set("height", height);
77                                 SUGAR.email2.listViewLayout.render();
78                 });
79             se.listViewLayout.render();
80             //CSS hack for now
81             se.listViewLayout.get("element").parentNode.parentNode.style.padding = "0px"
82             var rp = se.listViewLayout.resizePreview = function() {
83                 var pre = Dom.get("displayEmailFramePreview");
84                 if (pre) {
85                         var parent = Dom.getAncestorByClassName(pre, "yui-layout-bd");
86                         pre.style.height = (parent.clientHeight - pre.offsetTop) + "px";
87                 }
88             };
89             se.listViewLayout.getUnitByPosition("bottom").on("heightChange", se.autoSetLayout);
90             se.listViewLayout.getUnitByPosition("right").on("endResize", se.autoSetLayout);
91             se.e2Layout.setPreviewPanel(rows);
92             se.previewLayout = se.listViewLayout;
93             return se.listViewLayout;
94         },
95         
96         getInnerLayout2Rows : function() {
97             return this.getInnerLayout(true);
98         },
99         getInnerLayout2Columns : function() {
100             return this.getInnerLayout(false);
101         },
102         
103         init : function(){
104             // initialize state manager, we will use cookies
105                 var viewHeight = document.documentElement ? document.documentElement.clientHeight : self.innerHeight;
106             var heightOffset = $('#dcmenu').length > 0 ? $('#dcmenu').height() : $('#header').height();
107                 se.complexLayout = new YAHOO.widget.Layout("container", {
108                         border:true,
109                 hideOnLayout: true,
110                 height: Dom.getViewportHeight() - heightOffset - 65,
111                 width: Dom.getViewportWidth() - 40,
112                 units: [{
113                         position: "center",
114                     scroll:false,
115                     body: "<div id='emailtabs'></div>"
116                 },
117                 {
118                         position: "left",
119                         scroll: true,
120                         body: "<div id='lefttabs'></div>",
121                     collapse: true,
122                     width: 210,
123                     minWidth: 100,
124                     resize:true,
125                     useShim:true,
126                     titlebar: true,
127                     header: "&nbsp;"
128                 },
129                 {
130                     header: Dom.get('footerLinks').innerHTML,
131                                         position: 'bottom',
132                                         id: 'mbfooter',
133                                         height: 22,
134                                         border: false
135                 }]
136             });
137                 se.complexLayout.render();
138                 var tp = se.innerLayout = new YAHOO.widget.TabView("emailtabs");
139                         tp.addTab(new YAHOO.widget.Tab({ 
140                                 label: "Inbox",
141                                 scroll : true,
142                                 content : "<div id='listViewDiv'/>",
143                                 id : "center",
144                                 active : true
145                         }));
146                 var centerEl = se.complexLayout.getUnitByPosition('center').get('wrap');
147                         tp.appendTo(centerEl);
148                         //CSS hack for now
149                         tp.get("element").style.borderRight = "1px solid #666"
150                         
151                         var listV =  this.getInnerLayout2Rows();
152                         listV.set("height", tp.get("element").clientHeight - 25);
153                         listV.render();
154             tp.on("activeTabChange", function ()
155             {
156                 se.complexLayout.resize();
157             });
158
159             se.leftTabs = new YAHOO.widget.TabView("lefttabs");
160             var folderTab = new YAHOO.widget.Tab({ 
161                                 label: app_strings.LBL_EMAIL_FOLDERS_SHORT,
162                                 scroll : true,
163                                 content : "<div id='emailtree'/>",
164                                 id : "tree",
165                                 active : true
166                         });
167             folderTab.on("activeChange", function(o){ 
168                 if (o.newValue) {
169                         se.complexLayout.getUnitByPosition("left").set("header", app_strings.LBL_EMAIL_FOLDERS);
170                 }
171             });
172             se.leftTabs.addTab(folderTab);
173             
174             var tabContent = SUGAR.util.getAndRemove("searchTab");
175             var searchTab = new YAHOO.widget.Tab({ 
176                                 label: app_strings.LBL_EMAIL_SEARCH_SHORT,
177                                 scroll : true,
178                                 content : tabContent.innerHTML,
179                                 id : tabContent.id
180                         });
181             searchTab.on("activeChange", function(o){ 
182                 if (o.newValue) 
183                 {
184                         se.complexLayout.getUnitByPosition("left").set("header", app_strings.LBL_EMAIL_SEARCH);
185                    //Setup the calendars if needed
186                        Calendar.setup ({inputField : "searchDateFrom", ifFormat : calFormat, showsTime : false, button : "searchDateFrom_trigger", singleClick : true, step : 1, weekNumbers:false});
187                        Calendar.setup ({inputField : "searchDateTo", ifFormat : calFormat, showsTime : false, button : "searchDateTo_trigger", singleClick : true, step : 1, weekNumbers:false});
188                    
189                        //Initalize sqs object for assigned user name 
190                        se.e2Layout.initSQSObject('advancedSearchForm','assigned_user_name');  
191                        
192                        //Attach event handler for when the relate module option is selected for the correct sqs object
193                        var parentSearchArgs = {'formName':'advancedSearchForm','fieldName':'data_parent_name_search',
194                                                 'moduleSelectField':'data_parent_type_search','fieldId':'data_parent_id_search'};
195                        YAHOO.util.Event.addListener('data_parent_type_search', 'change',function(){ 
196                            SUGAR.email2.composeLayout.enableQuickSearchRelate(null,parentSearchArgs) });
197                        
198                        //If enter key is pressed, perform search
199                        var  addKeyPressFields = ['searchSubject','searchFrom','searchTo','data_parent_name_search','searchDateTo','searchDateFrom','attachmentsSearch','assigned_user_name'];
200                        for(var i=0; i < addKeyPressFields.length;i++)
201                        {
202                        YAHOO.util.Event.addListener(window.document.forms['advancedSearchForm'].elements[addKeyPressFields[i]],"keydown", function(e){
203                                 if (e.keyCode == 13) {
204                                         YAHOO.util.Event.stopEvent(e);
205                                         SUGAR.email2.search.searchAdvanced();
206                                 }
207                        });
208                        }
209                                    //Initiate quick search for the search tab.  Do this only when the tab is selected rather than onDomLoad for perf. gains.
210                        enableQS(true);
211                        //Clear parent values if selecting another parent type.
212                        YAHOO.util.Event.addListener('data_parent_type_search','change', 
213                            function(){ 
214                                document.getElementById('data_parent_id_search').value =''; 
215                                document.getElementById('data_parent_name_search').value =''; 
216                            });
217                 
218                 }
219             });
220             se.leftTabs.addTab(searchTab);
221             
222             var resizeTabBody = function() {
223                 var height = SUGAR.email2.leftTabs.get("element").clientHeight - 30;
224                                 SUGAR.email2.leftTabs.get("activeTab").get("contentEl").parentNode.style.height = height + "px";
225             }
226             resizeTabBody();
227             se.complexLayout.on("render", resizeTabBody);
228             se.leftTabs.on("activeTabChange", resizeTabBody);
229                         //hack to allow left pane scroll bar to fully show
230                 var lefttabsDiv = document.getElementById('lefttabs');
231                         var lefttabsDivParent = Dom.getAncestorBy(lefttabsDiv);
232                         var lefttabsDivGParent = Dom.getAncestorBy(lefttabsDivParent);
233                         lefttabsDivParent.style.width = lefttabsDivGParent.offsetWidth - 10 + "px";
234           
235         },
236         initSQSObject: function(formName,fieldName)
237         {
238             var fullFieldName = formName + '_' + fieldName; //SQS Convention
239             var resultName = fullFieldName + '_' + 'results';
240             
241             if (QSFieldsArray[fullFieldName] != null) 
242             {
243                 QSFieldsArray[fullFieldName].destroy();
244                 delete QSFieldsArray[fullFieldName];
245             }
246             if (QSProcessedFieldsArray[fullFieldName])
247             QSProcessedFieldsArray[fullFieldName] = false;
248
249             if( Dom.get(resultName) )
250             {
251                 var obj = document.getElementById(resultName);
252                 obj.parentNode.removeChild(obj);
253             }
254         },
255         setPreviewPanel: function(rows) {
256                 if (rows) {
257                 SUGAR.email2.listViewLayout.getUnitByPosition("right").set("width", 0);
258                 SUGAR.email2.listViewLayout.getUnitByPosition("bottom").set("height", 250);
259                 Dom.get("listRight").innerHTML = "";
260                 Dom.get("listBottom").innerHTML = "<div id='_blank' />";
261             } else {
262                 SUGAR.email2.listViewLayout.getUnitByPosition("bottom").set("height", 0);
263                 SUGAR.email2.listViewLayout.getUnitByPosition("right").set("width", 250);
264                 Dom.get("listBottom").innerHTML = "";
265                 Dom.get("listRight").innerHTML = "<div id='_blank' />";
266             }
267         }
268     };
269         se.e2Layout.init();
270 }
271
272 var myBufferedListenerObject = new Object();
273 myBufferedListenerObject.refit = function() {
274     if(SUGAR.email2.grid) {
275         SUGAR.email2.grid.autoSize();
276     }
277 }