Record.js

Ext.data.Record = function(data, id){
    this.id = (id || id === 0) ? id : ++Ext.data.Record.AUTO_ID;
    this.data = data;
};

Ext.data.Record.create = function(o){
    var f = function(){
        f.superclass.constructor.apply(this, arguments);
    };
    Ext.extend(f, Ext.data.Record);
    var p = f.prototype;
    p.fields = new Ext.util.MixedCollection(false, function(field){
        return field.name;
    });
    for(var i = 0, len = o.length; i < len; i++){
        p.fields.add(new Ext.data.Field(o[i]));
    }
    f.getField = function(name){
        return p.fields.get(name);  
    };
    return f;
};

Ext.data.Record.AUTO_ID = 1000;

Ext.data.Record.prototype = {
    dirty : false,
    editing : false,
    error: null,
    modified: null,
    
    join : function(store){
        this.store = store;
    },
    
    set : function(name, value){
        if(this.data[name] == value){
            return;
        }
        this.dirty = true;
        if(!this.modified){
            this.modified = {};
        }
        this.modified[name] = this.data[name];
        this.data[name] = value;
        if(!this.editing){
            this.store.afterEdit(this);
        }       
    },
    
    get : function(name){
        return this.data[name]; 
    },
    
    beginEdit : function(){
        this.editing = true;
        this.modified = {}; 
    },
    
    cancelEdit : function(){
        this.editing = false;
        delete this.modified;
    },
    
    endEdit : function(){
        this.editing = false;
        if(this.dirty){
            this.store.afterEdit(this);
        }
    },
    
    reject : function(){
        this.dirty = false;
        delete this.modified;
    },
    
    commit : function(){
        var m = this.modified;
        for(var n in m){
            if(typeof m[n] != 'function'){
                this.values[n] = m[n];
            }
        }
        this.dirty = false;
        delete this.modified;
    },
    
    hasError : function(){
        return this.error != null;
    },
    
    clearError : function(){
        this.error = null;
    }
};

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.