YUI.add('tag-linker', function(Y) { var Lang = Y.Lang, Widget = Y.Widget, Node = Y.Node; var NS = Y.namespace('mazzle'); NS.TagLinker = TagLinker; /* TagLinker class constructor */ function TagLinker(config) { TagLinker.superclass.constructor.apply(this, arguments); } /* * Required NAME static field, to identify the Widget class and * used as an event prefix, to generate class names etc. (set to the * class name in camel case). */ TagLinker.NAME = "tag-linker"; /* * The attribute configuration for the TagLinker widget. Attributes can be * defined with default values, get/set functions and validator functions * as with any other class extending Base. */ TagLinker.ATTRS = { tag: { value: null }, sources: { value: {} }, limit: { value: 3 } }; /* TagLinker extends the base Widget class */ Y.extend(TagLinker, Widget, { initializer: function() { }, destructor : function() { }, renderUI : function() { var content = this.get("contentBox"); var tagNode = content.appendChild(Node.create('
')); var linkBox = content.appendChild(Node.create('')); var controls = content.appendChild(''); this.submitButton = controls.appendChild(''); this.cancelButton = controls.appendChild(''); this._renderSources(linkBox); this.tagNode = tagNode; }, bindUI : function() { var sources = this.get("sources"); this.after("tagChange", this.syncUI); this.cancelButton.on("click", this._cancel, this); this.submitButton.on("click", this._submit, this); /*for(var key in sources) { Y.delegate("click", this._itemSelect, sources[key]._list, "li input", this, key); }*/ }, syncUI : function() { var tag = this.get("tag"); if(tag) { this.tagNode.setContent(tag); this._fetchConcepts(); } else { this.tagNode.setContent(""); // hide source results } }, _cancel: function() { var tag = this.get("tag"); this.fire("cancel", {"tag":tag}); }, _submit: function() { var tag = this.get("tag"), sources = this.get("sources"), selected = []; for(var key in sources) { var source = sources[key], items = source.items, nodes = source._list.all("li"); nodes.each(function(node, i) { var concept = items[i]; if(node.one(".check:checked")) { selected.push({value:concept.id, label:concept.name, source:key}); } }) } this.fire("submit", {"tag":tag, concepts:selected}); }, _renderSources : function(node) { var sources = this.get("sources"); for(var key in sources) { var source = sources[key], label = source.label; //img = source.img; var box = node.appendChild(Node.create('')); //box.appendChild(''); box.appendChild('