Changeset 2558


Ignore:
Timestamp:
02/08/13 15:20:26 (11 years ago)
Author:
twagoo
Message:

Check component usage before deletion attempt. Refs #275

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/DeleteService.as

    r1896 r2558  
    1515        import mx.rpc.http.HTTPService;
    1616        import mx.utils.StringUtil;
    17 
     17       
    1818        [Event(name="itemDeleted", type="flash.events.Event")]
    19 
     19       
    2020        public class DeleteService extends EventDispatcher {
    2121                public static const ITEM_DELETED:String = "itemDeleted";
    2222                private var service:HTTPService;
    2323                private static const DELETE_METHOD:Object = {"method": "delete"};
    24 
     24               
    2525                private static var _instance:DeleteService = new DeleteService();
    26 
     26               
    2727                public function DeleteService() {
    2828                        if (_instance != null) {
     
    3434                        service.method = HTTPRequestMessage.POST_METHOD;
    3535                }
    36 
     36               
    3737                public function deleteItem(item:ItemDescription):void {
    3838                        CursorManager.setBusyCursor();
    39                         var url:URI = new URI(item.dataUrl);
     39                       
     40                        var deleteUrl:URI = new URI(item.dataUrl);
    4041                        if (item.isInUserSpace) {
    41                                 url.setQueryValue(Config.PARAM_USERSPACE, "true");
     42                                deleteUrl.setQueryValue(Config.PARAM_USERSPACE, "true");
    4243                        }
    43                         sendDelete(url);
     44                       
     45                        var  usageService:ComponentUsageService = new ComponentUsageService(item, item.isInUserSpace);
     46                        usageService.addEventListener(ComponentUsageCheckEvent.COMPONENT_IN_USE,
     47                                function (event:ComponentUsageCheckEvent):void{
     48                                        if(event.isComponentInUse){
     49                                                onComponentInUse(event);
     50                                        } else {
     51                                                sendDelete(deleteUrl);
     52                                        }
     53                                });
     54                        usageService.checkUsage();
     55                }
     56               
     57                public function onComponentInUse(event:ComponentUsageCheckEvent):void{
     58                        var messageBody:String = "The component cannot be deleted because it is used by the following component(s) and/or profile(s):\n\n";
     59                        for each(var name:String in event.itemUsingComponent){
     60                                messageBody += " - " + name + "\n";
     61                        }
     62                        CursorManager.removeBusyCursor();
     63                        Alert.show(messageBody,"Component is used");
    4464                }
    4565               
     
    6181                        service.send(DELETE_METHOD);
    6282                }
    63 
     83               
    6484                private function handleResult(resultEvent:ResultEvent):void {
    6585                        CursorManager.removeBusyCursor();
     
    7090                        }
    7191                }
    72 
     92               
    7393                public function handleError(faultEvent:FaultEvent):void {
    7494                        CursorManager.removeBusyCursor();
     
    81101                        }
    82102                }
    83 
     103               
    84104                public static function get instance():DeleteService {
    85105                        return _instance;
Note: See TracChangeset for help on using the changeset viewer.