11 Oct 2011

New GitHub Account and a Request for Help

No Comments Code Snippets, Programming / Web Development

Recently, I’ve been getting a lot of comments on my blog post ExtJS 4: Combo Boxes, loadRecord() and Remote Stores that have offered some really great feedback including a lot of suggestions for changes that should be made. Unfortunately, I haven’t had the time to integrate any of the suggested fixes. At the same time, I don’t like having code that doesn’t work quite right and help the community.

To alleviate this problem, I’ve create a GitHub Account and created a repository just for the code snippets I put on this site. I encourage you to take a look at what I’ve got in there (more will be added soon) and see if you can make any improvements. Feel free to fork, comment and commit to your heart’s content. I’d really appreciate it.

Thanks again for all of your comments and support. I look forward to seeing what you can do!

10 Oct 2011

ExtJS 4: Parsing Filters From the FilterFeature Using PHP

No Comments Code Snippets, Programming / Web Development

I wrote this method a few weeks ago and though I’d share it. It parses ExtJS filters sent in by the FilterFeature.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?
function parseExtJSFilters() {
    if(!isset($_GET['filter') { // No filter passed in
        return FALSE;
    }
    $filters = json_decode($_GET['filter']); // Decode the filter
    if($filters == NULL) { // If we couldn't decode the filter
        return FALSE;
    }
    $whereClauses = array(); // Stores whereClauses
    foreach($filters as $filter) {
        switch($filter->type) {
            case 'boolean':
                $filter->value = ($filter->value === TRUE) ? '1' : '0'; // Convert value for DB
                $whereClauses[] = "$filter->field = $filter->value" ;
                break;
            case 'date':
                $filter->value = "'$filter->value'"; // Enclose data in quotes
            case 'numeric':
                switch($filter->comparison) {
                    case 'lt': // Less Than
                        $whereClauses[] = "$filter->field < $filter->value";
                        break;
                    case 'gt': // Greather Than
                        $whereClauses[] = "$filter->field > $filter->value";
                        break;
                    case 'eq': // Equal To
                        $whereClauses[] = "$filter->field = $filter->value";
                        break;
                }
                break;
            case 'list':
                $listItems = array();
                foreach($filter->value as $value) {
                    $listItems[] = "'$value'";
                }
                $whereClauses[] = "$filter->field IN(" . implode(',', $listItems) . ')';
                break;
            case 'string':
            default: // Assume string
                $whereClauses[] = "(
                    $filter->field LIKE '{$filter->value}%' OR
                    $filter->field LIKE '%{$filter->value}' OR 
                    $filter->field LIKE '%{$filter->value}%' OR
                    $filter->field = '{$filter->value}' 
                )";
                break;
        }
    }
    if(count($whereClauses) > 0) {
        return implode(' AND ', $whereClauses);
    }
    return FALSE;        
}
?><?
function parseExtJSFilters() {
    if(!isset($_GET['filter') { // No filter passed in
        return FALSE;
    }
    $filters = json_decode($_GET['filter']); // Decode the filter
    if($filters == NULL) { // If we couldn't decode the filter
        return FALSE;
    }
    $whereClauses = array(); // Stores whereClauses
    foreach($filters as $filter) {
        switch($filter->type) {
            case 'boolean':
                $filter->value = ($filter->value === TRUE) ? '1' : '0'; // Convert value for DB
                $whereClauses[] = "$filter->field = $filter->value" ;
                break;
            case 'date':
                $filter->value = "'$filter->value'"; // Enclose data in quotes
            case 'numeric':
                switch($filter->comparison) {
                    case 'lt': // Less Than
                        $whereClauses[] = "$filter->field < $filter->value";
                        break;
                    case 'gt': // Greather Than
                        $whereClauses[] = "$filter->field > $filter->value";
                        break;
                    case 'eq': // Equal To
                        $whereClauses[] = "$filter->field = $filter->value";
                        break;
                }
                break;
            case 'list':
                $listItems = array();
                foreach($filter->value as $value) {
                    $listItems[] = "'$value'";
                }
                $whereClauses[] = "$filter->field IN(" . implode(',', $listItems) . ')';
                break;
            case 'string':
            default: // Assume string
                $whereClauses[] = "(
                    $filter->field LIKE '{$filter->value}%' OR
                    $filter->field LIKE '%{$filter->value}' OR 
                    $filter->field LIKE '%{$filter->value}%' OR
                    $filter->field = '{$filter->value}' 
                )";
                break;
        }
    }
    if(count($whereClauses) > 0) {
        return implode(' AND ', $whereClauses);
    }
    return FALSE;        
}
?>

You can view examples of using the FilterFeature in ExtJS 4 on the ExtJS 4 examples page for grid filtering.

Update: The source code for this snippet is available here.

02 Oct 2011

ExtJS 4: Passing Filters Between a Grid and a Chart Store

No Comments Programming / Web Development

In preparation for another round of Envato screencasts, I’ve been messing around with the new Charting API that comes with ExtJS 4. For this project, I wanted to show how you can filter a grid full of data and have it change the data in the pie chart. Unfortunately, I soon discovered that pie charts (or rather, charts in general) and data grids take two different types of data. Read more

14 Aug 2011

Envato Extras and a New Portfolio Item

No Comments Programming / Web Development

Recently, Envato announced a new website: Envato Extras. The purpose of this site is to showcase applications, tools and utilities that people have built using the Envato API. A while back, I created a simple mobile app using Sencha Touch that used the Envato API to grab popular items from the Audio Jungle website and display them in a mobile friendly list. You can check out the application on the Envato Extras website or you can head over to my portfolio and view the item there.

04 Jul 2011

ExtJS 4: Combo Boxes, loadRecord() and Remote Stores

8 Comments Code Snippets, Programming / Web Development

A while back I ran into an interesting issue regarding loading records from the database into a form that contained combo boxes driven by remote stores. The problem was, when the record got loaded into the form, the stores for the combo boxes hadn’t loaded, so all the combo boxes said “select one” instead of the option that was chosen when the form got submitted. After doing some digging, I came up with a way around this issue: Read more

28 Jun 2011

ExtJS 4: Using Listeners objects in Controllers (this.control)

1 Comment Code Snippets, Programming / Web Development

When setting up a controller in ExtJS 4, you might do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
Ext.define('app.controller.myController', {
    init: function() {
        this.control({
            'form > textfield': {
                change: this.textFieldChange
            }
        })
    },
    textFieldChange: function(textField, newValue, oldValue, options) {
      alert('The text box went from' + oldValue + ' to ' + newValue);
    }
})

What this code is saying is “Find every textfield inside of the form in the current view (usually the viewport) and, whenever the value changes, fire the textFieldChange method”. Now, this is fine and all, but what if your textFieldChange method sent a request to the server? That would mean that, for every character you typed, a new request would be created and sent to the server causing a lot of unnecessary overhead. Read more

26 Jun 2011

ExtJS 4: Proxy Calling ‘Create’ Instead of ‘Update’ When Saving Record

26 Comments Programming / Web Development

Recently, while working with a model and proxy in ExtJS 4, I ran into the issue where the model’s proxy would call the ‘create’ action instead of ‘update’ when saving changes to an existing record. Read more

17 Apr 2011

PAX Prime Registration and Burnout

No Comments Life

This weekend, my wife and I registered for PAX Prime. For those of you who don’t know, PAX is the Penny Arcade Expo and is a gaming convention that covers the spectrum: console, tabletop, boardgames, and pen and paper. In addition to all the games, several panels will be held and there’s a good chance some of my favorite geek celebrities will be in attendance. In addition to the amazing convention, I’m looking forward to taking my wife around Seattle and showing her all the cool sites I saw when I was at An Event Apart back in March. Read more

07 Apr 2011

How I’d Improve the Twitter iPhone App

No Comments Code Snippets

Recently, I started using Twitter’s native iPhone app. Overall, I really enjoy it, but there’s one thing about it that drives me just nuts: The settings screen(s). Read more

02 Apr 2011

Finding Myself at An Event Apart 2011 (Seattle, WA)

No Comments Life, Programming / Web Development

For the past five years of my life, I’ve been a web developer. I’ve written probably a million lines of code and have developed at least 5 distinct medium to large-scale web applications or sites. Despite my accomplishments, whenever I get around other web professionals I feel like I don’t belong. Couple this with the quality of both the attendees and speakers at An Event Apart in Seattle, and I felt downright stupid. Everywhere I went, I saw lanyards containing some of the biggest names in the industry: Facebook, Microsoft, PageRank, and THQ. In this sea of giants, of people who have changed the face of the web, who was I? What had I accomplished? Did I really deserve to be here, or was my attendance simply a matter of paying for a ticket? Am I a fraud? That last question was the one I had to answer if I was going to truly gain anything from this conference. Read more