| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 | Ext.Loader.setConfig({enabled: true});Ext.Loader.setPath('Ext.ux', '../ux/');Ext.require([    'Ext.ux.ajax.JsonSimlet',    'Ext.ux.ajax.SimManager',    'Ext.data.*',    'Ext.grid.*']);Ext.onReady(function() {    var data = [{        "name": "Cheesecake Factory",        "cuisine": "American"    }, {        "name": "Creamery",        "cuisine": "American"    }, {        "name": "Crepevine",        "cuisine": "American"    }, {        "name": "Gordon Biersch",        "cuisine": "American"    }, {        "name": "MacArthur Park",        "cuisine": "American"    }, {        "name": "Old Pro",        "cuisine": "American"    }, {        "name": "Shokolaat",        "cuisine": "American"    }, {        "name": "Slider Bar",        "cuisine": "American"    }, {        "name": "University Cafe",        "cuisine": "American"    }, {        "name": "Madame Tam",        "cuisine": "Asian"    }, {        "name": "House of Bagels",        "cuisine": "Bagels"    }, {        "name": "Nola's",        "cuisine": "Cajun"    }, {        "name": "St Michael's Alley",        "cuisine": "Californian"    }, {        "name": "Coconuts Caribbean Restaurant & Bar",        "cuisine": "Caribbean"    }, {        "name": "Mango Caribbean Cafe",        "cuisine": "Caribbean"    }, {        "name": "Jing Jing",        "cuisine": "Chinese"    }, {        "name": "Mandarin Gourmet",        "cuisine": "Chinese"    }, {        "name": "Tai Pan",        "cuisine": "Chinese"    }, {        "name": "Coupa Cafe",        "cuisine": "Coffee"    }, {        "name": "Lytton Coffee Company",        "cuisine": "Coffee"    }, {        "name": "Peet's Coffee",        "cuisine": "Coffee"    }, {        "name": "Starbucks",        "cuisine": "Coffee"    }, {        "name": "Rose & Crown",        "cuisine": "English"    }, {        "name": "Bistro Maxine",        "cuisine": "French"    }, {        "name": "Cafe Epi",        "cuisine": "French"    }, {        "name": "Darbar Indian Cuisine",        "cuisine": "Indian"    }, {        "name": "Hyderabad House",        "cuisine": "Indian"    }, {        "name": "Janta",        "cuisine": "Indian"    }, {        "name": "Junoon",        "cuisine": "Indian"    }, {        "name": "Mantra",        "cuisine": "Indian"    }, {        "name": "Buca di Beppo",        "cuisine": "Italian"    }, {        "name": "Cafe Renzo",        "cuisine": "Italian"    }, {        "name": "Cafe Renzo",        "cuisine": "Italian"    }, {        "name": "Il Fornaio",        "cuisine": "Italian"    }, {        "name": "La Strada",        "cuisine": "Italian"    }, {        "name": "Osteria",        "cuisine": "Italian"    }, {        "name": "Pasta?",        "cuisine": "Italian"    }, {        "name": "Vero",        "cuisine": "Italian"    }, {        "name": "Baklava",        "cuisine": "Mediterranean"    }, {        "name": "Cafe 220",        "cuisine": "Mediterranean"    }, {        "name": "Cafe Renaissance",        "cuisine": "Mediterranean"    }, {        "name": "Evvia Estiatorio",        "cuisine": "Mediterranean"    }, {        "name": "Gyros-Gyros",        "cuisine": "Mediterranean"    }, {        "name": "Kan Zeman",        "cuisine": "Mediterranean"    }, {        "name": "Lavanda",        "cuisine": "Mediterranean"    }, {        "name": "Reposado",        "cuisine": "Mexican"    }, {        "name": "Sancho's Taquira",        "cuisine": "Mexican"    }, {        "name": "California Pizza Kitchen",        "cuisine": "Pizza"    }, {        "name": "New York Pizza",        "cuisine": "Pizza"    }, {        "name": "Patxi's Pizza",        "cuisine": "Pizza"    }, {        "name": "Pizza My Heart",        "cuisine": "Pizza"    }, {        "name": "Round Table",        "cuisine": "Pizza"    }, {        "name": "Pluto's",        "cuisine": "Salad"    }, {        "name": "Sprout Cafe",        "cuisine": "Salad"    }, {        "name": "The Prolific Oven",        "cuisine": "Sandwiches"    }, {        "name": "Kanpai",        "cuisine": "Sushi"    }, {        "name": "Miyake",        "cuisine": "Sushi"    }, {        "name": "Sushi Tomo",        "cuisine": "Sushi"    }, {        "name": "Joya",        "cuisine": "Tapas"    }, {        "name": "Bangkok Cuisine",        "cuisine": "Thai"    }, {        "name": "Krung Siam",        "cuisine": "Thai"    }, {        "name": "Siam Royal",        "cuisine": "Thai"    }, {        "name": "Thaiphoon",        "cuisine": "Thai"    }, {        "name": "Garden Fresh",        "cuisine": "Vegan"    }, {        "name": "Loving Hut",        "cuisine": "Vegan"    }, {        "name": "Tamarine",        "cuisine": "Vietnamese"    }, {        "name": "Three Seasons",        "cuisine": "Vietnamese"    }];    // wrapped in closure to prevent global vars.    Ext.define('Restaurant', {        extend: 'Ext.data.Model',        fields: ['name', 'cuisine']    });    Ext.ux.ajax.SimManager.init({        delay: 30,        defaultSimlet: null    }).register({        'readRestaurants': {            data: data,            stype: 'json',            getData: Ext.Function.createInterceptor(Ext.ux.ajax.JsonSimlet.prototype.getData, function() {                delete this.currentOrder;            }),                        // JsonSimlet respects limit param. We want to return ALL the data            getPage: function(ctx, data) {                return data;            }        }    }).register({        'createRestaurant': {            stype: 'json',            getData: function(ctx) {                var recData = Ext.JSON.decode(ctx.xhr.body);                delete recData.id;                data.push(recData);                return [recData]            }        }    });    var restaurants = Ext.create('Ext.data.Store', {        storeId: 'restaraunts',        model: 'Restaurant',        groupField: 'cuisine',        remoteGroup: true,        sorters: ['name'],        proxy: {            api: {                create: 'createRestaurant',                read: 'readRestaurants'            },            actionMethods: {                create : 'GET',                read   : 'GET'            },            noCache: false,            type: 'ajax',            reader: 'json',            writer: 'json'        },        autoLoad: true,        autoSync: true,        listeners: {            // Clear grouping button only valid if the store is grouped            groupchange: function() {                grid.down('[text=Clear Grouping]').setDisabled(!restaurants.isGrouped());            },            // Upon successful add of a new restaurant, invoke the server to sort and group            write: function(s, operation) {                if (operation.action === 'create' && operation.success === true) {                    restaurants.sort();                }            }        }    });        var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{        groupHeaderTpl: 'Cuisine: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',        hideGroupedHeader: true    });    var grid = Ext.create('Ext.grid.Panel', {        renderTo: Ext.getBody(),        collapsible: true,        iconCls: 'icon-grid',        frame: true,        store: restaurants,        width: 600,        height: 400,        title: 'Restaurants',        resizable: true,        features: [groupingFeature],        columns: [{            text: 'Name',            flex: 1,            dataIndex: 'name'        },{            text: 'Cuisine',            flex: 1,            dataIndex: 'cuisine'        }],        fbar  : [{            text: 'New Restaurant',            handler: function() {                newRestaurantDialog.show();            }        },            '->', {            text:'Clear Grouping',            iconCls: 'icon-clear-group',            handler : function(b) {                groupingFeature.disable();            }        }]    });        var newRestaurantDialog = Ext.create('Ext.window.Window', {        closeAction: 'hide',        title: 'Add a new restaurant',        // Make the Window out of a <form> el so that the <button type="submit"> will invoke its handler upon CR        autoEl: 'form',        width: 400,        bodyPadding: 5,        layout: 'anchor',        defaults: {            anchor: '100%'        },        defaultFocus: '[name=name]',        items: [{            xtype: 'textfield',            fieldLabel: 'Name',            name: 'name'        }, {            xtype: 'textfield',            fieldLabel: 'Cuisine',            name: 'cuisine'        }],        buttons: [{            text: 'Add',            type: 'submit',            handler: function() {                var newRec = Ext.ModelManager.create({name: newRestaurantDialog.down('[name=name]').getValue(), cuisine: newRestaurantDialog.down('[name=cuisine]').getValue()}, 'Restaurant');                restaurants.add(newRec);                newRestaurantDialog.hide();                newRestaurantDialog.el.dom.reset();            }        }, {            text: 'Cancel',            handler: function() {                newRestaurantDialog.hide();            }        }]    });});
 |