Caritatis

Just another WordPress.com weblog

jQgrid change element in form based on another August 12, 2011

Filed under: jQgrid — caritatis @ 4:56 pm

David Hansen, 2009/09/19 15:59

Here’s an example of using editoptions dataEvents to change another form element based on an onChange event in a <select>. In this case, the form contains Job_Name and Job_Number fields. The value of the Job_Number field is set using the value of the selected Job_Name option.

 {  name:   'Job_Number',
    index: '`Job #`',
    editable: true,
    edittype: 'text',
    editoptions: { size: 10, readonly: 'readonly'},
    editrules: {required: true },
    formoptions: { label: 'Job #' },
    width: 10,
    formatter: 'integer',
    formatoptions: { thousandsSeparator: '' },
    searchoptions: { sopt: ['eq','ne','lt','le','gt','ge', 'in', 'ni'] },
    align: 'right',
    sortable: true
 },
 {  name:   'Job_Name',
    index: '`Job Name`',
    editable: true,
    edittype: 'select',
    editoptions: { size: 1,
                   dataUrl: 'Includes/tblJobSelect.php',
                   dataEvents: [
                      {  type: 'change',
                         fn: function(e) {
                            $('input#Job_Number').val(this.value);
                         }
                      }
                   ]
    },
    formoptions: { label: 'Job Name' },
    searchoptions: { sopt: ['eq','ne','lt','le','gt','ge', 'cn', 'nc', 'bw', 'bn'] },
    align: 'right',
    width: 150,
    align: 'left',
    sortable: true
 },

this – in $(‘input#Job_Number’).val(this.value); – refers to the DOM element associated with the onChange event, the Job_Name <select>, in this case.

The dataUrl returns plain text HTML ”<select><option value=999>Some Job Name</option>…</select>” that jqGrid uses to create the select.

Notice the use of the readonly attribute on the Job_Number field.

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules

 

jQuery Note August 12, 2011

Filed under: jQuery — caritatis @ 4:54 pm

When using the jQuery library, make sure the code you write is always enclosed in the $.ready function:

$(function () {
    //Type in your code here
});

This makes sure that the code you write will be executed once the page has finished loading

from:  http://stackoverflow.com/questions/345540/how-to-disable-a-select-box-not-inside-a-form

 

JavaScript Object “Inspector” July 19, 2011

Filed under: JavaScript — caritatis @ 7:42 pm

I found this today on a site, and it’s easy to use when using someone else’s object that you just don’t have the info for:

<SCRIPT>
ret = prompt (“Enter object”, “document”);
obj = eval(ret);
var temp = “”;
for (x in obj)
temp += x + “: ” + obj[x] + “\n”;
alert (temp);
</SCRIPT>

OR:

obj = match;
var temp = ”;
for (x in obj)
temp += x + ‘: ‘ + obj[x] + ‘\n’;
alert (temp);

Found on : http://javascript.internet.com/debug-guide.html. The page is OLD (Netscape 2?, Win 3.1?), but it still has some handy tips, like this :)

 

Great IE/Windows info July 15, 2011

Filed under: IE,Testing — caritatis @ 7:06 pm

I stumbled upon the Elegant Code blog today & found some excellent information, I’m going to keep an eye on this site, totally awesome!

He has a good writeup of Firebug vs IE 8 Developer Toolbar
http://elegantcode.com/2009/05/18/firefoxfirebug-vs-ie8-developer-toolbar/

He also pointed out some virtual PCs provided by MS:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=11575

I’ll have to play with it on my new windows 7 vm, hmm a vm on a vm, we’ll see how that goes:
http://www.microsoft.com/windows/virtual-pc/default.aspx

 

More things to consider with sending emails July 14, 2011

Filed under: Email — caritatis @ 12:43 pm
Tags:

Suggestions from google

http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=1311182

# SPF record: An SPF record is a list of IP addresses that are authorized to send mail for a particular domain. For more information on how to publish an SPF record, please visit http://www.openspf.org.

DKIM: DKIM (DomainKeys Identified Mail) is a way to digitally sign messages and verify that the messages were sent by a particular domain. It works like a wax seal on an envelope, preventing messages from being tampered with.

 

Awesome SQL Profiler Post July 8, 2011

Filed under: SQL — caritatis @ 2:34 pm
Tags:

I stumbled upon this post while researching computed columns:
Top 10 Hidden Gems in SQL Server 2005

http://technet.microsoft.com/en-us/library/cc917696.aspx

It led me to this post when I was trying to figure out how to use sys.dm_exec_query_stats. Awesome information about “How To Get High Quality Information About Query Performance”

http://sqlblog.com/blogs/elisabeth_redei/archive/2009/03/01/how-to-get-high-quality-information-about-query-performance.aspx

Here’s a quick & dirty sql query:

select    sql_handle, (total_elapsed_time – total_worker_time) as blockedtime,
total_worker_time as cputime,
(total_physical_reads+total_logical_reads+total_logical_writes) as iocycles,
qs.execution_count , text
from  sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
order by blockedtime

 

Some Email checking sites June 27, 2011

Filed under: Email — caritatis @ 3:03 pm
Tags: ,

Mailgun may be a good service–very much what I was looking for as a way to send emails through someone who will keep up with making the emails work!

http://documentation.mailgun.net/Documentation/FAQs#GMail_says_.22Signed_by_mailgun.us.22_about_messages_I_send

Sender Score: https://www.senderscore.org
Sender Base: http://www.senderbase.com/senderbase_queries/main
AOL: http://postmaster.aol.com/Postmaster.Reputation.php
–also look at this for a way to get on the whitelist

 

Searching for all or one May 27, 2011

Filed under: Email — caritatis @ 8:30 pm

Since I only do this once or twice a year, I always forget the trick.  If you need to search on an id (or full text) and you want everything or just that id, use isnull, ex:

and s.SportID = isnull(@SportID,s.SportID)

It doesn’t seem to work as I’d like for a left outer join.  You can put it in the left outer join “on” clause, but if you have an id and nothing matches it, you get everything–not the empty set I’d like to get.  If you put it in the where clause and there is no id, you get nothing–even though I’d like to get everything.

 

Using an ajax-called cfc with Application.cfc April 15, 2011

Filed under: ColdFusion — caritatis @ 7:05 pm

If you want to use onRequest and you have cfc functions called by ajax (or other services), you’ll have a problem.  To get around this remove the onRequest function when you’re calling a cfc.  Do this in onRequestStart.

        <!— onRequest function breaks calls to cfc for json —>
  <cfif right(arguments.targetPage,4)  is “.cfc”>
            <cfset StructDelete(variables,”onRequest”)/>
            <cfset StructDelete( THIS, “OnRequest” ) />
  </cfif>

 

Getting rid of Word junk February 4, 2011

Filed under: ColdFusion,Drupal,FCK Editor — caritatis @ 9:01 pm

FROM:  http://tim.mackey.ie/CleanWordHTMLUsingRegularExpressions.aspx

Haven’t tried this, but looks good.

Wednesday, November 23, 2005 3:40:36 PM (GMT Standard Time, UTC+00:00) ( .Net General )

Introduction

I’ve spent a long time trying many different approaches at getting rid of MS Word HTML, when importing or pasting text into my content management system, with very mixed success.  Previous efforts involved using the MSHTML Element Dom but this was slow and difficult to implement.  i think i’ve finally found a satisfactory and fast solution using only regular expressions.  Please feel free to use it in your applications, and post any improvements you may find.

The Code

/// <summary>
/// Removes all FONT and SPAN tags, and all Class and Style attributes.
/// Designed to get rid of non-standard Microsoft Word HTML tags.
/// </summary>
private string CleanHtml(string html)
{
    // start by completely removing all unwanted tags
    html = Regex.Replace(html, @"<[/]?(font|span|xml|del|ins|[ovwxp]:\w+)[^>]*?>", "", RegexOptions.IgnoreCase);
    // then run another pass over the html (twice), removing unwanted attributes
    html = Regex.Replace(html, @"<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","<$1$2>", RegexOptions.IgnoreCase);
    html = Regex.Replace(html, @"<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","<$1$2>", RegexOptions.IgnoreCase);
    return html;
}

Samples of non-standard Microsoft Word HTML

<SPAN lang=EN-IE style="mso-ansi-language: EN-IE">
<p>
<UL style="MARGIN-TOP: 0cm" type=circle>
<o:p>&nbsp;</o:p>
<li style='mso-list:l3 level1 lfo3;tab-stops:list 36.0pt'>

Explanation of Regular Expressions

I’ve spent a good deal of time examining the problematic tags that MS Word inserts in its HTML, some examples are shown above.  The above code is based on a few requirements for my CMS:

  • remove all FONT and SPAN tags, because all the content in my CMS is done through style-sheets.
  • remove all CLASS and STYLE tags because they mean nothing outside of the original word document
  • remove all namespace tags and attributes like <o:p> and < … v:shape … >

The first regular expression removes unwanted tags, and is broken down as follows:

<[/]?(font|span|xml|del|ins|[ovwxp]:\w+)[^>]*?>
  • match an open tag character <
  • and optionally match a close tag sequence </  (because we also want to remove the closing tags)
  • match any of the list of unwanted tags: font,span,xml,del,ins
  • a pattern is given to match any of the namespace tags, anything beginning with o,v,w,x,p, followed by a : followed by another word
  • match any attributes as far as the closing tag character >
  • the replace string for this regex is “”, which will completely remove the instances of any matching tags.
  • note that we are not removing anything between the tags, just the tags themselves

The second regular expression removes unwanted attributes, and is broken down as follows:

<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>
  • match an open tag character <
  • capture any text before the unwanted attribute (This is $1 in the replace expression)
  • match (but don’t capture) any of the unwanted attributes: class, lang, style, size, face, o:p, v:shape etc.
  • there should always be an = character after the attribute name
  • match the value of the attribute by identifying the delimiters. these can be single quotes, or double quotes, or no quotes at all.
  • for single quotes, the pattern is: ‘ followed by anything but a ‘ followed by a ‘
  • similarly for double quotes.
  • for a non-delimited attribute value, i specify the pattern as anything except the closing tag character >
  • lastly, capture whatever comes after the unwanted attribute in ([^>]*)
  • the replacement string <$1$2> reconstructs the tag without the unwanted attribute found in the middle.
  • note: this only removes one occurence of an unwanted attribute, this is why i run the same regex twice.  For example, take the html fragment: <p style=”Margin-TOP:3em”>
    the regex will only remove one of these attributes.  Running the regex twice will remove the second one.  I can’t think of any reasonable cases where it would need to be run more than that.

Suggestions!

If you have any suggestions or improvments, please post them here as comments.
Thanks :)

Lots of great comments!  Here’s one in CF:

<cffunction name=”cleanUpWord” access=”public” output=”false” returntype=”string” returnformat=”JSON” hint=”I clean up MS Word code”>
<cfargument name=”inputString” type=”string” required=”yes”>

<cfset var local = StructNew()>

<!— The two regex expressions in this function were taken from http://tim.mackey.ie/CleanWordHTMLUsingRegularExpressions.aspx —>

<cfset local.cleanText = ReplaceNoCase(arguments.inputString,”<p “,”<p><p “,”all”)> <!— Keep our P tag when it has bullshit MS Word attributes —>
<cfset local.cleanText = ReReplaceNoCase(local.cleanText,”<[/]?(font|span|xml|del|ins|o|st1|[ovwxp]:\w+)[^>]*?>”,”",”all”)> <!— Borrowed Regex —>
<cfset local.cleanText = ReReplaceNoCase(local.cleanText,”<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:’[^']*’|”"[^""]*”"|[^\s>]+)([^>]*)>”,”",”all”)> <!— Borrowed Regex —>
<cfset local.cleanText = ReplaceNoCase(local.cleanText,”&ndash;”,”-”,”all”)> <!— Get rid of unnecessary escape sequences —>
<cfset local.cleanText = ReReplaceNoCase(local.cleanText,”&rsquo;|&lsquo;”,”‘”,”all”)> <!— Get rid of unnecessary escape sequences —>
<cfset local.cleanText = ReReplaceNoCase(local.cleanText,”&rdquo;|&ldquo;”,”"”",”all”)> <!— Get rid of unnecessary escape sequences —>

<cfset local.cleanText = ReReplaceNoCase(local.cleanText,”“|””,”&quot;”,”all”)> <!— Get rid of MS Word SmartQuotes —>

<cfreturn local.cleanText>
</cffunction>

 

 
Follow

Get every new post delivered to your Inbox.