Rev 5266 | Rev 5560 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
// Vix specific Javascript for jquery use//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Generate a confirmation dialog// Args: text - Body of the message// parms - A simple object of options - see defaults// Special: position of 'center' will place in center of visible screen.// Note: will return BEFORE the user makes a selection// Can call a function and/or a URL if confirmed// Can 'show' a progress element// See 'defaults' below for bits that can be modified////////////////////////////////////////////////////////////////////////////////////////////////////////////////////function vixConfirm(text, parms){var defaults = {resizable: true,height: 'auto',width : 'auto',modal: true,position: { my: "top", at: "top+100", of: window },title: "Confirm",icon: "images/i_warning.gif",url : null,ok : null,post : null,button : "Confirm",progress : "#ProgressBar"};$.extend( defaults, parms);defaults.open = function() {$(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus();var markup = '<img src="'+defaults.icon+'" style="float:left; margin:0 7px 20px 0;">' + text;$(this).html(markup);};defaults.close = function() {$(this).remove();};defaults.buttons = [{text : defaults.button,click : function (){if (defaults.ok != null ){defaults.ok(defaults);}if ( defaults.progress != null) {$(defaults.progress).show().css("visibility", "visible");}if (defaults.url != null ) {window.location.href = defaults.url;}if (defaults.post != null ) {$('form[name="'+defaults.post+'"]').submit();}$(this).dialog("close");}},{text : 'Cancel',click : function (){$(this).dialog("close");}}];var dd = $( "<div>Confirm</div>" ).dialog(defaults);// Once the dialog has been instantiated the autosize dimensions are known// and the dialog can be correctly positionedif (defaults.position == 'center'){dd.dialog("widget").center();console.log("Center in Window");}else{dd.dialog("widget").position(defaults.position);console.log("Original position");}// Return false incase this is used as an onClickreturn false;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Compatability function// Confirm Deletion of an item// Assumes that the item is within an 'anchor' and that an href can be located// Uses VixConfirm to do the heavy lifting////////////////////////////////////////////////////////////////////////////////////////////////////////////////////function vixConfirmDelete (txt){var href = window.event.currentTarget.href;vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})return false;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Similar to 'alert', but uses the jquery dialog mechnaism// Note: will return BEFORE the user makes a selection// Returns a Defereed object that will be rejected when the dialog is closed.////////////////////////////////////////////////////////////////////////////////////////////////////////////////////function vixAlert(text){var dbo = $.Deferred();var dd = $( "<div>Alert</div>" ).dialog({resizable: true,height: 'auto',width : 'auto',modal: true,title:'Alert',position: { my: "top", at: "top+100", of: window },open: function() {$(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);},close : function() {$(this).remove();dbo.reject();},buttons: {"Ok": function() {$(this).dialog("close");}}});// Once the dialog has been instantiated the autosize dimensions are known// and the dialog can be correctly positioned// Note: Appears that we need to position it twice// Once in the dialog creation, and once heredd.dialog("widget").position({ my: "top", at: "top+100", of: window });return dbo;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// jQuery extension function// Position an element inthe center of the visible window. Not the document and not the window(viewport).////////////////////////////////////////////////////////////////////////////////////////////////////////////////////jQuery.fn.center = function () {// Support many browsersvar w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;this.css("position","fixed");this.css("top", Math.max(0, ((h - $(this).outerHeight()) / 2) ) + "px");this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");return this;}//--------- Support to open modal dialog in an iFrame// Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title" data-width=500 data-height=300>Link Text</a>//var vixIframe = {};$(document).ready(function () {$('.vixIframeDialog').on('click', function (e) {e.preventDefault();vixIframe.parent = this;vixIframe.pagetitle = $(this).attr("title");var page = $(this).attr("href");var iframe = $('<iframe onload="resizeIframe(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + page + '" width="100%" height="100%" ></iframe>');var $dialog = $('<div></div>').html(iframe);var $dialog2 = $dialog.dialog({autoOpen: true,modal: true,zheight: $(this).data('height')|| 200,zwidth: $(this).data('width') || 300,height : 'auto,', width : 'auto',dialogClass: "rounded_box",title: 'Loading - ' + vixIframe.pagetitle,close: function(event, ui){//console.log('closing dialog');$(this).dialog("destroy");vixIframe = {};window.onbeforeunload = null;window.onunload = null;},});vixIframe.Dialog = $dialog;vixIframe.DialogWidget = $($dialog2).dialog('widget');//$(currentDialogWidget).find(".ui-dialog-titlebar").remove();$(vixIframe.DialogWidget).position({my:'top', at: 'top+100', of : window});//$dialog.dialog('open');// Prevent the user from navigating away from the iframe// window.onbeforeunload = function(){// console.log("confirmBrowseAway");// console.log("window.location.href:" + window.location.href);// parent.closeIFrame(12);// return null};window.onunload = function(){console.log("Unloading");//parent.closeIFrame(12);}});//// Prevent (at least control) the user from navigating within the iframe// If this invocation is within an iFrame, then close the iFrame if// the user attempt to navigate away from the iFrame.// This means that the iFrame cannot replace itself//if (typeof parent.vixIframe.pagetitle !== 'undefined'){console.log("DocumentReady within iframe");//window.onbeforeunload = function(){console.log("onbeforeunload");parent.closeIFrame(13); return null};window.onunload = function(){console.log("Unloading within iframe");//parent.closeIFrame(13);}}});function resizeIframe(iframe) {iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";$(vixIframe.Dialog).height(iframe.height);//console.log ("Resize Iframe:",iframe.height );iframe.width = iframe.contentWindow.document.body.scrollWidth;$(vixIframe.Dialog).width(iframe.width);//console.log ("Resize Iframe:",iframe.width );$(vixIframe.DialogWidget).position({my:'top', at: 'top+100', of : window});// New reset the titlevixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);//console.log("Ifame:", vixIframe)};function closeIFrame(aa){if (vixIframe.Dialog != null) {console.log('closing iframe:' + aa);vixIframe.Dialog.dialog('close');vixIframe = {};}}