GetEthnicCommand.as 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.imt.intimamedia.commands.initialization
  2. {
  3. import com.adobe.cairngorm.control.CairngormEvent;
  4. import com.imt.flex.cairngormExtended.command.SuperCommand;
  5. import com.imt.intimamedia.business.InitializationDelegate;
  6. import com.imt.intimamedia.model.ApplicationModelLocator;
  7. import com.imt.intimamedia.views.common.ImtToaster;
  8. import com.imt.intimamedia.vo.GenericObject;
  9. import mx.collections.ArrayCollection;
  10. import mx.collections.Sort;
  11. import mx.collections.SortField;
  12. import mx.resources.ResourceManager;
  13. import mx.rpc.events.FaultEvent;
  14. import mx.rpc.events.ResultEvent;
  15. import mx.utils.ObjectUtil;
  16. /**
  17. * Commande de récupération des ethnies
  18. */
  19. public class GetEthnicCommand extends SuperCommand
  20. {
  21. [Bindable]
  22. private var _model : ApplicationModelLocator = ApplicationModelLocator.getInstance();
  23. /**
  24. * Execution de la commande
  25. *
  26. * @param event Evénement de type CairngormEvent
  27. * @return void
  28. */
  29. override public function execute( event : CairngormEvent ) : void
  30. {
  31. super.execute( event );
  32. var delegate : InitializationDelegate = new InitializationDelegate( this );
  33. delegate.getEthnic();
  34. }
  35. /**
  36. * Résultat de la commande
  37. *
  38. * @param result Un objet
  39. * @return void
  40. */
  41. override public function result( result : Object ) : void
  42. {
  43. super.result( result );
  44. var resultEvent : ResultEvent = ResultEvent( result );
  45. var ethnic : ArrayCollection = new ArrayCollection();
  46. for each( var code : String in (resultEvent.result as Array) )
  47. {
  48. var item : GenericObject = new GenericObject();
  49. item.code = code
  50. item.label = ResourceManager.getInstance().getString( "ethnic", code );
  51. ethnic.addItem( item );
  52. }
  53. _model.ethnic = ObjectUtil.copy( ethnic ) as ArrayCollection;
  54. var dataSortField : SortField = new SortField();
  55. dataSortField.name = "label";
  56. dataSortField.numeric = false;
  57. var sort : Sort = new Sort();
  58. sort.fields = [ dataSortField ];
  59. _model.ethnic.sort = sort;
  60. _model.ethnic.refresh();
  61. }
  62. /**
  63. * Résultat de la commande
  64. *
  65. * @param result Un objet
  66. * @return void
  67. */
  68. override public function fault( fault : Object ) : void
  69. {
  70. super.fault( fault );
  71. var toastMessage : ImtToaster = new ImtToaster();
  72. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'error.title');
  73. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.questions') + " (" + ResourceManager.getInstance().getString('errors', ( fault as FaultEvent ).fault.faultString) +")";
  74. toastMessage.level = ImtToaster.ERROR;
  75. _model.toaster.toast( toastMessage );
  76. }
  77. }
  78. }