@@ -44,40 +44,51 @@ domainsModule.factory('DomainFactory', function($resource, $rootScope) {
44
44
} ) ;
45
45
}
46
46
else {
47
- Domain . save ( domain , function ( d ) {
47
+ var domain_copy = _ . clone ( domain ) ;
48
+ domain . _id = 'ffffffffffffffffffffffff' ; // create a temporary ID
49
+ $rootScope . domains . push ( domain ) ;
50
+ $rootScope . calculateDomainAreaMap ( ) ;
51
+ Domain . save ( domain_copy , function ( d ) {
48
52
console . log ( 'successfully added domain!' , d ) ;
49
- $rootScope . domains . push ( d ) ;
53
+ domain . _id = d . _id ;
50
54
$rootScope . calculateDomainAreaMap ( ) ;
51
55
} , function ( response ) {
52
56
$rootScope . onError ( 'creating a domain' , response . data . error ) ;
57
+ $rootScope . domains = _ . without ( $rootScope . domains , domain ) ;
58
+ $rootScope . calculateDomainAreaMap ( ) ;
53
59
} ) ;
54
60
}
55
61
$rootScope . newDomain ( ) ;
56
62
} ;
57
63
58
64
$rootScope . deleteDomain = function ( domain ) {
65
+ var deleted_areas = [ ] ;
66
+ $rootScope . domains = _ . reject ( $rootScope . domains , function ( _domain ) {
67
+ return _domain . name === domain . name ;
68
+ } ) ;
69
+ _ . each ( $rootScope . domain_area_map [ domain . _id ] , function ( area ) {
70
+ deleted_areas . push ( area ) ;
71
+ $rootScope . handleDeletedArea ( area , false ) ;
72
+ } ) ;
73
+ $rootScope . calculateDomainAreaMap ( ) ;
59
74
domain . $delete ( { id : domain . _id } , function ( success ) {
60
75
console . log ( 'successfully deleted domain!' , domain ) ;
61
- $rootScope . domains = _ . reject ( $rootScope . domains , function ( _domain ) {
62
- return _domain . name === domain . name ;
63
- } ) ;
64
- _ . each ( $rootScope . domain_area_map [ domain . _id ] , function ( area ) {
65
- $rootScope . handleDeletedArea ( area , false ) ;
66
- } ) ;
67
- $rootScope . calculateDomainAreaMap ( ) ;
68
76
} , function ( response ) {
69
77
$rootScope . onError ( 'deleting a domain' , response . data . error ) ;
78
+ $rootScope . domains . push ( domain ) ;
79
+ _ . each ( deleted_areas , function ( area ) {
80
+ $rootScope . handleAddedArea ( area , false ) ;
81
+ } ) ;
82
+ $rootScope . calculateDomainAreaMap ( ) ;
70
83
} ) ;
71
84
} ;
72
85
73
86
var Domain = $resource ( '/api/domain/:id' , null ,
74
87
{ update : { method : 'PUT' } }
75
88
) ;
76
89
Domain . list = function ( cb ) {
77
- console . log ( 'Domain.list called' ) ;
78
90
if ( _ . isUndefined ( $rootScope . domains ) ) {
79
91
Domain . query ( function ( domains ) {
80
- console . log ( 'Domain.list cb' ) ;
81
92
$rootScope . domains = domains ;
82
93
if ( _ . isFunction ( cb ) ) { cb ( ) ; }
83
94
} , function ( response ) {
0 commit comments