
/* Services */

/**
 * Admin Survey service
 */
angular.module('myApp.services')
    .factory('Modal', function ($dialog, $location) {
        'use strict';
        return {
            confirmDelete: function (object, options) {
                options = options || {};

                var msg, title, buttons;
                if (options.label) {
                    msg = 'Do you want to delete "' + options.label + '" ?';
                } else {
                    msg = 'Do you want to delete it ?';
                }
                title = 'Confirm deletion';
                buttons = [
                    {result: 'cancel', label: 'Cancel'},
                    {result: 'delete', label: 'Delete', cssClass: 'btn-danger'}
                ];

                $dialog.messageBox(title, msg, buttons)
                    .open()
                    .then(function (result) {
                        if (result === 'delete') {
                            var params = options.params || {};
                            params.id = object.id;

                            // If we have an array, look for the element before we delete it
                            var toSplice = null;
                            if (options.objects) {
                                angular.forEach(options.objects, function (o, i) {
                                    if (object.id === o.id) {
                                        toSplice = i;
                                    }
                                });
                            }

                            object.$delete(params, function () {

                                // remove from local storage
                                if (toSplice != null) {
                                    options.objects.splice(toSplice, 1);
                                }

                                if (options.returnUrl) {
                                    $location.path(options.returnUrl);
                                }
                            });
                        }
                    });
            }
        };
    });
@@ -151,24 +151,25 @@
 trict';%0A
+%0A
         
 return %7B
@@ -164,28 +164,11 @@
     
-return %7B%0A           
+var
  con
@@ -177,17 +177,26 @@
 rmDelete
-:
+Internal =
  functio
@@ -225,28 +225,24 @@
             
-    
 options = op
@@ -263,28 +263,24 @@
             
- 
-   
 var msg, tit
@@ -296,36 +296,32 @@
 ns;%0A            
-    
 if (options.labe
@@ -321,28 +321,24 @@
 ns.label) %7B%0A
-    
             
@@ -410,20 +410,16 @@
         
- 
-   
 %7D else %7B
@@ -419,20 +419,16 @@
  else %7B%0A
-    
         
@@ -479,32 +479,26 @@
             
-    %7D%0A  
+%7D%0A
             
@@ -497,18 +497,16 @@
         
-  
 title = 
@@ -525,20 +525,16 @@
 etion';%0A
-    
         
@@ -557,36 +557,32 @@
                 
-    
 %7Bresult: 'cancel
@@ -610,36 +610,32 @@
                 
-  
-  
 %7Bresult: 'delete
@@ -694,20 +694,12 @@
     
-    %5D;%0A%0A    
+%5D;%0A%0A
     
@@ -766,20 +766,16 @@
     
-   
- 
 .open()%0A
     
@@ -770,20 +770,16 @@
 .open()%0A
-    
         
@@ -828,28 +828,24 @@
             
-    
 if (result =
@@ -879,28 +879,24 @@
             
-   
- 
 var params =
@@ -942,20 +942,16 @@
         
-    
 params.i
@@ -990,20 +990,16 @@
         
-  
-  
 // If we
@@ -1055,20 +1055,16 @@
 lete it%0A
-    
         
@@ -1116,36 +1116,32 @@
                 
-    
 if (options.obje
@@ -1143,28 +1143,24 @@
 .objects) %7B%0A
-    
             
@@ -1222,28 +1222,24 @@
 on (o, i) %7B%0A
-    
             
@@ -1320,20 +1320,16 @@
         
-    
 toSplice
@@ -1334,20 +1334,16 @@
 ce = i;%0A
-    
         
@@ -1388,36 +1388,32 @@
                 
-    
 %7D);%0A            
@@ -1420,35 +1420,27 @@
             
- 
-   %7D%0A%0A    
+%7D%0A%0A
             
@@ -1517,20 +1517,16 @@
         
-    
 // remov
@@ -1570,28 +1570,24 @@
             
- 
-   
 if (toSplice
@@ -1594,28 +1594,24 @@
  != null) %7B%0A
-    
             
@@ -1687,36 +1687,32 @@
                 
-    
 %7D%0A%0A             
@@ -1718,36 +1718,32 @@
                 
-  
-  
 if (options.retu
@@ -1747,28 +1747,24 @@
 eturnUrl) %7B%0A
-    
             
@@ -1818,32 +1818,54 @@
 rnUrl);%0A        
+                    %7D%0A
                 
@@ -1865,32 +1865,34 @@
                %7D
+);
 %0A               
@@ -1883,32 +1883,39 @@
 %0A               
+     %7D%0A
              %7D);
@@ -1907,32 +1907,35 @@
             
+   
 %7D);%0A    
             
@@ -1914,32 +1914,479 @@
         %7D);%0A    
+    %7D;%0A%0A        return %7B%0A            confirmDelete: function (object, options) %7B%0A%0A                // If we detect objects is a promise, wait for the promise to be completed and then show dialog%0A                if (options.objects && typeof options.objects.then == 'function') %7B%0A                    options.objects.then(function(data)%7B%0A                        options.objects = data;%0A                        confirmDeleteInternal(object, options);%0A
                 
@@ -2386,32 +2386,34 @@
            %7D
+);
 %0A       
             
@@ -2392,32 +2392,43 @@
      %7D);%0A       
+         %7D%0A
              %7D);
@@ -2416,35 +2416,169 @@
  %7D%0A             
-%7D);
+   // Otherwise show dialog directly%0A                else %7B%0A                    confirmDeleteInternal(object, options);%0A                %7D
 %0A            %7D%0A 

Support promise for deleteConfirmation