-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
214 lines (161 loc) · 5.6 KB
/
app.js
File metadata and controls
214 lines (161 loc) · 5.6 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* File: app.js
*
* This file was generated by Sencha Architect version 2.0.0.
* http://www.sencha.com/products/architect/
*
* This file requires use of the Sencha Touch 2.0.x library, under independent license.
* License of Sencha Architect does not include license for Sencha Touch 2.0.x. For more
* details see http://www.sencha.com/license or contact license@sencha.com.
*
* This file will be auto-generated each and everytime you save your project.
*
* Do NOT hand edit this file.
*/
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
models: [
'Movie',
'ImdbMovie',
'GlobalAppSettings'
],
stores: [
'MoviesStore'
],
views: [
'MoviesList',
'MovieFormPanel',
'MoviesContainer',
'MoviesNavigationView'
],
name: 'Movies',
I________________________________________I: function() {
},
I___I_add_the_movies_proxies_at_the_launch____I: function() {
},
I_________________________________________I: function() {
},
getDefaultServicesRootUrl: function() {
return 'http://moviesrest.apphb.com';
//return 'http://localhost:55867'; // I use this url for local debug
},
setServicesRootUrl: function(newRootUrl) {
var GlobalSettings = Ext.create('Movies.model.GlobalAppSettings', {
id: this.getApplication().getDefaultServicesRootUrl(),
RootUrl : newRootUrl
});
// We can save Ed directly without having to add him to a Store first because we
// configured a RestProxy this will automatically send a POST request to the url /users
GlobalSettings.save({
scope: this,
failure: function(record, operation) {
//do something if the load failed
//Ext.Msg.alert('Error', 'Can not save settings!', Ext.emptyFn);
},
success: function(ed) {
}
});
},
getServicesRootUrl: function() {
this.result = 'no url';
var GlobalAppSettingsModel = Ext.ModelMgr.getModel('Movies.model.GlobalAppSettings');
GlobalAppSettingsModel.load(this.getApplication().getDefaultServicesRootUrl(), {
scope: this,
failure: function(record, operation) {
//do something if the load failed
var DefaultServicesRootUrl = this.getApplication().getDefaultServicesRootUrl();
this.result = DefaultServicesRootUrl;
this.getApplication().setServicesRootUrl(DefaultServicesRootUrl);
},
success: function(record, operation) {
//do something if the load succeeded
var rootUrl = record.get('RootUrl');
this.result = rootUrl;
},
callback: function(record, operation) {
//do something whether the load succeeded or failed
}
});
return this.result;
},
getResetServiceUrl: function() {
return this.getApplication().getServicesRootUrl() + "/reset-movies?format=json";
},
getMoviesServiceUrl: function() {
return this.getApplication().getServicesRootUrl() + '/movies';
},
updateMovieModelProxyUrl: function() {
// proxy with the currect URL
var modelProxy = {
type: 'rest',
extraParams: {
format: 'json'
},
url: this.getApplication().getMoviesServiceUrl(), // <----------------------------- the url
format: '',
reader: {
type: 'json',
rootProperty: 'Movie'
},
writer: {
type: 'json',
rootProperty: ''
}
};
//get the store
var store = Ext.getStore('MoviesStore');
// update store url
store.load();
//get the model
var model = Ext.ModelManager.getModel('Movies.model.Movie');
// update model proxy
model.setProxy(modelProxy);
},
updateMoviesStoreProxyUrl: function() {
// proxy with the currect URL
var storeProxy = {
type: 'jsonp',
extraParams: {
format: 'json'
},
url: this.getApplication().getMoviesServiceUrl(), // <----------------------------- the url
recordParam: '',
reader: {
type: 'json',
rootProperty: 'Movies'
}
};
//get the store
var store = Ext.getStore('MoviesStore');
// update store url
store.setProxy(storeProxy);
// load the store
store.load();
},
updateMoviesStoreAndModelPRoxyUrl: function() {
this.getApplication().updateMoviesStoreProxyUrl();
this.getApplication().updateMovieModelProxyUrl();
},
launch: function() {
if (Ext.os.is.Phone) {
Ext.create('Movies.view.MoviesNavigationView', {
fullscreen: true
});
Movies.app.disableImdbRecordUpdate = true; // doesn't work on mobile devices from some unknown reason
} else {
Ext.Viewport.add({
xclass: 'Movies.view.MoviesNavigationView',
width: 380,
height: 420,
centered: true,
modal: true,
hideOnMaskTap: false
}).show();
Movies.app.disableImdbRecordUpdate = false;
}
this.getApplication().updateMoviesStoreAndModelPRoxyUrl();
Movies.app.disableNextImdbRecordUpdate = false;
}
});