amalgame/commit

set source_language select options based on selected source vocab

authorJacco van Ossenbruggen
Thu Sep 18 09:12:09 2014 +0200
committerJacco van Ossenbruggen
Thu Sep 18 09:12:09 2014 +0200
commite62e2f0ebb9224071fd4ad4e672eff62ad5ea2c9
tree456eb9895b059d4e28b1bf09be75b4f8ecf08f07
parentaeb298f66a7d8e158fff31cdfeefd25918b10f57
Diff style: patch stat
diff --git a/web/js/controls.js b/web/js/controls.js
index a5d2465..6d00d91 100644
--- a/web/js/controls.js
+++ b/web/js/controls.js
@@ -66,6 +66,9 @@ YUI.add('controls', function(Y) {
 
 			// toggle the controls when selected is changed
 			this.after('selectedChange', this.syncUI, this);
+			this.after('nodesChange', this.syncUI, this);
+			this.after('nodesChange', function(e) { Y.log('nodesChange in controls'); Y.log(e);});
+
 			this.syncUI();
 		},
 
@@ -157,6 +160,8 @@ YUI.add('controls', function(Y) {
 		syncUI : function() {
 			var selected = this.get("selected");
 			type = selected ? selected.type : "";
+			Y.log('syncUI controls');
+			Y.log(selected);
 
 			// add mapping selection radio buttons with available mappings to components that need them
 			this._setMappingSelecter();
@@ -172,12 +177,11 @@ YUI.add('controls', function(Y) {
 
 			NODE_CONTROLS_ACTIVE.removeClass("disabled");
 
-			// Disable controls requiring secondairy mappings if there are non:
+			// Disable controls requiring secondairy mappings if there are none:
 			if (!secSelecter || !secSelecter.getContent()) {
 				Y.all(".secinput").addClass("disabled");
 			}
 
-
 			// enable input select when a vocabulary is selected
 			NODE_INPUT_BTN.setAttribute("disabled", true);
 			NODE_SOURCE_BTN.setAttribute("disabled", true);
@@ -266,9 +270,25 @@ YUI.add('controls', function(Y) {
 
 		_valueSet : function(selected, which) {
 			if(selected) {
+				if (which == 'source') this._setLanguageOptions(selected);
 				Y.one("#"+which+'Label').set("value", selected.label);
 				Y.one("#"+which).set("value", selected.uri);
 			}
+		},
+
+		_setLanguageOptions : function(node) {
+			Y.log('_setLanguageOptions');
+			Y.log(node);	
+			if (!node || !node.stats || !node.stats.languages) return;
+			var langs = node.stats.languages;
+			Y.all('select.source_language').each(function(n) {
+				Y.log(n);
+				n.get('childNodes').remove();
+				for(var i in langs) {
+					var l = langs[i];
+					n.append('<option value="' + l +'">'+l+'</option>');
+				}
+			});
 		}
 
 	});