Extjs4 Color Picker in a drop down control for use on forms and in editable grids

Ok so I needed a color picker that I could stick in an editable grid or just use as a form field, but I did not want to render the complete box with the little color squares in the form, and well, a grid is pretty tight on space.

I went ahead and designed a color picker combo box that puts the hex value in the input field and underlines it in the selected color. One of the notable features is the monitorMouseLeave method that is found in Ext.Element, this performs an action after the users mouse leaves an element after a preset amount of time. In the code below it is used to hide the drop down color fields after the user leaves the picker for half a second. This way we don’t force them to make a selection, but do not penalize them for coloring outside of the lines with their mouse.

Ext.define('Ext.ux.ColorPickerCombo', {
	extend: 'Ext.form.field.Trigger',
	alias: 'widget.colorcbo',
	triggerTip: 'Please select a color.',
 	onTriggerClick: function() {
	  var me = this; 
	  picker = Ext.create('Ext.picker.Color', {     
		pickerField: this,     
		ownerCt: this,    
		renderTo: document.body,     
		floating: true,    
		hidden: true,    
		focusOnShow: true,
		style: {
            	backgroundColor: "#fff"
        	} ,
		listeners: {
            	scope:this,
            	select: function(field, value, opts){
		me.setValue('#' + value);
		me.inputEl.setStyle({backgroundColor:value});
		picker.hide();
	},
	show: function(field,opts){
		field.getEl().monitorMouseLeave(500, field.hide, field);
		}
        	}
});
       picker.alignTo(me.inputEl, 'tl-bl?');
       picker.show(me.inputEl);
	}	
});

Extjs4.x Plugin that adds a help icon and rich tooltip to your field labels

I wanted to do two things, demonstrate how to write a plug-in and make something useful that would help out those who see a need in having an easy to configure help icon / tool tip to use with their extjs form fields.
Don’t forget if you are going to use tool tips in your application you will have to initialize quick tips by adding the line below into your code.

Ext.QuickTips.init();

The end result of the plugin is to add the small help icon to the far right hand corner of the form field, and then add a tooltip with some text that helps the user understand what to do with the form field like maybe an explanation of the contents or some business rules that apply to the input.

In order to add the question mark to the field label you will need some CSS . I have provided the code below, please note that the question mark can be downloaded here, and then you would have to modify the image url to point to the correct folder.

.icon-help{background-image:url(../images/help.png) !important;background-repeat:no-repeat;background-position:center;}

To use the plugin after you write it just add the following line to your form field configuration, with the help text that you want to show up in the tooltip replacing the default text (‘Help button text’) in the snippet below. You may pass HTML code and it will be rendered as HTML. It is very important to note that you must use the xtype that contains the word field as the postfix or combobox otherwise the xtype value will not validate and the plugin will assume that you are trying to add it to an object that is not a field.

Now let’s get to the good stuff, writing our first plugin which will be used by just adding the line below to your form field element when you are done.

plugins: [new helpQtip('Help button text')]

Plugin Code

Now for the plugin itself. First if you take a look closely you see the following block of code:

return{
    init:function(me){

    }
}	

This block of code is required for all plugins and basically attaches this object to the parent allowing your new plugin to add functionality to the existing ext component. You see ‘me’ being passed; this is actually a reference to itself.

Next, the thing that kind of jumps out at you is Ext.Function.createSequence. This creates a combined sequence of the original function plus the passed function. The passed function is called after the original function. This is important in this case as we need the fields to render before we can query the dom and add the help icon div. If your plugin was to rely on a function that needed to be called before the original function you would need to use createSequence’s twin Ext.Function.createInterceptor.

Finally, if we are going to mess with render and add some div’s to the document for pete’s sake we will need to make sure we destroy then when the object gets destroyed. To accomplish this we add an interceptor to the destroy function and remove the div from the dom.

The source code for the plugin is below, hopefully this has given you enough information to get started on writing your own plugins.

helpQtip = function(txt) {
return {
init: function(me) {
	var label 	  = me.fieldLabel; 
	var xt  	  = me.getXType().substr(4);
	if (xt == 'field' || xt == 'obox'){
 // Add in custom onRender and on Destroy events
	var id  = me.getId(), lbl = me.getFieldLabel();
 // Get the fieldLabel element
    Ext.apply( me,{
    render: Ext.Function.createSequence(me.render,function(ct, position) {
        var domNode = Ext.DomQuery.select('*[id=' + id + '-labelEl]'); 
            if(domNode){	
                var tipTxt = '<b>Help</b><br><p>' + txt + '</p>'; 
                var tipWdth = domNode[0].offsetWidth * 2;	
                // Create the dom object that contains the question mark image
                var helpDiv = {
                    tag:'div',
                    id:id + '-help',
                    html:'&nbsp;',
                    cls:'icon-help',	                                          
               style:'display:inline;
                      cursor:help;width:25px;
                      float:right;padding:1px 1px 5px 1px;'
                    } // End var helpDiv
// Add the help div to the document
                Ext.DomHelper.append(domNode[0],helpDiv);
// Attach the help tool tip to the help div
                var tip = Ext.create('Ext.tip.ToolTip', {
                    target:id + '-help',
                    html: tipTxt,
                    minWidth:tipWdth,
                    title:lbl,
                    autoHide:false,
                    closable:true,
                    closeAction:'hide'
                });
	  }// End of if(domNode)
	}), // End of render Sequence
	destroy:  Ext.Function.createSequence(me.destroy,function() {
		var helpDomNode = Ext.DomQuery.select('*[id=' + id + '-help]'); 	
		if(helpDomNode){
			Ext.removeNode(helpDomNode);
		}
	}) // End of Destroy Sequence
	})// End of Ext.apply
	}// End of if (xt == 'field') 
}// End Init Function 
};
};

A quick extjs4 form panel override that lets you really clear your form fields, not just reset them

I think everyone who has been working on putting out apps with ext knows that the reset() feature actually resets the form to the initial state which may or may not be blank, so I went ahead and wrote the following quick override that will loop through all of the form fields and place a blank space in them.

Ext.override(Ext.form.Panel, {
    clearForm: function (){
        me = this;
// Get form returns the ext basic form object
        me.getForm().getFields().each(function(f) {
	f.setValue('');
    });
}
});

To call the code just place the override somewhere at the top of your JavaScript and then anytime you want to clear a form the following will do the trick:

form_name.clearForm();

Some advice on IT management from a marketing pro

I noticed that Seth Godin posted a piece on the tendency to take star programmers and transform them into mediocre managers, it’s a mistake that cuts you twice, once with the loss of the key performer, and twice with the fact that you now have a management problem to deal with that may impede more key performers from joining the team. I asked and received permission to post the piece here in its entirety. The original can be found at this link, and a lot of other stuff on management and marketing that may be of intrest.

The extraordinary software development manager

Being good at programming is insufficient qualification for becoming a world class software project manager/leader. Too often, we take our best coders and turn them into incompetent managers because it seems like a logical next step, and because we don’t pay adequate attention to what we really want from these critical executives. (Hint, this is about many fields, not merely software).

1. Clients want useful visibility into the future in terms of costs, timing and deliverables

in fact, it’s almost impossible to be too clear, to benchmark enough and most of all, to overdo the work of identifying forks in the road when it comes to decision making. When a client hires a developer or a company embarks on a software project, they are lost. Even something as complex as building a house is dwarfed by the rapid change, shifting priorities and most of all, the requirement for the new, that’s involved in even a simple software project.

The indispensable software development manager is aware of this and lays it all out for us.

2. Code is going to be used, reviewed, updated and inspected by people other than the person writing it

At some point in the next [insert time frame], a dozen people we have never met will either be updating or using this code, whether they are people we hire or people we partner with. It’s tempting to question the value of an organized architecture and clear code commenting, but again, it’s almost impossible for an organization to overdo this. We don’t have time to do it over so we have to spend the time to do it right. In software programming only the amateur’s approach rewards speed over long-term usability.

3. A great programmer is worth thirty times as much as a good one.

Which means that hiring a good programmer in a competitive field is a killer error. It also means that managing a programmer in a way that accepts ‘good’ will lead to a fail as well.

4. Programming at scale is more like building a skyscraper than putting together a dinner party

Architecture in the acquisition of infrastructure and tools is one of the highest leverage pieces of work a tech company can do. Smart architecture decisions will save  hundreds of thousands of dollars and earn millions. We’ll only make those decisions if we can clearly understand our options.

Or, you can have some newbies hack something together real quick. Up to you.

Forget you identity, what about your pacemaker

The video below highlights a serious problem with medical devices that are as sophisticated as a large computer was just a decade ago. Dr. Rubin of Johns Hopkins outlines the hacks that the academic community have taken against implanted medical devices. Six years ago implanted devices were outfitted with wireless capabilities so that the devices can be updated without surgeons having to open you up.

Some of the devices include defibrillators, pacemakers, embedded insulin pumps.