Moved gilbert-related code to match the distutil changes.
[philo.git] / philo / contrib / gilbert / static / gilbert / lib / models.js
1 Ext.ns('Gilbert.lib.models');
2
3
4 Gilbert.lib.models.Model = Ext.extend(Object, {
5         
6         constructor: function (config) {
7                 Ext.apply(this, config);
8                 this.drag_drop_group = 'Gilbert.lib.models.Model(' + this.app_label + ',' + this.name + ') ';
9         },
10         
11         create_reader: function (config) {
12                 return new Ext.data.JsonReader(Ext.applyIf(config||{}, {}));
13         },
14         
15         create_writer: function (config) {
16                 return new Ext.data.JsonWriter(Ext.applyIf(config||{}, {
17                         encode: false,
18                 }));
19         },
20         
21         create_proxy: function (config) {
22                 return new Ext.data.DirectProxy(Ext.applyIf(config||{},{
23                         paramsAsHash: true,
24                         api: {
25                                 read: this.api.data_read,
26                                 create: this.api.data_create,
27                                 update: this.api.data_update,
28                                 destroy: this.api.data_destroy,
29                         },
30                 }));
31         },
32         
33         create_store: function (config) {
34                 return new Ext.data.Store(Ext.applyIf(config||{},{
35                         proxy: this.create_proxy(),
36                         reader: this.create_reader(),
37                         writer: this.create_writer(),
38                         remoteSort: true,
39                 }));
40         },
41         
42 });
43
44
45 Gilbert.lib.models.ModelInstance = Ext.extend(Object, {
46         
47         constructor: function (model, pk, __unicode__) {
48                 this.model = model;
49                 this.pk = pk;
50                 this.__unicode__ = __unicode__
51         },
52         
53 });
54
55
56 Ext.data.Types.GILBERTMODELFOREIGNKEY = {
57         
58         convert: function (v, data) {
59                 if (v) {
60                         return new Gilbert.lib.models.ModelInstance(Gilbert.get_model(v.app_label, v.name), v.pk, v.__unicode__);
61                 } else {
62                         return null;
63                 }
64         },
65         
66         sortType: Ext.data.SortTypes.none,
67         
68         type: 'gilbertmodelforeignkey',
69         
70 }
71
72
73 Ext.data.Types.GILBERTMODELFILEFIELD = {
74         
75         convert: function (v, data) {
76                 if (v) {
77                         return v.url;
78                 } else {
79                         return null;
80                 }
81         },
82         
83         sortType: Ext.data.SortTypes.none,
84         
85         type: 'gilbertmodelfilefield',
86         
87 }