Saturday, February 15, 2014

jQuery UI dialog jump issue workaround

When jQueryUI Dialog is used with "draggable = on", it would jump down by the scroll offset of parent page when the Dialog is being dragged via mouse. One of the nice workarounds to keep the draggable jQuery UI dialog in proper position without "jumping down" would be to set the dialog's parent position to 'fixed'. (By the way, this is the default behavior of Bootstrap's default modal window behavior, too.)

Below is a simple example to implement this workaround to a jQuery UI dialog. This works equally well for both modal and non-modal dialogs.

$(function(){
  $('#dialog_1').dialog({
    autoOpen: false,
    create: function( event ){  
      // set dialog's parent position to 'fixed' under the create event    
      $( event.target ).parent().css( 'position', 'fixed' );
    }
  });
  $('#btn_1').click(function(){
    // to reposition the dialog to the center when re-opened
    $('#dialog_1').dialog( 'option', 'position', 'center' );
    $('#dialog_1').dialog( 'open' );
  });
});

Hopefully, this workaround will provide better user experience on top of all the great features in jQuery UI library.

Tuesday, February 11, 2014

Get disk space info of all drives

The following SQL Server stored procedure could be useful when you need to get all disk space info quickly.


ALTER procedure [dbo].[usp_get_disk_space_info]
( @freeDiskSpace varchar(4000) output, @totalDiskSpace varchar(4000) output )
as
begin
 exec ( 'sp_configure ''xp_cmdshell'', 1' )
 exec ( 'reconfigure')
 declare @psinfo table ( data nvarchar(1000) )
 declare @t table(Drive varchar(2), FreeSpaceGB decimal(17,1), SizeGB decimal(17,1))
 insert into @psinfo
 EXEC xp_cmdshell 'Powershell.exe "Get-WMIObject Win32_LogicalDisk -filter "DriveType=3"| Format-Table DeviceID, FreeSpace, Size"' 
 delete from @psinfo where data is null or data like '%DeviceID%' or data like '%---%'
 update @psinfo set data = REPLACE(data, ' ', ',');
 ;With DriveSpace as (
 select SUBSTRING(data,1,2)  as [Drive], 
 replace((left((substring(data,(patindex('%[0-9]%',data)) , len(data))),CHARINDEX(',', (substring(data,(patindex('%[0-9]%',data)) , len(data))))-1)),',','') 
 as [FreeSpace] , 
 replace(right((substring(data,(patindex('%[0-9]%',data)) , len(data))),PATINDEX('%,%', (substring(data,(patindex('%[0-9]%',data)) , len(data))))) ,',','') 
 as [Size] 
 from @psinfo
 ) 
 insert into @t
 SELECT Drive, 
 convert(dec( 6,2),CONVERT(dec(17,1),FreeSpace)/(1024*1024*1024)) as FreeSpaceGB, 
 convert(dec( 6,2),CONVERT(dec(17,1), size)/(1024*1024*1024)) as SizeGB 
 FROM DriveSpace;
 declare @FreeSpaceGB varchar(1000)
 declare @SizeGB varchar(1000)
 set @FreeSpaceGB = stuff((select ', ' + Drive + ' ' + cast(FreeSpaceGB as varchar) + 'GB' from  @t for XML PATH('') ), 1, 2, '')
 set @SizeGB = stuff((select ', ' + Drive + ' ' + cast(SizeGB as varchar) + 'GB' from  @t for XML PATH('') ), 1, 2, '')

 select @freeDiskSpace = @FreeSpaceGB
 select @totalDiskSpace = @SizeGB


 exec ( 'sp_configure ''xp_cmdshell'', 0' )
 exec ( 'reconfigure')

end