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