/**
 * MindCMS 3
 *
 * @class   msObjectCollection
 * JS msObjectCollection object definition
 *
 * @package CMS3
 * @author Francisc Ungureanu <francisc.ungureanu@mindbench.nl>
 * @copyright Mindbench Active Media B.V.
 * @version $Id: msObjectCollection.js 8776 2009-03-17 14:06:40Z rma $
 *
 * Details:
 * This holds the instance of all objects created (buttons, toolbars, plugins, modules, ribbon, etc.
 *   
 */
msObjectCollection = Class.create({
   component_count : 0,
   
   items: [],
   items_map: {},
   
   initialize: function () {
   },
   
   //custom search by any property field of the object (xtype, id, name, title, etc)
   findBy: function (property_name, property_value) {
     var result = [];
     for(var i=0; i<this.items.length; i++) {
       if(this.items[i][property_name] && this.items[i][property_name] == property_value) result.push(this.items[i]);
     }
     
     return result.length ? result : false;
   },
   
   add: function (item) {
     if(!item.id) item.id = 'msr-component-' + (++this.component_count);
     
     this.items_map[item.id] = item;
     this.items.push(item);
   },
   
   findById: function (id) {
     return this.findBy('id', id);
   },

   getById: function (id) {
     return this.items_map[id] ? this.items_map[id] : false;
   },
   
   getAll: function() {
     return this.items;
   }
   
});

var msCMSObjects = new msObjectCollection();
