[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 /*+*********************************************************************************** 2 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 3 * ("License"); You may not use this file except in compliance with the License 4 * The Original Code is: vtiger CRM Open Source 5 * The Initial Developer of the Original Code is vtiger. 6 * Portions created by vtiger are Copyright (C) vtiger. 7 * All Rights Reserved. 8 *************************************************************************************/ 9 10 var Vtiger_Index_Js = { 11 12 /** 13 * Function to show email preview in popup 14 */ 15 showEmailPreview : function(recordId, parentId) { 16 var popupInstance = Vtiger_Popup_Js.getInstance(); 17 var params = {}; 18 params['module'] = "Emails"; 19 params['view'] = "ComposeEmail"; 20 params['mode'] = "emailPreview"; 21 params['record'] = recordId; 22 params['parentId'] = parentId; 23 params['relatedLoad'] = true; 24 popupInstance.show(params); 25 }, 26 27 registerWidgetsEvents : function() { 28 var widgets = jQuery('div.widgetContainer'); 29 widgets.on({ 30 shown: function(e) { 31 var widgetContainer = jQuery(e.currentTarget); 32 Vtiger_Index_Js.loadWidgets(widgetContainer); 33 var key = widgetContainer.attr('id'); 34 app.cacheSet(key, 1); 35 }, 36 hidden: function(e) { 37 var widgetContainer = jQuery(e.currentTarget); 38 var imageEle = widgetContainer.parent().find('.imageElement'); 39 var imagePath = imageEle.data('rightimage'); 40 imageEle.attr('src',imagePath); 41 var key = widgetContainer.attr('id'); 42 app.cacheSet(key, 0); 43 } 44 }); 45 }, 46 47 /** 48 * Function is used to load the sidebar widgets 49 * @param widgetContainer - widget container 50 * @param open - widget should be open or closed 51 */ 52 loadWidgets : function(widgetContainer, open) { 53 var message = jQuery('.loadingWidgetMsg').html(); 54 55 if(widgetContainer.html() != '') { 56 var imageEle = widgetContainer.parent().find('.imageElement'); 57 var imagePath = imageEle.data('downimage'); 58 imageEle.attr('src',imagePath); 59 widgetContainer.css('height', 'auto'); 60 return; 61 } 62 63 widgetContainer.progressIndicator({'message' : message}); 64 var url = widgetContainer.data('url'); 65 66 var listViewWidgetParams = { 67 "type":"GET", "url":"index.php", 68 "dataType":"html", "data":url 69 } 70 AppConnector.request(listViewWidgetParams).then( 71 function(data){ 72 if(typeof open == 'undefined') open = true; 73 if(open){ 74 widgetContainer.progressIndicator({'mode':'hide'}); 75 var imageEle = widgetContainer.parent().find('.imageElement'); 76 var imagePath = imageEle.data('downimage'); 77 imageEle.attr('src',imagePath); 78 widgetContainer.css('height', 'auto'); 79 } 80 widgetContainer.html(data); 81 var label = widgetContainer.closest('.quickWidget').find('.quickWidgetHeader').data('label'); 82 jQuery('.bodyContents').trigger('Vtiger.Widget.Load.'+label,jQuery(widgetContainer)); 83 } 84 ); 85 }, 86 87 loadWidgetsOnLoad : function(){ 88 var widgets = jQuery('div.widgetContainer'); 89 widgets.each(function(index,element){ 90 var widgetContainer = jQuery(element); 91 var key = widgetContainer.attr('id'); 92 var value = app.cacheGet(key); 93 if(value != null){ 94 if(value == 1) { 95 Vtiger_Index_Js.loadWidgets(widgetContainer); 96 widgetContainer.addClass('in'); 97 } else { 98 var imageEle = widgetContainer.parent().find('.imageElement'); 99 var imagePath = imageEle.data('rightimage'); 100 imageEle.attr('src',imagePath); 101 } 102 } 103 104 }); 105 106 }, 107 108 /** 109 * Function to change user theme(colour) 110 * @params : colour name 111 */ 112 changeSkin : function() { 113 jQuery('.themeElement').on('click', function(e) { 114 e.stopPropagation(); 115 var currentElement = jQuery(e.currentTarget); 116 currentElement.closest('#themeContainer').hide(); 117 118 var progressElement = jQuery('#progressDiv'); 119 progressElement.progressIndicator(); 120 121 var params = { 122 'module' : 'Users', 123 'action' : 'SaveAjax', 124 'record' : jQuery('#current_user_id').val(), 125 'field' : 'theme', 126 'value' : currentElement.data('skinName') 127 } 128 AppConnector.request(params).then(function(data) { 129 if(data.success && data.result) { 130 progressElement.progressIndicator({'mode':'hide'}); 131 jQuery('.settingIcons').removeClass('open'); 132 window.location.reload(); 133 } 134 }, 135 function(error,err){ 136 }); 137 }) 138 }, 139 140 /** 141 * Function to show compose email popup based on number of 142 * email fields in given module,if email fields are more than 143 * one given option for user to select email for whom mail should 144 * be sent,or else straight away open compose email popup 145 * @params : accepts params object 146 * 147 * @cb: callback function to recieve the child window reference. 148 */ 149 150 showComposeEmailPopup : function(params, cb){ 151 var currentModule = "Emails"; 152 Vtiger_Helper_Js.checkServerConfig(currentModule).then(function(data){ 153 if(data == true){ 154 var css = jQuery.extend({'text-align' : 'left'},css); 155 AppConnector.request(params).then( 156 function(data) { 157 var cbargs = []; 158 if(data) { 159 data = jQuery(data); 160 var form = data.find('#SendEmailFormStep1'); 161 var emailFields = form.find('.emailField'); 162 var length = emailFields.length; 163 var emailEditInstance = new Emails_MassEdit_Js(); 164 if(length > 1) { 165 app.showModalWindow(data,function(data){ 166 emailEditInstance.registerEmailFieldSelectionEvent(); 167 if( jQuery('#multiEmailContainer').height() > 300 ){ 168 jQuery('#multiEmailContainer').slimScroll({ 169 height: '300px', 170 railVisible: true, 171 alwaysVisible: true, 172 size: '6px' 173 }); 174 } 175 },css); 176 } else { 177 emailFields.attr('checked','checked'); 178 var params = form.serializeFormData(); 179 // http://stackoverflow.com/questions/13953321/how-can-i-call-a-window-child-function-in-javascript 180 // This could be useful for the caller to invoke child window methods post load. 181 var win = emailEditInstance.showComposeEmailForm(params); 182 cbargs.push(win); 183 } 184 } 185 if (typeof cb == 'function') cb.apply(null, cbargs); 186 }, 187 function(error,err){ 188 189 } 190 ); 191 } else { 192 Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_EMAIL_SERVER_CONFIGURATION')); 193 } 194 }) 195 196 }, 197 198 /** 199 * Function registers event for Calendar Reminder popups 200 */ 201 registerActivityReminder : function() { 202 var activityReminder = jQuery('#activityReminder').val(); 203 activityReminder = activityReminder * 1000; 204 if(activityReminder != '') { 205 var currentTime = new Date().getTime()/1000; 206 var nextActivityReminderCheck = app.cacheGet('nextActivityReminderCheckTime', 0); 207 if((currentTime + activityReminder) > nextActivityReminderCheck) { 208 Vtiger_Index_Js.requestReminder(); 209 setTimeout('Vtiger_Index_Js.requestReminder()', activityReminder); 210 app.cacheSet('nextActivityReminderCheckTime', currentTime + parseInt(activityReminder)); 211 } 212 } 213 }, 214 215 /** 216 * Function request for reminder popups 217 */ 218 requestReminder : function() { 219 var url = 'index.php?module=Calendar&action=ActivityReminder&mode=getReminders'; 220 AppConnector.request(url).then(function(data){ 221 if(data.success && data.result) { 222 for(i=0; i< data.result.length; i++) { 223 var record = data.result[i]; 224 Vtiger_Index_Js.showReminderPopup(record); 225 } 226 } 227 }); 228 }, 229 230 /** 231 * Function display the Reminder popup 232 */ 233 showReminderPopup : function(record) { 234 var params = { 235 title: ' <span style="position: relative; top: 8px;">'+record.activitytype+' - '+ 236 '<a target="_blank" href="index.php?module=Calendar&view=Detail&record='+record.id+'">'+record.subject+'</a></span>', 237 text: '<div class="row-fluid" style="color:black">\n\ 238 <span class="span12">'+app.vtranslate('JS_START_DATE_TIME')+' : '+record.date_start+'</span>\n\ 239 <span class="span8">'+app.vtranslate('JS_END_DATE_TIME')+' : '+record.due_date+'</span>'+ 240 '<span class="span3 right"><h4><a id="reminder_'+record.id+'" class="pull-right" href=#>' 241 +app.vtranslate('JS_POSTPONE')+'</a></h4></span></div>', 242 width: '30%', 243 min_height: '75px', 244 addclass:'vtReminder', 245 icon: 'vtReminder-icon', 246 hide:false, 247 closer:true, 248 type:'info', 249 after_open:function(p) { 250 jQuery(p).data('info', record); 251 } 252 }; 253 var notify = Vtiger_Helper_Js.showPnotify(params); 254 255 jQuery('#reminder_'+record.id).bind('click', function() { 256 notify.remove(); 257 var url = 'index.php?module=Calendar&action=ActivityReminder&mode=postpone&record='+record.id; 258 AppConnector.request(url); 259 }); 260 }, 261 registerResizeEvent: function(){ 262 $(window).resize(function() { 263 if(this.resizeTO) clearTimeout(this.resizeTO); 264 this.resizeTO = setTimeout(function() { 265 $(this).trigger('resizeEnd'); 266 }, 600); 267 }); 268 $(window).bind('resizeEnd', function() { 269 Vtiger_Index_Js.adjustTopMenuBarItems(); 270 }); 271 }, 272 /** 273 * Function to make top-bar menu responsive. 274 */ 275 adjustTopMenuBarItems: function() { 276 // Dedicated space for all dropdown text 277 var TOLERANT_MAX_GAP = 125; // px 278 var menuBarWrapper = ($(window).outerWidth() < 1161) ? jQuery('#mediumNav') : jQuery('#largeNav'); 279 var topMenuBarWidth = menuBarWrapper.parent().outerWidth(); 280 var optionalBarItems = jQuery('.opttabs', menuBarWrapper), optionalBarItemsCount = optionalBarItems.length; 281 var optionalBarItemIndex = optionalBarItemsCount; 282 function enableOptionalTopMenuItem() { 283 var opttab = (optionalBarItemIndex > 0) ? optionalBarItems[optionalBarItemIndex-1] : null; 284 if (opttab) { opttab = jQuery(opttab); opttab.hide(); optionalBarItemIndex--; } 285 return opttab; 286 } 287 // Loop and enable hidden menu item until the tolerant width is reached. 288 var stopLoop = false; 289 do { 290 if((topMenuBarWidth - menuBarWrapper.outerWidth()) < TOLERANT_MAX_GAP){ 291 var lastOptTab = enableOptionalTopMenuItem(); 292 if (lastOptTab == null || (topMenuBarWidth - menuBarWrapper.outerWidth()) > TOLERANT_MAX_GAP) { 293 if(lastOptTab) lastOptTab.hide(); 294 stopLoop = true; break; 295 } 296 }else{ 297 stopLoop = true; break; 298 } 299 } while (!stopLoop); 300 // Required to get the functionality of All drop-down working. 301 jQuery(window).load(function(){ 302 jQuery("#topMenus").css({'overflow':'visible'}); 303 }); 304 }, 305 306 /** 307 * Function to trigger tooltip feature. 308 */ 309 registerTooltipEvents: function() { 310 var references = jQuery.merge(jQuery('[data-field-type="reference"] > a'), jQuery('[data-field-type="multireference"] > a')); 311 var lastPopovers = []; 312 313 // Fetching reference fields often is not a good idea on a given page. 314 // The caching is done based on the URL so we can reuse. 315 var CACHE_ENABLED = true; // TODO - add cache timeout support. 316 317 function prepareAndShowTooltipView() { 318 hideAllTooltipViews(); 319 320 var el = jQuery(this); 321 var url = el.attr('href')? el.attr('href') : ''; 322 if (url == '') { 323 return; 324 } 325 326 // Rewrite URL to retrieve Tooltip view. 327 url = url.replace('view=', 'xview=') + '&view=TooltipAjax'; 328 329 var cachedView = CACHE_ENABLED ? jQuery('[data-url-cached="'+url+'"]') : null; 330 if (cachedView && cachedView.length) { 331 showTooltip(el, cachedView.html()); 332 } else { 333 AppConnector.request(url).then(function(data){ 334 cachedView = jQuery('<div>').css({display:'none'}).attr('data-url-cached', url); 335 cachedView.html(data); 336 jQuery('body').append(cachedView); 337 showTooltip(el, data); 338 }); 339 } 340 } 341 342 function get_popover_placement(el) { 343 var width = window.innerWidth; 344 var left_pos = jQuery(el).offset().left; 345 if (width - left_pos > 400) return 'right'; 346 return 'left'; 347 } 348 349 function showTooltip(el, data) { 350 var the_placement = get_popover_placement(el); 351 el.popover({ 352 //title: '', - Is derived from the Anchor Element (el). 353 trigger: 'manual', 354 content: data, 355 animation: false, 356 placement: the_placement, 357 template: '<div class="popover popover-tooltip"><div class="arrow"></div><div class="popover-inner"><button name="vtTooltipClose" class="close" style="color:white;opacity:1;font-weight:lighter;position:relative;top:3px;right:3px;">x</button><h3 class="popover-title"></h3><div class="popover-content"><div></div></div></div></div>' 358 }); 359 lastPopovers.push(el.popover('show')); 360 registerToolTipDestroy(); 361 } 362 363 function hideAllTooltipViews() { 364 // Hide all previous popover 365 var lastPopover = null; 366 while (lastPopover = lastPopovers.pop()) { 367 lastPopover.popover('hide'); 368 } 369 } 370 371 references.each(function(index, el){ 372 jQuery(el).hoverIntent({ 373 interval: 100, 374 sensitivity: 7, 375 timeout: 10, 376 over: prepareAndShowTooltipView, 377 out: hideAllTooltipViews 378 }); 379 }); 380 381 function registerToolTipDestroy() { 382 jQuery('button[name="vtTooltipClose"]').on('click', function(e){ 383 var lastPopover = lastPopovers.pop(); 384 lastPopover.popover('hide'); 385 }); 386 } 387 }, 388 389 registerShowHideLeftPanelEvent : function() { 390 jQuery('#toggleButton').click(function(e){ 391 e.preventDefault(); 392 var leftPanel = jQuery('#leftPanel'); 393 var rightPanel = jQuery('#rightPanel'); 394 var tButtonImage = jQuery('#tButtonImage'); 395 if (leftPanel.attr('class').indexOf(' hide') == -1) { 396 var leftPanelshow = 1; 397 leftPanel.addClass('hide'); 398 rightPanel.removeClass('span10').addClass('span12'); 399 tButtonImage.removeClass('icon-chevron-left').addClass("icon-chevron-right"); 400 } else { 401 var leftPanelshow = 0; 402 leftPanel.removeClass('hide'); 403 rightPanel.removeClass('span12').addClass('span10'); 404 tButtonImage.removeClass('icon-chevron-right').addClass("icon-chevron-left"); 405 } 406 var params = { 407 'module' : 'Users', 408 'action' : 'IndexAjax', 409 'mode' : 'toggleLeftPanel', 410 'showPanel' : leftPanelshow 411 } 412 AppConnector.request(params); 413 }); 414 }, 415 416 registerEvents : function(){ 417 Vtiger_Index_Js.registerWidgetsEvents(); 418 Vtiger_Index_Js.loadWidgetsOnLoad(); 419 Vtiger_Index_Js.registerActivityReminder(); 420 Vtiger_Index_Js.adjustTopMenuBarItems(); 421 Vtiger_Index_Js.registerPostAjaxEvents(); 422 Vtiger_Index_Js.changeSkin(); 423 Vtiger_Index_Js.registerShowHideLeftPanelEvent(); 424 Vtiger_Index_Js.registerResizeEvent(); 425 }, 426 427 registerPostAjaxEvents: function() { 428 Vtiger_Index_Js.registerTooltipEvents(); 429 } 430 } 431 432 433 //On Page Load 434 jQuery(document).ready(function() { 435 Vtiger_Index_Js.registerEvents(); 436 app.listenPostAjaxReady(function() { 437 Vtiger_Index_Js.registerPostAjaxEvents(); 438 }); 439 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |