Latest Technology news..

Main menu

Monthly Archives: February 2012

Post navigation

Then God said to Adam, “You listened to your wife and ate fruit from the tree. Cursed is the ground because of you. Through hard work you will get your food, every day of your life.”

This Adam curse continues and now – we have to work hard every day to earn our food. It is inevitable fact – most of us spend at work more than half of conscious adult life. How well do you spend this half of our life? Are you unhappy, stressed or bored on your job?

Why people are unhappy at work?

Conflicts with other people and especially your boss. We all humans and, surprisingly not only you, but everybody has own agenda, interests and needs. Conflicts often happen, because we forget about this. Care about people around you and you’ll enjoy their company much more.

Burnout – too much pressure, too much stress, too little time to think about yourself. Stress comes from inside – we are creators of own stress. There are hundreds ways to relieve – better organization, delegation of responsibility, better communication with co-workers. External factors are most important: enjoyment from family, home, physical activity and leisure, fulfilling personal life and achievements. At the end, we work to live, not living to work.

Lack of variety and challenge. And first step to have interesting and enjoyable job is to design your job.

Designing your job

Don’t allow to treat yourself as a pluggable work unit. You should have

Control over your task assignments and execution.

Environment and time to focus on your tasks.

Clear goals and immediate feedback.

Enjoyment from work comes at very specific point: when our tasks and challenges match our capabilities (Mihaly Csikszentmihal, Flow). Work should be not overwhelmingly complex and not too simple. With these conditions you will enjoy your work and grow quickly.

Me, Inc. or Hire yourself.

Don’t allow other people to decide what you do, your career and your future – not your manager, company or even trends in your profession. Take charge yourself and consider yourself as a mini enterprise.

Define alternative paths– from 2 previous steps you’ll discover alternative courses open to you today and in a future. Brainstorm all possible fields and occupations that would fit this general description. Add imagination.

Example: “I can receive certification, move to another company, freelance, become consulting coach or teach programming.”

Find gaps– what are you missing to move to alternative path or improve your current job position.

Example: “I should improve communication skills. I should learn new software platforms and try Agile.”

Put your work plan in action – abandon narrow path predetermined by your boss, company or profession. Focus on achievements and skills you need to advance on your current and future job in the same time. Use a good time/goals management system as GTD. Come up with Next Actions.

Most jobs are not created to make us happy. They are created to make money for someone else. If we allow them – they will suck our lives. Instead, we should take charge, design our jobs and hire ourselves.

Sigmund Freud gave simple receipt for happiness: “Work and Love”. And I hope you can break “curse of Adam” and love your work.

One of the most powerful interaction design patterns available to developers is “Drag and Drop.” We utilize Drag and Drop without really giving it much thought – especially when its done right. Here are 5 easy steps to ensure an elegant implementation.

Defining drag and drop
A drag operation, essentially, is a click gesture on some UI element while the mouse button is held down and the mouse is moved. A drop operation occurs when the mouse button is released after a drag operation.
From a high level, drag and drop decisions can be summed up by the following flow chart.
To speed up our development, Ext JS provides us with the Ext.dd classes to manage the basic decisions for us. In this post, we will cover coding for the appearance and removal of the drop invitation, invalid drop repair and what happens when a successful drop occurs.

Organzing the drag and drop classes
A first glance of the classes in the Ext.dd documentation might seem a bit intimidating. But, if we take a quick moment to look at the classes, we see that they all stem from the DragDrop class and most can be categorized into Drag or Drop groups. With a bit more time and digging, we can see that the classes can be further categorized into single node and multiple node drag or drop interactions.
In order to learn about the basics of drag and drop we’ll focus on applying single drag and drop interactions to DOM nodes. To do this, we’ll utilize the DD and DDTarget classes, which provide the base implementations for their respective drag and drop behaviors.
However, we need to discuss what our objectives are before we can start implementing drag and drop.

The task at hand
Lets say we’ve been asked to develop an application that will provide a rental car company the ability to place their cars and trucks in one of three states: available, rented or in repair status. The cars and trucks are only allowed to be placed in their respective “available” container.

To get started, we must make the cars and trucks “dragable”. For this, we’ll use DD. We’ll need to make the rented, repair and vehicle containers “drop targets”. For this we’ll use DDTarget. Lastly, we’ll use different drag drop groups to help enforce the requirement that cars and trucks can only be dropped into their respective “available” containers.
The HTML and CSS for this example is already constructed and can be downloaded here. With that downloaded, we can begin coding by adding drag operations to the cars and trucks.

Step 1: Starting with drag
To configure the vehicle DIVs elements as dragable, we’ll need to obtain a list and loop through it to instantiate new instances of DD. Here’s how we do it.Hide code highlighting

All drag and drop classes are designed to be implemented by means of overriding its methods. That’s why in the above code segment, we have create an empty object called overrides, which will be filled in later with overrides specific to the action we need.
We get of list of car and truck elements by leveraging the DomQuery select method to query the cars container for all the child div elements.
To make the cars and truck elements dragable, we create a new instance of DD, passing in the car or truck element to be dragged and the drag drop group that it is to participate in. Notice that the vehicle types have their own respective drag drop group. This will be important to remember later when we setup the rented and repair containers as drop targets.
Also notice that we’re applying the overrides object to the newly created instances of DD using Ext.apply., which is a handy way to add properties or methods to an existing object.
Before we can continue with our implementation, we need to take a quick moment to analyze what happens when you drag an element on screen. With this understanding, the rest of the implementation will fall into place.

Peeking at how drag nodes are affected
The first thing you’ll notice when dragging the car or truck elements around is that they will stick wherever they are dropped. This is OK for now because we’ve just begun our implementation. What is important is to understand how the drag nodes are being affected. This will aid us in coding for the return to their original positions when they are dropped on anything that is a valid drop target, which is known as an “invalid drop”.
The below illustration uses FireBug’s HTML inspection panel and highlights the changes being made by when a drag operation is applied to the Camaro element.Demo

While inspecting the drag element during a drag operation, we can see a style attribute added to the element with three CSS values populated: position, top and left. Further inspection reveals that the position attribute set to relative and top and left attributes updating while the node is being dragged around.
After a the drag gesture completes, the style attribute remains along with the styles contained therein. This is what we have to clean up when we code for the repair of an invalid drop. Until we setup proper drop targets, all drop operations are considered invalid.

Step 2: Repairing an invalid drop
The path of least resistance is to repair an invalid drop by reseting the style attribute that is applied during the drag operation. This means that the drag element would disappear from under the mouse and reappear where it originated and would be quite boring. To make it smoother, we’ll use Ext.Fx to animate this action.
Remember that the drag and drop classes were designed to have methods overridden. To implement repair, we’ll need to override the b4StartDrag, onInvalidDrop and endDrag methods.
Lets add the following methods to our overrides object above and we’ll discuss what they are and do.Hide code highlighting

// Called the instance the element is dragged.b4StartDrag : function(){// Cache the drag elementif(!this.el){this.el = Ext.get(this.getEl()); }//Cache the original XY Coordinates of the element, we'll use this later.this.originalXY = this.el.getXY(); }, // Called when element is dropped not anything other than a dropzone with the same ddgrouponInvalidDrop : function(){// Set a flag to invoke the animated repairthis.invalidDrop = true; }, // Called when the drag operation completesendDrag : function(){// Invoke the animation if the invalidDrop flag is set to trueif(this.invalidDrop === true){// Remove the drop invitationthis.el.removeClass('dropOK'); // Create the animation configuration objectvaranimCfgObj = {easing : 'elasticOut', duration : 1, scope : this, callback : function(){// Remove the position attributethis.el.dom.style.position = ''; }}; // Apply the repair animationthis.el.moveTo(this.originalXY[0], this.originalXY[1], animCfgObj); deletethis.invalidDrop; }},

In the above code, we begin by overriding the b4StartDrag method, which is called the instant the drag element starts being dragged around screen and makes it an ideal place to cache the drag element and original XY coordinates – which we will use later on in this process.
Next, we override onInvalidDrop, which is called when a drag node is dropped on anything other than a drop target that is participating in the same drag drop group. This override simply sets a local invalidDrop property to true, which will be used in the next method.
The last method we override is endDrag, which is called when the drag element is no longer being dragged around screen and the drag element is no longer being controlled by the mouse movements. This override will move the drag element back to its original X and Y position using animation. We configured the animation to use the elasticOut easing to provide a cool and fun bouncy effect at end of the animation.Demo

OK, now we have the repair operation complete. In order for it to work on the drop invitation and valid drop operations, we need to setup the drop targets.

Step 3: Configuring the drop targets
Our requirements dictate that we will allow cars and trucks to be in be dropped in the rented and repair containers as well as their respective original containers. To do this, we’ll need to instantiate instances of the DDTarget class.
Here’s how its done.Hide code highlighting

In the above code snippet, we have setup drop targets for the cars, trucks, rented and repair elements. Notice that the cars container element only participates in the “carsDDGroup” and the trucks container element participates in the “trucksDDGroup”. This helps enforce the requirement that cars and trucks can only be dropped in their originating container.
Next, we instantiate instances DDTarget for the rented and repair elements. Initially, they are configured to only participate in the “carsDDGroup”. In order to allow them to participate in the “trucksDDGroup”, we have to add it by means of addToGroup.
OK, now we’ve configured our drop targets. Lets see what happens when we drop the cars or trucks on a valid drop element.Demo

In exercising the drop targets, we see that the drag element stays exactly its dropped. That is, images can be dropped anywhere on a drop target and stay there. This means that our drop implementation is not complete.
To complete it, we need to actually code for the “complete drop” operation, by means of another override for the instances of DD that we created some time ago.

Step 4: Completing the drop
To complete the drop, we will need to actually drag the element from its parent element to the drop target element using DOM tools. This is accomplished by overriding the DD onDragDrop method.
Add the following method to the overrides object.Hide code highlighting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// Called upon successful drop of an element on a DDTarget with the sameonDragDrop : function(evtObj, targetElId){// Wrap the drop target element with Ext.ElementvardropEl = Ext.get(targetElId); // Perform the node move only if the drag element's // parent is not the same as the drop targetif(this.el.dom.parentNode.id != targetElId){// Move the elementdropEl.appendChild(this.el); // Remove the drag invitationthis.onDragOut(evtObj, targetElId); // Clear the stylesthis.el.dom.style.position =''; this.el.dom.style.top = ''; this.el.dom.style.left = ''; }else{// This was an invalid drop, initiate a repairthis.onInvalidDrop(); }

In the above override, the drag element is moved to the drop target element, but only if it is not the same as the drag element’s parent node. After the drag element is moved, the styles are cleared from it.
If the drop element is the same as the drag element’s parent, we ensure a repair operation occurs by calling this.onInvalidDrop.Demo

Upon a successful drop, the drag elements will now will be moved from their parent element to the drop target.
How does the user know if they are hovering above a valid drop target? We’ll give the user some visual feedback by configuring the drop invitation.

Step 5: Adding drop invitation
In order to make drag and drop a bit more useful, we need to provide feedback to the user on whether or not a drop operation can successfully occur. This means that we’ll have to override the onDragEnter and onDragOut methods
Add these last two methods to the overrides object.Hide code highlighting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Only called when the drag element is dragged over the a drop target with the same ddgrouponDragEnter : function(evtObj, targetElId){// Colorize the drag target if the drag node's parent is not the same as the drop targetif(targetElId != this.el.dom.parentNode.id){this.el.addClass('dropOK'); }else{// Remove the invitationthis.onDragOut(); }}, // Only called when element is dragged out of a dropzone with the same ddgrouponDragOut : function(evtObj, targetElId){this.el.removeClass('dropOK'); }

In the above code, we override the onDragEnter and onDragOut methods, both of which are only utilized when the drag element is interacting with a drop target participating in the same drag drop group.
The onDragEnter method is only called when the mouse cursor first intersects the boundaries of a drop target while a drag item is in drag mode. Likewise, onDragOut is called when the mouse cursor is first dragged outside the boundaries of the drop target while in drag mode.Demo

By adding overrides to the onDragEnter and onDragOut methods we can see that the background of the drag element will turn green when the mouse cursor first intersects a valid drop target and will lose its green background when it leaves the drop target or is dropped. This completes our implementation of drag and drop with DOM elements.

Summary
Today, we learned how to implement end to end drag and drop of DOM nodes using the first-level drag and drop implementation classes. From a high-level, we defined and discussed what drag and drop is and how to think about it in terms of the framework.
We also learned that the drag and drop classes can be grouped by drag or drop behaviors and whether or not they support single or multiple drag or drop operations. While implementing this behavior, we illustrated that the dd classes help make some of the behavioral decisions, and that we are responsible for coding the end-behaviors.
We hope you’ve enjoyed this thorough look at some fundamental drag and drop operations with DOM nodes. We look forward to bringing you more articles about this topic in the future.

Confessions of a Successful Entrepreneur

Lessons corporate executives can learn from entrepreneurs

When my friend Jim took the giant leap from corporate executive to technology entrepreneur back in 2000, even he never imagined that he would lead a Nasdaq listed company with over 20,000 employees in eight countries by 2009. How did he pull off this rare achievement? Many things, of course – strategy, ability to execute, funding, and able leadership to name a few. I asked Jim what he believed to be the biggest reason, and without hesitation, he attributed most of his success to the fact that he made some important behavior changes along the way. As I listened to him, I realized that this (the ability to make behavior and mindset changes) is common to all successful entrepreneurs, but always missed in analyst reports. Furthermore, I strongly believe they apply equally to people who want to remain and excel in corporate executive roles.

Here are the four changes Jim made:

1. From Shut to Open

In his corporate executive avatar, the more senior he became, the more he unknowingly shut himself off from people. As he became busier, he instructed his secretary to screen his calls and sequester his time. After all, how could he entertain every caller when he could barely finish his work? His assistants also took control of his e-mail in-box, only involving him in the “most critical” ones. He ignored anyone who “wasn’t worth it”. .

Once he started his own business, he quickly realized how important networks were. “It is not what you know, but who you know that matters in business. You cannot ignore anyone these days – who knows where the next big opportunity will come from,’” he told me. With this realization, he began to return each call and email personally with curiosity. Even today, with all his responsibilities as CEO, he wakes up at 5:00 a.m. everyday, answers his email for an hour over a cup of coffee, then goes for his morning run.

2. From Opportunistic to Helpful

During his days in the corner office of the division he headed for the old company, he routinely ignored help requests from friends and acquaintances. If someone called to ask him to recommend her son for an internship position, or if a friend asked him to introduce them to his company’s procurement guys, Jim usually did not bother unless he felt the person asking was important enough and could be of use to him in future. In most cases, he thought people were taking advantage of his position at the company.

In his early days as a businessman, Jim found a lot of closed doors. He noticed that the same people who had run after him when he was a senior corporate executive were now not returning his calls. His initial anger eventually gave way to humility and he realized that he must help anyone he can without weighing the usefulness of the person. Now as CEO he often tells his senior team, “You must go out of your way to genuinely help as many people as you can even if it is unclear how they might ever be useful to you – it is just good business.”

3. From Telling to Asking

As the big shot executive, he often told everyone how important his work was. As people asked him questions, he was happy to tell them everything he knew. After all, he was an expert in his field and it was only natural that people wanted to learn as much as they could from him. He felt really good about himself as people were so in awe of him. It was quite normal for him to spend a few hours at a party and come back without knowing much about the people he had met. He usually did most of the talking.

Now one can barely get a few sentences out of him when people try to probe about the importance of his work. He is far more interested in finding out about what others do, and never stops asking questions. He even attended a memory seminar which helps him remember the names of people he meets at social gatherings. I asked him why this sea change in behavior, and he was quick with his response: “It’s all about the people – you have to be genuinely interested in them…. As I proactively built this habit, I found that I felt deep intrinsic satisfaction when I knew I had understood (and helped) someone….. And usually in turn, they do their best for you. It’s a win-win habit.”