Subversion Repositories DevTools

Rev

Rev 5506 | Rev 5590 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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();
5560 dpurdie 72
         //console.log("Center in Window");
5266 dpurdie 73
     }
74
     else
75
     {
76
         dd.dialog("widget").position(defaults.position);
5560 dpurdie 77
         //console.log("Original position");
5266 dpurdie 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 () {
5560 dpurdie 154
    $('.vixIframeDialog').on('click', function(e){
155
		vixIframeDialog(e,this)
156
	});
5266 dpurdie 157
 
158
    //
159
    // Prevent (at least control) the user from navigating within the iframe
160
    // If this invocation is within an iFrame, then close the iFrame if
161
    // the user attempt to navigate away from the iFrame.
162
    //      This means that the iFrame cannot replace itself
163
    // 
164
    if (typeof parent.vixIframe.pagetitle !== 'undefined')
165
    {
5560 dpurdie 166
        //console.log("DocumentReady within iframe");
5266 dpurdie 167
        window.onunload = function(){
5560 dpurdie 168
            //console.log("Unloading within iframe");
5266 dpurdie 169
        }
170
    }
171
 
172
});
173
 
5560 dpurdie 174
//
175
//	Callable function to instantiate an Iframe Dialog
176
//  Need to trigger access from popup menus that cannot be procesed the document ready functions
177
// 	Parameters:
178
// 		e       - The event that invoked this call
179
// 		pthis	- The parent's context
180
//
181
function vixIframeDialog(e,pthis) {
182
	e.preventDefault();
183
	vixIframe.parent = pthis;
184
	vixIframe.pagetitle = $(pthis).attr("title");
185
	if (! vixIframe.pagetitle) {
186
		vixIframe.pagetitle = $(pthis).text();
187
	}
188
	var page = $(pthis).attr("href");
189
	var iframe = $('<iframe onload="resizeIframe(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + page + '" width="100%" height="100%" ></iframe>');
190
	var $dialog = $('<div></div>').html(iframe);
191
	var $dialog2 = $dialog.dialog({
192
		autoOpen: true,
193
		modal: true,
194
		zheight: $(pthis).data('height')|| 200,
195
		zwidth: $(pthis).data('width') || 300,
196
		height : 'auto,', width : 'auto',
197
		position : { my:'top', at: 'top+100', of : window },
198
		dialogClass: "rounded_box",
199
		title: 'Loading - ' + vixIframe.pagetitle,
200
		close: function(event, ui){
201
			//console.log('closing dialog');
202
			$(this).dialog("destroy");
203
			vixIframe = {};
204
			window.onbeforeunload = null;
205
			window.onunload = null;
206
 
207
			},
208
	});
209
	vixIframe.Dialog = $dialog;
210
	vixIframe.DialogWidget = $($dialog2).dialog('widget');
211
	return false;
212
}
213
 
5266 dpurdie 214
function resizeIframe(iframe) {
215
    iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
216
    $(vixIframe.Dialog).height(iframe.height);
217
    //console.log ("Resize Iframe:",iframe.height );
218
 
219
    iframe.width = iframe.contentWindow.document.body.scrollWidth;
220
    $(vixIframe.Dialog).width(iframe.width);
221
    //console.log ("Resize Iframe:",iframe.width );
222
 
223
    // New reset the title
224
    vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
225
    //console.log("Ifame:", vixIframe)
226
};
227
 
228
function closeIFrame(aa)
229
{
230
    if (vixIframe.Dialog != null) {
231
        console.log('closing iframe:' + aa);
232
        vixIframe.Dialog.dialog('close');
233
        vixIframe = {};
234
    }
235
}
236
 
237
 
238