Fix toggleFormMetaVisibility js function
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Aug 2016 15:49:15 +0200
changeset 1549 0129ebd034a0
parent 1548 989a88822b51
child 1550 01b8fdd3e2b0
Fix toggleFormMetaVisibility js function It wasn't working properly because of the extra 'metaFieldSwitch' class. This fix rely on the position of the icon class in the list of classes, mostly because: * I add no idea how to do it properly (without having to test for each icon) * It seems fine enough like that * I'm lazy
data/cubes.seda.js
views/widgets.py
--- a/data/cubes.seda.js	Thu Aug 25 11:48:41 2016 +0200
+++ b/data/cubes.seda.js	Thu Aug 25 15:49:15 2016 +0200
@@ -16,14 +16,17 @@
 
 seda = {
     toggleFormMetaVisibility: function(domid) {
-        $node = cw.jqNode(domid);
+        var $node = cw.jqNode(domid);
         $node.toggleClass('hidden');
-        $a = $node.parent().children('a');
-        if ($a.attr('class') == 'icon-list-add') {
-            $a.attr('class', 'icon-up-open');
+        var $a = $node.parent().children('a');
+        var classes = $a.attr('class').split(' ');
+        var icon = classes[0];
+        if (icon == 'icon-list-add') {
+            classes[0] = 'icon-up-open';
         } else {
-            $a.attr('class', 'icon-list-add');
+            classes[0] = 'icon-list-add';
         }
+        $a.attr('class', classes.join(' '));
     },
 
 };
--- a/views/widgets.py	Thu Aug 25 11:48:41 2016 +0200
+++ b/views/widgets.py	Thu Aug 25 15:49:15 2016 +0200
@@ -209,6 +209,7 @@
             icon = 'icon-list-add'
         wdgs.append(tags.a(u'', onclick=unicode(js.seda.toggleFormMetaVisibility(divid)),
                            href='javascript:$.noop()', title=form._cw._('show/hide meta fields'),
+                           # take care, related js relies on the icon class position
                            klass=icon + ' metaFieldSwitch'))
         wdgs.append(u'<div id="{0}" class="metaField{1}">'.format(divid, hidden))
         wdgs.append(self._render_subfield(form, self.annotation_field(form), renderer))