3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
18 'Ext.layout.container.Card',
19 'Ext.tip.QuickTipManager'
22 Ext.define('Customer', {
23 extend: 'Ext.data.Model',
40 extend: 'Ext.data.Model',
52 belongsTo: 'Customer',
64 Ext.define('OrderItem', {
65 extend: 'Ext.data.Model',
86 Ext.define('CustomerGrid', {
87 extend: 'Ext.grid.Panel',
88 alias: 'widget.customergrid',
92 initComponent: function(){
99 Logger.log('Customer store loaded', false);
120 handler: this.loadOrders,
126 this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
129 onSelectChange: function(selModel, selections) {
130 this.active = selections[0];
131 this.down('#load').setDisabled(!this.active);
134 loadOrders: function(){
135 var rec = this.active,
136 name = rec.get('name'),
137 owner = this.ownerCt,
141 orders = rec.orders();
142 if (orders.isLoading()) {
143 Logger.log('Begin loading orders: ' + rec.getId(), true);
145 orders.on('load', function(){
146 Logger.log('Order store loaded - ' + rec.getId(), false);
149 title: 'Orders - ' + rec.getId(),
154 owner.getLayout().next();
158 Ext.define('OrderGrid', {
159 extend: 'Ext.grid.Panel',
160 alias: 'widget.ordergrid',
162 initComponent: function(){
171 renderer: Ext.util.Format.dateRenderer('Y-m-d')
178 handler: this.onBackClick
181 text: 'Load Order Items',
183 handler: this.loadItems,
189 this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
192 onBackClick: function(){
193 this.ownerCt.getLayout().prev();
197 onSelectChange: function(selModel, selections) {
198 this.active = selections[0];
199 this.down('#load').setDisabled(!this.active);
202 loadItems: function(){
203 var customerName = this.customer.get('name'),
205 date = Ext.Date.format(rec.get('date'), 'Y-m-d'),
206 owner = this.ownerCt,
209 orderitems = rec.orderitems();
210 if (orderitems.isLoading()) {
211 Logger.log('Begin loading order items - ' + rec.getId(), true);
213 orderitems.on('load', function(){
214 Logger.log('Order items loaded - ' + rec.getId(), false);
217 title: 'Order Items - ' + rec.getId(),
218 xtype: 'orderitemgrid',
221 owner.getLayout().next();
225 Ext.define('OrderItemGrid', {
226 extend: 'Ext.grid.Panel',
227 alias: 'widget.orderitemgrid',
229 initComponent: function(){
240 dataIndex: 'quantity'
244 renderer: Ext.util.Format.usMoney
251 handler: this.onBackClick
254 text: 'Parent association loader',
255 tooltip: 'Demonstrate loading parent relationships - A new record will be created so we ignore any previous associations setup',
257 handler: this.onLoadClick,
263 this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
266 onSelectChange: function(selModel, selections) {
267 this.active = selections[0];
268 this.down('#load').setDisabled(!this.active);
271 onBackClick: function(){
272 this.ownerCt.getLayout().prev();
276 onLoadClick: function(){
277 var rec = this.active,
284 title: this.title.replace('Order Items', 'Order Item ' + id),
285 orderItemData: rec.data,
291 Ext.define('ItemLoader', {
292 extend: 'Ext.window.Window',
294 initComponent: function(){
300 text: 'Print order detail',
302 handler: this.onOrderClick
305 text: 'Print company detail',
308 handler: this.onCompanyClick
312 tpl: '<div>{type} {id} - {value}</div>',
313 tplWriteMode: 'append'
316 this.orderItem = new OrderItem(this.orderItemData, this.orderItemId);
319 onOrderClick: function(){
320 var id = this.orderItem.get('order_id'),
321 hasOrder = !!this.order;
324 Logger.log('Begin loading order - ' + id, true);
326 this.orderItem.getOrder({
328 success: function(order){
330 this.down('#company').enable();
332 Logger.log('Order loaded - ' + id, false);
337 value: Ext.Date.format(order.get('date'), 'Y-m-d')
343 onCompanyClick: function(){
344 var id = this.order.get('customer_id'),
345 hasCustomer = !!this.customer;
348 Logger.log('Begin loading customer - ' + id, true);
350 this.order.getCustomer({
352 success: function(customer){
353 this.customer = customer;
355 Logger.log('Customer loaded - ' + id, false);
359 id: customer.getId(),
360 value: customer.get('name')
367 Logger = (function(){
375 log: function(msg, isStart){
378 cls: isStart ? 'beforeload' : 'afterload',
381 panel.body.scroll('b', 100000, true);
386 Ext.onReady(function(){
388 var main = Ext.create('Ext.panel.Panel', {
389 renderTo: document.body,
405 tplWriteMode: 'append',
406 tpl: '<div class="{cls}">[{now:date("H:i:s")}] - {msg}</div>',
414 Logger.log('Begin loading customer store', true);
415 main.items.first().add({
416 xtype: 'customergrid'