forked from Katello/katello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
katello.common.js
192 lines (180 loc) · 6.93 KB
/
katello.common.js
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
/**
* Copyright 2014 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public
* License as published by the Free Software Foundation; either version
* 2 of the License (GPLv2) or (at your option) any later version.
* There is NO WARRANTY for this software, express or implied,
* including the implied warranties of MERCHANTABILITY,
* NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
* have received a copy of GPLv2 along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/
//requires jQuery
KT.common = (function() {
var root_url;
return {
height: function() {
return $(window).height();
},
width: function() {
return $(window).width();
},
scrollTop: function() {
return $(window).scrollTop();
},
scrollLeft: function() {
return $(window).scrollLeft();
},
decode: function(value){
var decoded = decodeURIComponent(value);
return decoded.replace(/\+/g, " ");
},
escapeId: function(myid) {
return myid.replace(/([ #;&,.%+*~\':"!\^$\[\]()=>|\/])/g,'\\$1');
},
customConfirm : function (params) {
var settings = {
message: undefined,
warning_message: undefined,
yes_text: katelloI18n.yes,
no_text: katelloI18n.no,
yes_callback: function(){},
no_callback: function(){},
include_cancel: false
},
confirmTrue = true,
confirmFalse = false;
$.extend(settings, params);
var message = "<div style='margin:20px;'><span class='status_confirm_icon'/><div style='margin-left: 24px; display:table;height:1%;'>" + settings.message + "</div></div>",
warning_message = (settings.warning_message === undefined) ? undefined : "<div style='margin:20px;'><span class='icon-warning-sign'/><div style='margin-left: 24px; display:table;height:1%;color:red;'>" + settings.warning_message + "</div></div>",
html = (warning_message === undefined) ? message : "<div>"+message+warning_message+"</div>",
buttons = {
"Yes": {
click : function () {
$(this).dialog("close");
$(this).dialog("destroy");
settings.yes_callback();
return confirmTrue;
},
'class' : 'button',
'text' : settings.yes_text
},
"No": {
click:function () {
$(this).dialog("close");
$(this).dialog("destroy");
settings.no_callback();
return confirmFalse;
},
'class' : 'button',
'text' : settings.no_text
}
};
if(settings.include_cancel === true) {
buttons["Cancel"] = {
click:function () {
$(this).dialog("close");
$(this).dialog("destroy");
return confirmFalse;
},
'class' : 'button',
'text' : katelloI18n.cancel
};
}
$(html).dialog({
closeOnEscape: true,
open: function (event, ui) {
$('.ui-dialog-titlebar-close').hide();
$('.confirmation').find('.ui-button')[1].focus();
},
modal: true,
resizable: false,
width: 450,
title: katelloI18n.confirmation,
dialogClass: "confirmation",
buttons: buttons
});
},
customAlert : function(message) {
var html = "<div style='margin:20px;'><span class='status_exclamation_icon'/><div style='margin-left: 24px; display:table;height:1%;'>" + message + "</div></div>";
$(html).dialog({
closeOnEscape: true,
open: function (event, ui) { $('.ui-dialog-titlebar-close').hide(); },
modal: true,
resizable: false,
width: 300,
title: katelloI18n.alert,
dialogClass: "alert",
stack: false,
buttons: {
"Ok": {
click : function () {
$(this).dialog("close");
$(this).dialog("destroy");
return false;
},
'class' : 'button',
'text' : katelloI18n.ok
}
}
});
},
orgSwitcherSetup : function() {
$('.favorite').live('click', function(e) {
KT.orgswitcher.checkboxChanged($(this).parent().find('.default_org'));
});
},
rootURL : function() {
if (root_url === undefined) {
root_url = KT.routes.options.prefix;
}
return root_url;
},
getSearchParams : function(val) {
var search_string;
if ($.bbq) {
search_string = $.bbq.getState('list_search');
}
if( search_string ){
return { 'search' : search_string };
} else {
return false;
}
},
spinner_path : function() {
return "/assets/spinner.gif";
},
to_human_readable_bytes : function(bytes) {
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'],
i;
if (bytes === 0) {
return '0';
} else {
i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
return ((i === 0) ? (bytes / Math.pow(1024, i)) : (bytes / Math.pow(1024, i)).toFixed(1)) + ' ' + sizes[i];
}
},
icon_hover_change : function(element, shade){
var background_position,
icon = element.find('i[data-change_on_hover="' + shade + '"]'),
shade_position;
if( icon.length > 0 ){
background_position = icon.css('background-position');
if( background_position !== undefined ){
background_position = background_position.split(" ");
shade_position = (background_position[1] === "0" || background_position[1] === "0px") ? ' -16px' : ' 0';
background_position = background_position[0] + shade_position;
icon.css({ 'background-position' : background_position });
}
}
},
link_hover_setup : function(shade){
$('a').live('mouseenter',
function(){ KT.common.icon_hover_change($(this), shade); }
).live('mouseleave',
function(){ KT.common.icon_hover_change($(this), shade); }
);
}
};
})(jQuery);