[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Vtiger/resources/ -> Header.js (source)

   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  jQuery.Class("Vtiger_Header_Js", {
  11      quickCreateModuleCache: {},
  12      self: false,
  13      getInstance: function() {
  14          if (this.self != false) {
  15              return this.self;
  16          }
  17          this.self = new Vtiger_Header_Js();
  18          return this.self;
  19      }
  20  }, {
  21      menuContainer: false,
  22      contentContainer: false,
  23      quickCreateCallBacks: [],
  24      init: function() {
  25          this.setMenuContainer('.navbar-fixed-top').setContentsContainer('.mainContainer');
  26      },
  27      setMenuContainer: function(element) {
  28          if (element instanceof jQuery) {
  29              this.menuContainer = element;
  30          } else {
  31              this.menuContainer = jQuery(element);
  32          }
  33          return this;
  34      },
  35      getMenuContainer: function() {
  36          return this.menuContainer;
  37      },
  38      setContentsContainer: function(element) {
  39          if (element instanceof jQuery) {
  40              this.contentContainer = element;
  41          } else {
  42              this.contentContainer = jQuery(element);
  43          }
  44          return this;
  45      },
  46      getContentsContainer: function() {
  47          return this.contentContainer;
  48      },
  49      getQuickCreateForm: function(url, moduleName, params) {
  50          var thisInstance = this;
  51          var aDeferred = jQuery.Deferred();
  52          var requestParams;
  53          if (typeof params == 'undefined') {
  54              params = {};
  55          }
  56          if ((!params.noCache) || (typeof (params.noCache) == "undefined")) {
  57              if (typeof Vtiger_Header_Js.quickCreateModuleCache[moduleName] != 'undefined') {
  58                  aDeferred.resolve(Vtiger_Header_Js.quickCreateModuleCache[moduleName]);
  59                  return aDeferred.promise();
  60              }
  61          }
  62          requestParams = url;
  63          if (typeof params.data != "undefined") {
  64              var requestParams = {};
  65              requestParams['data'] = params.data;
  66              requestParams['url'] = url;
  67          }
  68          AppConnector.request(requestParams).then(function(data) {
  69              if ((!params.noCache) || (typeof (params.noCache) == "undefined")) {
  70                  Vtiger_Header_Js.quickCreateModuleCache[moduleName] = data;
  71              }
  72              aDeferred.resolve(data);
  73          });
  74          return aDeferred.promise();
  75      },
  76      registerQuickCreateCallBack: function(callBackFunction) {
  77          if (typeof callBackFunction != 'function') {
  78              return false;
  79          }
  80          this.quickCreateCallBacks.push(callBackFunction);
  81          return true;
  82      },
  83      /**
  84       * Function which will align the contents container at specified height depending on the top fixed menu
  85       * It will caliculate the height by following formaula menuContianer.height+1     *
  86       */
  87      alignContentsContainer: function(topValue,speed, effect) {
  88          if (typeof topValue == 'undefined') {
  89              topValue = '90px';
  90          }
  91          var contentsContainer = this.getContentsContainer();
  92          contentsContainer.animate({'margin-top': topValue}, speed, effect);
  93          return this;
  94      },
  95      /**
  96       * Function to save the quickcreate module
  97       * @param accepts form element as parameter
  98       * @return returns deferred promise
  99       */
 100      quickCreateSave: function(form) {
 101          var aDeferred = jQuery.Deferred();
 102          var quickCreateSaveUrl = form.serializeFormData();
 103          AppConnector.request(quickCreateSaveUrl).then(
 104                  function(data) {
 105                      //TODO: App Message should be shown
 106                      aDeferred.resolve(data);
 107                  },
 108                  function(textStatus, errorThrown) {
 109                      aDeferred.reject(textStatus, errorThrown);
 110                  }
 111          );
 112          return aDeferred.promise();
 113      },
 114      /**
 115       * Function to navigate from quickcreate to editView Fullform
 116       * @param accepts form element as parameter
 117       */
 118      quickCreateGoToFullForm: function(form, editViewUrl) {
 119          var formData = form.serializeFormData();
 120          //As formData contains information about both view and action removed action and directed to view
 121          delete formData.module;
 122          delete formData.action;
 123          var formDataUrl = jQuery.param(formData);
 124          var completeUrl = editViewUrl + "&" + formDataUrl;
 125          window.location.href = completeUrl;
 126      },
 127      setAnnouncement: function() {
 128  //        var announcementoff = app.cacheGet('announcement.turnoff' , false);
 129  //        var announcementBtn = jQuery('#announcementBtn');
 130  //        var thisInstance = this;
 131  //        if(announcementoff === true) {
 132  //            jQuery('#announcement').hide();
 133  //            announcementBtn.attr('src', app.vimage_path('btnAnnounceOff.png'));
 134  //            thisInstance.alignContentsContainer('69px',0,'linear');
 135  //        }
 136  //        else{
 137  //            jQuery('#announcement').show();
 138  //            announcementBtn.attr('src', app.vimage_path('btnAnnounce.png'));
 139  //            thisInstance.alignContentsContainer('92px',0,'linear');
 140  //        }
 141      },
 142      registerAnnouncement: function() {
 143          var thisInstance = this;
 144          var announcementBtn = jQuery('#announcementBtn');
 145          var announcementTurnOffKey = 'announcement.turnoff';
 146  
 147          announcementBtn.click(function(e, manual) {
 148              var displayStatus = jQuery('#announcement').css('display');
 149              if (displayStatus == 'none') {
 150                  jQuery('#announcement').show();
 151                  thisInstance.alignContentsContainer('114px',200,'linear');
 152                  announcementBtn.attr('src', app.vimage_path('btnAnnounce.png'));
 153  
 154                  // Turn-on always
 155                  if (!manual) {
 156                      app.cacheSet(announcementTurnOffKey, false);
 157                  }
 158              } else {
 159                  thisInstance.alignContentsContainer('90px',200,'linear');
 160                  jQuery('#announcement').hide();
 161                  announcementBtn.attr('src', app.vimage_path('btnAnnounceOff.png'));
 162  
 163                  // Turn-off always
 164                  // NOTE: Add preference on server - to reenable on announcement content change.
 165                  if (!manual) {
 166                      app.cacheSet(announcementTurnOffKey, true);
 167                  }
 168  
 169              }
 170          });
 171  
 172          if (app.cacheGet(announcementTurnOffKey, false)) {
 173              announcementBtn.trigger('click', true);
 174          }
 175      },
 176      registerCalendarButtonClickEvent: function() {
 177          var element = jQuery('#calendarBtn');
 178          var dateFormat = element.data('dateFormat');
 179          var currentDate = element.data('date');
 180          var vtigerDateFormat = app.convertToDatePickerFormat(dateFormat);
 181          element.on('click', function(e) {
 182              e.stopImmediatePropagation();
 183              element.closest('div.nav').find('div.open').removeClass('open');
 184              var calendar = jQuery('#' + element.data('datepickerId'));
 185              if (jQuery(calendar).is(':visible')) {
 186                  element.DatePickerHide();
 187              } else {
 188                  element.DatePickerShow();
 189              }
 190          })
 191          element.DatePicker({
 192              format: vtigerDateFormat,
 193              date: currentDate,
 194              calendars: 1,
 195              starts: 1,
 196              className: 'globalCalendar'
 197          });
 198      },
 199      handleQuickCreateData: function(data, params) {
 200          if (typeof params == 'undefined') {
 201              params = {};
 202          }
 203          var thisInstance = this;
 204          app.showModalWindow(data, function(data) {
 205              var quickCreateForm = data.find('form[name="QuickCreate"]');
 206              var moduleName = quickCreateForm.find('[name="module"]').val();
 207              var editViewInstance = Vtiger_Edit_Js.getInstanceByModuleName(moduleName);
 208              editViewInstance.registerBasicEvents(quickCreateForm);
 209              quickCreateForm.validationEngine(app.validationEngineOptions);
 210              if (typeof params.callbackPostShown != "undefined") {
 211                  params.callbackPostShown(quickCreateForm);
 212              }
 213              thisInstance.registerQuickCreatePostLoadEvents(quickCreateForm, params);
 214              app.registerEventForDatePickerFields(quickCreateForm);
 215              var quickCreateContent = quickCreateForm.find('.quickCreateContent');
 216              var quickCreateContentHeight = quickCreateContent.height();
 217              var contentHeight = parseInt(quickCreateContentHeight);
 218              if (contentHeight > 300) {
 219                  app.showScrollBar(jQuery('.quickCreateContent'), {
 220                      'height': '300px'
 221                  });
 222              }
 223          });
 224      },
 225      registerQuickCreatePostLoadEvents: function(form, params) {
 226          var thisInstance = this;
 227          var submitSuccessCallbackFunction = params.callbackFunction;
 228          var goToFullFormCallBack = params.goToFullFormcallback;
 229          if (typeof submitSuccessCallbackFunction == 'undefined') {
 230              submitSuccessCallbackFunction = function() {
 231              };
 232          }
 233  
 234          form.on('submit', function(e) {
 235              var form = jQuery(e.currentTarget);
 236              var module = form.find('[name="module"]').val();
 237              //Form should submit only once for multiple clicks also
 238              if (typeof form.data('submit') != "undefined") {
 239                  return false;
 240              } else {
 241                  var invalidFields = form.data('jqv').InvalidFields;
 242  
 243                  if (invalidFields.length > 0) {
 244                      //If validation fails, form should submit again
 245                      form.removeData('submit');
 246                      form.closest('#globalmodal').find('.modal-header h3').progressIndicator({
 247                          'mode': 'hide'
 248                      });
 249                      e.preventDefault();
 250                      return;
 251                  } else {
 252                      //Once the form is submiting add data attribute to that form element
 253                      form.data('submit', 'true');
 254                      form.closest('#globalmodal').find('.modal-header h3').progressIndicator({
 255                          smallLoadingImage: true,
 256                          imageContainerCss: {
 257                              display: 'inline',
 258                              'margin-left': '18%',
 259                              position: 'absolute'
 260                          }
 261                      });
 262                  }
 263  
 264                  var recordPreSaveEvent = jQuery.Event(Vtiger_Edit_Js.recordPreSave);
 265                  form.trigger(recordPreSaveEvent, {
 266                      'value': 'edit',
 267                      'module': module
 268                  });
 269                  if (!(recordPreSaveEvent.isDefaultPrevented())) {
 270                      var targetInstance = thisInstance;
 271                      var moduleInstance = Vtiger_Edit_Js.getInstanceByModuleName(module);
 272                      if(typeof(moduleInstance.quickCreateSave) === 'function'){
 273                          targetInstance = moduleInstance;
 274                      }
 275                      
 276                      targetInstance.quickCreateSave(form).then(
 277                              function(data) {
 278                                  app.hideModalWindow();
 279                                  //fix for Refresh list view after Quick create 
 280                                  var parentModule=app.getModuleName(); 
 281                                  var viewname=app.getViewName(); 
 282                                  if((module == parentModule) && (viewname=="List")){ 
 283                                      var listinstance = new Vtiger_List_Js(); 
 284                                      listinstance.getListViewRecords();      
 285                                  } 
 286                                  submitSuccessCallbackFunction(data);
 287                                  var registeredCallBackList = thisInstance.quickCreateCallBacks;
 288                                  for (var index = 0; index < registeredCallBackList.length; index++) {
 289                                      var callBack = registeredCallBackList[index];
 290                                      callBack({
 291                                          'data': data,
 292                                          'name': form.find('[name="module"]').val()
 293                                      });
 294                                  }
 295                              },
 296                              function(error, err) {
 297                              }
 298                      );
 299                  } else {
 300                      //If validation fails in recordPreSaveEvent, form should submit again
 301                      form.removeData('submit');
 302                      form.closest('#globalmodal').find('.modal-header h3').progressIndicator({
 303                          'mode': 'hide'
 304                      });
 305                  }
 306                  e.preventDefault();
 307              }
 308          });
 309  
 310          form.find('#goToFullForm').on('click', function(e) {
 311              var form = jQuery(e.currentTarget).closest('form');
 312              var editViewUrl = jQuery(e.currentTarget).data('editViewUrl');
 313              if (typeof goToFullFormCallBack != "undefined") {
 314                  goToFullFormCallBack(form);
 315              }
 316              thisInstance.quickCreateGoToFullForm(form, editViewUrl);
 317          });
 318  
 319          this.registerTabEventsInQuickCreate(form);
 320      },
 321      registerTabEventsInQuickCreate: function(form) {
 322          var tabElements = form.find('.nav.nav-pills , .nav.nav-tabs').find('a');
 323  
 324          //This will remove the name attributes and assign it to data-element-name . We are doing this to avoid
 325          //Multiple element to send as in calendar
 326          var quickCreateTabOnHide = function(tabElement) {
 327              var container = jQuery(tabElement.attr('data-target'));
 328  
 329              container.find('[name]').each(function(index, element) {
 330                  element = jQuery(element);
 331                  element.attr('data-element-name', element.attr('name')).removeAttr('name');
 332              });
 333          }
 334  
 335          //This will add the name attributes and get value from data-element-name . We are doing this to avoid
 336          //Multiple element to send as in calendar
 337          var quickCreateTabOnShow = function(tabElement) {
 338              var container = jQuery(tabElement.attr('data-target'));
 339  
 340              container.find('[data-element-name]').each(function(index, element) {
 341                  element = jQuery(element);
 342                  element.attr('name', element.attr('data-element-name')).removeAttr('data-element-name');
 343              });
 344          }
 345  
 346          tabElements.on('shown', function(e) {
 347              var previousTab = jQuery(e.relatedTarget);
 348              var currentTab = jQuery(e.currentTarget);
 349  
 350              quickCreateTabOnHide(previousTab);
 351              quickCreateTabOnShow(currentTab);
 352  
 353              //while switching tabs we have to clear the invalid fields list
 354              form.data('jqv').InvalidFields = [];
 355  
 356          });
 357  
 358          //To show aleady non active element , this we are doing so that on load we can remove name attributes for other fields
 359          quickCreateTabOnHide(tabElements.closest('li').filter(':not(.active)').find('a'));
 360      },
 361      basicSearch: function() {
 362          var thisInstance = this;
 363          jQuery('#globalSearchValue').keypress(function(e) {
 364              var currentTarget = jQuery(e.currentTarget)
 365              if (e.which == 13) {
 366                  thisInstance.labelSearch(currentTarget);
 367              }
 368          });
 369      },
 370      labelSearch: function(currentTarget) {
 371          var val = currentTarget.val();
 372          if (val == '') {
 373              alert(app.vtranslate('JS_PLEASE_ENTER_SOME_VALUE'));
 374              currentTarget.focus();
 375              return false;
 376          }
 377          var basicSearch = new Vtiger_BasicSearch_Js();
 378          var progress = jQuery.progressIndicator();
 379          basicSearch.search(val).then(function(data) {
 380              basicSearch.showSearchResults(data);
 381              progress.progressIndicator({
 382                  'mode': 'hide'
 383              });
 384          });
 385      },
 386  
 387      adjustContentHeight: function(){
 388          if(app.getViewName() === 'Detail' || app.getViewName() === 'Calendar' || app.getViewName() === 'ExtensionImport'){
 389              if(jQuery('div.detailViewInfo > .related').outerHeight() > jQuery('div.detailViewInfo > div.details ').outerHeight()){
 390                  jQuery('div.detailViewInfo > div.details').css('min-height',jQuery('.detailViewInfo > .related').outerHeight());
 391              }
 392              bodyHeight = jQuery('div.detailViewContainer').outerHeight();
 393          }else{
 394              bodyHeight = jQuery(".bodyContents").outerHeight();
 395          }
 396          jQuery(".mainContainer").css('min-height', bodyHeight);
 397          jQuery(".mainContainer > .span2 ").css('min-height', bodyHeight);
 398          jQuery(".contentsDiv").css('min-height', bodyHeight);
 399      },
 400  
 401      registerEvents: function() {
 402          var thisInstance = this;
 403  
 404          //Show Alert if user is on a unsupported browser (IE7, IE8, ..etc)
 405          if(jQuery.browser.msie && jQuery.browser.version < 9.0) {
 406              if(app.getCookie('oldbrowser') != 'true') {
 407                  app.setCookie("oldbrowser",true, 365);
 408                  window.location.href = 'layouts/vlayout/modules/Vtiger/browsercompatibility/Browser_compatibility.html';
 409              }
 410          }
 411  
 412          jQuery('#globalSearch').click(function() {
 413              var advanceSearchInstance = new Vtiger_AdvanceSearch_Js();
 414              advanceSearchInstance.initiateSearch().then(function() {
 415                  advanceSearchInstance.selectBasicSearchValue();
 416              });
 417          });
 418          jQuery('#searchIcon').on('click', function(e) {
 419              var currentTarget = jQuery('#globalSearchValue');
 420              var pressEvent = jQuery.Event("keypress");
 421              pressEvent.which = 13;
 422              currentTarget.trigger(pressEvent);
 423          });
 424          thisInstance.registerAnnouncement();
 425          //this.setAnnouncement();
 426          jQuery('#announcementBtn').trigger('click');
 427  
 428          this.registerCalendarButtonClickEvent();
 429          jQuery('#moreMenu').click(function(e) {
 430              var moreElem = jQuery(e.currentTarget);
 431              var moreMenu = jQuery('.moreMenus', moreElem)
 432              var index = jQuery(".modulesList > li", thisInstance.getMenuContainer()).length;
 433              // for left aligning the more menus dropdown if the modules list is below 5
 434              if (index < 5) {
 435                  moreMenu.css('left', 0).addClass('leftAligned');
 436              }
 437          });
 438  
 439          //After selecting the global search module, focus the input element to type
 440          jQuery('#basicSearchModulesList').change(function() {
 441              jQuery('#globalSearchValue').focus();
 442          });
 443  
 444          thisInstance.basicSearch();
 445          jQuery('#quickCreateModules,#compactquickCreate').on("click", ".quickCreateModule", function(e, params) {
 446              if (typeof params == 'undefined') {
 447                  params = {};
 448              }
 449  
 450              if (typeof params.callbackFunction == 'undefined') {
 451                  params.callbackFunction = function() {
 452                  };
 453              }
 454  
 455              var quickCreateElem = jQuery(e.currentTarget);
 456              var quickCreateUrl = quickCreateElem.data('url');
 457              var quickCreateModuleName = quickCreateElem.data('name');
 458  
 459              var progress = jQuery.progressIndicator();
 460              thisInstance.getQuickCreateForm(quickCreateUrl, quickCreateModuleName, params).then(function(data) {
 461                  thisInstance.handleQuickCreateData(data, params);
 462                  progress.progressIndicator({
 463                      'mode': 'hide'
 464                  });
 465              });
 466  
 467          });
 468          if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){
 469              jQuery('#basicSearchModulesList_chzn').find('.chzn-results').css({'max-height':'350px','overflow-y':'scroll'});
 470          }
 471          else{
 472              app.showScrollBar(jQuery('#basicSearchModulesList_chzn').find('.chzn-results'),
 473              {
 474              height: '450px',
 475              railVisible: true,
 476              alwaysVisible: true,
 477              size: '6px'
 478          });
 479  
 480  
 481  
 482          //Added to support standard resolution 1024x768
 483          if (window.outerWidth <= 1024) {
 484              $('.headerLinksContainer').css('margin-right', '8px');
 485          }
 486  
 487          // setting sidebar Height wrt Content
 488          $(document).ajaxComplete(function() {
 489               Vtiger_Header_Js.getInstance().adjustContentHeight();
 490          });
 491          $(document).load(function() {
 492               Vtiger_Header_Js.getInstance().adjustContentHeight();
 493          });
 494      }
 495  }
 496  });
 497  jQuery(document).ready(function() {
 498  
 499  
 500      Vtiger_Header_Js.getInstance().registerEvents();
 501  
 502  });


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1