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 * Handles loading the sitemap popup
42 YAHOO.util.Event.onAvailable('sitemapLinkSpan',function()
44 document.getElementById('sitemapLinkSpan').onclick = function()
46 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
51 ajaxStatus.hideStatus();
52 document.getElementById('sm_holder').innerHTML = r.responseText;
53 with ( document.getElementById('sitemap').style ) {
55 position = "absolute";
59 document.getElementById('sitemapClose').onclick = function()
61 document.getElementById('sitemap').style.display = "none";
65 postData = 'module=Home&action=sitemap&GetSiteMap=now&sugar_body_only=true';
66 YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
73 var moduleLinks = document.getElementById('moduleList').getElementsByTagName("a");
74 moduleLinkMouseOver = function()
76 var matches = /grouptab_([0-9]+)/i.exec(this.id);
77 var tabNum = matches[1];
78 var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span");
79 for (var i = 0; i < moduleGroups.length; i++) {
81 moduleGroups[i].className = 'selected';
84 moduleGroups[i].className = '';
88 var groupList = document.getElementById('moduleList').getElementsByTagName("li");
89 var currentGroupItem = tabNum;
90 for (var i = 0; i < groupList.length; i++) {
91 var aElem = groupList[i].getElementsByTagName("a")[0];
92 if ( aElem == null ) {
93 // This is the blank <li> tag at the start of some themes, skip it
96 // notCurrentTabLeft, notCurrentTabRight, notCurrentTab
97 var classStarter = 'notC';
98 if ( aElem.id == "grouptab_"+tabNum ) {
99 // currentTabLeft, currentTabRight, currentTab
101 currentGroupItem = i;
103 var spanTags = groupList[i].getElementsByTagName("span");
104 for (var ii = 0 ; ii < spanTags.length; ii++ ) {
105 if ( spanTags[ii].className == null ) { continue; }
106 var oldClass = spanTags[ii].className.match(/urrentTab.*/);
107 spanTags[ii].className = classStarter + oldClass;
110 ////////////////////////////////////////////////////////////////////////////////////////
111 ////update submenu position
112 //get sub menu dom node
113 var menuHandle = moduleGroups[tabNum];
115 //get group tab dom node
116 var parentMenu = groupList[currentGroupItem];
118 if(menuHandle && parentMenu){
119 updateSubmenuPosition(menuHandle , parentMenu);
121 ////////////////////////////////////////////////////////////////////////////////////////
123 for (var i = 0; i < moduleLinks.length; i++) {
124 moduleLinks[i].onmouseover = moduleLinkMouseOver;
128 function updateSubmenuPosition(menuHandle , parentMenu){
133 while(p&&p.tagName.toUpperCase()!='BODY'){
140 var bw = checkBrowserWidth();
142 //If the mouse over on 'MoreMenu' group tab, stop the following function
146 //Calculate left position of the middle of current group tab .
147 var groupTabLeft = left + (parentMenu.offsetWidth / 2);
148 var subTabHalfLength = 0;
149 var children = menuHandle.getElementsByTagName('li');
150 for(var i = 0; i< children.length; i++){
151 //offsetWidth = width + padding + border
152 if(children[i].className == 'subTabMore' || children[i].parentNode.className == 'cssmenu'){
155 subTabHalfLength += parseInt(children[i].offsetWidth);
158 if(subTabHalfLength != 0){
159 subTabHalfLength = subTabHalfLength / 2;
162 var totalLengthInTheory = subTabHalfLength + groupTabLeft;
163 if(subTabHalfLength>0 && groupTabLeft >0){
164 if(subTabHalfLength >= groupTabLeft){
167 left = groupTabLeft - subTabHalfLength;
171 //If the sub menu length > browser length
172 if(totalLengthInTheory > bw){
173 var differ = totalLengthInTheory - bw;
174 left = groupTabLeft - subTabHalfLength - differ - 2;
178 menuHandle.style.marginLeft = left+'px';
182 YAHOO.util.Event.onDOMReady(function()
184 if ( document.getElementById('subModuleList') ) {
185 ////////////////////////////////////////////////////////////////////////////////////////
186 ////update current submenu position
187 var parentMenu = false;
188 var moduleListDom = document.getElementById('moduleList');
189 if(moduleListDom !=null){
190 var parentTabLis = moduleListDom.getElementsByTagName("li");
192 for(var ii = 0; ii < parentTabLis.length; ii++){
193 var spans = parentTabLis[ii].getElementsByTagName("span");
194 for(var jj =0; jj < spans.length; jj++){
195 if(spans[jj].className.match(/currentTab.*/)){
200 var parentMenu = parentTabLis[tabNum];
202 var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span");
203 for(var i = 0; i < moduleGroups.length; i++){
204 if(moduleGroups[i].className.match(/selected/)){
208 var menuHandle = moduleGroups[tabNum];
210 if(menuHandle && parentMenu){
211 updateSubmenuPosition(menuHandle , parentMenu);
214 ////////////////////////////////////////////////////////////////////////////////////////
218 * For the module list menu
220 SUGAR.themes = SUGAR.namespace("themes");
222 SUGAR.append(SUGAR.themes, {
224 setModuleTabs: function(html) {
225 var el = document.getElementById('ajaxHeader');
229 //This can fail hard if multiple events fired at the same time
230 YAHOO.util.Event.purgeElement(el, true);
231 for (var i in this.allMenuBars) {
232 if (this.allMenuBars[i].destroy)
233 this.allMenuBars[i].destroy();
236 //If the menu fails to load, we can get leave the user stranded, reload the page instead.
237 window.location.reload();
240 if (el.hasChildNodes()) {
241 while (el.childNodes.length >= 1) {
242 el.removeChild(el.firstChild);
246 el.innerHTML += html;
247 this.loadModuleList();
251 loadModuleList: function() {
252 var nodes = YAHOO.util.Selector.query('#moduleList>div'),
254 this.allMenuBars = {};
256 for (var i = 0 ; i < nodes.length ; i++) {
257 currMenuBar = SUGAR.themes.currMenuBar = new YAHOO.widget.MenuBar(nodes[i].id, {
258 autosubmenudisplay: true,
265 Call the "render" method with no arguments since the
266 markup for this MenuBar already exists in the page.
268 currMenuBar.render();
269 this.allMenuBars[nodes[i].id.substr(nodes[i].id.indexOf('_')+1)] = currMenuBar;
271 if (typeof YAHOO.util.Dom.getChildren(nodes[i]) == 'object' && YAHOO.util.Dom.getChildren(nodes[i]).shift().style.display != 'none') {
272 // This is the currently displayed menu bar
273 oMenuBar = currMenuBar;
277 * Handles changing the sub menu items when using grouptabs
279 YAHOO.util.Event.onAvailable('subModuleList',IKEADEBUG);
283 YAHOO.util.Event.onDOMReady(SUGAR.themes.loadModuleList, SUGAR.themes, true);