1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 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 ********************************************************************************/
39 //set up any action style menus
40 $(document).ready(function(){
41 $("ul.clickMenu").each(function(index, node){
42 $(node).sugarActionMenu();
47 * Handles loading the sitemap popup
49 YAHOO.util.Event.onAvailable('sitemapLinkSpan',function()
51 document.getElementById('sitemapLinkSpan').onclick = function()
53 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
58 ajaxStatus.hideStatus();
59 document.getElementById('sm_holder').innerHTML = r.responseText;
60 with ( document.getElementById('sitemap').style ) {
62 position = "absolute";
66 document.getElementById('sitemapClose').onclick = function()
68 document.getElementById('sitemap').style.display = "none";
72 postData = 'module=Home&action=sitemap&GetSiteMap=now&sugar_body_only=true';
73 YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
80 var moduleLinks = document.getElementById('moduleList').getElementsByTagName("a");
81 moduleLinkMouseOver = function()
83 var matches = /grouptab_([0-9]+)/i.exec(this.id);
84 var tabNum = matches[1];
85 var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span");
86 for (var i = 0; i < moduleGroups.length; i++) {
88 moduleGroups[i].className = 'selected';
91 moduleGroups[i].className = '';
95 var groupList = document.getElementById('moduleList').getElementsByTagName("li");
96 var currentGroupItem = tabNum;
97 for (var i = 0; i < groupList.length; i++) {
98 var aElem = groupList[i].getElementsByTagName("a")[0];
99 if ( aElem == null ) {
100 // This is the blank <li> tag at the start of some themes, skip it
103 // notCurrentTabLeft, notCurrentTabRight, notCurrentTab
104 var classStarter = 'notC';
105 if ( aElem.id == "grouptab_"+tabNum ) {
106 // currentTabLeft, currentTabRight, currentTab
108 currentGroupItem = i;
110 var spanTags = groupList[i].getElementsByTagName("span");
111 for (var ii = 0 ; ii < spanTags.length; ii++ ) {
112 if ( spanTags[ii].className == null ) { continue; }
113 var oldClass = spanTags[ii].className.match(/urrentTab.*/);
114 spanTags[ii].className = classStarter + oldClass;
117 ////////////////////////////////////////////////////////////////////////////////////////
118 ////update submenu position
119 //get sub menu dom node
120 var menuHandle = moduleGroups[tabNum];
122 //get group tab dom node
123 var parentMenu = groupList[currentGroupItem];
125 if(menuHandle && parentMenu){
126 updateSubmenuPosition(menuHandle , parentMenu);
128 ////////////////////////////////////////////////////////////////////////////////////////
130 for (var i = 0; i < moduleLinks.length; i++) {
131 moduleLinks[i].onmouseover = moduleLinkMouseOver;
135 function updateSubmenuPosition(menuHandle , parentMenu){
140 while(p&&p.tagName.toUpperCase()!='BODY'){
147 var bw = checkBrowserWidth();
149 //If the mouse over on 'MoreMenu' group tab, stop the following function
153 //Calculate left position of the middle of current group tab .
154 var groupTabLeft = left + (parentMenu.offsetWidth / 2);
155 var subTabHalfLength = 0;
156 var children = menuHandle.getElementsByTagName('li');
157 for(var i = 0; i< children.length; i++){
158 //offsetWidth = width + padding + border
159 if(children[i].className == 'subTabMore' || children[i].parentNode.className == 'cssmenu'){
162 subTabHalfLength += parseInt(children[i].offsetWidth);
165 if(subTabHalfLength != 0){
166 subTabHalfLength = subTabHalfLength / 2;
169 var totalLengthInTheory = subTabHalfLength + groupTabLeft;
170 if(subTabHalfLength>0 && groupTabLeft >0){
171 if(subTabHalfLength >= groupTabLeft){
174 left = groupTabLeft - subTabHalfLength;
178 //If the sub menu length > browser length
179 if(totalLengthInTheory > bw){
180 var differ = totalLengthInTheory - bw;
181 left = groupTabLeft - subTabHalfLength - differ - 2;
185 menuHandle.style.marginLeft = left+'px';
189 YAHOO.util.Event.onDOMReady(function()
191 if ( document.getElementById('subModuleList') ) {
192 ////////////////////////////////////////////////////////////////////////////////////////
193 ////update current submenu position
194 var parentMenu = false;
195 var moduleListDom = document.getElementById('moduleList');
196 if(moduleListDom !=null){
197 var parentTabLis = moduleListDom.getElementsByTagName("li");
199 for(var ii = 0; ii < parentTabLis.length; ii++){
200 var spans = parentTabLis[ii].getElementsByTagName("span");
201 for(var jj =0; jj < spans.length; jj++){
202 if(spans[jj].className.match(/currentTab.*/)){
207 var parentMenu = parentTabLis[tabNum];
209 var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span");
210 for(var i = 0; i < moduleGroups.length; i++){
211 if(moduleGroups[i].className.match(/selected/)){
215 var menuHandle = moduleGroups[tabNum];
217 if(menuHandle && parentMenu){
218 updateSubmenuPosition(menuHandle , parentMenu);
221 ////////////////////////////////////////////////////////////////////////////////////////
225 * For the module list menu
227 SUGAR.themes = SUGAR.namespace("themes");
229 SUGAR.append(SUGAR.themes, {
231 setModuleTabs: function(html) {
232 var el = document.getElementById('ajaxHeader');
236 //This can fail hard if multiple events fired at the same time
237 YAHOO.util.Event.purgeElement(el, true);
238 for (var i in this.allMenuBars) {
239 if (this.allMenuBars[i].destroy)
240 this.allMenuBars[i].destroy();
243 //If the menu fails to load, we can get leave the user stranded, reload the page instead.
244 window.location.reload();
247 if (el.hasChildNodes()) {
248 while (el.childNodes.length >= 1) {
249 el.removeChild(el.firstChild);
253 el.innerHTML += html;
254 this.loadModuleList();
257 actionMenu: function() {
258 //set up any action style menus
259 $("ul.clickMenu").each(function(index, node){
260 $(node).sugarActionMenu();
263 loadModuleList: function() {
264 var nodes = YAHOO.util.Selector.query('#moduleList>div'),
266 this.allMenuBars = {};
268 for (var i = 0 ; i < nodes.length ; i++) {
269 currMenuBar = SUGAR.themes.currMenuBar = new YAHOO.widget.MenuBar(nodes[i].id, {
270 autosubmenudisplay: true,
277 Call the "render" method with no arguments since the
278 markup for this MenuBar already exists in the page.
280 currMenuBar.render();
281 this.allMenuBars[nodes[i].id.substr(nodes[i].id.indexOf('_')+1)] = currMenuBar;
283 if (typeof YAHOO.util.Dom.getChildren(nodes[i]) == 'object' && YAHOO.util.Dom.getChildren(nodes[i]).shift().style.display != 'none') {
284 // This is the currently displayed menu bar
285 oMenuBar = currMenuBar;
289 * Handles changing the sub menu items when using grouptabs
291 YAHOO.util.Event.onAvailable('subModuleList',IKEADEBUG);
293 //dummy function to make classic theme work with 6.5
294 setCurrentTab: function(){}
297 YAHOO.util.Event.onDOMReady(SUGAR.themes.loadModuleList, SUGAR.themes, true);