Tuesday, July 22, 2008

Popup Window Manager

I was just reading a post by Rick Strahl about managing popup windows in the browser.  I actually authored a mini popup window manager a while back that tracks windows, allows you to easily close them, and most importantly (for my app I suppose), can prevent the same window from being opened twice, and if encountered, will simply focus that window.

The code is for MS AJAX but could easily be adopted for other platforms.

To use it, you need to register it globally via the pages Load event:

Sys.Application.add_load(function(sender, args) {
                window.popupWindowManager = new Mbccs.Psp.Web.Manager.PopupWindowManager(); 
            });

And to open a window (using the default height and width):

window.popupWindowManager.openWindow('myPage.aspx', false);

If you want to override the width/height:

window.popupWindowManager.openWindow('mypage.aspx', false, 800, 800)

The code looks like:

Mbccs.Psp.Web.Manager.PopupWindow = function Mbccs$Psp$Web$Manager$PopupWindow(url, handle, allowDuplicates) {
    this._url = url || null;
    this._handle = handle || null;
    this._allowDuplicates = allowDuplicates;
}

Mbccs.Psp.Web.Manager.PopupWindow.prototype = {
    get_url : function Mbccs$Psp$Web$Manager$PopupWindow$get_url() {
        return this._url;
    },
    get_handle : function Mbccs$Psp$Web$Manager$PopupWindow$get_handle() {
        return this._handle;
    },
    get_allowDuplicates : function Mbccs$Psp$Web$Manager$PopupWindow$get_allowDuplicates() {
        return this._allowDuplicates;
    }
}
Mbccs.Psp.Web.Manager.PopupWindow.registerClass('Mbccs.Psp.Web.Manager.PopupWindow');

Mbccs.Psp.Web.Manager.PopupWindowManager = function Mbccs$Psp$Web$Manager$PopupWindowManager() {   
    this._windows = [];   
}

Mbccs.Psp.Web.Manager.PopupWindowManager.prototype = {
    openWindow : function Mbccs$Psp$Web$Manager$PopupWindowManager$openWindow(url, allowDuplicates, width, height) {
        var allowOpen = true;
        var previousWindow = null;
        var previousWindowIndex = -1;
        var windows = this._windows;
        // Check for existing
        for(i = 0; i < windows.length; i++) {
            if(windows[i].get_url() == url) {
                allowOpen = windows[i].get_allowDuplicates();
                previousWindow = windows[i];
                previousWindowIndex = i;
                break;
            }
        }       
        if(!allowOpen) {
            if(previousWindow.get_handle().closed) {
                Array.removeAt(this._windows, previousWindowIndex);
                allowOpen = true;
            }
        }
        if(allowOpen) {
            var _width = width || 750;
            var _height = height || 700;
            var winName = 'win' + Math.floor(Math.random() * 100 + 1);
            var curWin = window.open(url, winName, 'width=' + _width + ',height=' + _height + ',resizable=yes,scrollbars=yes');                   
            var win = new Mbccs.Psp.Web.Manager.PopupWindow(url, curWin, allowDuplicates);                       
            this._windows.push(win);
            return win;
        } else {
            previousWindow.get_handle().focus();
            return previousWindow;
        }
    },
    closeAll : function Mbccs$Psp$Web$Manager$PopupWindowManager$closeAll() {
        var curWin = this._windows.pop();
        while(curWin != null) {
            curWin.get_handle().close();
            curWin = this._windows.pop();
        }
    }   
}

Monday, July 07, 2008

Using Virtual Machine Manager 2008 to manage Virtual Server 2005

I was trying to add a Virtual Server 2005 host to a Virtual Machine Manager 2008 Beta and I kept receiving the following error:

Error (421)
Agent installation failed on MBC02.mbccs.internal because of a WS-Management configuration error. 

Recommended Action
See the Virtual Machine Manager Help for information about configuring WS-Management.

 

Of course, being a beta product, that help section didn't exist and a search for "WS-Management" didn't yield anything.  WS-Management is installed by adding "Hardware Management" from Windows Components > Management and Monitoring tools (WinRM service), and this was installed on my server so I was pretty confused as to why I was receiving this message.

It turns out that you need to install WS-Management v1.1 which is provided as a hotfix from Microsoft.  You can download it from http://www.microsoft.com/downloads/details.aspx?FamilyID=845289ca-16cc-4c73-8934-dd46b5ed1d33&displaylang=en.

 

Hope this helps!