home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 136 / MOBICLIC136.ISO / pc / DATA / HOTE / libs / amfphp / amfphp.swf / scripts / __Packages / mx / remoting / RecordSet.as < prev    next >
Text File  |  2011-07-20  |  17KB  |  596 lines

  1. class mx.remoting.RecordSet extends Object
  2. {
  3.    static var version = "1.2.0.124";
  4.    static var init = mx.remoting.RecordSet.registerRecordSet();
  5.    function RecordSet(columnNames)
  6.    {
  7.       var _loc1_ = this;
  8.       super();
  9.       mx.events.EventDispatcher.initialize(_loc1_);
  10.       _loc1_._items = new Array();
  11.       _loc1_.uniqueID = 0;
  12.       if(_loc1_.mTitles == null)
  13.       {
  14.          if(_loc1_.serverInfo == null)
  15.          {
  16.             if(_loc1_.serverinfo != null)
  17.             {
  18.                _loc1_.serverInfo = _loc1_.serverinfo;
  19.             }
  20.          }
  21.          if(_loc1_.serverInfo == null)
  22.          {
  23.             _loc1_.mTitles = columnNames;
  24.          }
  25.          else if(_loc1_.serverInfo.version != 1)
  26.          {
  27.             mx.remoting.NetServices.trace("RecordSet","warning",100,"Received incompatible RecordSet version from server");
  28.          }
  29.          else
  30.          {
  31.             _loc1_.mTitles = _loc1_.serverInfo.columnNames;
  32.             _loc1_.mRecordsAvailable = 0;
  33.             _loc1_.setData(_loc1_.serverInfo.cursor != null ? _loc1_.serverInfo.cursor - 1 : 0,_loc1_.serverInfo.initialData);
  34.             if(_loc1_.serverInfo.initialData.length != _loc1_.serverInfo.totalCount)
  35.             {
  36.                _loc1_.mRecordSetID = _loc1_.serverInfo.id;
  37.                if(_loc1_.mRecordSetID != null)
  38.                {
  39.                   _loc1_.serviceName = _loc1_.serverInfo.serviceName != null ? _loc1_.serverInfo.serviceName : "RecordSet";
  40.                   _loc1_.mTotalCount = _loc1_.serverInfo.totalCount;
  41.                   _loc1_.mDeliveryMode = "ondemand";
  42.                   _loc1_.mAllNotified = false;
  43.                   _loc1_.mOutstandingRecordCount = 0;
  44.                }
  45.                else
  46.                {
  47.                   mx.remoting.NetServices.trace("RecordSet","warning",102,"Missing some records, but there\'s no RecordSet id");
  48.                }
  49.             }
  50.             _loc1_.serverInfo = null;
  51.          }
  52.       }
  53.    }
  54.    function addItem(item)
  55.    {
  56.       this.addItemAt(this.__get__length(),item);
  57.    }
  58.    function addItemAt(index, item)
  59.    {
  60.       var _loc1_ = index;
  61.       var _loc2_ = this;
  62.       var _loc3_ = true;
  63.       if(_loc1_ < _loc2_.__get__length() && _loc1_ >= 0)
  64.       {
  65.          _loc2_.items.splice(_loc1_,0,item);
  66.          addr55:
  67.          if(_loc3_)
  68.          {
  69.             item.__ID__ = _loc2_.uniqueID++;
  70.          }
  71.          _loc2_.updateViews("addItems",_loc1_,_loc1_);
  72.       }
  73.       else if(_loc1_ == _loc2_.__get__length())
  74.       {
  75.          _loc2_.items[_loc1_] = item;
  76.          ┬º┬ºgoto(addr55);
  77.       }
  78.       else
  79.       {
  80.          _loc3_ = false;
  81.          mx.remoting.NetServices.trace("Cannot add an item outside the bounds of the RecordSet");
  82.       }
  83.    }
  84.    function addEventListener(event, listener)
  85.    {
  86.    }
  87.    function clear()
  88.    {
  89.       var _loc1_ = this;
  90.       if(!_loc1_.checkLocal())
  91.       {
  92.          var _loc2_ = _loc1_.items.length;
  93.          _loc1_.items.splice(0);
  94.          _loc1_.uniqueID = 0;
  95.          _loc1_.updateViews("removeItems",0,_loc2_);
  96.       }
  97.    }
  98.    function contains(itmToCheck)
  99.    {
  100.       var _loc2_ = itmToCheck;
  101.       if(this.isObjectEmpty(_loc2_))
  102.       {
  103.          return false;
  104.       }
  105.       var itemAtIndex;
  106.       var _loc3_ = undefined;
  107.       var _loc1_ = 0;
  108.       while(true)
  109.       {
  110.          if(_loc1_ >= this.items.length)
  111.          {
  112.             return false;
  113.          }
  114.          itemAtIndex = this.items[_loc1_];
  115.          _loc3_ = true;
  116.          for(var t in _loc2_)
  117.          {
  118.             if(_loc2_[t] != itemAtIndex[t])
  119.             {
  120.                _loc3_ = false;
  121.                break;
  122.             }
  123.          }
  124.          if(_loc3_)
  125.          {
  126.             break;
  127.          }
  128.          _loc1_ = _loc1_ + 1;
  129.       }
  130.       return true;
  131.    }
  132.    function getColumnNames()
  133.    {
  134.       return this.mTitles;
  135.    }
  136.    function get columnNames()
  137.    {
  138.       return this.getColumnNames();
  139.    }
  140.    function getLocalLength()
  141.    {
  142.       return this.items.length;
  143.    }
  144.    function getLength()
  145.    {
  146.       var _loc1_ = this;
  147.       if(_loc1_.mRecordSetID != null)
  148.       {
  149.          return _loc1_.mTotalCount;
  150.       }
  151.       return _loc1_.items.length;
  152.    }
  153.    function getIterator()
  154.    {
  155.       var _loc1_ = new mx.remoting.RecordSetIterator(this);
  156.       return _loc1_;
  157.    }
  158.    function get length()
  159.    {
  160.       return this.getLength();
  161.    }
  162.    function getItemAt(index)
  163.    {
  164.       var _loc1_ = index;
  165.       var _loc2_ = this;
  166.       if(_loc1_ < 0 || _loc1_ >= _loc2_.__get__length())
  167.       {
  168.          return null;
  169.       }
  170.       if(_loc2_.mRecordSetID == null)
  171.       {
  172.          return _loc2_.items[_loc1_];
  173.       }
  174.       _loc2_.requestRecord(_loc1_);
  175.       var _loc3_ = _loc2_.items[_loc1_];
  176.       if(_loc3_ == 1)
  177.       {
  178.          return "in progress";
  179.       }
  180.       return _loc3_;
  181.    }
  182.    function getItemID(index)
  183.    {
  184.       return this.items[index].__ID__;
  185.    }
  186.    function get items()
  187.    {
  188.       return this._items;
  189.    }
  190.    function initialize(info)
  191.    {
  192.    }
  193.    function filter(filterFunction, context)
  194.    {
  195.       if(this.checkLocal())
  196.       {
  197.       }
  198.       var _loc3_ = new mx.remoting.RecordSet(this.mTitles);
  199.       var rcount = this.__get__length();
  200.       var _loc2_ = 0;
  201.       while(_loc2_ < rcount)
  202.       {
  203.          var _loc1_ = this.getItemAt(_loc2_);
  204.          if(_loc1_ != null && _loc1_ != 1 && filterFunction(_loc1_,context))
  205.          {
  206.             _loc3_.addItem(_loc1_);
  207.          }
  208.          _loc2_ = _loc2_ + 1;
  209.       }
  210.       return _loc3_;
  211.    }
  212.    function sortItems(compareFunc, optionFlags)
  213.    {
  214.       var _loc1_ = this;
  215.       if(!_loc1_.checkLocal())
  216.       {
  217.          _loc1_.items.sort(compareFunc,optionFlags);
  218.          _loc1_.updateViews("sort");
  219.       }
  220.    }
  221.    function sortItemsBy(fieldNames, order, optionFlags)
  222.    {
  223.       var _loc1_ = this;
  224.       if(!_loc1_.checkLocal())
  225.       {
  226.          if(typeof order == "string")
  227.          {
  228.             _loc1_.items.sortOn(fieldNames);
  229.             if(order.toUpperCase() == "DESC")
  230.             {
  231.                _loc1_.items.reverse();
  232.             }
  233.          }
  234.          else
  235.          {
  236.             _loc1_.items.sortOn(fieldNames,optionFlags);
  237.          }
  238.          _loc1_.updateViews("sort");
  239.       }
  240.    }
  241.    function sort(compareFunc)
  242.    {
  243.       var _loc1_ = this;
  244.       if(!_loc1_.checkLocal())
  245.       {
  246.          _loc1_.items.sort(compareFunc);
  247.          _loc1_.updateViews("sort");
  248.       }
  249.    }
  250.    function isEmpty()
  251.    {
  252.       return this.items.length == 0;
  253.    }
  254.    function isLocal()
  255.    {
  256.       return this.mRecordSetID == null;
  257.    }
  258.    function isFullyPopulated()
  259.    {
  260.       return this.isLocal();
  261.    }
  262.    function getRemoteLength()
  263.    {
  264.       var _loc1_ = this;
  265.       if(_loc1_.isLocal())
  266.       {
  267.          return _loc1_.mRecordsAvailable;
  268.       }
  269.       return _loc1_.mTotalCount;
  270.    }
  271.    function getNumberAvailable()
  272.    {
  273.       var _loc1_ = this;
  274.       if(_loc1_.isLocal())
  275.       {
  276.          return _loc1_.getLength();
  277.       }
  278.       return _loc1_.mRecordsAvailable;
  279.    }
  280.    function replaceItemAt(index, item)
  281.    {
  282.       var _loc1_ = index;
  283.       var _loc2_ = this;
  284.       if(_loc1_ >= 0 && _loc1_ <= _loc2_.__get__length())
  285.       {
  286.          var _loc3_ = _loc2_.getItemID(_loc1_);
  287.          _loc2_.items[_loc1_] = item;
  288.          _loc2_.items[_loc1_].__ID__ = _loc3_;
  289.          _loc2_.updateViews("updateItems",_loc1_,_loc1_);
  290.       }
  291.    }
  292.    function removeAll()
  293.    {
  294.       this.clear();
  295.    }
  296.    function removeItemAt(index)
  297.    {
  298.       var _loc1_ = index;
  299.       var _loc2_ = this;
  300.       var _loc3_ = _loc2_._items[_loc1_];
  301.       _loc2_._items.splice(_loc1_,1);
  302.       var rItems = [_loc2_._items[_loc1_]];
  303.       var rIDs = [_loc2_.getItemID(_loc1_)];
  304.       _loc2_.dispatchEvent({type:"modelChanged",eventName:"removeItems",firstItem:_loc1_,lastItem:_loc1_,removedItems:rItems,removedIDs:rIDs});
  305.       return _loc3_;
  306.    }
  307.    function removeEventListener(event, listener)
  308.    {
  309.    }
  310.    function requestRange(range)
  311.    {
  312.       var _loc1_ = range.getStart();
  313.       var _loc2_ = range.getEnd();
  314.       return this.internalRequestRange(_loc1_,_loc2_);
  315.    }
  316.    function setDeliveryMode(mode, pagesize, numPrefetchPages)
  317.    {
  318.       var _loc1_ = this;
  319.       var _loc2_ = pagesize;
  320.       var _loc3_ = numPrefetchPages;
  321.       _loc1_.mDeliveryMode = mode.toLowerCase();
  322.       _loc1_.stopFetchAll();
  323.       if(_loc2_ == null || _loc2_ <= 0)
  324.       {
  325.          _loc2_ = 25;
  326.       }
  327.       switch(_loc1_.mDeliveryMode)
  328.       {
  329.          case "ondemand":
  330.             break;
  331.          case "page":
  332.             if(_loc3_ == null)
  333.             {
  334.                _loc3_ = 0;
  335.             }
  336.             _loc1_.mPageSize = _loc2_;
  337.             _loc1_.mNumPrefetchPages = _loc3_;
  338.             break;
  339.          case "fetchall":
  340.             _loc1_.stopFetchAll();
  341.             _loc1_.startFetchAll(_loc2_);
  342.             break;
  343.          default:
  344.             mx.remoting.NetServices.trace("RecordSet","warning",107,"SetDeliveryMode: unknown mode string");
  345.       }
  346.    }
  347.    function editField(index, fieldName, value)
  348.    {
  349.       this.changeFieldValue(index,fieldName,value);
  350.    }
  351.    function getEditingData(index, fieldName)
  352.    {
  353.       return this.items[index][fieldName];
  354.    }
  355.    function setField(index, fieldName, value)
  356.    {
  357.       this.changeFieldValue(index,fieldName,value);
  358.    }
  359.    function changeFieldValue(index, fieldName, value)
  360.    {
  361.       var _loc1_ = index;
  362.       var _loc2_ = this;
  363.       if(!_loc2_.checkLocal())
  364.       {
  365.          if(!(_loc1_ < 0 || _loc1_ >= _loc2_.getLength()))
  366.          {
  367.             _loc2_.items[_loc1_][fieldName] = value;
  368.             _loc2_.updateViews("updateItems",_loc1_,_loc1_);
  369.          }
  370.       }
  371.    }
  372.    function isObjectEmpty(objToCheck)
  373.    {
  374.       var _loc2_ = objToCheck;
  375.       var _loc1_ = true;
  376.       for(var _loc3_ in _loc2_)
  377.       {
  378.          _loc1_ = false;
  379.          return _loc1_;
  380.          break;
  381.       }
  382.       return _loc1_;
  383.    }
  384.    function arrayToObject(anArray)
  385.    {
  386.       if(this.mTitles == null)
  387.       {
  388.          mx.remoting.NetServices.trace("RecordSet","warning",105,"getItem: titles are not available");
  389.          return null;
  390.       }
  391.       var _loc3_ = new Object();
  392.       var alen = anArray.length;
  393.       var _loc2_ = undefined;
  394.       var _loc1_ = 0;
  395.       while(_loc1_ < alen)
  396.       {
  397.          _loc2_ = this.mTitles[_loc1_];
  398.          if(_loc2_ == null)
  399.          {
  400.             _loc2_ = "column" + _loc1_ + 1;
  401.          }
  402.          _loc3_[_loc2_] = anArray[_loc1_];
  403.          _loc1_ = _loc1_ + 1;
  404.       }
  405.       return _loc3_;
  406.    }
  407.    function checkLocal()
  408.    {
  409.       if(this.isLocal())
  410.       {
  411.          return false;
  412.       }
  413.       mx.remoting.NetServices.trace("RecordSet","warning",108,"Operation not allowed on partial recordset");
  414.       return true;
  415.    }
  416.    function getRecordSetService()
  417.    {
  418.       var _loc1_ = this;
  419.       if(_loc1_.mRecordSetService == null)
  420.       {
  421.          if(_loc1_.gateway_conn == null)
  422.          {
  423.             _loc1_.gateway_conn = mx.remoting.NetServices.createGatewayConnection();
  424.          }
  425.          else if(_global.netDebugInstance != undefined)
  426.          {
  427.             _loc1_.gateway_conn = _loc1_.gateway_conn.clone();
  428.          }
  429.          if(_global.netDebugInstance != undefined)
  430.          {
  431.             _loc1_.gateway_conn.setupRecordSet();
  432.             _loc1_.gateway_conn.setDebugId("RecordSet " + _loc1_.mRecordSetID);
  433.          }
  434.          _loc1_.mRecordSetService = _loc1_.gateway_conn.getService(_loc1_.serviceName,_loc1_);
  435.          if(_loc1_.mRecordSetService == null)
  436.          {
  437.             mx.remoting.NetServices.trace("RecordSet","warning",101,"Failed to create RecordSet service");
  438.             _loc1_.mRecordSetService = null;
  439.          }
  440.       }
  441.       return _loc1_.mRecordSetService;
  442.    }
  443.    function internalRequestRange(index, lastIndex)
  444.    {
  445.       var _loc1_ = index;
  446.       var _loc2_ = this;
  447.       var highestRequested = -1;
  448.       if(_loc1_ < 0)
  449.       {
  450.          _loc1_ = 0;
  451.       }
  452.       if(lastIndex >= _loc2_.getRemoteLength())
  453.       {
  454.          lastIndex = _loc2_.getRemoteLength() - 1;
  455.       }
  456.       var _loc3_ = undefined;
  457.       var last;
  458.       while(_loc1_ <= lastIndex)
  459.       {
  460.          while(_loc1_ <= lastIndex && _loc2_.items[_loc1_] != null)
  461.          {
  462.             _loc1_ = _loc1_ + 1;
  463.          }
  464.          _loc3_ = _loc1_;
  465.          while(_loc1_ <= lastIndex && _loc2_.items[_loc1_] == null)
  466.          {
  467.             _loc2_.mOutstandingRecordCount = _loc2_.mOutstandingRecordCount + 1;
  468.             _loc2_.items[_loc1_] = 1;
  469.             _loc1_ = _loc1_ + 1;
  470.          }
  471.          last = _loc1_ - 1;
  472.          if(_loc3_ <= last)
  473.          {
  474.             _loc2_.logger.logInfo(" Fetching records from index [" + _loc3_ + "] to index [" + last + "]");
  475.             _loc2_.getRecordSetService().getRecords(_loc2_.mRecordSetID,_loc3_ + 1,last - _loc3_ + 1);
  476.             highestRequested = last;
  477.             _loc2_.updateViews("fetchRows",_loc3_,last);
  478.          }
  479.       }
  480.       return highestRequested;
  481.    }
  482.    function removeItems(index, len)
  483.    {
  484.       var _loc3_ = index;
  485.       var _loc2_ = new Array();
  486.       var _loc1_ = 0;
  487.       while(_loc1_ < len)
  488.       {
  489.          _loc2_.push(this.getItemID(_loc3_ + _loc1_));
  490.          _loc1_ = _loc1_ + 1;
  491.       }
  492.       var oldItems = this.items.splice(_loc3_,len);
  493.       this.dispatchEvent({type:"modelChanged",eventName:"removeItems",firstItem:_loc3_,lastItem:_loc3_ + len - 1,removedItems:oldItems,removedIDs:_loc2_});
  494.    }
  495.    function getRecords_Result(info)
  496.    {
  497.       var _loc1_ = this;
  498.       var _loc2_ = info;
  499.       _loc1_.setData(_loc2_.Cursor - 1,_loc2_.Page);
  500.       _loc1_.mOutstandingRecordCount -= _loc2_.Page.length;
  501.       _loc1_.updateViews("updateItems",_loc2_.Cursor - 1,_loc2_.Cursor - 1 + _loc2_.Page.length - 1);
  502.       if(_loc1_.mRecordsAvailable == _loc1_.mTotalCount && !_loc1_.mAllNotified)
  503.       {
  504.          _loc1_.updateViews("allRows");
  505.          _loc1_.mRecordSetService.release();
  506.          _loc1_.mAllNotified = true;
  507.          _loc1_.mRecordSetID = null;
  508.          _loc1_.mRecordSetService = null;
  509.       }
  510.    }
  511.    function release_Result()
  512.    {
  513.    }
  514.    function requestOneRecord(index)
  515.    {
  516.       var _loc1_ = this;
  517.       var _loc2_ = index;
  518.       if(_loc1_.items[_loc2_] == null)
  519.       {
  520.          if(_loc1_.mDeliveryMode == "ondemand")
  521.          {
  522.             _loc1_.logger.logInfo(" INFO: Fetching Record [" + _loc2_ + "]");
  523.          }
  524.          _loc1_.getRecordSetService().getRecords(_loc1_.mRecordSetID,_loc2_ + 1,1);
  525.          _loc1_.mOutstandingRecordCount = _loc1_.mOutstandingRecordCount + 1;
  526.          _loc1_.items[_loc2_] = 1;
  527.          _loc1_.updateViews("fetchRows",_loc2_,_loc2_);
  528.       }
  529.    }
  530.    function requestRecord(index)
  531.    {
  532.       var _loc1_ = this;
  533.       if(_loc1_.mDeliveryMode != "page")
  534.       {
  535.          _loc1_.requestOneRecord(index);
  536.       }
  537.       else
  538.       {
  539.          var _loc2_ = int(index / _loc1_.mPageSize) * _loc1_.mPageSize;
  540.          var _loc3_ = _loc2_ + _loc1_.mPageSize * (_loc1_.mNumPrefetchPages + 1) - 1;
  541.          _loc1_.internalRequestRange(_loc2_,_loc3_);
  542.       }
  543.    }
  544.    function _setParentService(service)
  545.    {
  546.       this.gateway_conn = service.nc;
  547.    }
  548.    function setData(start, dataArray)
  549.    {
  550.       var _loc1_ = this;
  551.       var datalen = dataArray.length;
  552.       var _loc3_ = undefined;
  553.       var rec;
  554.       var _loc2_ = 0;
  555.       while(_loc2_ < datalen)
  556.       {
  557.          _loc3_ = _loc2_ + start;
  558.          rec = _loc1_.items[_loc3_];
  559.          if(rec != null && rec != 1)
  560.          {
  561.             mx.remoting.NetServices.trace("RecordSet","warning",106,"Already got record # " + _loc3_);
  562.          }
  563.          else
  564.          {
  565.             _loc1_.mRecordsAvailable += 1;
  566.          }
  567.          _loc1_.items[_loc3_] = _loc1_.arrayToObject(dataArray[_loc2_]);
  568.          _loc1_.items[_loc3_].__ID__ = _loc1_.uniqueID++;
  569.          _loc2_ = _loc2_ + 1;
  570.       }
  571.    }
  572.    function startFetchAll(pagesize)
  573.    {
  574.       var _loc1_ = this;
  575.       if(_loc1_.mDataFetcher != null)
  576.       {
  577.          _loc1_.mDataFetcher.disable();
  578.       }
  579.       _loc1_.mDataFetcher = new mx.remoting.RsDataFetcher(_loc1_,pagesize);
  580.    }
  581.    function stopFetchAll()
  582.    {
  583.       this.mDataFetcher.disable();
  584.       this.mDataFetcher = null;
  585.    }
  586.    function updateViews(event, first, last)
  587.    {
  588.       this.dispatchEvent({type:"modelChanged",eventName:event,firstItem:first,lastItem:last});
  589.    }
  590.    static function registerRecordSet()
  591.    {
  592.       Object.registerClass("RecordSet",mx.remoting.RecordSet);
  593.       return true;
  594.    }
  595. }
  596.