/*+*********************************************************************************** * The contents of this file are subject to the vtiger CRM Public License Version 1.0 * ("License"); You may not use this file except in compliance with the License * The Original Code is: vtiger CRM Open Source * The Initial Developer of the Original Code is vtiger. * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. *************************************************************************************/ var Vtiger_Index_Js = { /** * Function to show email preview in popup */ showEmailPreview : function(recordId, parentId) { var popupInstance = Vtiger_Popup_Js.getInstance(); var params = {}; params['module'] = "Emails"; params['view'] = "ComposeEmail"; params['mode'] = "emailPreview"; params['record'] = recordId; params['parentId'] = parentId; params['relatedLoad'] = true; popupInstance.show(params); }, registerWidgetsEvents : function() { var widgets = jQuery('div.widgetContainer'); widgets.on({ shown: function(e) { var widgetContainer = jQuery(e.currentTarget); Vtiger_Index_Js.loadWidgets(widgetContainer); var key = widgetContainer.attr('id'); app.cacheSet(key, 1); }, hidden: function(e) { var widgetContainer = jQuery(e.currentTarget); var imageEle = widgetContainer.parent().find('.imageElement'); var imagePath = imageEle.data('rightimage'); imageEle.attr('src',imagePath); var key = widgetContainer.attr('id'); app.cacheSet(key, 0); } }); }, /** * Function is used to load the sidebar widgets * @param widgetContainer - widget container * @param open - widget should be open or closed */ loadWidgets : function(widgetContainer, open) { var message = jQuery('.loadingWidgetMsg').html(); if(widgetContainer.html() != '') { var imageEle = widgetContainer.parent().find('.imageElement'); var imagePath = imageEle.data('downimage'); imageEle.attr('src',imagePath); widgetContainer.css('height', 'auto'); return; } widgetContainer.progressIndicator({'message' : message}); var url = widgetContainer.data('url'); var listViewWidgetParams = { "type":"GET", "url":"index.php", "dataType":"html", "data":url } AppConnector.request(listViewWidgetParams).then( function(data){ if(typeof open == 'undefined') open = true; if(open){ widgetContainer.progressIndicator({'mode':'hide'}); var imageEle = widgetContainer.parent().find('.imageElement'); var imagePath = imageEle.data('downimage'); imageEle.attr('src',imagePath); widgetContainer.css('height', 'auto'); } widgetContainer.html(data); var label = widgetContainer.closest('.quickWidget').find('.quickWidgetHeader').data('label'); jQuery('.bodyContents').trigger('Vtiger.Widget.Load.'+label,jQuery(widgetContainer)); } ); }, loadWidgetsOnLoad : function(){ var widgets = jQuery('div.widgetContainer'); widgets.each(function(index,element){ var widgetContainer = jQuery(element); var key = widgetContainer.attr('id'); var value = app.cacheGet(key); if(value != null){ if(value == 1) { Vtiger_Index_Js.loadWidgets(widgetContainer); widgetContainer.addClass('in'); } else { var imageEle = widgetContainer.parent().find('.imageElement'); var imagePath = imageEle.data('rightimage'); imageEle.attr('src',imagePath); } } }); }, /** * Function to change user theme(colour) * @params : colour name */ changeSkin : function() { jQuery('.themeElement').on('click', function(e) { e.stopPropagation(); var currentElement = jQuery(e.currentTarget); currentElement.closest('#themeContainer').hide(); var progressElement = jQuery('#progressDiv'); progressElement.progressIndicator(); var params = { 'module' : 'Users', 'action' : 'SaveAjax', 'record' : jQuery('#current_user_id').val(), 'field' : 'theme', 'value' : currentElement.data('skinName') } AppConnector.request(params).then(function(data) { if(data.success && data.result) { progressElement.progressIndicator({'mode':'hide'}); jQuery('.settingIcons').removeClass('open'); window.location.reload(); } }, function(error,err){ }); }) }, /** * Function to show compose email popup based on number of * email fields in given module,if email fields are more than * one given option for user to select email for whom mail should * be sent,or else straight away open compose email popup * @params : accepts params object * * @cb: callback function to recieve the child window reference. */ showComposeEmailPopup : function(params, cb){ var currentModule = "Emails"; Vtiger_Helper_Js.checkServerConfig(currentModule).then(function(data){ if(data == true){ var css = jQuery.extend({'text-align' : 'left'},css); AppConnector.request(params).then( function(data) { var cbargs = []; if(data) { data = jQuery(data); var form = data.find('#SendEmailFormStep1'); var emailFields = form.find('.emailField'); var length = emailFields.length; var emailEditInstance = new Emails_MassEdit_Js(); if(length > 1) { app.showModalWindow(data,function(data){ emailEditInstance.registerEmailFieldSelectionEvent(); if( jQuery('#multiEmailContainer').height() > 300 ){ jQuery('#multiEmailContainer').slimScroll({ height: '300px', railVisible: true, alwaysVisible: true, size: '6px' }); } },css); } else { emailFields.attr('checked','checked'); var params = form.serializeFormData(); // http://stackoverflow.com/questions/13953321/how-can-i-call-a-window-child-function-in-javascript // This could be useful for the caller to invoke child window methods post load. var win = emailEditInstance.showComposeEmailForm(params); cbargs.push(win); } } if (typeof cb == 'function') cb.apply(null, cbargs); }, function(error,err){ } ); } else { Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_EMAIL_SERVER_CONFIGURATION')); } }) }, /** * Function registers event for Calendar Reminder popups */ registerActivityReminder : function() { var activityReminder = jQuery('#activityReminder').val(); activityReminder = activityReminder * 1000; if(activityReminder != '') { var currentTime = new Date().getTime()/1000; var nextActivityReminderCheck = app.cacheGet('nextActivityReminderCheckTime', 0); if((currentTime + activityReminder) > nextActivityReminderCheck) { Vtiger_Index_Js.requestReminder(); setTimeout('Vtiger_Index_Js.requestReminder()', activityReminder); app.cacheSet('nextActivityReminderCheckTime', currentTime + parseInt(activityReminder)); } } }, /** * Function request for reminder popups */ requestReminder : function() { var url = 'index.php?module=Calendar&action=ActivityReminder&mode=getReminders'; AppConnector.request(url).then(function(data){ if(data.success && data.result) { for(i=0; i< data.result.length; i++) { var record = data.result[i]; Vtiger_Index_Js.showReminderPopup(record); } } }); }, /** * Function display the Reminder popup */ showReminderPopup : function(record) { var params = { title: ' '+record.activitytype+' - '+ ''+record.subject+'', text: '