Display terms extensions
authorThierry Florac <thierry.florac@onf.fr>
Tue, 10 Jul 2018 16:57:41 +0200
changeset 74 9f4143b02965
parent 73 6eaae503e35d
child 75 51fae4ef929a
Display terms extensions
src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.js
src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.min.js
src/pyams_thesaurus/zmi/term.py
src/pyams_thesaurus/zmi/thesaurus.py
--- a/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.js	Tue Jul 10 15:46:24 2018 +0200
+++ b/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.js	Tue Jul 10 16:57:41 2018 +0200
@@ -66,6 +66,16 @@
 									  .html(node.label)
 									  .appendTo(span);
 					span.appendTo(li);
+					if (node.extensions) {
+						for (var i=0; i < node.extensions.length; i++) {
+							var extension = node.extensions[i];
+							$(extension.icon).addClass('hint opaque align-base padding-left-5')
+											 .attr('data-ams-url', extension.view)
+											 .attr('data-toggle', 'modal')
+											 .attr('title', extension.title)
+											 .appendTo(li);
+						}
+					}
 					$('<ul></ul>').addClass('hidden group')
 								  .appendTo(li);
 					li.appendTo(group);
--- a/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.min.js	Tue Jul 10 15:46:24 2018 +0200
+++ b/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.min.js	Tue Jul 10 16:57:41 2018 +0200
@@ -1,1 +1,1 @@
-(function(c,a){var b={tree:{displaySubNodes:function(h,f,d){if(d===undefined){d=c('span.term:withtext("'+h+'")').siblings("i[data-ams-click-handler]")}var p=d.parents("span.label").siblings("ul.group");var o=p.closest("ul.group").closest("li");p.empty();for(var j in f){if(!f.hasOwnProperty(j)){continue}var g=f[j];var q=c("<li></li>");g.extracts.reverse();for(var m in g.extracts){if(!g.extracts.hasOwnProperty(m)){continue}var i=g.extracts[m];var e=c("<div></div>").addClass("pull-right margin-right-2").appendTo(q);var r=c("<i></i>").attr("data-ams-extract-name",i.name).addClass("fa fa-fw fa-square extract-checker").css("color","#"+i.color).appendTo(e);var l=c('>div i.extract-checker[data-ams-extract-name="'+i.name+'"]',o);if(l.hasClass("used")){if(i.used){r.addClass("used")}else{r.removeClass("fa-square").addClass("fa-square-o")}var k=c("i.switcher",'table.extracts tr[data-ams-element-name="'+i.name+'"]');if(!k.hasClass("fa-eye")){r.css("visibility","hidden")}}else{r.addClass("disabled").css("color","silver")}}var n=c("<span></span>").addClass("label label-success").addClass(g.css_class).attr("data-ams-url",g.view).attr("data-toggle","modal");if(g.expand){c("<i></i>").addClass("fa fa-lg fa-plus-circle").attr("data-ams-click-handler","PyAMS_thesaurus.tree.expand").attr("data-ams-stop-propagation",true).appendTo(n)}c("<span></span>").addClass("term").html(g.label).appendTo(n);n.appendTo(q);c("<ul></ul>").addClass("hidden group").appendTo(q);q.appendTo(p);if(g.subnodes){b.tree.displaySubNodes(g.label,g.subnodes)}}p.removeClass("hidden");d.removeClass("fa-gear").addClass("fa-minus-circle")},expand:function(){var f=c(this);if(f.hasClass("fa-plus-circle")){f.removeClass("fa-plus-circle").addClass("fa-gear");var d=f.siblings("span.term").text();var e=f.closest("div.tree").data("ams-tree-context");MyAMS.ajax.post(e+"/get-nodes.json",{term:d},function(g){b.tree.displaySubNodes(d,g.nodes,f)})}else{b.tree.collapse.call(this)}},collapse:function(){var d=c(this);d.parents("span.label").siblings("ul.group").addClass("hidden");d.removeClass("fa-minus-circle").addClass("fa-plus-circle")},updateTerm:function(d){var e=c('span.term:withtext("'+d.term+'")').siblings("i[data-ams-click-handler]");if(e.hasClass("fa-minus-circle")){b.tree.collapse.call(e)}b.tree.expand.call(e)},findTerm:function(d){MyAMS.ajax.post("get-parent-nodes.json",{term:d.term},function(f){b.tree.displaySubNodes(f.parent,f.nodes);var e=c('span.term:withtext("'+f.term+'")').parents("span.label");c("html,body").animate({scrollTop:e.offset().top-100},1000);e.css("background-color","darkgreen").off("mouseover").on("mouseover",function(){c(this).css("background-color","")})})},switchExtract:function(){return function(){var e=c("i.fa",c(this));var d=e.parents("tr:first").data("ams-element-name");if(e.hasClass("fa-eye-slash")){b.tree.showExtract.call(this,d,e)}else{b.tree.hideExtract.call(this,d,e)}}},showExtract:function(e,d){c('i.extract-checker[data-ams-extract-name="'+e+'"]').css("visibility","");d.removeClass("fa-eye-slash").removeClass("text-danger").addClass("fa-eye")},hideExtract:function(e,d){c('i.extract-checker[data-ams-extract-name="'+e+'"]').css("visibility","hidden");d.removeClass("fa-eye").addClass("fa-eye-slash").addClass("text-danger")}},search:function(){var d=c(this).val();b.tree.findTerm({term:d})}};c(document).on("click","i.extract-checker",function(g){var d=c(this);if(d.hasClass("disabled")){return}var f=c("span.term",d.closest("div").siblings("span"));MyAMS.ajax.post("switch-extract.json",{term:f.text(),extract:d.data("ams-extract-name")},function(e){if(e.status){MyAMS.ajax.handleJSON(e)}else{if(e.used){d.removeClass("fa-square-o").addClass("fa-square used");c('>li >div i.extract-checker[data-ams-extract-name="'+e.extract+'"]',d.closest("div").siblings("ul.group")).removeClass("fa-square disabled").addClass("fa-square-o").css("color","#"+e.color)}else{d.removeClass("fa-square used").addClass("fa-square-o");c('i.extract-checker[data-ams-extract-name="'+e.extract+'"]',d.closest("div").siblings("ul.group")).removeClass("fa-square-o").addClass("fa-square disabled").css("color","silver")}}})});a.PyAMS_thesaurus=b})(jQuery,this);
\ No newline at end of file
+!function(a,s){"use strict";var e={tree:{displaySubNodes:function(s,t,r){void 0===r&&(r=a('span.term:withtext("'+s+'")').siblings("i[data-ams-click-handler]"));var l=r.parents("span.label").siblings("ul.group"),i=l.closest("ul.group").closest("li");l.empty();for(var d in t)if(t.hasOwnProperty(d)){var n=t[d],c=a("<li></li>");n.extracts.reverse();for(var o in n.extracts)if(n.extracts.hasOwnProperty(o)){var u=n.extracts[o],m=a("<div></div>").addClass("pull-right margin-right-2").appendTo(c),p=a("<i></i>").attr("data-ams-extract-name",u.name).addClass("fa fa-fw fa-square extract-checker").css("color","#"+u.color).appendTo(m);a('>div i.extract-checker[data-ams-extract-name="'+u.name+'"]',i).hasClass("used")?(u.used?p.addClass("used"):p.removeClass("fa-square").addClass("fa-square-o"),a("i.switcher",'table.extracts tr[data-ams-element-name="'+u.name+'"]').hasClass("fa-eye")||p.css("visibility","hidden")):p.addClass("disabled").css("color","silver")}var f=a("<span></span>").addClass("label label-success").addClass(n.css_class).attr("data-ams-url",n.view).attr("data-toggle","modal");if(n.expand&&a("<i></i>").addClass("fa fa-lg fa-plus-circle").attr("data-ams-click-handler","PyAMS_thesaurus.tree.expand").attr("data-ams-stop-propagation",!0).appendTo(f),a("<span></span>").addClass("term").html(n.label).appendTo(f),f.appendTo(c),n.extensions)for(var h=0;h<n.extensions.length;h++){var v=n.extensions[h];a(v.icon).addClass("hint opaque align-base padding-left-5").attr("data-ams-url",v.view).attr("data-toggle","modal").attr("title",v.title).appendTo(c)}a("<ul></ul>").addClass("hidden group").appendTo(c),c.appendTo(l),n.subnodes&&e.tree.displaySubNodes(n.label,n.subnodes)}l.removeClass("hidden"),r.removeClass("fa-gear").addClass("fa-minus-circle")},expand:function(){var s=a(this);if(s.hasClass("fa-plus-circle")){s.removeClass("fa-plus-circle").addClass("fa-gear");var t=s.siblings("span.term").text(),r=s.closest("div.tree").data("ams-tree-context");MyAMS.ajax.post(r+"/get-nodes.json",{term:t},function(a){e.tree.displaySubNodes(t,a.nodes,s)})}else e.tree.collapse.call(this)},collapse:function(){var s=a(this);s.parents("span.label").siblings("ul.group").addClass("hidden"),s.removeClass("fa-minus-circle").addClass("fa-plus-circle")},updateTerm:function(s){var t=a('span.term:withtext("'+s.term+'")').siblings("i[data-ams-click-handler]");t.hasClass("fa-minus-circle")&&e.tree.collapse.call(t),e.tree.expand.call(t)},findTerm:function(s){MyAMS.ajax.post("get-parent-nodes.json",{term:s.term},function(s){e.tree.displaySubNodes(s.parent,s.nodes);var t=a('span.term:withtext("'+s.term+'")').parents("span.label");a("html,body").animate({scrollTop:t.offset().top-100},1e3),t.css("background-color","darkgreen").off("mouseover").on("mouseover",function(){a(this).css("background-color","")})})},switchExtract:function(){return function(){var s=a("i.fa",a(this)),t=s.parents("tr:first").data("ams-element-name");s.hasClass("fa-eye-slash")?e.tree.showExtract.call(this,t,s):e.tree.hideExtract.call(this,t,s)}},showExtract:function(s,e){a('i.extract-checker[data-ams-extract-name="'+s+'"]').css("visibility",""),e.removeClass("fa-eye-slash").removeClass("text-danger").addClass("fa-eye")},hideExtract:function(s,e){a('i.extract-checker[data-ams-extract-name="'+s+'"]').css("visibility","hidden"),e.removeClass("fa-eye").addClass("fa-eye-slash").addClass("text-danger")}},search:function(){var s=a(this).val();e.tree.findTerm({term:s})}};a(document).on("click","i.extract-checker",function(s){var e=a(this);if(!e.hasClass("disabled")){var t=a("span.term",e.closest("div").siblings("span"));MyAMS.ajax.post("switch-extract.json",{term:t.text(),extract:e.data("ams-extract-name")},function(s){s.status?MyAMS.ajax.handleJSON(s):s.used?(e.removeClass("fa-square-o").addClass("fa-square used"),a('>li >div i.extract-checker[data-ams-extract-name="'+s.extract+'"]',e.closest("div").siblings("ul.group")).removeClass("fa-square disabled").addClass("fa-square-o").css("color","#"+s.color)):(e.removeClass("fa-square used").addClass("fa-square-o"),a('i.extract-checker[data-ams-extract-name="'+s.extract+'"]',e.closest("div").siblings("ul.group")).removeClass("fa-square-o").addClass("fa-square disabled").css("color","silver"))})}}),s.PyAMS_thesaurus=e}(jQuery,this);
--- a/src/pyams_thesaurus/zmi/term.py	Tue Jul 10 15:46:24 2018 +0200
+++ b/src/pyams_thesaurus/zmi/term.py	Tue Jul 10 16:57:41 2018 +0200
@@ -261,7 +261,7 @@
             }
         else:
             term_changes = changes.get(IThesaurusTerm, ())
-            if ('status' in term_changes) or ('label' in term_changes):
+            if ('status' in term_changes) or ('label' in term_changes) or ('extensions' in term_changes):
                 label = (self.context.generic or self.context).label.replace("'", "&#039;")
                 return {
                     'status': 'callback',
--- a/src/pyams_thesaurus/zmi/thesaurus.py	Tue Jul 10 15:46:24 2018 +0200
+++ b/src/pyams_thesaurus/zmi/thesaurus.py	Tue Jul 10 16:57:41 2018 +0200
@@ -301,7 +301,7 @@
                                          'color': extract.color,
                                          'used': name in (node.context.extracts or ())}
                                         for name, extract in sorted(extracts.items(), key=lambda x: x[0])],
-                           'extensions': [{'title': translate(ext.label, context=self.request),
+                           'extensions': [{'title': translate(ext.label),
                                            'icon': ext.icon,
                                            'view': absolute_url(node.context, self.request, ext.target_view)}
                                           for ext in node.context.query_extensions()],