template: started documenting the myplugin template to use the Plugin class and demonstrate the different functionalities
+from unfold.plugin import Plugin
+
+class Hazelnut (Plugin):
+
+ # set checkboxes if a final column with checkboxes is desired
+ # pass columns as the initial set of columns
+ # if None then this is taken from the query's fields
+ def __init__ (self, query=None, query_all=None, checkboxes=False, columns=None, datatables_options={}, **settings):
+ Plugin.__init__ (self, **settings)
+ self.query = query
+ # Until we have a proper way to access queries in Python
+ self.query_all = query_all
+ self.query_all_uuid = query_all.query_uuid if query_all else None
+ self.checkboxes=checkboxes
+ # XXX We need to have some hidden columns until we properly handle dynamic queries
+ if columns is not None:
+ self.columns=columns
+ self.hidden_columns = []
+ elif self.query:
+ self.columns = self.query.fields
+ if query_all:
+ # We need a list because sets are not JSON-serilizable
+ self.hidden_columns = list(self.query_all.fields - self.query.fields)
+ else:
+ self.hidden_columns = []
+ else:
+ self.columns = []
+ self.hidden_columns = []
+ self.datatables_options=datatables_options
+
+ def template_file (self):
+ return "hazelnut.html"
+
+ def template_env (self, request):
+ env={}
+ env.update(self.__dict__)
+ env['columns']=self.columns
+ return env
+
+ def requirements (self):
+ reqs = {
+ 'js_files' : [ "js/hazelnut.js",
+ "js/manifold.js", "js/manifold-query.js",
+ "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js",
+ "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js",
+ "js/unfold-helper.js",
+ ] ,
+ 'css_files': [ "css/hazelnut.css" ,
+ "css/dataTables.bootstrap.css",
+ ],
+ }
+ return reqs
+
+ # the list of things passed to the js plugin
+ def json_settings_list (self):
+ return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes', 'datatables_options', 'hidden_columns']
+++ /dev/null
-from unfold.plugin import Plugin
-
-class Hazelnut (Plugin):
-
- # set checkboxes if a final column with checkboxes is desired
- # pass columns as the initial set of columns
- # if None then this is taken from the query's fields
- def __init__ (self, query=None, query_all=None, checkboxes=False, columns=None, datatables_options={}, **settings):
- Plugin.__init__ (self, **settings)
- self.query = query
- # Until we have a proper way to access queries in Python
- self.query_all = query_all
- self.query_all_uuid = query_all.query_uuid if query_all else None
- self.checkboxes=checkboxes
- # XXX We need to have some hidden columns until we properly handle dynamic queries
- if columns is not None:
- self.columns=columns
- self.hidden_columns = []
- elif self.query:
- self.columns = self.query.fields
- if query_all:
- # We need a list because sets are not JSON-serilizable
- self.hidden_columns = list(self.query_all.fields - self.query.fields)
- else:
- self.hidden_columns = []
- else:
- self.columns = []
- self.hidden_columns = []
- self.datatables_options=datatables_options
-
- def template_file (self):
- return "hazelnut.html"
-
- def template_env (self, request):
- env={}
- env.update(self.__dict__)
- env['columns']=self.columns
- return env
-
- def requirements (self):
- reqs = {
- 'js_files' : [ "js/hazelnut.js",
- "js/manifold.js", "js/manifold-query.js",
- "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js",
- "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js",
- "js/unfold-helper.js",
- ] ,
- 'css_files': [ "css/hazelnut.css" ,
- "css/dataTables.bootstrap.css",
- ],
- }
- return reqs
-
- # the list of things passed to the js plugin
- def json_settings_list (self):
- return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes', 'datatables_options', 'hidden_columns']
/**
- * MySlice MyPlugin demonstration plugin
- * Version: 0.1.0
- * URL: http://www.myslice.info
- * Description: Template for writing new plugins and illustrating the different possibilities of the plugin API
- * Requires:
- * Author: The MySlice Team
- * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités
- * License: GPLv3
+ * MyPlugin: demonstration plugin
+ * Version: 0.1
+ * Description: Template for writing new plugins and illustrating the different
+ * possibilities of the plugin API.
+ * This file is part of the Manifold project
+ * Requires: js/plugin.js
+ * URL: http://www.myslice.info
+ * Author: Jordan Augé <jordan.auge@lip6.fr>
+ * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités
+ * License: GPLv3
*/
-/*
- * It's a best practice to pass jQuery to an IIFE (Immediately Invoked Function
- * Expression) that maps it to the dollar sign so it can't be overwritten by
- * another library in the scope of its execution.
- */
-(function( $ ){
+(function($){
+
+ var MyPlugin = Plugin.extend({
+
+ // Constructor
+ init: function(options, element) {
+ // Call the parent constructor, see FAQ when forgotten
+ this._super(options, element);
- var PLUGIN_NAME = 'MyPlugin';
+ // Explain this will allow query events to be handled
+ // What happens when we don't define some events ?
+ // Some can be less efficient
+ this.listen_query(options.query_uuid);
+ this.listen_query(options.query_uuid, 'all');
- // Routing calls
- jQuery.fn.ResourcesSelected = function( method ) {
- if ( methods[method] ) {
- return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return methods.init.apply( this, arguments );
- } else {
- jQuery.error( 'Method ' + method + ' does not exist on jQuery' + PLUGIN_NAME );
- }
+ // GUI Event binding
+ // call function
- };
+ },
- /***************************************************************************
- * Public methods
- ***************************************************************************/
+ /* GUI EVENTS */
- var methods = {
+ // a function to bind events here
+ // how to raise manifold events
- /**
- * @brief Plugin initialization
- * @param options : an associative array of setting values
- * @return : a jQuery collection of objects on which the plugin is
- * applied, which allows to maintain chainability of calls
- */
- init : function( options ) {
+ /* GUI MANIPULATION */
- return this.each(function(){
+ // We advise you to write function to change behaviour of the GUI
+ // Will use naming helpers to access content _inside_ the plugin
+ // always refer to these functions in the remaining of the code
- var $this = $(this);
+ show_hide_button: function()
+ {
+ // this.id, this.el, this.cl, this.els
+ // same output as a jquery selector with some guarantees
+ },
- /* An object that will hold private variables and methods */
- var s = new ResourcesSelected(options);
- $(this).data('Manifold', s);
-
- }); // this.each
- }, // init
+ /* TEMPLATES */
- /**
- * @brief Plugin destruction
- * @return : a jQuery collection of objects on which the plugin is
- * applied, which allows to maintain chainability of calls
- */
- destroy : function( ) {
+ // see in the html template
+ // How to load a template, use of mustache
- return this.each(function(){
- var $this = jQuery(this), data = $this.data('Manifold');
- jQuery(window).unbind('Manifold');
- data.Manifold.remove();
- $this.removeData('Manifold');
- })
+ /* QUERY HANDLERS */
- }, // destroy
+ // How to make sure the plugin is not desynchronized
+ // He should manifest its interest in filters, fields or records
+ // functions triggered only if the proper listen is done
- }; // var methods
+ // no prefix
- /***************************************************************************
- * ResourcesSelected object
- ***************************************************************************/
+ on_filter_added: function(filter)
+ {
- function MyPlugin(options)
- {
- /* member variables */
+ },
- this.options = options;
+ // ... be sure to list all events here
- /* methods */
+ /* RECORD HANDLERS */
+
+ on_record_received: function(record)
+ {
+ //
+ },
- /* constructor */
+ });
- } // function MyPlugin
+ // TODO Here use cases for instanciating plugins in different ways like in the pastie.
})(jQuery);