Subversion Repositories DevTools

Rev

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