Browse files

gallery-2012.10.03-20-02 Satyam gallery-fwt-treeview

  • Loading branch information...
1 parent c439e8f commit 4cf228fe7f09cbd462845694aa91571ab5aaa723 YUI Builder committed Oct 3, 2012
View
17 src/gallery-fwt-treeview/assets/gallery-fwt-treeview-core.css
@@ -0,0 +1,17 @@
+.yui3-fw-treeview ul {
+ list-style: none;
+ cursor:pointer ;
+}
+.yui3-fw-treeview li {
+ clear: both;
+ overflow: hidden;
+}
+.yui3-fw-treeview li .yui3-fw-treeview-content,
+.yui3-fw-treeview li .yui3-fw-treeview-toggle,
+.yui3-fw-treeview li .yui3-fw-treeview-selection,
+.yui3-fw-treeview li .yui3-fw-treeview-icon {
+ float: left;
+}
+.yui3-fw-treeview li.yui3-flyweight-tree-node-collapsed ul.yui3-flyweight-tree-node-children {
+ display: none;
+}
View
76 src/gallery-fwt-treeview/assets/skins/sam/gallery-fwt-treeview-skin.css
@@ -0,0 +1,76 @@
+.yui3-skin-sam .yui3-fw-treeview ul {
+ padding-left: 18px;
+}
+.yui3-skin-sam .yui3-fw-treeview > ul {
+ background: none;
+ padding-left: 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-loading .yui3-fw-treeview-toggle {
+ background: url(treeview-loading.gif) 0 0 no-repeat;
+}
+.yui3-skin-sam .yui3-fw-treeview li {
+ background: url(treeview-sprite.png) -318px 0 repeat-y;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-last-child {
+ background: none;
+}
+.yui3-skin-sam .yui3-fw-treeview li .yui3-fw-treeview-toggle {
+ width:18px; height:22px;
+ float: left;
+}
+.yui3-skin-sam .yui3-fw-treeview .yui3-fw-treeview-toggle {
+ background: url(treeview-sprite.png) 0 0 repeat-y;
+
+}
+
+
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-no-children > .yui3-fw-treeview-toggle {
+ background-position: -18px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-no-children.yui3-flyweight-tree-node-last-child > .yui3-fw-treeview-toggle {
+ background-position: -36px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-expanded > .yui3-fw-treeview-toggle {
+ background-position: -54px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-expanded > .yui3-fw-treeview-toggle:hover {
+ background-position: -72px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-expanded.yui3-flyweight-tree-node-last-child > .yui3-fw-treeview-toggle {
+ background-position: -90px 0;
+}
+
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-expanded.yui3-flyweight-tree-node-last-child > .yui3-fw-treeview-toggle:hover {
+ background-position: -108px 0;
+}
+
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-collapsed > .yui3-fw-treeview-toggle {
+ background-position: -126px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-collapsed > .yui3-fw-treeview-toggle:hover {
+ background-position: -144px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-collapsed.yui3-flyweight-tree-node-last-child > .yui3-fw-treeview-toggle {
+ background-position: -162px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview li.yui3-flyweight-tree-node-collapsed.yui3-flyweight-tree-node-last-child > .yui3-fw-treeview-toggle:hover {
+ background-position: -180px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview .yui3-fw-treeview-selection {
+ display:none;
+}
+.yui3-skin-sam .yui3-fw-treeview-checkbox .yui3-fw-treeview .yui3-fw-treeview-selection {
+ width: 16px;
+ height:22px;
+ background: url(treeview-sprite.png) 0 0 no-repeat;
+ display:block;
+}
+.yui3-skin-sam .yui3-fw-treeview-checkbox .yui3-fw-treeview .yui3-fw-treeview-selected-state-0 > .yui3-fw-treeview-selection {
+ background-position: -270px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview-checkbox .yui3-fw-treeview .yui3-fw-treeview-selected-state-1 > .yui3-fw-treeview-selection {
+ background-position: -302px 0;
+}
+.yui3-skin-sam .yui3-fw-treeview-checkbox .yui3-fw-treeview .yui3-fw-treeview-selected-state-2 > .yui3-fw-treeview-selection {
+ background-position: -286px 0;
+}
View
BIN src/gallery-fwt-treeview/assets/skins/sam/treeview-loading.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/gallery-fwt-treeview/assets/skins/sam/treeview-sprite.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/gallery-fwt-treeview/assets/skins/sam/treeview-sprite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
13 src/gallery-fwt-treeview/build.json
@@ -0,0 +1,13 @@
+{
+ "name": "gallery-fwt-treeview",
+ "builds": {
+ "gallery-fwt-treeview": {
+ "jsfiles": [
+ "fwtv-constants.js",
+ "fw-treeview.js",
+ "fw-treenode.js"
+ ],
+ "meta": {}
+ }
+ }
+}
View
28 src/gallery-fwt-treeview/build.properties
@@ -0,0 +1,28 @@
+# Flyweight TreeView Build Properties
+
+# As long as the 'builder' project is cloned to the default folder
+# next to the 'yui3-gallery' project folder, the 'builddir' property does not
+# need to be changed
+#
+# If the 'builder' project is checked out to an alternate location, this
+# property should be updated to point to the checkout location.
+builddir=../../../builder/componentbuild
+
+# The name of the component. E.g. event, attribute, widget
+component=gallery-fwt-treeview
+
+# The list of files which should be concatenated to create the component
+# NOTE: For a css component. (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
+# component.jsfiles=fwt-treeview.js, fwt-treeviewHelperClass.js, fwt-treeviewSubComponentClass.js
+component.jsfiles=fwtv-constants.js, fw-treeview.js, fw-treenode.js
+
+# The list of modules this component. requires. Used to set up the Y.add module call for YUI 3.
+component.requires=gallery-flyweight-tree, widget, base-build
+
+# The list of modules this component. supersedes. Used to set up the Y.add module call for YUI 3.
+component.supersedes=
+
+# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3.
+component.optional=
+# If your module has a skin file, set this flag to "true"
+component.skinnable=true
View
7 src/gallery-fwt-treeview/build.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- YUI 3 Gallery Component Build File -->
+<project name="Flyweight TreeView" default="local">
+ <description>Flyweight TreeView Build File</description>
+ <property file="build.properties" />
+ <import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
+</project>
View
188 src/gallery-fwt-treeview/js/fw-treenode.js
@@ -0,0 +1,188 @@
+/** This class must not be generated directly.
+ * Instances of it will be provided by FWTreeView as required.
+ *
+ * Subclasses might be defined based on it.
+ * Usually, they will add further attributes and redefine the TEMPLATE to
+ * show those extra attributes.
+ *
+ * @module gallery-fwt-treeview
+ */
+/**
+ *
+ * @class FWTreeNode
+ * @extends FlyweightTreeNode
+ */
+/**
+ * @constructor
+ */
+ Y.FWTreeNode = Y.Base.create(
+ 'fw-treenode',
+ Y.FlyweightTreeNode,
+ [],
+ {
+ initializer: function() {
+ this.after('click', this._afterClick, this);
+ this.after('selectedChange', this._afterSelectedChange, this);
+ },
+ /**
+ * Responds to the click event by toggling the node
+ * @method _afterClick
+ * @param ev {EventFacade}
+ * @private
+ */
+ _afterClick: function (ev) {
+ var target = ev.domEvent.target;
+ if (target.hasClass(CNAMES.toggle)) {
+ this.toggle();
+ } else if (target.hasClass(CNAMES.selection)) {
+ this.toggleSelection();
+ } else if (target.hasClass(CNAMES.content) || target.hasClass(CNAMES.icon)) {
+ if (this.get('root').get('toggleOnLabelClick')) {
+ this.toggle();
+ }
+ }
+ },
+ /**
+ * Sugar method to toggle the selected state of a node.
+ * @method toggleSelection
+ */
+ toggleSelection: function() {
+ this.set('selected', (this.get('selected')?NOT_SELECTED:FULLY_SELECTED));
+ },
+ /**
+ * Changes the UI to reflect the selected state and propagates the selection up and/or down.
+ * @method _afterSelectedChange
+ * @param ev {EventFacade} out of which
+ * @param ev.src {String} if not undefined it can be `'propagateUp'` or `'propagateDown'` so that propagation goes in just one direction and doesn't bounce back.
+ * @private
+ */
+ _afterSelectedChange: function (ev) {
+ var selected = ev.newVal;
+
+ if (!this.isRoot()) {
+ Y.one('#' + this.get('id')).replaceClass('yui3-fw-treeview-selected-state-' + ev.prevVal,'yui3-fw-treeview-selected-state-' + selected);
+ if (this.get('propagateUp') && ev.src !== 'propagatingDown') {
+ this.getParent()._childSelectedChange().release();
+ }
+ }
+ if (this.get('propagateDown') && ev.src !== 'propagatingUp') {
+ this.forSomeChildren(function(node) {
+ node.set('selected' , selected, 'propagatingDown');
+ });
+ }
+ },
+ /**
+ * Overrides the original in FlyweightTreeNode so as to propagate the selected state
+ * on dynamically loaded nodes.
+ * @method _dynamicLoadReturn
+ * @private
+ */
+ _dynamicLoadReturn: function () {
+ Y.FWTreeNode.superclass._dynamicLoadReturn.apply(this, arguments);
+ if (this.get('propagateDown')) {
+ var selected = this.get('selected');
+ this.forSomeChildren(function(node) {
+ node.set('selected' , selected, 'propagatingDown');
+ });
+ }
+
+ },
+ /**
+ * When propagating selection up, it is called by a child when changing its selected state
+ * so that the parent adjusts its own state accordingly.
+ * @method _childSelectedChange
+ * @private
+ */
+ _childSelectedChange: function () {
+ var count = 0, selCount = 0;
+ this.forSomeChildren(function (node) {
+ count +=2;
+ selCount += node.get('selected');
+ });
+ this.set('selected', (selCount === 0?NOT_SELECTED:(selCount === count?FULLY_SELECTED:PARTIALLY_SELECTED)), {src:'propagatingUp'});
+ return this;
+ }
+
+ },
+ {
+ /**
+ * Template to produce the markup for a node in the tree.
+ * @property TEMPLATE
+ * @type String
+ * @static
+ */
+ TEMPLATE: Lang.sub('<li id="{id}" class="{cname_node} {sel_prefix}-{selected}"><div class="{toggle}"></div><div class="{icon}"></div><div class="{selection}"></div><div class="{content}">{label}</div><ul class="{cname_children}">{children}</ul></li>', CNAMES),
+ /**
+ * Constant to use with the `selected` attribute to indicate the node is not selected.
+ * @property NOT_SELECTED
+ * @type integer
+ * @value 0
+ * @static
+ * @final
+ */
+ NOT_SELECTED:NOT_SELECTED,
+ /**
+ * Constant to use with the `selected` attribute to indicate some
+ * but not all of the children of this node are selected.
+ * This state should only be acquired by upward propagation from descendants.
+ * @property PARTIALLY_SELECTED
+ * @type integer
+ * @value 1
+ * @static
+ * @final
+ */
+ PARTIALLY_SELECTED:PARTIALLY_SELECTED,
+ /**
+ * Constant to use with the `selected` attribute to indicate the node is selected.
+ * @property FULLY_SELECTED
+ * @type integer
+ * @value 2
+ * @static
+ * @final
+ */
+ FULLY_SELECTED:FULLY_SELECTED,
+ ATTRS: {
+ /**
+ * Selected/highlighted state of the node.
+ * It can be
+ *
+ * - Y.FWTreeNode.NOT_SELECTED (0) not selected
+ * - Y.FWTreeNode.PARTIALLY_SELECTED (1) partially selected: some children are selected, some not or partially selected.
+ * - Y.FWTreeNode.FULLY_SELECTED (2) fully selected.
+ *
+ * The partially selected state can only be the result of selection propagating up from a child node.
+ * The attribute might return PARTIALLY_SELECTED but the developer should never set that value.
+ * @attribute selected
+ * @type Integer
+ * @value NOT_SELECTED
+ */
+ selected: {
+ value:NOT_SELECTED,
+ validator:function (value) {
+ return value === NOT_SELECTED || value === FULLY_SELECTED || value === PARTIALLY_SELECTED;
+ }
+ },
+ /**
+ * Whether selection of one node should propagate to its parent.
+ * @attribute propagateUp
+ * @type Boolean
+ * @value true
+ */
+ propagateUp: {
+ value: true,
+ validator: Lang.isBoolean
+ },
+ /**
+ * Whether selection of one node should propagate to its children.
+ * @attribute propagateDown
+ * @type Boolean
+ * @value true
+ */
+ propagateDown: {
+ value: true,
+ validator: Lang.isBoolean
+ }
+ }
+ }
+);
+
View
103 src/gallery-fwt-treeview/js/fw-treeview.js
@@ -0,0 +1,103 @@
+/** Creates a Treeview using the FlyweightTreeManager extension to handle its nodes.
+ * It creates the tree based on an object passed as the `tree` attribute in the constructor.
+ * @example
+ *
+ var tv = new Y.FWTreeView({tree: [
+ {
+ label:'label 0',
+ children: [
+ {
+ label: 'label 0-0',
+ children: [
+ {label: 'label 0-0-0'},
+ {label: 'label 0-0-1'}
+ ]
+ },
+ {label: 'label 0-1'}
+ ]
+ },
+ {label: 'label 1'}
+
+ ]});
+ tv.render('#container');
+
+ * @module gallery-fwt-treeview
+ */
+/**
+ * @class FWTreeView
+ * @extends Widget
+ * @uses FlyweightTreeManager
+ */
+/**
+ * @constructor
+ * @param config {Object} Configuration attributes, amongst them:
+ * @param config.tree {Array} Array of objects defining the first level of nodes.
+ * @param config.tree.label {String} Text of HTML markup to be shown in the node
+ * @param [config.tree.expanded=true] {Boolean} Whether the children of this node should be visible.
+ * @param [config.tree.children] {Array} Further definitions for the children of this node
+ * @param [config.tree.type=FWTreeNode] {FWTreeNode | String} Class used to create instances for this node.
+ * It can be a reference to an object or a name that can be resolved as `Y[name]`.
+ * @param [config.tree.id=Y.guid()] {String} Identifier to assign to the DOM element containing this node.
+ * @param [config.tree.template] {String} Template for this particular node.
+ */
+Y.FWTreeView = Y.Base.create(
+ 'fw-treeview',
+ Y.Widget,
+ [Y.FlyweightTreeManager],
+ {
+ /**
+ * Widget lifecycle method
+ * @method initializer
+ * @param config {object} configuration object of which
+ * `tree` contains the tree configuration.
+ */
+ initializer: function (config) {
+ this._domEvents = ['click'];
+ this._loadConfig(config.tree);
+ },
+ /**
+ * Widget lifecyle method
+ * I opted for not including this method in FlyweightTreeManager so that
+ * it can be used to extend Base, not just Widget
+ * @method renderUI
+ * @protected
+ */
+ renderUI: function () {
+ this.get(CBX).setContent(this._getHTML());
+ },
+ /**
+ * Overrides the default CONTENT_TEMPLATE to make it an unordered list instead of a div
+ * @property CONTENT_TEMPLATE
+ * @type String
+ */
+ CONTENT_TEMPLATE: '<ul></ul>'
+
+ },
+ {
+ ATTRS: {
+ /**
+ * Override for the `defaultType` value of FlyweightTreeManager
+ * so it creates FWTreeNode instances instead of the default.
+ * @attribute defaultType
+ * @type String
+ * @default 'FWTreeNode'
+ */
+ defaultType: {
+ value: 'FWTreeNode'
+ },
+ /**
+ * Enables toggling by clicking on the label item instead of just the toggle icon.
+ * @attribute toggleOnLabelClick
+ * @type Boolean
+ * @value false
+ */
+ toggleOnLabelClick: {
+ value:false,
+ validator:Lang.isBoolean
+ }
+
+
+ }
+
+ }
+);
View
19 src/gallery-fwt-treeview/js/fwtv-constants.js
@@ -0,0 +1,19 @@
+'use strict';
+/*jslint white: true */
+var Lang = Y.Lang,
+ // DOT = '.',
+ getCName = Y.ClassNameManager.getClassName,
+ cName = function (name) {
+ return getCName('fw-treeview', name);
+ },
+ CNAMES = {
+ toggle: cName('toggle'),
+ icon: cName('icon'),
+ selection: cName('selection'),
+ content: cName('content'),
+ sel_prefix: cName('selected-state')
+ },
+ CBX = 'contentBox',
+ NOT_SELECTED = 0,
+ PARTIALLY_SELECTED = 1,
+ FULLY_SELECTED = 2;
View
6 src/gallery-fwt-treeview/meta/meta.json
@@ -0,0 +1,6 @@
+{
+ "gallery-fwt-treeview": {
+ "requires":["gallery-flyweight-tree","widget","base-build"],
+ "skinnable": true
+ }
+}
View
7 src/gallery-fwt-treeview/nbproject/project.properties
@@ -0,0 +1,7 @@
+include.path=${php.global.include.path}
+php.version=PHP_5
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+web.root=.
View
9 src/gallery-fwt-treeview/nbproject/project.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.php.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/php-project/1">
+ <name>gallery-fwt-treeview</name>
+ </data>
+ </configuration>
+</project>
View
239 src/gallery-fwt-treeview/tests/sample.html
@@ -0,0 +1,239 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <script type="text/javascript" src="http://yui.yahooapis.com/3.7.1/build/yui/yui-min.js"></script>
+ </head>
+ <body class="yui3-skin-sam">
+ <a href="out/index.html">API docs</a>
+ <h1>A Tree:</h1>
+ <div id="container"></div>
+ <h1>A dynamic tree with multiple node types:</h1>
+ <p>The nodes of this tree are read from YQL, any replies rely on that service.
+ The long connecting lines might look funny sometimes because they are borrowed from YUI2 TreeView and
+ they assumed limits on the height of a line so for lengthy lines, the sprite overflows into the next element.
+ With a proper sprite, this would not happen.</p>
+ <div id="dynTree"></div>
+ <!-- h1>A form:</h1>
+ <div id="form"></div -->
+ <script>
+ YUI({
+ groups: {
+ gallery: {
+// base:'../../../build/',
+ base:'http://satyam.github.com/yui3-gallery/build/',
+ modules: {
+ 'gallery-flyweight-tree': {
+ path:'gallery-flyweight-tree/gallery-flyweight-tree.js',
+ requires:["base-base","base-build","classnamemanager"]
+ },
+ 'gallery-fwt-treeview': {
+ path: 'gallery-fwt-treeview/gallery-fwt-treeview.js',
+ requires: ["gallery-flyweight-tree","widget","base-build"],
+ skinnable: true
+ }
+ }
+ }
+ },
+ lang:'es'
+ }).use('gallery-fwt-treeview','yql', function (Y) {
+ 'use strict';
+ /*jslint white:true*/
+ var Lang = Y.Lang,
+ tv = new Y.FWTreeView({tree: [
+ {
+ label:'label 0',
+ children: [
+ {
+ label: 'label 0-0',
+ expanded: false,
+ children: [
+ {
+ label: 'label 0-0-0'
+ },
+ {
+ label: 'label 0-0-1',
+ children: [
+ {label: 'label 0-0-1'}
+ ]
+ }
+ ]
+ },
+ {
+ label: 'label 0-1'
+ }
+ ]
+ },
+ {
+ label: 'label 1'
+ }
+
+ ]});
+ tv.render('#container');
+ var ArtistNode = Y.Base.create(
+ 'artist-node',
+ Y.FWTreeNode,
+ [],
+ {
+
+ },{
+ TEMPLATE: '<li id="{id}" class="artistnode {cname_node}"><div class="yui3-fw-treeview-toggle"><\/div><div class="yui3-fw-treeview-content"><a href="{url}">{label}<\/a><\/div><ul class="{cname_children}">{children}<\/ul><\/li>',
+ ATTRS: {
+ url: {},
+ artistId: {}
+ }
+
+ }
+ );
+ var AlbumNode = Y.Base.create(
+ 'album-node',
+ Y.FWTreeNode,
+ [],
+ {
+
+ },{
+ TEMPLATE: '<li id="{id}" class="albumnode {cname_node}"><div class="yui3-fw-treeview-toggle"><\/div><div class="yui3-fw-treeview-content"><a href="{url}">{label}<\/a> ({publisher})<\/div><ul class="{cname_children}">{children}<\/ul><\/li>',
+ ATTRS: {
+ url: {},
+ albumId: {},
+ publisher: {}
+ }
+
+ }
+ );
+ var TrackNode = Y.Base.create(
+ 'track-node',
+ Y.FWTreeNode,
+ [],
+ {
+
+ },{
+ // {"Track":{"discNumber":"1","duration":"0","popularity":"3","title":"Karaoke: Crazy For You","trackNumber":"1"}}
+ TEMPLATE: '<li id="{id}" class="tracknode {cname_node}"><div class="yui3-fw-treeview-toggle"><\/div><div class="yui3-fw-treeview-content">[disc:{discNumber} - track:{trackNumber} - duration: {duration}]: {label}<\/div><ul class="{cname_children}">{children}<\/ul><\/li>',
+ ATTRS: {
+ discNumber: {},
+ trackNumber: {},
+ duration: {}
+ }
+
+ }
+ );
+
+ Y.YQL('select id, name, url from music.artist.search where keyword="Madonna" | sort(field="trackCount", descending="true")', function(response) {
+ if (!response.query.count) {
+ Y.one('#dynTree').setContent('YQL query for Madonna returned no records or failed');
+ return;
+ }
+ var cfg = [],
+ results = response.query.results.Artist || [];
+
+ if (!Lang.isArray(results)) {
+ results = [results];
+ }
+ Y.Array.each(results, function (entry) {
+ cfg.push( {
+ label: entry.name,
+ artistId: entry.id,
+ url: entry.url,
+ type:ArtistNode
+
+ });
+ });
+ (new Y.FWTreeView({
+ dynamicLoader: function (node, callback) {
+ if (node instanceof ArtistNode) {
+ Y.YQL(Lang.sub('select id, title, releaseYear, label, url from music.release.artist where id="{artistId}" | sort(field="releaseYear", descending="true")', node.getAttrs()), function (response) {
+ if (!response.query.count) {
+ alert(Lang.sub('YQL query for albums by {label} failed or returned no results', node.getAttrs()));
+ callback();
+ return;
+ }
+ var cfg = [],
+ results = response.query.results.Release || [];
+
+ if (!Lang.isArray(results)) {
+ results = [results];
+ };
+ Y.Array.each(results, function (entry) {
+ cfg.push( {
+ label: entry.title || ' ',
+ publisher: entry.label || 'unknown publisher',
+ albumId: entry.id,
+ url: entry.url || '#',
+ type:AlbumNode
+
+ });
+ });
+ callback(cfg);
+ return;
+ });
+
+ }
+ if (node instanceof AlbumNode) {
+ Y.YQL(Lang.sub('select Track.discNumber, Track.trackNumber, Track.duration, Track.title, Track.popularity from music.release.id where ids="{albumId}" and response="tracks"', node.getAttrs()), function (response) {
+
+ if (!response.query.count) {
+ alert(Lang.sub('YQL query for album "{label}" failed or returned no results', node.getAttrs()));
+ callback();
+ return;
+ }
+ var cfg = [],
+ results = response.query.results.Release || [];
+
+ if (!Lang.isArray(results)) {
+ results = [results];
+ };
+ Y.Array.each(results, function (entry) {
+ entry = entry.Track;
+ // {"Track":{"discNumber":"1","duration":"0","popularity":"3","title":"Karaoke: Crazy For You","trackNumber":"1"}}
+ cfg.push( {
+ label: entry.title || '- no title -',
+ discNumber: entry.discNumber || 1,
+ trackNumber: entry.trackNumber || '-',
+ duration: entry.duration || '--:--',
+ type:TrackNode,
+ isLeaf:true
+
+ });
+ });
+ callback(cfg);
+ return;
+ });
+
+ }
+ },
+ tree: cfg
+ })).render('#dynTree');
+ });
+
+// var f = new Y.Form({fields: [
+// {
+// label: 'First Field',
+// name: 'firstField',
+// value: 1
+// },
+// {
+// label: 'Second Field',
+// name: 'secondField',
+// value: 2
+//
+// },
+// {
+// type:'FieldSet',
+// label:'Set of Fields',
+// children: [
+// {
+// label: 'First Child Field'
+// },
+// {
+// label: 'Second Child field'
+// }
+// ]
+// }
+// ]});
+// f.render('#form');
+ });
+ </script>
+ </body>
+</html>

0 comments on commit 4cf228f

Please sign in to comment.