Switch to strict mode
authorThierry Florac <thierry.florac@onf.fr>
Tue, 16 May 2017 11:23:05 +0200
changeset 27 ad5f7192d437
parent 26 f8e004744ae9
child 28 b10a699c5559
Switch to strict mode
src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.js
src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.min.js
--- 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);
--- a/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.min.js	Tue May 16 11:22:11 2017 +0200
+++ b/src/pyams_thesaurus/zmi/resources/js/pyams_thesaurus.min.js	Tue May 16 11:23:05 2017 +0200
@@ -1,1 +1,1 @@
-(function(a){PyAMS_thesaurus={tree:{displaySubNodes:function(f,d,b){if(b===undefined){b=a('span.term:withtext("'+f+'")').siblings("i[data-ams-click-handler]")}var n=b.parents("span.label").siblings("ul.group");var m=n.closest("ul.group").closest("li");n.empty();for(var h in d){var e=d[h];var o=a("<li></li>");e.extracts.reverse();for(var k in e.extracts){var g=e.extracts[k];var c=a("<div></div>").addClass("pull-right margin-right-2").appendTo(o);var p=a("<i></i>").attr("data-ams-extract-name",g.name).addClass("fa fa-fw fa-square extract-checker").css("color","#"+g.color).appendTo(c);var j=a('>div i.extract-checker[data-ams-extract-name="'+g.name+'"]',m);if(j.hasClass("used")){if(g.used){p.addClass("used")}else{p.removeClass("fa-square").addClass("fa-square-o")}var i=a("i.switcher",'table.extracts tr[data-ams-element-name="'+g.name+'"]');if(!i.hasClass("fa-eye")){p.css("visibility","hidden")}}else{p.addClass("disabled").css("color","silver")}}var l=a("<span></span>").addClass("label label-success").addClass(e.css_class).attr("data-ams-url",e.view).attr("data-toggle","modal");if(e.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",true).appendTo(l)}a("<span></span>").addClass("term").html(e.label).appendTo(l);l.appendTo(o);a("<ul></ul>").addClass("hidden group").appendTo(o);o.appendTo(n);if(e.subnodes){PyAMS_thesaurus.tree.displaySubNodes(e.label,e.subnodes)}}n.removeClass("hidden");b.removeClass("fa-gear").addClass("fa-minus-circle")},expand:function(){var d=a(this);if(d.hasClass("fa-plus-circle")){d.removeClass("fa-plus-circle").addClass("fa-gear");var b=d.siblings("span.term").text();var c=d.closest("div.tree").data("ams-tree-context");MyAMS.ajax.post(c+"/get-nodes.json",{term:b},function(e){PyAMS_thesaurus.tree.displaySubNodes(b,e.nodes,d)})}else{PyAMS_thesaurus.tree.collapse.call(this)}},collapse:function(){var b=a(this);b.parents("span.label").siblings("ul.group").addClass("hidden");b.removeClass("fa-minus-circle").addClass("fa-plus-circle")},updateTerm:function(b){var c=a('span.term:withtext("'+b.term+'")').siblings("i[data-ams-click-handler]");if(c.hasClass("fa-minus-circle")){PyAMS_thesaurus.tree.collapse.call(c)}PyAMS_thesaurus.tree.expand.call(c)},findTerm:function(b){MyAMS.ajax.post("get-parent-nodes.json",{term:b.term},function(d){PyAMS_thesaurus.tree.displaySubNodes(d.parent,d.nodes);var c=a('span.term:withtext("'+d.term+'")').parents("span.label");a("html,body").animate({scrollTop:c.offset().top-100},1000);c.css("background-color","darkgreen").off("mouseover").on("mouseover",function(){a(this).css("background-color","")})})},switchExtract:function(){return function(){var c=a("i.fa",a(this));var b=c.parents("tr:first").data("ams-element-name");if(c.hasClass("fa-eye-slash")){PyAMS_thesaurus.tree.showExtract.call(this,b,c)}else{PyAMS_thesaurus.tree.hideExtract.call(this,b,c)}}},showExtract:function(c,b){a('i.extract-checker[data-ams-extract-name="'+c+'"]').css("visibility","");b.removeClass("fa-eye-slash").removeClass("text-danger").addClass("fa-eye")},hideExtract:function(c,b){a('i.extract-checker[data-ams-extract-name="'+c+'"]').css("visibility","hidden");b.removeClass("fa-eye").addClass("fa-eye-slash").addClass("text-danger")}},search:function(){var b=a(this).val();PyAMS_thesaurus.tree.findTerm({term:b})}};a(document).on("click","i.extract-checker",function(d){var b=a(this);if(b.hasClass("disabled")){return}var c=a("span.term",b.closest("div").siblings("span"));MyAMS.ajax.post("switch-extract.json",{term:c.text(),extract:b.data("ams-extract-name")},function(e){if(e.status){MyAMS.ajax.handleJSON(e)}else{if(e.used){b.removeClass("fa-square-o").addClass("fa-square used");a('>li >div i.extract-checker[data-ams-extract-name="'+e.extract+'"]',b.closest("div").siblings("ul.group")).removeClass("fa-square disabled").addClass("fa-square-o").css("color","#"+e.color)}else{b.removeClass("fa-square used").addClass("fa-square-o");a('i.extract-checker[data-ams-extract-name="'+e.extract+'"]',b.closest("div").siblings("ul.group")).removeClass("fa-square-o").addClass("fa-square disabled").css("color","silver")}}})})})(jQuery);
\ No newline at end of file
+(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