ManifestReader

by Shaun Ellis

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<body>
Hi
</body>

JavaScript

var Collection = Backbone.Model.extend({
    initialize : function(){
        console.log('Collection has been initialized.');
        setID(this);
        logObj(this);
        this.on('change', function(){
            logChange(this);
        });
        
    },
    defaults: {
        id: null,
        within: [],
        label: 'Untitled',
        type: 'collection',
        description: '',
        attribution: 'Unattributed',
        collections: [],
        manifests: []
      }
    
});

var CanvasCollection = Backbone.Collection.extend({
  model: Canvas
});

var Manifest = Backbone.Model.extend({
    initialize : function(){
        console.log('Manifest has been initialized.');
        setID(this);
        logObj(this);
        this.on('change', function(){
            logChange(this);
        });
      },
    defaults: {
        label: 'Untitled',
        type: 'manifest',
        within: [],
        viewingDirection: 'left-to-right',
        viewingHint: 'paged',
        sequences: [] // first sequence is the default
      }
});

var Sequence = Backbone.Model.extend({
    initialize : function(){
        console.log('Sequence has been initialized.');
        setID(this);
        logObj(this);
        this.on('change', function(){
            logChange(this);
        });
        this.on("invalid", function(model, error){
            console.log(error);
        });
      },
    defaults: {
        label: 'Untitled',
        type: 'sequence',
        startCanvas: null,
        canvases: []    
      },
    validate: function(attributes){
        if(attributes.canvases){ 
            if(attributes.canvases.length < 1){ 
                return "Your sequence must have at least one canvas in it.";
            }
        }else{
            return "Your sequence must have at least one canvas in it.";
        }
    },
    addCanvas: function(canvas){
        var c = this.get("canvases").clone(); // we need to clone to trigger change event
       ...