/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.collections.Store"); dojo.require("dojo.lang.common"); /* Store * Designed to be a simple store of data with access methods... * specifically to be mixed into other objects (such as widgets). */ dojo.collections.Store = function(/* array? */jsonArray){ // summary // Data Store with accessor methods. var data = []; this.keyField = "Id"; this.get = function(){ // summary // Get the internal data array, should not be used. return data; // array }; this.getByKey = function(/* string */key){ // summary // Find the internal data object by key. for(var i=0; i1) { field = parts.pop(); do{ if(parts[i].indexOf("()")>-1){ var temp=parts[i++].split("()")[0]; if(!o[temp]){ dojo.raise("dojo.collections.Store.getField(obj, '" + field + "'): '" + temp + "' is not a property of the passed object."); } else { // this *will* throw an error if the method in question can't be invoked without arguments. o = o[temp](); } } else { o = o[parts[i++]]; } } while (i-1){ data.splice(idx,1); } }; this.removeDataByKey = function(/*string*/key){ // summary // remove the object at key from the internal data array. this.removeData(this.getDataByKey(key)); }; this.removeDataByIndex = function(/*number*/idx){ // summary // remove the object at idx from the internal data array. this.removeData(this.getDataByIndex(idx)); }; if(jsonArray && jsonArray.length && jsonArray[0]){ this.setData(jsonArray); } }; dojo.extend(dojo.collections.Store, { getField:function(/*object*/obj, /*string*/field){ // helper to get the nested value if needed. var parts=field.split("."), i=0, o=obj; do{ if(parts[i].indexOf("()")>-1){ var temp=parts[i++].split("()")[0]; if(!o[temp]){ dojo.raise("dojo.collections.Store.getField(obj, '" + field + "'): '" + temp + "' is not a property of the passed object."); } else { // this *will* throw an error if the method in question can't be invoked without arguments. o = o[temp](); } } else { o = o[parts[i++]]; } } while (i -1){ p = p.split("."); while(p.length>1){ var pr = p.shift(); o[pr] = {}; o = o[pr]; } p = p[0]; } var type = meta[i].getType(); if(type == String){ o[p] = data; } else { if(data){ o[p] = new type(data); } else { o[p] = new type(); } } } return obj; }; // we have initialization data, let's parse it. var arr=[]; for(var i=0; i