]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * This class manages the login process.\r | |
3 | */\r | |
4 | Ext.define('Ticket.LoginManager', {\r | |
5 | config: {\r | |
6 | /**\r | |
7 | * @cfg {Class} model\r | |
8 | * The model class from which to create the "user" record from the login.\r | |
9 | */\r | |
10 | model: null,\r | |
11 | \r | |
12 | /**\r | |
13 | * @cfg {Ext.data.Session} session\r | |
14 | */\r | |
15 | session: null\r | |
16 | },\r | |
17 | \r | |
18 | constructor: function (config) {\r | |
19 | this.initConfig(config);\r | |
20 | },\r | |
21 | \r | |
22 | applyModel: function(model) {\r | |
23 | return model && Ext.data.schema.Schema.lookupEntity(model);\r | |
24 | },\r | |
25 | \r | |
26 | login: function(options) {\r | |
27 | Ext.Ajax.request({\r | |
28 | url: '/authenticate',\r | |
29 | method: 'GET',\r | |
30 | params: options.data,\r | |
31 | scope: this,\r | |
32 | callback: this.onLoginReturn,\r | |
33 | original: options\r | |
34 | });\r | |
35 | },\r | |
36 | \r | |
37 | onLoginReturn: function(options, success, response) {\r | |
38 | options = options.original;\r | |
39 | var session = this.getSession(),\r | |
40 | resultSet;\r | |
41 | \r | |
42 | if (success) {\r | |
43 | resultSet = this.getModel().getProxy().getReader().read(response, {\r | |
44 | recordCreator: session ? session.recordCreator : null\r | |
45 | });\r | |
46 | \r | |
47 | if (resultSet.getSuccess()) {\r | |
48 | Ext.callback(options.success, options.scope, [resultSet.getRecords()[0]]);\r | |
49 | return;\r | |
50 | }\r | |
51 | }\r | |
52 | \r | |
53 | Ext.callback(options.failure, options.scope, [response, resultSet]);\r | |
54 | }\r | |
55 | });\r |