Subversion Repositories DevTools

Rev

Rev 6651 | Rev 6697 | 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",
5598 dpurdie 26
        progress : "#ProgressBar",
6577 dpurdie 27
        cancel : true,
28
        timeout : null,
29
        dlg : null
5190 dpurdie 30
     };
31
     $.extend( defaults, parms);
32
 
33
     defaults.open = function() {
34
        $(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus(); 
6577 dpurdie 35
        var markup = "";
36
        if (defaults.icon != null ) {
37
            markup += '<img src="'+ defaults.icon+ '" style="float:left; margin:0 7px 20px 0;">';
38
            }
39
        markup += text;
5190 dpurdie 40
        $(this).html(markup);
6577 dpurdie 41
         if ( defaults.timeout != null ) {
42
             setTimeout(function(){
43
                 defaults.dlg.dialog("close");
44
                }, defaults.timeout);
45
         }
5190 dpurdie 46
     };
47
 
48
    defaults.close = function() {
49
        $(this).remove();
50
    };
51
 
6577 dpurdie 52
    defaults.buttons = [];
53
    if ( defaults.button != null ) {
54
        defaults.buttons.push({
55
            text : defaults.button,
56
            click : function (){
57
                    if (defaults.ok != null ){
58
                        defaults.ok(defaults);
59
                    }
60
                    if ( defaults.progress != null) {
61
                        $(defaults.progress).show().css("visibility", "visible");    
62
                    }
63
                    if (defaults.url != null ) {
64
                        window.location.href = defaults.url;
65
                    }
66
                    if (defaults.post != null ) {
67
                        $('form[name="'+defaults.post+'"]').submit();    
68
                    }
69
                    $(this).dialog("close");
5190 dpurdie 70
                }
6577 dpurdie 71
        });
72
    }
73
 
74
    if(typeof(defaults.cancel) == 'boolean' && defaults.cancel) {
75
        defaults.buttons.push({
76
            text : 'Cancel',
77
            click : function (){
78
                $(this).dialog("close");
5190 dpurdie 79
                }
6577 dpurdie 80
        });
81
    }
5190 dpurdie 82
 
83
     var dd = $( "<div>Confirm</div>" ).dialog(defaults);
6577 dpurdie 84
     defaults.dlg = dd;
5190 dpurdie 85
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 86
     // and the dialog can be correctly positioned
87
     if (defaults.position == 'center')
88
     {
89
         dd.dialog("widget").center();
5560 dpurdie 90
         //console.log("Center in Window");
5266 dpurdie 91
     }
92
     else
93
     {
94
         dd.dialog("widget").position(defaults.position);
5560 dpurdie 95
         //console.log("Original position");
5266 dpurdie 96
     }
97
 
5190 dpurdie 98
     // Return false incase this is used as an onClick
99
     return false;
100
}
101
 
102
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103
// Compatability function
104
//      Confirm Deletion of an item
105
//      Assumes that the item is within an 'anchor' and that an href can be located
106
//      Uses VixConfirm to do the heavy lifting
107
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108
function vixConfirmDelete (txt)
109
{
110
    var href = window.event.currentTarget.href;
111
    vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})
112
    return false;
113
}
114
 
115
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116
//  Similar to 'alert', but uses the jquery dialog mechnaism
117
//  Note: will return BEFORE the user makes a selection
118
//  Returns a Defereed object that will be rejected when the dialog is closed.
119
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120
function vixAlert(text){
121
     var dbo = $.Deferred();
5207 dpurdie 122
     var dd = $( "<div>Alert</div>" ).dialog({
5190 dpurdie 123
        resizable: true,
124
        height: 'auto',
125
        width : 'auto',
126
        modal: true,
127
        title:'Alert',
5227 dpurdie 128
        position: { my: "top", at: "top+100", of: window },
5190 dpurdie 129
        open: function() {
130
            $(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
131
        },
132
        close : function() {
133
            $(this).remove();
134
            dbo.reject();
135
        },
136
        buttons: {
137
            "Ok": function() {
138
                $(this).dialog("close");
139
            }
140
        }
141
     });
5207 dpurdie 142
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 143
     // and the dialog can be correctly positioned
5227 dpurdie 144
     // Note: Appears that we need to position it twice
145
     //       Once in the dialog creation, and once here
5207 dpurdie 146
     dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
147
 
148
     return dbo;
5190 dpurdie 149
}
150
 
5266 dpurdie 151
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
152
//  jQuery extension function
153
//  Position an element inthe center of the visible window. Not the document and not the window(viewport).
154
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155
jQuery.fn.center = function () {
5190 dpurdie 156
 
5266 dpurdie 157
    //  Support many browsers
158
    var w = window.innerWidth  || document.documentElement.clientWidth  || document.body.clientWidth;
159
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
160
 
161
    this.css("position","fixed");
162
    this.css("top", Math.max(0,  ((h - $(this).outerHeight()) / 2) ) + "px");
163
    this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");
164
    return this;
165
}
166
 
167
//--------- Support to open modal dialog in an iFrame
5590 dpurdie 168
//  Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title">Link Text</a>
5266 dpurdie 169
//
170
var vixIframe = {};
171
$(document).ready(function () {
5560 dpurdie 172
    $('.vixIframeDialog').on('click', function(e){
5590 dpurdie 173
		if (!vixIframe.parent) {
174
			e.preventDefault();
175
			vixIframe.parent = this;
176
			vixIframe.pagetitle = $(this).attr("title");
177
			if (! vixIframe.pagetitle) {
178
				vixIframe.pagetitle = $(this).text();
179
			}
180
			vixIframe.url = $(this).attr("href");
181
			vixIframeDialogCommon();
182
		}
5560 dpurdie 183
	});
5266 dpurdie 184
 
185
    //
186
    // Prevent (at least control) the user from navigating within the iframe
187
    // If this invocation is within an iFrame, then close the iFrame if
188
    // the user attempt to navigate away from the iFrame.
189
    //      This means that the iFrame cannot replace itself
190
    // 
191
    if (typeof parent.vixIframe.pagetitle !== 'undefined')
192
    {
5560 dpurdie 193
        //console.log("DocumentReady within iframe");
5266 dpurdie 194
        window.onunload = function(){
5560 dpurdie 195
            //console.log("Unloading within iframe");
5266 dpurdie 196
        }
197
    }
198
 
199
});
200
 
5560 dpurdie 201
//
202
//	Callable function to instantiate an Iframe Dialog
5590 dpurdie 203
//  Used in a replacement for MM_openBrWindow called MM_openVixIFrame
5560 dpurdie 204
// 	Parameters:
205
// 		pthis	- The parent's context
6625 dpurdie 206
//		url		- URL of the window content
5590 dpurdie 207
//  	winName	- Title of the new Window
208
 
209
function vixIframeDialog2(pthis, url, winName)
210
{
5560 dpurdie 211
	vixIframe.parent = pthis;
5590 dpurdie 212
	vixIframe.pagetitle = winName;
213
	vixIframe.url = url;
214
	vixIframeDialogCommon();
215
}
216
 
217
function vixIframeDialogCommon()
218
{
219
	var iframe = $('<iframe onload="IframeLoaded(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + vixIframe.url + '" width="100%" height="100%" ></iframe>');
5560 dpurdie 220
	var $dialog = $('<div></div>').html(iframe);
221
	var $dialog2 = $dialog.dialog({
222
		autoOpen: true,
223
		modal: true,
5590 dpurdie 224
		height : 'auto,', 
225
		width : 'auto',
226
		resizable: false,
5560 dpurdie 227
		position : { my:'top', at: 'top+100', of : window },
228
		dialogClass: "rounded_box",
229
		title: 'Loading - ' + vixIframe.pagetitle,
230
		close: function(event, ui){
231
			//console.log('closing dialog');
232
			$(this).dialog("destroy");
233
			vixIframe = {};
234
			window.onbeforeunload = null;
235
			window.onunload = null;
236
			},
5590 dpurdie 237
		// Prevent Chrome from adding scrollbars when dragged
238
		dragStop: function( event, ui ){
239
			vixIframe.IFrame.parentElement.style.overflow = "";
240
			},
241
		dragStart: function( event, ui ){
242
			vixIframe.IFrame.parentElement.style.overflow = "hidden";
243
			}
5560 dpurdie 244
	});
245
	vixIframe.Dialog = $dialog;
5590 dpurdie 246
	vixIframe.DialogProps = $dialog2;
5560 dpurdie 247
	vixIframe.DialogWidget = $($dialog2).dialog('widget');
5597 dpurdie 248
 
5560 dpurdie 249
	return false;
250
}
5590 dpurdie 251
//
252
//	Called when the iframe is loaded or reloaded
253
//
254
function IframeLoaded(iframe) {
255
	// Save to resize iframe
256
	vixIframe.IFrame = iframe;
5560 dpurdie 257
 
5590 dpurdie 258
	// Reset the title
259
	vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
5266 dpurdie 260
 
5590 dpurdie 261
	// Resize the frame
262
	resizeIframe();
5266 dpurdie 263
};
5590 dpurdie 264
//
265
//	This function can be called from within the iframe to have it resized
266
//	Used if the iframe is too dynamic and extends itself from time to time
267
//
268
function resizeIframe()
269
{
270
    if (vixIframe.IFrame != null) {
271
		iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
272
		$(vixIframe.Dialog).height(iframe.height);
273
		//console.log ("Resize Iframe:",iframe.height );
5266 dpurdie 274
 
5590 dpurdie 275
		iframe.width = iframe.contentWindow.document.body.scrollWidth + "px";
276
		$(vixIframe.Dialog).width(iframe.width);
277
		//console.log ("Resize Iframe:",iframe.width );
278
 
279
		// Reposition the dialog
280
		$(vixIframe.DialogWidget).position($(vixIframe.DialogProps).dialog("option").position);
281
	}
282
}
283
//
284
//	This function can be called from with the iframe to close the Iframe
285
//	Often wired up to the cancel button
286
function closeIFrame()
5266 dpurdie 287
{
288
    if (vixIframe.Dialog != null) {
5590 dpurdie 289
        //console.log('closing iframe');
5266 dpurdie 290
        vixIframe.Dialog.dialog('close');
291
        vixIframe = {};
292
    }
293
}
294
 
6427 dpurdie 295
//
6626 dpurdie 296
//  Copy the HTML from an element into the clipboard
297
//  Highlight the element clipped
298
//
299
function vixEl2Clip( el ) {
300
    // Get the text and clean it up
301
    var html = $.trim(el.html());
302
 
303
    var breakToken = '_______break_______';
304
    var lineBreakedHtml = html.replace(/<br\s?\/?>/gi, breakToken).replace(/<p\.*?>(.*?)<\/p>/gi, breakToken + '$1' + breakToken);
305
    var text = $('<div>').html(lineBreakedHtml).text().replace(new RegExp(breakToken, 'g'), '\r\n');
306
    text = $.trim(text);
307
 
308
    // Copy to clipboard
309
    var $temp = $("<textarea>");
310
    $(el).append($temp);
311
    $temp.val(text).select();
312
    document.execCommand("copy");
313
    $temp.remove();
314
 
315
 
316
    // Highlight the text that has been selected
317
    el.effect("highlight", {}, 1000);
318
    // el.css('background-color', 'rgba(0, 102, 255, .5)');
319
    // el.animate({backgroundColor: 'transparent'}, '1000');
320
 
321
    return el;
322
}
323
 
324
//
6427 dpurdie 325
//  Add copy to clipboard icon to every element with a class of 'clip'
326
//
327
$( document ).ready(function() {
6626 dpurdie 328
    var myClipHandler = function (event) {
6427 dpurdie 329
        // Get element to clip
6626 dpurdie 330
        vixEl2Clip($(this).find('.clipSel').eq(0));
331
    }
5266 dpurdie 332
 
6626 dpurdie 333
    $('.clip').on("click", myClipHandler).on("dblclick", myClipHandler);
5266 dpurdie 334
 
6626 dpurdie 335
    // Add a clip image to every class of either .clip
336
    $('.clip').wrapInner('<span class=clipSel></span>').append(
6427 dpurdie 337
        $('<img />')
338
            .attr({
339
                title : "Copy to clipboard",
340
                src : "images/CopyToClipboard.ico",
341
                height : "12px",
342
                width : "12px",
343
                hspace : "0px",
344
                align : "absmiddle",
345
                border : "0"
346
                })
6626 dpurdie 347
    );
348
});
6427 dpurdie 349
 
6626 dpurdie 350
// Copy data from a named element to clipboard
351
// Supports multi-line data with <p> and <br> in it
352
//      Elements have a class of clipElement and have an attribute of data-target=elementId
353
$( document ).on('click', '.clipElement', function(event){
354
 
355
    var ename = $(this).data('target');
356
    var el = $('#' + ename);
357
    vixEl2Clip(el);
6427 dpurdie 358
});
359
 
6592 dpurdie 360
// Add a clipThis handler to each element with a clipThis class
6610 dpurdie 361
//      Will copy the text of the element to the clipboard
362
//      Add dynamically so that it will be invoked on dynamically created elements
6592 dpurdie 363
$( document ).on('click', '.clipThis', function(event){
364
    var txt = $(this).eq(0).text();
365
    vixTextToClipBoard(txt, {note : "Copied to Clipboard", duration : 1000});
366
});
367
 
6610 dpurdie 368
// Copy data from element to clipboard
369
//      Elements have a class of clipData and an attribute of data-clip=xxx
370
//  Add dynamically so that it will be invoked on dynamically created elements
371
$( document ).on('click', '.clipData', function(event){
372
    var txt = $(this).data('clip');
373
    vixTextToClipBoard(txt, {note : "Copied to Clipboard", duration : 1000});
374
});
375
 
376
 
377
// Invoke mailto on elements with a suitable class
378
//  Elements with class mailto. and a data item of email
379
// Add dynamically so that it will be invoked on newly created elements
380
$( document ).on('click', '.mailto', function(event){
381
    var email = $(this).data('email');
382
    var name =  $(this).data('name');
6623 dpurdie 383
    var uname =  $(this).data('uname');
6610 dpurdie 384
    if ( !name ) {
385
        name =  $(this).eq(0).text();
386
    }
387
 
388
    var menu = '<div class="rex_clm" >&nbsp;Select Operation</div>';
389
    if ( name ) {
390
        menu += '<div class="mmItem clipData" data-clip="' + name + '">Copy Name to Clipboard</div>';
391
    }
6623 dpurdie 392
    if ( uname ) {
393
        menu += '<div class="mmItem clipData" data-clip="' + uname + '">Copy Login Name to Clipboard</div>';
394
    }
6610 dpurdie 395
    menu += '<div class="mmItem clipData" data-clip="' + email + '">Copy Email Address to Clipboard</div>';
396
    menu += '<div onClick="window.open(\'mailto:' + email + '\', \'_blank\');" class="mmItem">Send Email</div>';
397
    showmenu(event,menu);
398
    event.stopImmediatePropagation();
399
    event.stopPropagation();
400
    return false;
401
});
402
 
6589 dpurdie 403
// Copy text to clipboard
404
function vixTextToClipBoard(txt, options){
405
    if ( txt == null ) {
406
        return;
407
    }
408
    var opts  = {
409
        note : "Data copied to Clipboard",
410
        title: "Notification",
411
        notify : true,
412
        timeout : 100,
413
        duration: 2000,
414
    }
415
    $.extend(opts, options);
6427 dpurdie 416
 
6589 dpurdie 417
    var $temp = $("<textarea>");
6641 dpurdie 418
    $("body").prepend($temp);
6589 dpurdie 419
    $temp.val(txt).select();
420
    document.execCommand("copy");
421
    $temp.remove();
6427 dpurdie 422
 
6589 dpurdie 423
    if ( opts.notify ) {
424
        vixConfirm(opts.note, {
425
            title: opts.title,
6641 dpurdie 426
            icon : "images/i_info.png",
427
            cancel: false,
6589 dpurdie 428
            button: null,
429
            timeout : opts.timeout,
430
            modal : false,
6641 dpurdie 431
            minHeight: 10,
6589 dpurdie 432
            hide: { effect: 'fade', duration: opts.duration }
433
            });
434
    }
435
}
436
 
6651 dpurdie 437
//  Export Table as CSV support functions
438
//      Allow a table that has been tagged with a class of etable to be exported
439
// 
440
// Global variable for use of the table to CSV widget
441
// Used to convey info though the selection callback
442
//
443
var vixEtableData;
444
 
445
$( document ).ready(function() {
446
    vixEtableInit();
447
});
448
 
449
//      vixPostPageLoad is called when dynamic DOM elements are loaded 
450
function vixPostPageLoad(){
451
    vixEtableInit();
452
}
453
 
454
//  Init all elements marked with a class of 'etable'
455
//      Insert an icon
456
//      Remove original class so that the DOM can be scanned again
457
function vixEtableInit(){
458
    $('.etable').css('position', 'relative');
459
    $('.etable th:last-child').append(
460
            $('<img />')
461
                .attr({
462
                    title : "Export table as CSV",
463
                    src : "images/CopyToClipboard.ico",
464
                    height : "12px",
465
                    width : "12px",
466
                    hspace : "0px",
467
                    align : "absmiddle",
468
                    border : "0"
469
                    })
470
                .css({position : 'absolute', top : '0px', right : '0px'})
471
                .click(function(event){
472
                    vixEtableData =  $(this).closest('table');
473
                    var menu = '<div class="rex_clm" >&nbsp;Select Operation</div>';
6695 dpurdie 474
                    menu += '<div class="mmItem" onClick="vixEtableProc(\'popup\');">Show&nbsp;in&nbsp;New&nbsp;Window</div>';
475
                    menu += '<div class="mmItem" onClick="vixEtableProc(\'modal\');">Show in Dialog</div>';
6651 dpurdie 476
                    menu += '<div class="mmItem" onClick="vixEtableProc(\'download\');">Download File</div>';
477
                    menu += '<div class="mmItem" onClick="vixEtableProc(\'clip\');">Copy to Clipboard</div>';
478
                    showmenu(event,menu);
479
                    event.stopImmediatePropagation();
480
                    event.stopPropagation();
481
                    return false;
482
                    })
483
        );
484
    $('.etable').addClass('etable-done').removeClass('etable');
485
}
486
 
487
//  Global function to support post-selection processing of CSV data
488
function vixEtableProc(mode) {
489
    var tdata = vixEtableData.data('etable')
490
    var defData = {
491
        delivery: mode,
492
        filename: 'data.csv',
493
        rowFilter: '.csvData'
494
        };
495
    $.extend(defData, tdata) ;
496
    var data = vixEtableData.TableCSVExport(defData);
497
    if ( mode == 'clip' ) {
498
        vixTextToClipBoard(data, {note : "CSV copied to Clipboard", duration : 1000});
499
    }
500
}
501
 
6695 dpurdie 502
// Create a new window in the center of the current screen
503
//  A wrapper for window.open(), with a few smarts
504
//  Does not position correctly on Widows-Edge
505
function PopupCenter(url, title, w, h) {
506
    // Fixes dual-screen position                         Most browsers      Firefox
507
    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
508
    var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
6651 dpurdie 509
 
6695 dpurdie 510
    var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
511
    var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
6651 dpurdie 512
 
6695 dpurdie 513
    var left = ((width / 2) - (w / 2)) + dualScreenLeft;
514
    var top = ((height / 2) - (h / 2)) + dualScreenTop;
515
    var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
6651 dpurdie 516
 
6695 dpurdie 517
    // Puts focus on the newWindow
518
    if (window.focus) {
519
        newWindow.focus();
520
    }
6651 dpurdie 521
 
6695 dpurdie 522
    return newWindow;
523
}
6651 dpurdie 524
 
525
 
526
 
6695 dpurdie 527
 
528
 
529
 
530
 
531
 
532