YUI.add('annotation-form', function(Y) { var Lang = Y.Lang, Widget = Y.Widget, Node = Y.Node; var NS = Y.namespace('mazzle'); NS.AnnotationForm = AnnotationForm; /* AnnotationForm class constructor */ function AnnotationForm(config) { AnnotationForm.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). */ AnnotationForm.NAME = "annotation-form"; /* * The attribute configuration for the AnnotationForm widget. Attributes can be * defined with default values, get/set functions and validator functions * as with any other class extending Base. */ AnnotationForm.ATTRS = { target: { value: null }, fields: { value: { person:{label:"Person"}, location:{label:"Location"}, subject:{label:"Subject"} } }, annotations: { value: {} } }; /* AnnotationForm extends the base Widget class */ Y.extend(AnnotationForm, Widget, { initializer: function() { }, destructor : function() { }, renderUI : function() { var fields = this.get("fields"); for (var key in fields) { this._renderField(fields[key]); } }, bindUI : function() { var fields = this.get("fields"); this.after("annotationsChange", function(e) {this.syncUI()}); for(var key in fields) { Y.delegate("click", this._itemDelete, fields[key].list, "li .delete", this, key); } }, syncUI : function() { var fields = this.get("fields"), annotations = this.get("annotations"); for (var key in fields) { if(key) { this._setAnnotation(fields[key], annotations[key]); } } }, _itemDelete : function(e, field) { var node = e.currentTarget, parent = node.get("parentNode"); parent.remove(); this.fire("delete", {source:field, value:parent.get("id")}); }, _renderField : function(field) { var content = this.get("contentBox"), label = field.label; var box = content.appendChild(Node.create('
')); box.appendChild('