--- a/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.js Tue May 16 11:22:11 2017 +0200
+++ b/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.js Tue May 16 11:23:05 2017 +0200
@@ -1,6 +1,9 @@
-(function($) {
+/* globals MyAMS */
+(function($, globals) {
- PyAMS_thesaurus = {
+ 'use strict';
+
+ var PyAMS_thesaurus = {
tree: {
@@ -8,16 +11,23 @@
* Display term sub-nodes
*/
displaySubNodes: function(term, nodes, source) {
- if (source === undefined)
+ if (source === undefined) {
source = $('span.term:withtext("' + term + '")').siblings('i[data-ams-click-handler]');
+ }
var group = source.parents('span.label').siblings('ul.group');
var parent = group.closest('ul.group').closest('li');
group.empty();
for (var index in nodes) {
+ if (!nodes.hasOwnProperty(index)) {
+ continue;
+ }
var node = nodes[index];
var li = $('<li></li>');
node.extracts.reverse();
for (var ext_index in node.extracts) {
+ if (!node.extracts.hasOwnProperty(ext_index)) {
+ continue;
+ }
var extract = node.extracts[ext_index];
var div = $('<div></div>').addClass('pull-right margin-right-2')
.appendTo(li);
@@ -46,11 +56,12 @@
.addClass(node.css_class)
.attr('data-ams-url', node.view)
.attr('data-toggle', 'modal');
- if (node.expand)
+ if (node.expand) {
$('<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(span);
+ }
$('<span></span>').addClass('term')
.html(node.label)
.appendTo(span);
@@ -58,8 +69,9 @@
$('<ul></ul>').addClass('hidden group')
.appendTo(li);
li.appendTo(group);
- if (node.subnodes)
+ if (node.subnodes) {
PyAMS_thesaurus.tree.displaySubNodes(node.label, node.subnodes);
+ }
}
group.removeClass('hidden');
source.removeClass('fa-gear')
@@ -99,8 +111,9 @@
*/
updateTerm: function(options) {
var element = $('span.term:withtext("' + options.term + '")').siblings('i[data-ams-click-handler]');
- if (element.hasClass('fa-minus-circle'))
+ if (element.hasClass('fa-minus-circle')) {
PyAMS_thesaurus.tree.collapse.call(element);
+ }
PyAMS_thesaurus.tree.expand.call(element);
},
@@ -116,7 +129,7 @@
.off('mouseover')
.on('mouseover', function() {
$(this).css('background-color', '');
- })
+ });
});
},
@@ -130,11 +143,12 @@
return function() {
var switcher = $('i.fa', $(this));
var extract = switcher.parents('tr:first').data('ams-element-name');
- if (switcher.hasClass('fa-eye-slash'))
+ if (switcher.hasClass('fa-eye-slash')) {
PyAMS_thesaurus.tree.showExtract.call(this, extract, switcher);
- else
+ } else {
PyAMS_thesaurus.tree.hideExtract.call(this, extract, switcher);
- }
+ }
+ };
},
/**
@@ -170,8 +184,9 @@
$(document).on('click', 'i.extract-checker', function(e) {
var checker = $(this);
- if (checker.hasClass('disabled'))
+ if (checker.hasClass('disabled')) {
return;
+ }
var term = $('span.term', checker.closest('div').siblings('span'));
MyAMS.ajax.post('switch-extract.json', {term: term.text(),
extract: checker.data('ams-extract-name')}, function(data) {
@@ -194,5 +209,6 @@
}
});
});
+ globals.PyAMS_thesaurus = PyAMS_thesaurus;
-})(jQuery);
+})(jQuery, this);