| 5190 |
dpurdie |
1 |
// Vix specific Javascript for jquery use
|
|
|
2 |
//
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// Generate a confirmation dialog
|
|
|
5 |
// Args: text - Body of the message
|
|
|
6 |
// parms - A simple object of options - see defaults
|
| 5266 |
dpurdie |
7 |
// Special: position of 'center' will place in center of visible screen.
|
| 5190 |
dpurdie |
8 |
// Note: will return BEFORE the user makes a selection
|
|
|
9 |
// Can call a function and/or a URL if confirmed
|
|
|
10 |
// Can 'show' a progress element
|
|
|
11 |
// See 'defaults' below for bits that can be modified
|
|
|
12 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
13 |
function vixConfirm(text, parms){
|
|
|
14 |
var defaults = {
|
|
|
15 |
resizable: true,
|
|
|
16 |
height: 'auto',
|
|
|
17 |
width : 'auto',
|
|
|
18 |
modal: true,
|
|
|
19 |
position: { my: "top", at: "top+100", of: window },
|
|
|
20 |
title: "Confirm",
|
|
|
21 |
icon: "images/i_warning.gif",
|
|
|
22 |
url : null,
|
|
|
23 |
ok : null,
|
|
|
24 |
post : null,
|
|
|
25 |
button : "Confirm",
|
| 5245 |
dpurdie |
26 |
progress : "#ProgressBar"
|
| 5190 |
dpurdie |
27 |
};
|
|
|
28 |
$.extend( defaults, parms);
|
|
|
29 |
|
|
|
30 |
defaults.open = function() {
|
|
|
31 |
$(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus();
|
|
|
32 |
var markup = '<img src="'+defaults.icon+'" style="float:left; margin:0 7px 20px 0;">' + text;
|
|
|
33 |
$(this).html(markup);
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
defaults.close = function() {
|
|
|
37 |
$(this).remove();
|
|
|
38 |
};
|
|
|
39 |
|
|
|
40 |
defaults.buttons = [
|
|
|
41 |
{
|
|
|
42 |
text : defaults.button,
|
|
|
43 |
click : function (){
|
|
|
44 |
if (defaults.ok != null ){
|
|
|
45 |
defaults.ok(defaults);
|
|
|
46 |
}
|
|
|
47 |
if ( defaults.progress != null) {
|
|
|
48 |
$(defaults.progress).show().css("visibility", "visible");
|
|
|
49 |
}
|
|
|
50 |
if (defaults.url != null ) {
|
|
|
51 |
window.location.href = defaults.url;
|
|
|
52 |
}
|
|
|
53 |
if (defaults.post != null ) {
|
|
|
54 |
$('form[name="'+defaults.post+'"]').submit();
|
|
|
55 |
}
|
|
|
56 |
$(this).dialog("close");
|
|
|
57 |
}
|
|
|
58 |
},
|
|
|
59 |
{
|
|
|
60 |
text : 'Cancel',
|
|
|
61 |
click : function (){
|
|
|
62 |
$(this).dialog("close");
|
|
|
63 |
}
|
|
|
64 |
}];
|
|
|
65 |
|
|
|
66 |
var dd = $( "<div>Confirm</div>" ).dialog(defaults);
|
|
|
67 |
// Once the dialog has been instantiated the autosize dimensions are known
|
| 5266 |
dpurdie |
68 |
// and the dialog can be correctly positioned
|
|
|
69 |
if (defaults.position == 'center')
|
|
|
70 |
{
|
|
|
71 |
dd.dialog("widget").center();
|
|
|
72 |
console.log("Center in Window");
|
|
|
73 |
}
|
|
|
74 |
else
|
|
|
75 |
{
|
|
|
76 |
dd.dialog("widget").position(defaults.position);
|
|
|
77 |
console.log("Original position");
|
|
|
78 |
}
|
|
|
79 |
|
| 5190 |
dpurdie |
80 |
// Return false incase this is used as an onClick
|
|
|
81 |
return false;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
85 |
// Compatability function
|
|
|
86 |
// Confirm Deletion of an item
|
|
|
87 |
// Assumes that the item is within an 'anchor' and that an href can be located
|
|
|
88 |
// Uses VixConfirm to do the heavy lifting
|
|
|
89 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
90 |
function vixConfirmDelete (txt)
|
|
|
91 |
{
|
|
|
92 |
var href = window.event.currentTarget.href;
|
|
|
93 |
vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})
|
|
|
94 |
return false;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
98 |
// Similar to 'alert', but uses the jquery dialog mechnaism
|
|
|
99 |
// Note: will return BEFORE the user makes a selection
|
|
|
100 |
// Returns a Defereed object that will be rejected when the dialog is closed.
|
|
|
101 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
102 |
function vixAlert(text){
|
|
|
103 |
var dbo = $.Deferred();
|
| 5207 |
dpurdie |
104 |
var dd = $( "<div>Alert</div>" ).dialog({
|
| 5190 |
dpurdie |
105 |
resizable: true,
|
|
|
106 |
height: 'auto',
|
|
|
107 |
width : 'auto',
|
|
|
108 |
modal: true,
|
|
|
109 |
title:'Alert',
|
| 5227 |
dpurdie |
110 |
position: { my: "top", at: "top+100", of: window },
|
| 5190 |
dpurdie |
111 |
open: function() {
|
|
|
112 |
$(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
|
|
|
113 |
},
|
|
|
114 |
close : function() {
|
|
|
115 |
$(this).remove();
|
|
|
116 |
dbo.reject();
|
|
|
117 |
},
|
|
|
118 |
buttons: {
|
|
|
119 |
"Ok": function() {
|
|
|
120 |
$(this).dialog("close");
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
});
|
| 5207 |
dpurdie |
124 |
// Once the dialog has been instantiated the autosize dimensions are known
|
| 5266 |
dpurdie |
125 |
// and the dialog can be correctly positioned
|
| 5227 |
dpurdie |
126 |
// Note: Appears that we need to position it twice
|
|
|
127 |
// Once in the dialog creation, and once here
|
| 5207 |
dpurdie |
128 |
dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
|
|
|
129 |
|
|
|
130 |
return dbo;
|
| 5190 |
dpurdie |
131 |
}
|
|
|
132 |
|
| 5266 |
dpurdie |
133 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
134 |
// jQuery extension function
|
|
|
135 |
// Position an element inthe center of the visible window. Not the document and not the window(viewport).
|
|
|
136 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
137 |
jQuery.fn.center = function () {
|
| 5190 |
dpurdie |
138 |
|
| 5266 |
dpurdie |
139 |
// Support many browsers
|
|
|
140 |
var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
|
141 |
var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
|
142 |
|
|
|
143 |
this.css("position","fixed");
|
|
|
144 |
this.css("top", Math.max(0, ((h - $(this).outerHeight()) / 2) ) + "px");
|
|
|
145 |
this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");
|
|
|
146 |
return this;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
//--------- Support to open modal dialog in an iFrame
|
|
|
150 |
// Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title" data-width=500 data-height=300>Link Text</a>
|
|
|
151 |
//
|
|
|
152 |
var vixIframe = {};
|
|
|
153 |
$(document).ready(function () {
|
|
|
154 |
$('.vixIframeDialog').on('click', function (e) {
|
|
|
155 |
e.preventDefault();
|
|
|
156 |
vixIframe.parent = this;
|
|
|
157 |
vixIframe.pagetitle = $(this).attr("title");
|
|
|
158 |
var page = $(this).attr("href");
|
|
|
159 |
var iframe = $('<iframe onload="resizeIframe(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + page + '" width="100%" height="100%" ></iframe>');
|
|
|
160 |
var $dialog = $('<div></div>').html(iframe);
|
|
|
161 |
var $dialog2 = $dialog.dialog({
|
|
|
162 |
autoOpen: true,
|
|
|
163 |
modal: true,
|
|
|
164 |
zheight: $(this).data('height')|| 200,
|
|
|
165 |
zwidth: $(this).data('width') || 300,
|
|
|
166 |
height : 'auto,', width : 'auto',
|
|
|
167 |
dialogClass: "rounded_box",
|
|
|
168 |
title: 'Loading - ' + vixIframe.pagetitle,
|
|
|
169 |
close: function(event, ui){
|
|
|
170 |
//console.log('closing dialog');
|
|
|
171 |
$(this).dialog("destroy");
|
|
|
172 |
vixIframe = {};
|
|
|
173 |
window.onbeforeunload = null;
|
|
|
174 |
window.onunload = null;
|
|
|
175 |
|
|
|
176 |
},
|
|
|
177 |
});
|
|
|
178 |
vixIframe.Dialog = $dialog;
|
|
|
179 |
vixIframe.DialogWidget = $($dialog2).dialog('widget');
|
|
|
180 |
//$(currentDialogWidget).find(".ui-dialog-titlebar").remove();
|
|
|
181 |
$(vixIframe.DialogWidget).position({my:'top', at: 'top+100', of : window});
|
|
|
182 |
//$dialog.dialog('open');
|
|
|
183 |
|
|
|
184 |
// Prevent the user from navigating away from the iframe
|
|
|
185 |
|
|
|
186 |
// window.onbeforeunload = function(){
|
|
|
187 |
// console.log("confirmBrowseAway");
|
|
|
188 |
// console.log("window.location.href:" + window.location.href);
|
|
|
189 |
// parent.closeIFrame(12);
|
|
|
190 |
// return null};
|
|
|
191 |
window.onunload = function(){
|
|
|
192 |
console.log("Unloading");
|
|
|
193 |
//parent.closeIFrame(12);
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
});
|
|
|
197 |
|
|
|
198 |
//
|
|
|
199 |
// Prevent (at least control) the user from navigating within the iframe
|
|
|
200 |
// If this invocation is within an iFrame, then close the iFrame if
|
|
|
201 |
// the user attempt to navigate away from the iFrame.
|
|
|
202 |
// This means that the iFrame cannot replace itself
|
|
|
203 |
//
|
|
|
204 |
if (typeof parent.vixIframe.pagetitle !== 'undefined')
|
|
|
205 |
{
|
|
|
206 |
console.log("DocumentReady within iframe");
|
|
|
207 |
//window.onbeforeunload = function(){console.log("onbeforeunload");parent.closeIFrame(13); return null};
|
|
|
208 |
window.onunload = function(){
|
|
|
209 |
console.log("Unloading within iframe");
|
|
|
210 |
//parent.closeIFrame(13);
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
});
|
|
|
215 |
|
|
|
216 |
function resizeIframe(iframe) {
|
|
|
217 |
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
|
|
|
218 |
$(vixIframe.Dialog).height(iframe.height);
|
|
|
219 |
//console.log ("Resize Iframe:",iframe.height );
|
|
|
220 |
|
|
|
221 |
iframe.width = iframe.contentWindow.document.body.scrollWidth;
|
|
|
222 |
$(vixIframe.Dialog).width(iframe.width);
|
|
|
223 |
//console.log ("Resize Iframe:",iframe.width );
|
|
|
224 |
|
|
|
225 |
$(vixIframe.DialogWidget).position({my:'top', at: 'top+100', of : window});
|
|
|
226 |
|
|
|
227 |
// New reset the title
|
|
|
228 |
vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
|
|
|
229 |
//console.log("Ifame:", vixIframe)
|
|
|
230 |
};
|
|
|
231 |
|
|
|
232 |
function closeIFrame(aa)
|
|
|
233 |
{
|
|
|
234 |
if (vixIframe.Dialog != null) {
|
|
|
235 |
console.log('closing iframe:' + aa);
|
|
|
236 |
vixIframe.Dialog.dialog('close');
|
|
|
237 |
vixIframe = {};
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|