Skip to content

Commit

Permalink
gallery-2010.12.01-21-32 goonieiam gallery-yui3treeview-datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed Dec 1, 2010
1 parent 18086d6 commit 2b619ba
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/gallery-yui3treeview-datasource/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Treeview datasource plugin 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-yui3treeview-datasource

# 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=my.custom.module.js, my.custom.moduleHelperClass.js,my.custom.moduleSubComponentClass.js
component.jsfiles = treeview-datasource-plugin.js

# The list of modules this component requires. Used to set up the Y.add module call for YUI 3.
component.requires= gallery-yui3treeview,plugin,datasource, datasource-jsonschema

# The list of modules this component supersedes. Used to set up the Y.add module call for YUI 3.
# component.supersedes= gallery-yui3treeview,plugin,datasource,datasource-jsonschema

# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3.
component.optional=


7 changes: 7 additions & 0 deletions src/gallery-yui3treeview-datasource/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- YUI 3 Gallery Component Build File -->
<project name="YU3-Treeview-Datasource-plugin" default="local">
<description>YU3-Treeview-Datasource-plugin Build File</description>
<property file="build.properties" />
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
</project>
142 changes: 142 additions & 0 deletions src/gallery-yui3treeview-datasource/js/treeview-datasource-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@

/**
* Treeview data plugin, it allows for dynamic data retreiving and loading
* @class TreeviewDatasource
* @constructor
* @uses Y.DataSource
* @extends Y.Plugin.base
*/

var TreeviewDatasource = function () {
TreeviewDatasource.superclass.constructor.apply(this, arguments);
};

TreeviewDatasource.NAME = 'TreeviewDatasource';
TreeviewDatasource.NS = 'ds';

TreeviewDatasource.ATTRS = {
/**
* The source URL
* @attribute source
* @type String
*/
source : {
value : null
},

/**
* The load Message to display while waiting for the new data
* @attribute loadingMsg
* @type String || Y.Node
*/
loadingMsg: {
value : null
},

/**
* The JSON DataSchema
* @attribute dataSchemaJSON
* @type {Object}
* @properties : resultListLocator, resultFields, metaFields.
*/
dataSchemaJSON : {
value : {
resultListLocator : null,
resultFields : null,
metaFields : null
}
},

/**
* The method to use to retrieve the data: IO,GET,Local
* @attribute sourceMethod
* @type String
*/
sourceMethod : {
value : null
}
};

Y.extend(TreeviewDatasource, Y.Plugin.Base, {
initializer : function () {
var sourceMethod = this.get("sourceMethod"),
dataSchemaJSON = this.get("dataSchemaJSON");

this.publish('sendRequest', {
defaultFn: this._makeRequest
});

this.publish('onDataReturnSuccess', {
defaultFn: this._defSuccessHandler
});

this.publish('onDataReturnFailure', {
defaultFn: this._defFailureHandler
});

switch (sourceMethod) {
case "io":
this.treedatasource = new Y.DataSource.IO({source: this.get("source")});
break;
case "get":
this.treedatasource = new Y.DataSource.Get({source: this.get("source")});
break;
case "local":
this.treedatasource = new Y.DataSource.Local({source: this.get("source")});
break;
}

this.treedatasource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: dataSchemaJSON.resultListLocator,
resultFields : dataSchemaJSON.resultFields
}
});

this.set("treeDataSource",this.treedatasource);
},

_tree : null,


_defSuccessHandler : function(e) {
var tree = this._tree;

Y.fire("onDataReturnSuccess",{data:e});
if (this.get("loadingMsg")) {
tree.get("contentBox").set("innerHTML","");
}
tree.add(e.response.results);
this.get("host").get("contentBox").focusManager.refresh();
},

_defFailureHandler : function(e) {
Y.fire("onDataSourceFailure",{data:e});
},

_makeRequest : function (e) {
var callback = {
success : Y.bind(this._defSuccessHandler, this),
failure :Y.bind(this._defFailureHandler, this)
},
loadingMsg = this.get("loadingMsg"),
request = e.request,
loadOnDemand,
tree = e.node;

loadOnDemand = tree.get("loadOnDemand");

if (loadOnDemand !== false) {
tree.set("loadOnDemand",false);
this._tree = tree;
if (loadingMsg) {
tree.get("contentBox").set("innerHTML",loadingMsg);
}
this.treedatasource.sendRequest({request:"?"+request,callback:callback});
}
}
});

Y.namespace('Plugin');
Y.Plugin.TreeviewDatasource = TreeviewDatasource;

0 comments on commit 2b619ba

Please sign in to comment.