]> git.proxmox.com Git - sencha-touch.git/blob - src/examples/device/app/controller/Purchases.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / examples / device / app / controller / Purchases.js
1 Ext.define('Device.controller.Purchases', {
2 extend: 'Ext.app.Controller',
3 requires: ['Ext.device.Purchases'],
4
5 config: {
6 refs: {
7 productsList: 'purchases list#products',
8 purchasesList: 'purchases list#purchases',
9 purchaseProduct: 'purchases #purchaseProduct',
10 completePurchase: 'purchases #completePurchase'
11 },
12
13 control: {
14 productsList: {
15 deselect: 'onProductDeselect',
16 select: 'onProductSelect'
17 },
18 purchasesList: {
19 deselect: 'onPurchaseDeselect',
20 select: 'onPurchaseSelect'
21 },
22 'purchases #loadProducts': {
23 tap: 'loadProducts'
24 },
25 'purchases #loadPurchases': {
26 tap: 'loadPurchases'
27 },
28 purchaseProduct: {
29 tap: 'purchaseProduct'
30 },
31 completePurchase: {
32 tap: 'completePurchase'
33 }
34 }
35 },
36
37 loadProducts: function() {
38 var list = this.getProductsList();
39
40 Ext.device.Purchases.getProducts({
41 scope: this,
42 success: function(store) {
43 list.setStore(store);
44 },
45 failure: function() {
46 Ext.device.Notification.show({
47 title: 'Product',
48 message: 'Problem loading products'
49 });
50 }
51 });
52 },
53
54 purchaseProduct: function() {
55 var list = this.getProductsList(),
56 record = list.getSelection()[0];
57
58 if (!record) {
59 return;
60 }
61
62 record.purchase({
63 success: function() {
64 this.loadPurchases();
65
66 Ext.device.Notification.show({
67 title: 'Purchase Product',
68 message: 'Problem completing purchase'
69 });
70 },
71 failure: function() {
72 Ext.device.Notification.show({
73 title: 'Purchase Product',
74 message: 'Problem purchasing product'
75 });
76 }
77 });
78 },
79
80 completePurchase: function() {
81 var list = this.getPurchasesList(),
82 record = list.getSelection()[0];
83
84 if (!record) {
85 return;
86 }
87
88 record.complete({
89 success: function() {
90 this.loadPurchases();
91
92 Ext.device.Notification.show({
93 title: 'Complete Purchase',
94 message: 'Purchase completed'
95 });
96 },
97 failure: function() {
98 Ext.device.Notification.show({
99 title:'Complete Purchase',
100 message: 'Problem completing purchase'
101 });
102 }
103 });
104 },
105
106 onProductDeselect: function(view, record) {
107 this.getPurchaseProduct().setDisabled(true);
108 },
109
110 onProductSelect: function(view, record) {
111 this.getPurchaseProduct().setDisabled(false);
112 },
113
114 onPurchaseDeselect: function(view, record) {
115 this.getCompletePurchase().setDisabled(true);
116 },
117
118 onPurchaseSelect: function(view, record) {
119 this.getCompletePurchase().setDisabled(false);
120 },
121
122 loadPurchases: function() {
123 var list = this.getPurchasesList();
124
125 Ext.device.Purchases.getPendingPurchases({
126 scope: this,
127 success: function(store) {
128 list.setStore(store);
129 },
130 failure: function() {
131 Ext.device.Notification.show({
132 title: 'Error',
133 message: 'Problem loading purchases'
134 });
135 }
136 });
137 }
138 });