cleanup between plugin.name and plugin.uuid
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Dec 2012 12:02:00 +0000 (13:02 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Dec 2012 12:02:00 +0000 (13:02 +0100)
only keep plugin.domid that may be passed at plugin-creation time if needed

engine/composite.py
engine/plugin.py
engine/query.py
engine/static/js/plugin.js
engine/templates/plugin.html
engine/templates/plugin_setenv.js
engine/views.py
plugins/templates/tabs.html
plugins/templates/verticallayout.html
slice/views.py

index 2560d99..6d6ceec 100644 (file)
@@ -15,8 +15,8 @@ class Composite (Plugin):
         # this is designed so as to support a template like
         # {% for son in sons %} {{ son.rendered }} ...
         def is_active (son):
-#            print 'comparing >%s< and >%s<'%(son.name,self.active)
-            return son.name==self.active
+#            print 'comparing >%s< and >%s<'%(son.domid,self.active)
+            return son.domid==self.active
         ranks=range(len(self.sons))
         env = { 'sons':
                  [ { 'rendered': son.render(request),
@@ -24,8 +24,7 @@ class Composite (Plugin):
                      'active': is_active(son),
                      # this should probably come from son._settings..
                      'title': son.title,
-                     'name': son.name,
-                     'uuid': son.uuid,
+                     'domid': son.domid,
                      'classname': son.classname,
                      }
                    for (son,rank) in zip(self.sons,ranks) ]}
index fa01567..4ae6fbf 100644 (file)
@@ -18,44 +18,42 @@ DEBUG= [ 'Tabs' ]
 
 class Plugin:
 
-    # using a simple incremental scheme to generate uuids for now
-    uuid=0
+    # using a simple incremental scheme to generate domids for now
+    # we just need this to be unique in a page
+    domid=0
 
-    # xxx should generate some random id
     @staticmethod
-    def newuuid():
-        Plugin.uuid += 1
-        return Plugin.uuid
+    def newdomid():
+        Plugin.domid += 1
+        return "plugin-%d"%Plugin.domid
 
     ########## 
     # Constructor
     #### mandatory
     # . title: is used visually for displaying the widget
-    # . name:  a simple id suitable for forging css names
     #### optional
-    # . togglable: whether it can be turned on and off from the UI
-    #   like e.g. PleKitToggle
+    # . togglable: whether it can be turned on and off (like PleKitToggle)
     # . toggled: if togglable, what's the initial status
-    # . visible: if not set the plugin does not show up at all,
-    #   not quite sure what this was for
+    # . visible: if not set the plugin does not show up at all
+    #            (not quite sure what this was for)
     #### internal data
-    # . uuid: created internally
+    # . domid: created internally, but can be set at creation time if needed
+    #          useful for hand-made css, or for selecting an active plugin in a composite
     # . rank: this is for plugins sons of a composite plugin
     #### custom
     # any other setting can also be set when creating the object, like
     # p=Plugin(foo='bar')
     # which will result in 'foo' being accessible to the template engine
     # 
-    def __init__ (self, title, name,
+    def __init__ (self, title, domid=None,
                   visible=True, togglable=True, toggled=True, **settings):
         # what is in this dictionary will get exposed to template and to javascript
         self._settings=settings
         self.title=title
-        self.name=name
-        self.add_to_settings ( ['title','name'] )
-        self.uuid=Plugin.newuuid()
+        if not domid: domid=Plugin.newdomid()
+        self.domid=domid
         self.classname=self._classname()
-        self.add_to_settings ( [ 'uuid', 'classname' ] )
+        self.add_to_settings ( ['title', 'domid', 'classname'] )
         self.visible=visible
         self.togglable=togglable
         self.toggled=toggled
@@ -94,7 +92,6 @@ class Plugin:
     # returns the html code for that plugin
     # in essence, wraps the results of self.render_content ()
     def render (self, request):
-        uuid = self.uuid
         # initialize prelude placeholder if needed
         self._init_prelude (request)
         # call render_content
@@ -105,8 +102,9 @@ class Plugin:
         env.update(self._settings)
         result = render_to_string ('plugin.html',env)
 
-        # expose _settings in json format to js, and add plugin_uuid: uuid in the mix
-        js_env = { 'plugin_uuid' : self.uuid }
+        # expose _settings in json format to js, and add plugin_uuid: domid in the mix
+        # NOTE this plugin_uuid thing might occur in js files, ** do not rename **
+        js_env = { 'plugin_uuid' : self.domid }
         js_env.update (self._settings)
         settings_json = json.dumps (js_env, separators=(',',':'))
         env ['settings_json' ] = settings_json
index 62b4783..9b22cbd 100644 (file)
@@ -1,6 +1,8 @@
 # needed imports
 # uniqid
 
+xxx this code is broken and not used 
+
 class Query:
 
     def __init__ (self):
@@ -11,6 +13,7 @@ class Query:
         self.params=[]
         self.fields=[]
         self.unique=False
+        # xxx 
         self.uuid=uniquid()
         self.sort=None
         self.limit=None
index ae21642..c5a9de8 100644 (file)
@@ -4,13 +4,13 @@
 $(document).ready(function() {
     $('.plugin-hide').each(function() {
        $(this).click(function () { 
-           var plugin='#'+$(this).attr('id').replace('hide-','plugin-'); 
+           var plugin='#'+$(this).attr('id').replace('hide-',''); 
            var show='#'+$(this).attr('id').replace('hide-','show-'); 
            jQuery(plugin).hide(); jQuery(show).show(); $(this).hide();});
        })
     $('.plugin-show').each(function() {
        $(this).click(function () { 
-           var plugin='#'+$(this).attr('id').replace('show-','plugin-'); 
+           var plugin='#'+$(this).attr('id').replace('show-',''); 
            var hide='#'+$(this).attr('id').replace('show-','hide-'); 
            jQuery(plugin).show(); jQuery(hide).show(); $(this).hide();});
        })
index 7d5195e..8f9518d 100644 (file)
@@ -1,22 +1,22 @@
-{#<!--begin {{ classname }}{{ name }}{{ uuid }}-->#}
+{#<!--begin {{ classname }}{{ domid }}-->#}
 {% if visible %}
-<div class='plugin-toggle' id='{{ name }}'>
+<div class='plugin-toggle' id='toggle-{{ domid }}'>
 {% if togglable %}
   {% if not toggled %}
-<p id='show-{{ uuid }}' class='plugin-show'><a href='#'><span>&raquo; Show {{ classname }} "{{ title }}"</span></a></p>
-<p id='hide-{{ uuid }}' class='plugin-hide' style='display:none;'><a href='#'><span>&laquo; Hide {{ classname }} "{{ title }}"</span></a></p>
+<p id='show-{{ domid }}' class='plugin-show'><a href='#'><span>&raquo; Show {{ classname }} "{{ title }}"</span></a></p>
+<p id='hide-{{ domid }}' class='plugin-hide' style='display:none;'><a href='#'><span>&laquo; Hide {{ classname }} "{{ title }}"</span></a></p>
   {% else %}
-<p id='show-{{ uuid }}' class='plugin-show' style='display:none;'><a href='#'><span>&raquo; Show {{ classname }} "{{ title }}"</span></a></p>
-<p id='hide-{{ uuid }}' class='plugin-hide'><a href='#'><span>&laquo; Hide {{ classname }} "{{ title }}"</span></a></p>
+<p id='show-{{ domid }}' class='plugin-show' style='display:none;'><a href='#'><span>&raquo; Show {{ classname }} "{{ title }}"</span></a></p>
+<p id='hide-{{ domid }}' class='plugin-hide'><a href='#'><span>&laquo; Hide {{ classname }} "{{ title }}"</span></a></p>
   {% endif %}{# toggled #}
 {% endif %}{# togglable #}
 {% endif %}{# visible #}
 
-<div class='plugin {{ classname }}' id='plugin-{{ uuid }}' {% if not toggled %}style='display:none'{% endif %}>
+<div class='plugin {{ classname }}' id='{{ domid }}' {% if not toggled %}style='display:none;'{% endif %}>
 {{ plugin_content|safe }}
-</div><!--plugin {{ classname }}{{ name }}{{ uuid }}-->
+</div><!--plugin {{ classname }}{{ domid }}-->
 
 {% if visible %}
 </div>
 {% endif %}{# visible #}
-{#<!--end {{ classname }}{{ name }}{{ uuid }}-->#}
+{#<!--end {{ classname }}{{ domid }}-->#}
index ae01f6d..2cfd6e3 100644 (file)
@@ -1,6 +1,6 @@
 {# from plugin.php Plugin.render() #}
 {# Plugin initialization (if the plugin has the right structure) #}
-if (typeof jQuery('#plugin-{{ uuid }}').{{ classname }} != 'undefined') {
-    jQuery('#plugin-{{ uuid }}').{{ classname }}({{ settings_json|safe }});
-    {#jQuery('#{{ uuid }}').{{ classname }}('show');#}
+if (typeof jQuery('#{{ domid }}').{{ classname }} != 'undefined') {
+    jQuery('#{{ domid }}').{{ classname }}({{ settings_json|safe }});
+    {#jQuery('#{{ domid }}').{{ classname }}('show');#}
 }; 
index bb7ba16..aaefc36 100644 (file)
@@ -23,26 +23,26 @@ def test_plugin_view (request):
     template_env = {}
     
     main_plugin = \
-        VerticalLayout ( title='title for the vertical layout',name='vertical1',
+        VerticalLayout ( title='title for the vertical layout',domid='vertical1',
         sons = [ SimpleList (title='SimpleList and dataTables',
-                             name='simplelist1',
+                             domid='simplelist1',
                              list=hard_wired_list, 
                              header='Hard wired', 
                              foo='the value for foo',
                              with_datatables=True,
                              toggled=False),
-                 Tabs (title='Sample Tabs',name='tabs1',
+                 Tabs (title='Sample Tabs',domid='tabs1',
                        active='raw1',
-                       sons = [ Raw (title='a raw plugin',name='raw1',
+                       sons = [ Raw (title='a raw plugin',domid='raw1',
                                      togglable=False,
                                      html= 3*lorem_p),
-                                SliceList(title='a slice list',name='slicelist-main',
+                                SliceList(title='a slice list',domid='slicelist-main',
                                           togglable=False,
                                           list=hard_wired_slice_names),
-                                Raw (title='raw title',name='raw2',
+                                Raw (title='raw title',domid='raw2',
                                      togglable=False,html=lorem) ]),
                  SimpleList (title='SimpleList with slice names', 
-                             name='simplelist2',
+                             domid='simplelist2',
                              list=hard_wired_slice_names,
                              ) ] )
     # define 'content_main' to the template engine
@@ -50,7 +50,7 @@ def test_plugin_view (request):
 
     ##########
     # lacks a/href to /slice/%s
-    related_plugin = SliceList (title='SliceList plugin',name='slicelist1',
+    related_plugin = SliceList (title='SliceList plugin',domid='slicelist1',
                                 with_datatables='yes', 
                                 list=hard_wired_slice_names, 
                                 header='Slices')
index fe50e1f..54cd575 100644 (file)
@@ -1,12 +1,12 @@
 {# could try to set class='active' on the one we want to highlight #}
-<ul class="nav nav-tabs" id='{{ uuid }}'>
+<ul class="nav nav-tabs" id=tab-'{{ domid }}'>
 {% for son in sons %}
-<li> <a href="#{{ son.uuid }}" data-toggle="tab">{{ son.title }}</a> </li>
+<li> <a href="#{{ son.domid }}" data-toggle="tab">{{ son.title }}</a> </li>
 {% endfor %}
 </ul><!--nav-tabs-->
 <div class="tab-content">
 {% for son in sons %}
-<div class="tab-pane fade in{% if son.active %} active{% endif %}" id="{{ son.uuid }}">
+<div class="tab-pane fade in{% if son.active %} active{% endif %}" id="{{ son.domid }}">
 {{ son.rendered }}
 </div><!--tab-pane-->
 {% endfor %}
index 052dc49..53ce590 100644 (file)
@@ -1,7 +1,7 @@
-<div id='{{ uuid }}'>
+<div id='div-{{ domid }}'>
 {% for son in sons %}
 <h3>{{ son.title }}</h3>
-<div id='{{ name }}-{{ son.rank }}'>
+<div id='tab-{{ son.domid }}'>
 {{ son.rendered }}
 </div>
 {% endfor %}
index ecfeb8c..55eb66d 100644 (file)
@@ -10,6 +10,7 @@ from myslice.viewutils import topmenu_items, the_user
 # tmp
 from myslice.viewutils import lorem, hard_wired_slice_names
 
+# we take name from the URL and propagate in the template
 @login_required
 def fake_slice_view (request, name=None):
     title='Fake Slice Page'