[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/resources/ -> ProgressIndicator.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  (function( $ ) {
  11  
  12    var ProgressIndicatorHelper = function() {
  13      var thisInstance = this;
  14  
  15      this.defaults = {
  16          'position' : 'append',
  17          'mode' : 'show',
  18          'blockInfo' : {
  19              'elementToBlock' : 'body'
  20          },
  21          'message' : ''
  22      }
  23  
  24      this.imageContainerCss = {
  25          'text-align' : 'center'
  26      }
  27  
  28      this.blockOverlayCSS = {
  29          'opacity' : '0.2'
  30      }
  31  
  32      this.blockCss = {
  33          'border':        '',
  34          'backgroundColor':'',
  35          'background-clip': 'border-box',
  36          'border-radius': '2px'
  37      }
  38  
  39      this.showTopCSS ={
  40          'left'      : '48.2%',
  41          'position': 'fixed',
  42          'top'      : '4.5%',
  43          'z-index' : '100000'
  44      }
  45  
  46      this.showOnTop = false;
  47  
  48      this.init = function(element, options){
  49          if(typeof options == 'undefined'){
  50              options = {};
  51          }
  52  
  53          thisInstance.options = $.extend(true, this.defaults, options);
  54          thisInstance.container = element;
  55          thisInstance.position = options.position;
  56          if(typeof options.imageContainerCss != 'undefined'){
  57              thisInstance.imageContainerCss = $.extend(true,this.imageContainerCss,options.imageContainerCss);
  58          }
  59          if(this.isBlockMode()) {
  60              thisInstance.elementToBlock = $(thisInstance.options.blockInfo.elementToBlock);
  61          }
  62          return this;
  63      }
  64  
  65      this.initActions = function() {
  66          if(this.options.mode == 'show'){
  67              this.show();
  68          }else if(this.options.mode == 'hide') {
  69              this.hide();
  70          }
  71      }
  72      
  73      this.getImagePath = function() {
  74          if(this.options.smallLoadingImage == true && typeof this.options.smallLoadingImage != 'undefined' ) {
  75              return app.vimage_path('loading.gif');
  76          } else {
  77              return app.vimage_path('loading.gif');
  78          }
  79      }
  80  
  81      this.isPageBlockMode = function() {
  82          if ( (typeof this.elementToBlock  != 'undefined' )&& this.elementToBlock.is('body')) {
  83              return true;
  84          }
  85          return false;
  86      }
  87  
  88      this.isBlockMode = function() {
  89          if((typeof this.options.blockInfo != 'undefined')  && (this.options.blockInfo.enabled==true)) {
  90              return true;
  91          }
  92          return false;
  93      }
  94  
  95      this.show = function(){
  96          // TODO use app.vimage_path
  97          var imagePath = this.getImagePath();
  98          var imageHtml = '<div class="imageHolder">'+
  99                              '<img class="loadinImg alignMiddle" src="'+imagePath+'" />'+
 100                          '</div>';
 101          var jQImageHtml = jQuery(imageHtml).css(this.imageContainerCss);
 102          if(thisInstance.options.message.length > 0) {
 103              var jQMessage = thisInstance.options.message;
 104              if(!(jQMessage instanceof jQuery)){
 105                  jQMessage = jQuery('<span></span>').html(jQMessage)
 106              }
 107              var messageContainer = jQuery('<div class="message"></div>').append(jQMessage);
 108              jQImageHtml.append(messageContainer);
 109          }
 110  
 111          if(this.isBlockMode()) {
 112              jQImageHtml.addClass('blockMessageContainer');
 113          }
 114  
 115          switch(thisInstance.position) {
 116                  case "prepend":
 117                          thisInstance.container.prepend(jQImageHtml);
 118                          break;
 119                  case "html":
 120                          thisInstance.container.html(jQImageHtml);
 121                          break;
 122                  case "replace":
 123                          thisInstance.container.replaceWith(jQImageHtml);
 124                          break;
 125                  default:
 126                      thisInstance.container.append(jQImageHtml);
 127          }
 128          if(this.isBlockMode()) {
 129              thisInstance.blockedElement = thisInstance.elementToBlock;
 130              if(thisInstance.isPageBlockMode()) {
 131                  $.blockUI({
 132                      'message' : thisInstance.container,
 133                      'overlayCSS' : thisInstance.blockOverlayCSS,
 134                      'css' : thisInstance.blockCss
 135                  });
 136              }else{
 137                  thisInstance.elementToBlock.block({
 138                      'message' : thisInstance.container,
 139                      'overlayCSS' : thisInstance.blockOverlayCSS,
 140                      'css' : thisInstance.blockCss
 141                  })
 142              }
 143          }
 144  
 145          if(thisInstance.showOnTop) {
 146              this.container.css(this.showTopCSS).appendTo('body');
 147          }
 148      }
 149  
 150      this.hide = function() {
 151          $('.imageHolder',this.container).remove();
 152          if(typeof this.blockedElement != 'undefined') {
 153              if(this.isPageBlockMode()) {
 154                  $.unblockUI();
 155              }
 156              else{
 157                  this.blockedElement.unblock();
 158              }
 159          }
 160          this.container.removeData('progressIndicator');
 161      }
 162  
 163    }
 164  
 165    $.fn.progressIndicator = function(options) {
 166      var element = this;
 167      if(this.length <= 0) {
 168          element = jQuery('body');
 169      }
 170      return element.each(function(index, element){
 171          var jQueryObject = $(element);
 172          if(typeof jQueryObject.data('progressIndicator') != 'undefined'){
 173              var progressIndicatorInstance = jQueryObject.data('progressIndicator');
 174  
 175          }else{
 176              var progressIndicatorInstance = new ProgressIndicatorHelper();
 177              jQueryObject.data('progressIndicator',progressIndicatorInstance);
 178          }
 179          progressIndicatorInstance.init(jQueryObject, options).initActions();
 180      });
 181  
 182    };
 183  
 184    $.progressIndicator = function(options) {
 185        var progressImageContainer = jQuery('<div></div>');
 186        var progressIndicatorInstance = new ProgressIndicatorHelper();
 187        progressIndicatorInstance.init(progressImageContainer, options);
 188        if(!progressIndicatorInstance.isBlockMode()) {
 189            progressIndicatorInstance.showOnTop = true;
 190        }
 191        progressIndicatorInstance.initActions();
 192        return progressImageContainer.data('progressIndicator',progressIndicatorInstance);
 193    }
 194  
 195    //Change the z-index of the block overlay value
 196    $.blockUI.defaults.baseZ = 10000;
 197  })( jQuery );
 198  


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