Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.lmc.models
  2. {
  3.    
  4.    
  5.     import com.lmc.Events.ForemanEvent;
  6.     import com.lmc.utils.ApplicationStore;
  7.     import com.lmc.utils.foremanObject;
  8.    
  9.     import flash.events.EventDispatcher;
  10.     import flash.utils.Dictionary;
  11.    
  12.     import mx.collections.ArrayCollection;
  13.  
  14.     public class baseCollection extends ArrayCollection
  15.     {
  16.         public var name:String;
  17.         public var id:int;
  18.         private var foreman:foremanObject;
  19.         private var model:dataModel;
  20.         public var _type:String;
  21.         public var namehash:Dictionary = new Dictionary();
  22.         public function baseCollection(jsonObject:Object, type:String)
  23.         {
  24.            
  25.             super();
  26.             _type = type;
  27.             model = ApplicationStore.services["model"];
  28.             if (! model){
  29.                 model = new dataModel();
  30.                 model.modelsetup();
  31.                 ApplicationStore.services["model"] = model;
  32.                
  33.             }
  34.             foreman = model.getforemanInstance();
  35.             if (jsonObject){
  36.                 copy(jsonObject);
  37.             }
  38.         }
  39.        
  40.        
  41.         public function copy(jsonObject:Object):void{
  42.            
  43.             for each (var obj:Object in jsonObject){
  44.                 for each (var entity:Object in obj){
  45.                     // this extra loop strips off the type so object.typeobject
  46.                     this.addItem(entity);
  47.                     namehash[entity.id] = entity.name;
  48.                 }
  49.                
  50.             }
  51.             this.refresh();
  52.         }
  53.         public function refreshdata():Boolean{
  54.             this.removeAll();
  55.             this.getdata();
  56.             return super.refresh();
  57.            
  58.         }
  59.         public function getdata(fqdn:String="", option:String=""):void{
  60.            
  61.             foreman.fqdn = fqdn;
  62.             foreman.option = option;
  63.             foreman.settype(_type);
  64.             foreman.addEventListener(_type+"Refresh", onServiceHandler);
  65.             foreman.refresh();
  66.         }
  67.         private function onServiceHandler(event:ForemanEvent):void{
  68.             copy(event.eventdata);
  69.         }
  70.        
  71.         public function findbyname(name:String):*{
  72.             for each (var obj:HostGroup in this){
  73.                 if (obj.name == name){
  74.                     return obj;
  75.                 }
  76.             }
  77.             return "";
  78.         }
  79.         public function getSearchResults(name:String, query:String,searchtype:String="ForemanSearchResult"):void{
  80.             // will need to refresh the data
  81.             foreman.addEventListener(searchtype, searchHandler);
  82.             foreman.search(this._type, query + name);
  83.         }
  84.         public function searchHandler(event:ForemanEvent):void{
  85.            
  86.         }
  87.     }
  88.    
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement