All of my work from commits: dd4a194, 692644a, 4a60203, 5de46bc, 152042d, 64a2d4e...
[philo.git] / contrib / gilbert / templates / gilbert / api.js
1 Ext.Ajax.on('beforerequest', function (connection, options) {
2         if (!(/^http:.*/.test(options.url) || /^https:.*/.test(options.url))) {
3                 options.headers = Ext.apply(options.headers||{}, {
4                         'X-CSRFToken': '{{ csrf_token }}',
5                 });
6         }
7 });
8
9
10 Ext.ns('Gilbert.api');
11 {% for provider in providers %}Ext.Direct.addProvider({{ provider|safe }});{% endfor %}
12
13
14 Gilbert.on('ready', function (application) {{% for app_label, models in model_registry.items %}{% for name, admin in models.items %}
15         application.register_model('{{ app_label }}', '{{ name }}', new Gilbert.lib.models.Model({
16                 app_label: '{{ app_label }}',
17                 name: '{{ name }}',
18                 verbose_name: '{{ admin.model_meta.verbose_name }}',
19                 verbose_name_plural: '{{ admin.model_meta.verbose_name_plural }}',
20                 searchable: {% if admin.search_fields %}true{% else %}false{% endif %},
21                 columns: {{ admin.data_columns_spec_json|safe }},
22                 iconCls: 'icon-{{ admin.icon_name }}',
23                 api: Gilbert.api.models.{{ app_label }}.{{ name }},
24         }));
25 {% endfor %}{% endfor %}});
26
27
28 Gilbert.on('ready', function (application) {
29         application.register_plugin('_about_window', {
30                 init: function(application) {
31                         var application = this.application = application;
32                         
33                         var plugin = this;
34                         
35                         application.mainmenu.remove(application.mainmenu.items.items[0]);
36                         
37                         application.mainmenu.insert(0, {
38                                 xtype: 'button',
39                                 text: '<span style="font-weight: bolder; text-transform: uppercase;">{{ gilbert.title|safe }}</span>',
40                                 handler: function(button, event) {
41                                         plugin.showAbout(button);
42                                 },
43                         });
44                 },
45                 showAbout: function(sender) {
46                         var application = this.application;
47                         
48                         if (!this.about_window) {
49                                 var about_window = this.about_window = application.create_window({
50                                         height: 176,
51                                         width: 284,
52                                         header: false,
53                                         html: '<h1>{{ gilbert.title|safe }}</h1><h2>Version {{ gilbert.version|safe }}</h2><div id="credits">{{ gilbert.credits|safe }}</div>',
54                                         bodyStyle: 'background: none; font-size: larger; line-height: 1.4em; text-align: center;',
55                                         modal: true,
56                                         closeAction: 'hide',
57                                         closable: false,
58                                         resizable: false,
59                                         draggable: false,
60                                         minimizable: false,
61                                         fbar: [{
62                                                 text: 'OK',
63                                                 handler: function(button, event) {
64                                                         about_window.hide();
65                                                 }
66                                         }],
67                                         defaultButton: 0,
68                                 });
69                         }
70                         this.about_window.show();
71                         this.about_window.focus();
72                 },
73         });
74 });