summaryrefslogtreecommitdiff
path: root/includes/js/dojox/dtl/contrib/data.js
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/dtl/contrib/data.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/dtl/contrib/data.js')
-rw-r--r--includes/js/dojox/dtl/contrib/data.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/includes/js/dojox/dtl/contrib/data.js b/includes/js/dojox/dtl/contrib/data.js
new file mode 100644
index 0000000..5ca3aa7
--- /dev/null
+++ b/includes/js/dojox/dtl/contrib/data.js
@@ -0,0 +1,89 @@
+if(!dojo._hasResource["dojox.dtl.contrib.data"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.dtl.contrib.data"] = true;
+dojo.provide("dojox.dtl.contrib.data");
+dojo.require("dojox.dtl._base");
+
+(function(){
+ var dd = dojox.dtl;
+ var ddcd = dd.contrib.data;
+
+ ddcd._BoundItem = dojo.extend(function(item, store){
+ this.item = item;
+ this.store = store;
+ },
+ {
+ get: function(key){
+ var store = this.store;
+ var item = this.item;
+
+ if(key == "getLabel"){
+ return store.getLabel(item);
+ }else if(key == "getAttributes"){
+ return store.getAttributes(item);
+ }else if(key == "getIdentity"){
+ if(store.getIdentity){
+ return store.getIdentity(item);
+ }
+ return "Store has no identity API";
+ }else{
+ if(store.hasAttribute(item, key)){
+ var value = store.getValue(item, key);
+ return (dojo.isObject(value) && store.isItem(value)) ? new ddcd._BoundItem(value, store) : value;
+ }else if(key.slice(-1) == "s" && store.hasAttribute(item, key.slice(0, -1))){
+ return dojo.map(store.getValues(item, key.slice(0, -1)), function(value){
+ return (dojo.isObject(value) && store.isItem(value)) ? new ddcd._BoundItem(value, store) : value;
+ });
+ }
+ }
+ }
+ });
+
+ ddcd.BindDataNode = dojo.extend(function(items, store, alias){
+ this.items = new dd._Filter(items);
+ this.store = new dd._Filter(store);
+ this.alias = alias;
+ },
+ {
+ render: function(context, buffer){
+ var items = this.items.resolve(context);
+ var store = this.store.resolve(context);
+ if(!store){
+ throw new Error("data_bind didn't receive a store");
+ }
+
+ var list = [];
+ if(items){
+ for(var i = 0, item; item = items[i]; i++){
+ list.push(new ddcd._BoundItem(item, store));
+ }
+ }
+
+ context[this.alias] = list;
+ return buffer;
+ },
+ unrender: function(context, buffer){
+ return buffer;
+ },
+ clone: function(){
+ return this;
+ }
+ });
+
+ dojo.mixin(ddcd, {
+ bind_data: function(parser, text){
+ var parts = dd.text.pySplit(text);
+
+ if(parts[2] != 'to' || parts[4] != 'as' || !parts[5]){
+ throw new Error("data_bind expects the format: 'data_bind items to store as varName'");
+ }
+
+ return new ddcd.BindDataNode(parts[1], parts[3], parts[5]);
+ }
+ });
+
+ dd.register.tags("dojox.dtl.contrib", {
+ "data": ["bind_data"]
+ });
+})();
+
+}