]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/javascript/complexLayout.js
Release 6.5.0
[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             
155             se.leftTabs = new YAHOO.widget.TabView("lefttabs");
156             var folderTab = new YAHOO.widget.Tab({ 
157                                 label: app_strings.LBL_EMAIL_FOLDERS_SHORT,
158                                 scroll : true,
159                                 content : "<div id='emailtree'/>",
160                                 id : "tree",
161                                 active : true
162                         });
163             folderTab.on("activeChange", function(o){ 
164                 if (o.newValue) {
165                         se.complexLayout.getUnitByPosition("left").set("header", app_strings.LBL_EMAIL_FOLDERS);
166                 }
167             });
168             se.leftTabs.addTab(folderTab);
169             
170             var tabContent = SUGAR.util.getAndRemove("searchTab");
171             var searchTab = new YAHOO.widget.Tab({ 
172                                 label: app_strings.LBL_EMAIL_SEARCH_SHORT,
173                                 scroll : true,
174                                 content : tabContent.innerHTML,
175                                 id : tabContent.id
176                         });
177             searchTab.on("activeChange", function(o){ 
178                 if (o.newValue) 
179                 {
180                         se.complexLayout.getUnitByPosition("left").set("header", app_strings.LBL_EMAIL_SEARCH);
181                    //Setup the calendars if needed
182                        Calendar.setup ({inputField : "searchDateFrom", ifFormat : calFormat, showsTime : false, button : "searchDateFrom_trigger", singleClick : true, step : 1, weekNumbers:false});
183                        Calendar.setup ({inputField : "searchDateTo", ifFormat : calFormat, showsTime : false, button : "searchDateTo_trigger", singleClick : true, step : 1, weekNumbers:false});
184                    
185                        //Initalize sqs object for assigned user name 
186                        se.e2Layout.initSQSObject('advancedSearchForm','assigned_user_name');  
187                        
188                        //Attach event handler for when the relate module option is selected for the correct sqs object
189                        var parentSearchArgs = {'formName':'advancedSearchForm','fieldName':'data_parent_name_search',
190                                                 'moduleSelectField':'data_parent_type_search','fieldId':'data_parent_id_search'};
191                        YAHOO.util.Event.addListener('data_parent_type_search', 'change',function(){ 
192                            SUGAR.email2.composeLayout.enableQuickSearchRelate(null,parentSearchArgs) });
193                        
194                        //If enter key is pressed, perform search
195                        var  addKeyPressFields = ['searchSubject','searchFrom','searchTo','data_parent_name_search','searchDateTo','searchDateFrom','attachmentsSearch','assigned_user_name'];
196                        for(var i=0; i < addKeyPressFields.length;i++)
197                        {
198                        YAHOO.util.Event.addListener(window.document.forms['advancedSearchForm'].elements[addKeyPressFields[i]],"keydown", function(e){
199                                 if (e.keyCode == 13) {
200                                         YAHOO.util.Event.stopEvent(e);
201                                         SUGAR.email2.search.searchAdvanced();
202                                 }
203                        });
204                        }
205                                    //Initiate quick search for the search tab.  Do this only when the tab is selected rather than onDomLoad for perf. gains.
206                        enableQS(true);
207                        //Clear parent values if selecting another parent type.
208                        YAHOO.util.Event.addListener('data_parent_type_search','change', 
209                            function(){ 
210                                document.getElementById('data_parent_id_search').value =''; 
211                                document.getElementById('data_parent_name_search').value =''; 
212                            });
213                 
214                 }
215             });
216             se.leftTabs.addTab(searchTab);
217             
218             var resizeTabBody = function() {
219                 var height = SUGAR.email2.leftTabs.get("element").clientHeight - 30;
220                                 SUGAR.email2.leftTabs.get("activeTab").get("contentEl").parentNode.style.height = height + "px";
221             }
222             resizeTabBody();
223             se.complexLayout.on("render", resizeTabBody);
224             se.leftTabs.on("activeTabChange", resizeTabBody);
225                         //hack to allow left pane scroll bar to fully show
226                 var lefttabsDiv = document.getElementById('lefttabs');
227                         var lefttabsDivParent = Dom.getAncestorBy(lefttabsDiv);
228                         var lefttabsDivGParent = Dom.getAncestorBy(lefttabsDivParent);
229                         lefttabsDivParent.style.width = lefttabsDivGParent.offsetWidth - 10 + "px";
230           
231         },
232         initSQSObject: function(formName,fieldName)
233         {
234             var fullFieldName = formName + '_' + fieldName; //SQS Convention
235             var resultName = fullFieldName + '_' + 'results';
236             
237             if (QSFieldsArray[fullFieldName] != null) 
238             {
239                 QSFieldsArray[fullFieldName].destroy();
240                 delete QSFieldsArray[fullFieldName];
241             }
242             if (QSProcessedFieldsArray[fullFieldName])
243             QSProcessedFieldsArray[fullFieldName] = false;
244
245             if( Dom.get(resultName) )
246             {
247                 var obj = document.getElementById(resultName);
248                 obj.parentNode.removeChild(obj);
249             }
250         },
251         setPreviewPanel: function(rows) {
252                 if (rows) {
253                 SUGAR.email2.listViewLayout.getUnitByPosition("right").set("width", 0);
254                 SUGAR.email2.listViewLayout.getUnitByPosition("bottom").set("height", 250);
255                 Dom.get("listRight").innerHTML = "";
256                 Dom.get("listBottom").innerHTML = "<div id='_blank' />";
257             } else {
258                 SUGAR.email2.listViewLayout.getUnitByPosition("bottom").set("height", 0);
259                 SUGAR.email2.listViewLayout.getUnitByPosition("right").set("width", 250);
260                 Dom.get("listBottom").innerHTML = "";
261                 Dom.get("listRight").innerHTML = "<div id='_blank' />";
262             }
263         }
264     };
265         se.e2Layout.init();
266 }
267
268 var myBufferedListenerObject = new Object();
269 myBufferedListenerObject.refit = function() {
270     if(SUGAR.email2.grid) {
271         SUGAR.email2.grid.autoSize();
272     }
273 }