Plugin VTAM by Frederic Francois (Univ Bristol) integrated into slice view
[myslice.git] / plugins / univbrisvtam / __init__.py
1 from unfold.plugin import Plugin
2
3 class UnivbrisVtam (Plugin):
4     def __init__ (self, query=None, query_all=None, sync_query=None,
5                   checkboxes=False, columns=None, 
6                   init_key=None,
7                   datatables_options={}, **settings):
8         Plugin.__init__ (self, **settings)
9         self.query          = query
10         self.query_uuid     = query.query_uuid if query else None
11         # Until we have a proper way to access queries in Python
12         self.query_all      = query_all
13         self.query_all_uuid = query_all.query_uuid if query_all else None
14         self.sync_query_uuid = sync_query.query_uuid if sync_query else None
15         self.checkboxes     = checkboxes
16         # XXX We need to have some hidden columns until we properly handle dynamic queries
17         if columns is not None:
18             self.columns=columns
19             self.hidden_columns = []
20         elif self.query:
21             self.columns = list (['Testbed', 'Virtualization Server', 'VM name', 'Delete'])
22             #replace production
23             #self.columns = self.query.fields
24             if query_all:
25                 #replace production
26                 self.hidden_columns = []
27                 # We need a list because sets are not JSON-serializable
28                 #self.hidden_columns = #list(self.query_all.fields - self.query.fields)
29             else:
30                 self.hidden_columns = []
31         else:
32             self.columns = []
33             self.hidden_columns = []
34
35         self.columns = list (['Testbed', 'Virtualization Server', 'VM name', 'Delete'])
36         self.init_key=init_key
37         self.datatables_options=datatables_options
38         # if checkboxes were required, we tell datatables about this column's type
39         # so that sorting can take place on a selected-first basis (or -last of course)
40         # this relies on the template exposing the checkboxes 'th' with class 'checkbox'
41         if self.checkboxes:
42             # we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
43             if 'aoColumns' in self.datatables_options:
44                 print 'WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded'
45                 del self.datatables_options['aoColumns']
46             # set aoColumnDefs in datatables_options - might already have stuff in there
47             aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
48             # here 'checkbox' is the class that we give to the <th> dom elem
49             # dom-checkbox is a sorting type that we define in querytable.js
50             aoColumnDefs.append ( {'aTargets': ['checkbox'], 'sSortDataType': 'dom-checkbox' } )
51
52     def template_file (self):
53         return "univbrisvtamplugin.html"
54
55     def template_env (self, request):
56         env={}
57         env.update(self.__dict__)
58         env['columns']=self.columns
59         return env
60
61     def requirements (self):
62         reqs = {
63             'js_files' : [ "js/spin-presets.js", "js/spin.min.js", "js/jquery.spin.js",
64  "js/dataTables.js",  "js/dataTables.bootstrap.js", "js/with-datatables.js", "js/jquery.jeditable.js", 
65                            "js/manifold.js", "js/manifold-query.js", 
66                            "js/unfold-helper.js",
67                            "js/univbrisvtam.js",
68                            ] ,
69             'css_files': [ "css/dataTables.bootstrap.css",
70                            "css/dataTables.full_numbers.css",
71                            "css/univbrisvtam.css", 
72                            ],
73             }
74         return reqs
75
76     def json_settings_list (self):
77         return ['plugin_uuid', 'domid', 
78                 'query_uuid', 'query_all_uuid', 'sync_query_uuid',
79                 'checkboxes', 'datatables_options', 
80                 'hidden_columns', 'init_key',]