Friday, December 4, 2009

Auto hide element using jQuery

If you are looking for a way to hide any segment of your page automatically after a given time then you are in the right place. All you have to do is insert the script file provided from this post and add ID and AutoHide attribute to your HTML element.

Script





Demo
This part will be hidden in 500 milliseconds.


This part will be hidden in 1 second.


This part will be hidden in 3 seconds.


This part will be hidden in 5 seconds.


Refresh page to view again. Click here to download the script.








Monday, August 31, 2009

Calling a custom database function in WHERE part of your entity

I have encountered a need to call a custom database function in WHERE part of the entity using entityspaces(2008.x.x) which does not support Raw SQL Injection Everywhere.

I have searched everywhere and posted inquiries in the friendly ES forum but theres no luck.

This task can be done easily using stored procedure but I wanted to use ES for I have other filters, join and grouping, all of this are already in place except for the part where I need to call the function.

Now LastQuery to the rescue, this property contains nothing until you make the query, so the idea is to call the query making sure that only one or zero record will be return then use the value of LastQuery to construct a new SQL Query/Statement with the datase function in it to be use in our entity custom load. I am not sure if this is a good practice but I works for me. See the code below.


' Make sure we only have one record for this load
Dim esqUsers As New UserCollectionQuery("uv")
esqUsers.es.Top = 1
esqUsers.es.PageSize = 10
esqUsers.es.PageNumber = _PageNumber

' this part will give us an entry point for insertion of call to our custom database function it will generate this string "uv.[UserID] IN ('-2')"
esqUsers.Where(esqUsers.UserID.OP(esWhereOperand.In, "-2".Split("!"c)))

' more filters, join and grouping here.

' Make the call so we can generate the LastQuery
esUsers = New UserCollection
esUsers.Load(esqUsers)

' Get last query
Dim strLastQuery As String = esqUsers.es.LastQuery
' Insert the call to the function
strLastQuery = strLastQuery.Replace("uv.[UserID] IN ('-2')", "database function & params")

' Make sure we have the data
strLastQuery = strLastQuery.Replace("TOP 1", "")

' You also need to update some parameters if needed.

' Now we call our custom load
esUsers.CustomLoad(strLastQuery)


The custom load function is very simple, see below:

Public Function CustomLoad(ByVal sSQL As String) As UserCollection
MyBase.Load(esQueryType.Text, sSQL)
Return Me
End Function


HTH




Friday, August 14, 2009

Grouping radio buttons the jQuery way.

I figured I’d share how to handle grouping of radio butons using jQuery.
Color:



Favorite:





Users:




Or

Groups:





All you need to do is use the same value for the GroupName attribute of your radio buttons.






Then insert the script below into your page:

<script language="javascript" src="http://vreboton.googlepages.com/jquery-1.3.2.min.js"></script>
<script language="javascript" src="http://vreboton.googlepages.com/jquery.vreboton.UniqueRadioButton.js"></script>









Tuesday, July 21, 2009

Check if a table exist using EntitySpaces in DotNetNuke

Using esUtility ExecuteScalar method the function(VB.Net) below given the table name will return true if the table exist in the database otherwise it will return false.

Public Shared Function TableExist(ByVal tableName As String) As Boolean
Dim strSQL As String = "SELECT Count(*) FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}[{objectQualifier}" & tableName & "]') AND OBJECTPROPERTY(id, N'IsTable') = 1"
strSQL = strSQL.Replace("{databaseOwner}", DotNetNuke.Common.Utilities.Config.GetDataBaseOwner())
strSQL = strSQL.Replace("{objectQualifier}", DotNetNuke.Common.Utilities.Config.GetObjectQualifer())

Dim util As New esUtility()
If util.ExecuteScalar(esQueryType.Text, strsql) > 0 Then
Return True
Else
Return False
End If
End Function





Thursday, July 16, 2009

Make sure your Javascripts are in the proper location in DotNetNuke

Calling the procedure below in your DotNetNuke module will make sure that your client script will be inserted in the proper place. Which is inside the Head tag.

The Code:
01.Public Sub InjectClientScript(ByVal page As System.Web.UI.Page, ByVal scriptKey As String, ByVal scriptSrc As String, Optional ByVal scriptValue As String = "")
02.    Dim objHead As Control = page.FindControl("Head")
03.    If objHead IsNot Nothing Then
04.        If objHead.FindControl(scriptKey) Is Nothing Then
05.            Dim jQueryControl As New HtmlGenericControl("script")
06.            jQueryControl.ID = scriptKey
07.            jQueryControl.Attributes.Add("type", "text/javascript")
08.            If scriptValue = "" Then
09.                jQueryControl.Attributes.Add("src", scriptSrc)
10.            Else
11.                jQueryControl.InnerHtml = scriptValue
12.            End If
13.            objHead.Controls.Add(jQueryControl)
14.        End If
15.    End If
16.End Sub



Sample:
Inserting a script file;
1.InjectClientScript(page, "jquery.1.3.2.min.js", "/js/jquery.1.3.2.min.js")

Result:
1.<script id="jquery.1.3.2.min.js" type="text/javascript" src="/js/jquery.1.3.2.min.js"></script>


Inserting a plain script;
1.InjectClientScript(page, "jQueryNoConflict", "", "jQuery.noConflict();")

Result:
1.<script id="jQueryNoConflict" type="text/javascript">jQuery.noConflict();</script>





Thursday, March 12, 2009

Show element in full screen using jQuery

While developing a module for Dotnetnuke I encountered a need to show a single element/control in fullscreen. This can be done using a set of complicated codes in the server. However, this can easily be achived in the client using jQuery. The idea is to iterate all the parents of the selected element and hide all their siblings. The code below will do just that.

(function($){

$.fn.ShowElementInFullScreen = function() {
return this.each(function(){
$(this).parents().each(function(i){$(this).siblings().hide()});
});
};
})(jQuery);


After inserting the code above to your page you can now call the function using the code below.

jQuery('#YourElementId').ShowElementInFullScreen();


I have no public url to demostrate this yet, but I will post as soon as I have one. If you happen to use this code please post a comment with the URL below for others to see how this works.

Show only the content of this entry. Hide the rest.
Show Me


Thanks,
v