[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/resources/ -> app.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  var app = {
  11  
  12      /**
  13       * variable stores client side language strings
  14       */
  15      languageString : [],
  16      
  17      
  18      weekDaysArray : {Sunday : 0,Monday : 1, Tuesday : 2, Wednesday : 3,Thursday : 4, Friday : 5, Saturday : 6},
  19  
  20      /**
  21       * Function to get the module name. This function will get the value from element which has id module
  22       * @return : string - module name
  23       */
  24      getModuleName : function() {
  25          return jQuery('#module').val();
  26      },
  27  
  28      /**
  29       * Function to get the module name. This function will get the value from element which has id module
  30       * @return : string - module name
  31       */
  32      getParentModuleName : function() {
  33          return jQuery('#parent').val();
  34      },
  35  
  36      /**
  37       * Function returns the current view name
  38       */
  39      getViewName : function() {
  40          return jQuery('#view').val();
  41      },
  42      /**
  43       * Function to get the contents container
  44       * @returns jQuery object
  45       */
  46      getContentsContainer : function() {
  47          return jQuery('.bodyContents');
  48      },
  49  
  50      /**
  51       * Function which will convert ui of select boxes.
  52       * @params parent - select element
  53       * @params view - select2
  54       * @params viewParams - select2 params
  55       * @returns jquery object list which represents changed select elements
  56       */
  57      changeSelectElementView : function(parent, view, viewParams){
  58  
  59          var selectElement = jQuery();
  60          if(typeof parent == 'undefined') {
  61              parent = jQuery('body');
  62          }
  63  
  64          //If view is select2, This will convert the ui of select boxes to select2 elements.
  65          if(view == 'select2') {
  66              app.showSelect2ElementView(parent, viewParams);
  67              return;
  68          }
  69          selectElement = jQuery('.chzn-select', parent);
  70          //parent itself is the element
  71          if(parent.is('select.chzn-select')) {
  72              selectElement = parent;
  73          }
  74  
  75          //fix for multiselect error prompt hide when validation is success
  76          selectElement.filter('[multiple]').filter('[data-validation-engine*="validate"]').on('change',function(e){
  77              jQuery(e.currentTarget).trigger('focusout');
  78          });
  79  
  80          var chosenElement = selectElement.chosen();
  81          var chosenSelectConainer = jQuery('.chzn-container');
  82          //Fix for z-index issue in IE 7
  83          if (jQuery.browser.msie && jQuery.browser.version === "7.0") {
  84              var zidx = 1000;
  85              chosenSelectConainer.each(function(){
  86                  $(this).css('z-index', zidx);
  87                  zidx-=10;
  88              });
  89          }
  90          return chosenSelectConainer;
  91      },
  92  
  93      /**
  94       * Function to destroy the chosen element and get back the basic select Element
  95       */
  96      destroyChosenElement : function(parent) {
  97          var selectElement = jQuery();
  98          if(typeof parent == 'undefined') {
  99              parent = jQuery('body');
 100          }
 101  
 102          selectElement = jQuery('.chzn-select', parent);
 103          //parent itself is the element
 104          if(parent.is('select.chzn-select')) {
 105              selectElement = parent;
 106          }
 107  
 108          selectElement.css('display','block').removeClass("chzn-done").data("chosen", null).next().remove();
 109  
 110          return selectElement;
 111  
 112      },
 113      /**
 114       * Function which will show the select2 element for select boxes . This will use select2 library
 115       */
 116      showSelect2ElementView : function(selectElement, params) {
 117          if(typeof params == 'undefined') {
 118              params = {};
 119          }
 120  
 121          var data = selectElement.data();
 122          if(data != null) {
 123              params = jQuery.extend(data,params);
 124          }
 125  
 126          // Sort DOM nodes alphabetically in select box.
 127          if (typeof params['customSortOptGroup'] != 'undefined' && params['customSortOptGroup']) {
 128              jQuery('optgroup', selectElement).each(function(){
 129                  var optgroup = jQuery(this);
 130                  var options  = optgroup.children().toArray().sort(function(a, b){
 131                      var aText = jQuery(a).text();
 132                      var bText = jQuery(b).text();
 133                      return aText < bText ? 1 : -1;
 134                  });
 135                  jQuery.each(options, function(i, v){
 136                      optgroup.prepend(v);
 137                  });
 138              });
 139              delete params['customSortOptGroup'];
 140          }
 141  
 142          //formatSelectionTooBig param is not defined even it has the maximumSelectionSize,
 143          //then we should send our custom function for formatSelectionTooBig
 144          if(typeof params.maximumSelectionSize != "undefined" && typeof params.formatSelectionTooBig == "undefined") {
 145              var limit = params.maximumSelectionSize;
 146              //custom function which will return the maximum selection size exceeds message.
 147              var formatSelectionExceeds = function(limit) {
 148                      return app.vtranslate('JS_YOU_CAN_SELECT_ONLY')+' '+limit+' '+app.vtranslate('JS_ITEMS');
 149              }
 150              params.formatSelectionTooBig = formatSelectionExceeds;
 151          }
 152          if(selectElement.attr('multiple') != 'undefined' && typeof params.closeOnSelect == 'undefined') {
 153              params.closeOnSelect = false;
 154          }
 155  
 156          selectElement.select2(params)
 157                       .on("open", function(e) {
 158                           var element = jQuery(e.currentTarget);
 159                           var instance = element.data('select2');
 160                           instance.dropdown.css('z-index',1000002);
 161                       });
 162          if(typeof params.maximumSelectionSize != "undefined") {
 163              app.registerChangeEventForMultiSelect(selectElement,params);
 164          }
 165          return selectElement;
 166      },
 167  
 168      /**
 169       * Function to check the maximum selection size of multiselect and update the results
 170       * @params <object> multiSelectElement
 171       * @params <object> select2 params
 172       */
 173  
 174      registerChangeEventForMultiSelect :  function(selectElement,params) {
 175          if(typeof selectElement == 'undefined') {
 176              return;
 177          }
 178          var instance = selectElement.data('select2');
 179          var limit = params.maximumSelectionSize;
 180          selectElement.on('change',function(e){
 181              var data = instance.data()
 182              if (jQuery.isArray(data) && data.length >= limit ) {
 183                  instance.updateResults();
 184              }
 185          });
 186  
 187      },
 188  
 189      /**
 190       * Function to get data of the child elements in serialized format
 191       * @params <object> parentElement - element in which the data should be serialized. Can be selector , domelement or jquery object
 192       * @params <String> returnFormat - optional which will indicate which format return value should be valid values "object" and "string"
 193       * @return <object> - encoded string or value map
 194       */
 195      getSerializedData : function(parentElement, returnFormat){
 196          if(typeof returnFormat == 'undefined') {
 197              returnFormat = 'string';
 198          }
 199  
 200          parentElement = jQuery(parentElement);
 201  
 202          var encodedString = parentElement.children().serialize();
 203          if(returnFormat == 'string'){
 204              return encodedString;
 205          }
 206          var keyValueMap = {};
 207          var valueList = encodedString.split('&')
 208  
 209          for(var index in valueList){
 210              var keyValueString = valueList[index];
 211              var keyValueArr = keyValueString.split('=');
 212              var nameOfElement = keyValueArr[0];
 213              var valueOfElement =  keyValueArr[1];
 214              keyValueMap[nameOfElement] = decodeURIComponent(valueOfElement);
 215          }
 216          return keyValueMap;
 217      },
 218  
 219      showModalWindow: function(data, url, cb, css) {
 220  
 221          var unBlockCb = function(){};
 222          var overlayCss = {};
 223  
 224          //null is also an object
 225          if(typeof data == 'object' && data != null && !(data instanceof jQuery)){
 226              css = data.css;
 227              cb = data.cb;
 228              url = data.url;
 229              unBlockCb = data.unblockcb;
 230              overlayCss = data.overlayCss;
 231              data = data.data
 232  
 233          }
 234          if (typeof url == 'function') {
 235              if(typeof cb == 'object') {
 236                  css = cb;
 237              }
 238              cb = url;
 239              url = false;
 240          }
 241          else if (typeof url == 'object') {
 242              cb = function() { };
 243              css = url;
 244              url = false;
 245          }
 246  
 247          if (typeof cb != 'function') {
 248              cb = function() { }
 249          }
 250  
 251          var id = 'globalmodal';
 252          var container = jQuery('#'+id);
 253          if (container.length) {
 254              container.remove();
 255          }
 256          container = jQuery('<div></div>');
 257          container.attr('id', id);
 258  
 259          var showModalData = function (data) {
 260  
 261              var defaultCss = {
 262                              'top' : '0px',
 263                              'width' : 'auto',
 264                              'cursor' : 'default',
 265                              'left' : '35px',
 266                              'text-align' : 'left',
 267                              'border-radius':'6px'
 268                              };
 269              var effectiveCss = defaultCss;
 270              if(typeof css == 'object') {
 271                  effectiveCss = jQuery.extend(defaultCss, css)
 272              }
 273  
 274              var defaultOverlayCss = {
 275                                          'cursor' : 'default'
 276                                      };
 277              var effectiveOverlayCss = defaultOverlayCss;
 278              if(typeof overlayCss == 'object' ) {
 279                  effectiveOverlayCss = jQuery.extend(defaultOverlayCss,overlayCss);
 280              }
 281              container.html(data);
 282  
 283              // Mimic bootstrap modal action body state change
 284              jQuery('body').addClass('modal-open');
 285  
 286              //container.modal();
 287              jQuery.blockUI({
 288                      'message' : container,
 289                      'overlayCSS' : effectiveOverlayCss,
 290                      'css' : effectiveCss,
 291  
 292                      // disable if you want key and mouse events to be enable for content that is blocked (fix for select2 search box)
 293                      bindEvents: false,
 294  
 295                      //Fix for overlay opacity issue in FF/Linux
 296                      applyPlatformOpacityRules : false
 297                  });
 298              var unblockUi = function() {
 299                  app.hideModalWindow(unBlockCb);
 300                  jQuery(document).unbind("keyup",escapeKeyHandler);
 301              }
 302              var escapeKeyHandler = function(e){
 303                  if (e.keyCode == 27) {
 304                          unblockUi();
 305                  }
 306              }
 307              jQuery('.blockOverlay').click(unblockUi);
 308              jQuery(document).on('keyup',escapeKeyHandler);
 309              jQuery('[data-dismiss="modal"]', container).click(unblockUi);
 310  
 311              container.closest('.blockMsg').position({
 312                  'of' : jQuery(window),
 313                  'my' : 'center top',
 314                  'at' : 'center top',
 315                  'collision' : 'flip none',
 316                  //TODO : By default the position of the container is taking as -ve so we are giving offset
 317                  // Check why it is happening
 318                  'offset' : '0 50'
 319              });
 320              //container.css({'height' : container.innerHeight()+15+'px'});
 321  
 322              // TODO Make it better with jQuery.on
 323              app.changeSelectElementView(container);
 324              //register all select2 Elements
 325              app.showSelect2ElementView(container.find('select.select2'));
 326              //register date fields event to show mini calendar on click of element
 327              app.registerEventForDatePickerFields(container);
 328              cb(container);
 329          }
 330  
 331          if (data) {
 332              showModalData(data)
 333  
 334          } else {
 335              jQuery.get(url).then(function(response){
 336                  showModalData(response);
 337              });
 338          }
 339  
 340          return container;
 341      },
 342  
 343      /**
 344       * Function which you can use to hide the modal
 345       * This api assumes that we are using block ui plugin and uses unblock api to unblock it
 346       */
 347      hideModalWindow : function(callback) {
 348          // Mimic bootstrap modal action body state change - helps to avoid body scroll
 349          // when modal is shown using css: http://stackoverflow.com/a/11013994
 350          jQuery('body').removeClass('modal-open');
 351  
 352          var id = 'globalmodal';
 353          var container = jQuery('#'+id);
 354          if (container.length <= 0) {
 355              return;
 356          }
 357  
 358          if(typeof callback != 'function') {
 359              callback = function() {};
 360          }
 361          jQuery.unblockUI({
 362              'onUnblock' : callback
 363          });
 364      },
 365  
 366      isHidden : function(element) {
 367          if(element.css('display')== 'none') {
 368              return true;
 369          }
 370          return false;
 371      },
 372  
 373      /**
 374       * Default validation eninge options
 375       */
 376      validationEngineOptions: {
 377          // Avoid scroll decision and let it scroll up page when form is too big
 378          // Reference: http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
 379          scroll: false,
 380          promptPosition: 'topLeft',
 381          //to support validation for chosen select box
 382          prettySelect : true,
 383          useSuffix: "_chzn",
 384          usePrefix : "s2id_"
 385      },
 386  
 387      /**
 388       * Function to push down the error message size when validation is invoked
 389       * @params : form Element
 390       */
 391  
 392      formAlignmentAfterValidation : function(form){
 393          // to avoid hiding of error message under the fixed nav bar
 394          var destination = form.find(".formError:not('.greenPopup'):first").offset().top;
 395          var resizedDestnation = destination-105;
 396          jQuery('html').animate({
 397              scrollTop:resizedDestnation
 398          }, 'slow');
 399      },
 400  
 401      /**
 402       * Function to push down the error message size when validation is invoked
 403       * @params : form Element
 404       */
 405      formAlignmentAfterValidation : function(form){
 406          // to avoid hiding of error message under the fixed nav bar
 407          var destination = form.find(".formError:not('.greenPopup'):first").offset().top;
 408          var resizedDestnation = destination-105;
 409          jQuery('html').animate({
 410              scrollTop:resizedDestnation
 411          }, 'slow');
 412      },
 413  
 414      convertToDatePickerFormat: function(dateFormat){
 415          if(dateFormat == 'yyyy-mm-dd'){
 416              return 'Y-m-d';
 417          } else if(dateFormat == 'mm-dd-yyyy') {
 418              return 'm-d-Y';
 419          } else if (dateFormat == 'dd-mm-yyyy') {
 420              return 'd-m-Y';
 421          }
 422      },
 423  
 424      convertTojQueryDatePickerFormat: function(dateFormat){
 425          var i = 0;
 426          var splitDateFormat = dateFormat.split('-');
 427          for(var i in splitDateFormat){
 428              var sectionDate = splitDateFormat[i];
 429              var sectionCount = sectionDate.length;
 430              if(sectionCount == 4){
 431                  var strippedString = sectionDate.substring(0,2);
 432                  splitDateFormat[i] = strippedString;
 433              }
 434          }
 435          var joinedDateFormat =  splitDateFormat.join('-');
 436          return joinedDateFormat;
 437      },
 438      getDateInVtigerFormat: function(dateFormat,dateObject){
 439          var finalFormat = app.convertTojQueryDatePickerFormat(dateFormat);
 440          var date = jQuery.datepicker.formatDate(finalFormat,dateObject);
 441          return date;
 442      },
 443  
 444      registerEventForTextAreaFields : function(parentElement) {
 445          if(typeof parentElement == 'undefined') {
 446              parentElement = jQuery('body');
 447          }
 448  
 449          parentElement = jQuery(parentElement);
 450  
 451          if(parentElement.is('textarea')){
 452              var element = parentElement;
 453          }else{
 454              var element = jQuery('textarea', parentElement);
 455          }
 456          if(element.length == 0){
 457              return;
 458          }
 459          element.autosize();
 460      },
 461  
 462      registerEventForDatePickerFields : function(parentElement,registerForAddon,customParams){
 463          if(typeof parentElement == 'undefined') {
 464              parentElement = jQuery('body');
 465          }
 466          if(typeof registerForAddon == 'undefined'){
 467              registerForAddon = true;
 468          }
 469  
 470          parentElement = jQuery(parentElement);
 471  
 472          if(parentElement.hasClass('dateField')){
 473              var element = parentElement;
 474          }else{
 475              var element = jQuery('.dateField', parentElement);
 476          }
 477          if(element.length == 0){
 478              return;
 479          }
 480          if(registerForAddon == true){
 481              var parentDateElem = element.closest('.date');
 482              jQuery('.add-on',parentDateElem).on('click',function(e){
 483                  var elem = jQuery(e.currentTarget);
 484                  //Using focus api of DOM instead of jQuery because show api of datePicker is calling e.preventDefault
 485                  //which is stopping from getting focus to input element
 486                  elem.closest('.date').find('input.dateField').get(0).focus();
 487              });
 488          }
 489          var dateFormat = element.data('dateFormat');
 490          var vtigerDateFormat = app.convertToDatePickerFormat(dateFormat);
 491          var language = jQuery('body').data('language');
 492          var lang = language.split('_');
 493          
 494          //Default first day of the week
 495          var defaultFirstDay = jQuery('#start_day').val();
 496          if(defaultFirstDay == '' || typeof(defaultFirstDay) == 'undefined'){
 497              var convertedFirstDay = 1
 498          } else {
 499              convertedFirstDay = this.weekDaysArray[defaultFirstDay];
 500          }
 501          var params = {
 502              format : vtigerDateFormat,
 503              calendars: 1,
 504              locale: $.fn.datepicker.dates[lang[0]],
 505              starts: convertedFirstDay,
 506              eventName : 'focus',
 507              onChange: function(formated){
 508                  var element = jQuery(this).data('datepicker').el;
 509                  element = jQuery(element);
 510                  var datePicker = jQuery('#'+ jQuery(this).data('datepicker').id);
 511                  var viewDaysElement = datePicker.find('table.datepickerViewDays');
 512                  //If it is in day mode and the prev value is not eqaul to current value
 513                  //Second condition is manily useful in places where user navigates to other month
 514                  if(viewDaysElement.length > 0 && element.val() != formated) {
 515                      element.DatePickerHide();
 516                      element.blur();
 517                  }
 518                  element.val(formated).trigger('change').focusout();
 519              }
 520          }
 521          if(typeof customParams != 'undefined'){
 522              var params = jQuery.extend(params,customParams);
 523          }
 524          element.each(function(index,domElement){
 525              var jQelement = jQuery(domElement);
 526              var dateObj = new Date();
 527              var selectedDate = app.getDateInVtigerFormat(dateFormat, dateObj);
 528              //Take the element value as current date or current date
 529              if(jQelement.val() != '') {
 530                  selectedDate = jQelement.val();
 531              }
 532              params.date = selectedDate;
 533              params.current = selectedDate;
 534              jQelement.DatePicker(params)
 535          });
 536  
 537      },
 538      registerEventForDateFields : function(parentElement) {
 539          if(typeof parentElement == 'undefined') {
 540              parentElement = jQuery('body');
 541          }
 542  
 543          parentElement = jQuery(parentElement);
 544  
 545          if(parentElement.hasClass('dateField')){
 546              var element = parentElement;
 547          }else{
 548              var element = jQuery('.dateField', parentElement);
 549          }
 550          element.datepicker({'autoclose':true}).on('changeDate', function(ev){
 551              var currentElement = jQuery(ev.currentTarget);
 552              var dateFormat = currentElement.data('dateFormat');
 553              var finalFormat = app.getDateInVtigerFormat(dateFormat,ev.date);
 554              var date = jQuery.datepicker.formatDate(finalFormat,ev.date);
 555              currentElement.val(date);
 556          });
 557      },
 558  
 559      /**
 560       * Function which will register time fields
 561       *
 562       * @params : container - jquery object which contains time fields with class timepicker-default or itself can be time field
 563       *             registerForAddon - boolean value to register the event for Addon or not
 564       *             params  - params for the  plugin
 565       *
 566       * @return : container to support chaining
 567       */
 568      registerEventForTimeFields : function(container, registerForAddon, params) {
 569  
 570          if(typeof cotainer == 'undefined') {
 571              container = jQuery('body');
 572          }
 573          if(typeof registerForAddon == 'undefined'){
 574              registerForAddon = true;
 575          }
 576  
 577          container = jQuery(container);
 578  
 579          if(container.hasClass('timepicker-default')) {
 580              var element = container;
 581          }else{
 582              var element = container.find('.timepicker-default');
 583          }
 584  
 585          if(registerForAddon == true){
 586              var parentTimeElem = element.closest('.time');
 587              jQuery('.add-on',parentTimeElem).on('click',function(e){
 588                  var elem = jQuery(e.currentTarget);
 589                  elem.closest('.time').find('.timepicker-default').focus();
 590              });
 591          }
 592  
 593          if(typeof params == 'undefined') {
 594              params = {};
 595          }
 596  
 597          var timeFormat = element.data('format');
 598          if(timeFormat == '24') {
 599              timeFormat = 'H:i';
 600          } else {
 601              timeFormat = 'h:i A';
 602          }
 603          var defaultsTimePickerParams = {
 604              'timeFormat' : timeFormat,
 605              'className'  : 'timePicker'
 606          };
 607          var params = jQuery.extend(defaultsTimePickerParams, params);
 608  
 609          element.timepicker(params);
 610  
 611          return container;
 612      },
 613  
 614      /**
 615       * Function to destroy time fields
 616       */
 617      destroyTimeFields : function(container) {
 618  
 619          if(typeof cotainer == 'undefined') {
 620              container = jQuery('body');
 621          }
 622  
 623          if(container.hasClass('timepicker-default')) {
 624              var element = container;
 625          }else{
 626              var element = container.find('.timepicker-default');
 627          }
 628          element.data('timepicker-list',null);
 629          return container;
 630      },
 631  
 632      /**
 633       * Function to get the chosen element from the raw select element
 634       * @params: select element
 635       * @return : chosenElement - corresponding chosen element
 636       */
 637      getChosenElementFromSelect : function(selectElement) {
 638          var selectId = selectElement.attr('id');
 639          var chosenEleId = selectId+"_chzn";
 640          return jQuery('#'+chosenEleId);
 641      },
 642  
 643      /**
 644       * Function to get the select2 element from the raw select element
 645       * @params: select element
 646       * @return : select2Element - corresponding select2 element
 647       */
 648      getSelect2ElementFromSelect : function(selectElement) {
 649          var selectId = selectElement.attr('id');
 650          //since select2 will add s2id_ to the id of select element
 651          var select2EleId = "s2id_"+selectId;
 652          return jQuery('#'+select2EleId);
 653      },
 654  
 655      /**
 656       * Function to get the select element from the chosen element
 657       * @params: chosen element
 658       * @return : selectElement - corresponding select element
 659       */
 660      getSelectElementFromChosen : function(chosenElement) {
 661          var chosenId = chosenElement.attr('id');
 662          var selectEleIdArr = chosenId.split('_chzn');
 663          var selectEleId = selectEleIdArr['0'];
 664          return jQuery('#'+selectEleId);
 665      },
 666  
 667      /**
 668       * Function to set with of the element to parent width
 669       * @params : jQuery element for which the action to take place
 670       */
 671      setInheritWidth : function(elements) {
 672          jQuery(elements).each(function(index,element){
 673              var parentWidth = jQuery(element).parent().width();
 674              jQuery(element).width(parentWidth);
 675          });
 676      },
 677  
 678  
 679      initGuiders: function (list) {
 680      },
 681  
 682      showScrollBar : function(element, options) {
 683          if(typeof options == 'undefined') {
 684              options = {};
 685          }
 686          if(typeof options.height == 'undefined') {
 687              options.height = element.css('height');
 688          }
 689  
 690          return element.slimScroll(options);
 691      },
 692  
 693      showHorizontalScrollBar : function(element, options) {
 694          if(typeof options == 'undefined') {
 695              options = {};
 696          }
 697          var params = {
 698              horizontalScroll: true,
 699              theme: "dark-thick",
 700              advanced: {
 701                  autoExpandHorizontalScroll:true
 702              }
 703          }
 704          if(typeof options != 'undefined'){
 705              var params = jQuery.extend(params,options);
 706          }
 707          return element.mCustomScrollbar(params);
 708      },
 709  
 710      /**
 711       * Function returns translated string
 712       */
 713      vtranslate : function(key) {
 714          if(app.languageString[key] != undefined) {
 715              return app.languageString[key];
 716          } else {
 717              var strings = jQuery('#js_strings').text();
 718              if(strings != '') {
 719                  app.languageString = JSON.parse(strings);
 720                  if(key in app.languageString){
 721                      return app.languageString[key];
 722                  }
 723              }
 724          }
 725          return key;
 726      },
 727  
 728      /**
 729       * Function which will set the contents height to window height
 730       */
 731      setContentsHeight : function() {
 732          var borderTopWidth = parseInt(jQuery(".mainContainer").css('margin-top'))+21; // (footer height 21px)
 733          jQuery('.bodyContents').css('min-height',(jQuery(window).innerHeight()-borderTopWidth));
 734      },
 735  
 736      /**
 737       * Function will return the current users layout + skin path
 738       * @param <string> img - image name
 739       * @return <string>
 740       */
 741      vimage_path : function(img) {
 742          return jQuery('body').data('skinpath')+ '/images/' + img ;
 743      },
 744  
 745      /*
 746       * Cache API on client-side
 747       */
 748      cacheNSKey: function(key) { // Namespace in client-storage
 749          return 'vtiger6.' + key;
 750      },
 751      cacheGet: function(key, defvalue) {
 752          key = this.cacheNSKey(key);
 753          return jQuery.jStorage.get(key, defvalue);
 754      },
 755      cacheSet: function(key, value) {
 756          key = this.cacheNSKey(key);
 757          jQuery.jStorage.set(key, value);
 758      },
 759      cacheClear : function(key) {
 760          key = this.cacheNSKey(key);
 761          return jQuery.jStorage.deleteKey(key);
 762      },
 763  
 764      htmlEncode : function(value){
 765          if (value) {
 766              return jQuery('<div />').text(value).html();
 767          } else {
 768              return '';
 769          }
 770      },
 771  
 772      htmlDecode : function(value) {
 773          if (value) {
 774              return $('<div />').html(value).text();
 775          } else {
 776              return '';
 777          }
 778      },
 779  
 780      /**
 781       * Function places an element at the center of the page
 782       * @param <jQuery Element> element
 783       */
 784      placeAtCenter : function(element) {
 785          element.css("position","absolute");
 786          element.css("top", ((jQuery(window).height() - element.outerHeight()) / 2) + jQuery(window).scrollTop() + "px");
 787          element.css("left", ((jQuery(window).width() - element.outerWidth()) / 2) + jQuery(window).scrollLeft() + "px");
 788      },
 789  
 790      getvalidationEngineOptions : function(select2Status){
 791          return app.validationEngineOptions;
 792      },
 793  
 794      /**
 795       * Function to notify UI page ready after AJAX changes.
 796       * This can help in re-registering the event handlers (which was done during ready event).
 797       */
 798      notifyPostAjaxReady: function() {
 799          jQuery(document).trigger('postajaxready');
 800      },
 801  
 802      /**
 803       * Listen to xready notiications.
 804       */
 805      listenPostAjaxReady: function(callback) {
 806          jQuery(document).on('postajaxready', callback);
 807      },
 808  
 809      /**
 810       * Form function handlers
 811       */
 812      setFormValues: function(kv) {
 813          for (var k in kv) {
 814              jQuery(k).val(kv[k]);
 815          }
 816      },
 817  
 818      setRTEValues: function(kv) {
 819          for (var k in kv) {
 820              var rte = CKEDITOR.instances[k];
 821              if (rte) rte.setData(kv[k]);
 822          }
 823      },
 824  
 825      /**
 826       * Function returns the javascript controller based on the current view
 827       */
 828      getPageController : function() {
 829          var moduleName = app.getModuleName();
 830          var view = app.getViewName()
 831          var parentModule = app.getParentModuleName();
 832  
 833          var moduleClassName = parentModule+"_"+moduleName+"_"+view+"_Js";
 834          if(typeof window[moduleClassName] == 'undefined'){
 835              moduleClassName = parentModule+"_Vtiger_"+view+"_Js";
 836          }
 837          if(typeof window[moduleClassName] == 'undefined') {
 838              moduleClassName = moduleName+"_"+view+"_Js";
 839          }
 840          if(typeof window[moduleClassName] == 'undefined') {
 841              moduleClassName = "Vtiger_"+view+"_Js";
 842          }
 843          if(typeof window[moduleClassName] != 'undefined') {
 844              return new window[moduleClassName]();
 845          }
 846      },
 847  
 848      /**
 849       * Function to decode the encoded htmlentities values
 850       */
 851      getDecodedValue : function(value) {
 852          return jQuery('<div></div>').html(value).text();
 853      },
 854  
 855      /**
 856       * Function to check whether the color is dark or light
 857       */
 858      getColorContrast: function(hexcolor){
 859          var r = parseInt(hexcolor.substr(0,2),16);
 860          var g = parseInt(hexcolor.substr(2,2),16);
 861          var b = parseInt(hexcolor.substr(4,2),16);
 862          var yiq = ((r*299)+(g*587)+(b*114))/1000;
 863          return (yiq >= 128) ? 'light' : 'dark';
 864      },
 865      
 866      updateRowHeight : function() {
 867          var rowType = jQuery('#row_type').val();
 868          if(rowType.length <=0 ){
 869              //Need to update the row height
 870              var widthType = app.cacheGet('widthType', 'mediumWidthType');
 871              var serverWidth = widthType;
 872              switch(serverWidth) {
 873                  case 'narrowWidthType' : serverWidth = 'narrow'; break;
 874                  case 'wideWidthType' : serverWidth = 'wide'; break;
 875                  default : serverWidth = 'medium';
 876              }
 877              var userid = jQuery('#current_user_id').val();
 878              var params = {
 879                  'module' : 'Users',
 880                  'action' : 'SaveAjax',
 881                  'record' : userid,
 882                  'value' : serverWidth,
 883                  'field' : 'rowheight'
 884              };
 885              AppConnector.request(params).then(function(){
 886                  jQuery(rowType).val(serverWidth);
 887              });
 888          }
 889      },
 890      
 891      getCookie : function(c_name) {
 892          var c_value = document.cookie;
 893          var c_start = c_value.indexOf(" " + c_name + "=");
 894          if (c_start == -1)
 895            {
 896            c_start = c_value.indexOf(c_name + "=");
 897            }
 898          if (c_start == -1)
 899            {
 900            c_value = null;
 901            }
 902          else
 903            {
 904            c_start = c_value.indexOf("=", c_start) + 1;
 905            var c_end = c_value.indexOf(";", c_start);
 906            if (c_end == -1)
 907              {
 908              c_end = c_value.length;
 909              }
 910            c_value = unescape(c_value.substring(c_start,c_end));
 911            }
 912          return c_value;
 913      },
 914  
 915      setCookie : function(c_name,value,exdays) {
 916          var exdate=new Date();
 917          exdate.setDate(exdate.getDate() + exdays);
 918          var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
 919          document.cookie=c_name + "=" + c_value;
 920      }
 921      
 922  }
 923  
 924  jQuery(document).ready(function(){
 925      app.changeSelectElementView();
 926  
 927      //register all select2 Elements
 928      app.showSelect2ElementView(jQuery('body').find('select.select2'));
 929  
 930      app.setContentsHeight();
 931      
 932      //Updating row height
 933      app.updateRowHeight();
 934      
 935      jQuery(window).resize(function(){
 936          app.setContentsHeight();
 937      })
 938  
 939      String.prototype.toCamelCase = function(){
 940          var value = this.valueOf();
 941          return  value.charAt(0).toUpperCase() + value.slice(1).toLowerCase()
 942      }
 943  
 944      // in IE resize option for textarea is not there, so we have to use .resizable() api
 945      if(jQuery.browser.msie || (/Trident/).test(navigator.userAgent)) {
 946          jQuery('textarea').resizable();
 947      }
 948      
 949      // Instantiate Page Controller
 950      var pageController = app.getPageController();
 951      if(pageController) pageController.registerEvents();
 952  });
 953  
 954  /* Global function for UI5 embed page to callback */
 955  function resizeUI5IframeReset() {
 956      jQuery('#ui5frame').height(650);
 957  }
 958  function resizeUI5Iframe(newHeight) {
 959      jQuery('#ui5frame').height(parseInt(newHeight,10)+15); // +15px - resize on IE without scrollbars
 960  }


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