]> git.uio.no Git - u/erikhf/frm.git/commitdiff
[bugfix] edit and add positions
authorErik Haider Forsén <erikhf@ifi.uio.no>
Thu, 10 Dec 2015 17:06:01 +0000 (18:06 +0100)
committerErik Haider Forsén <erikhf@ifi.uio.no>
Thu, 10 Dec 2015 17:06:12 +0000 (18:06 +0100)
package.json
src/components/app.html
src/components/sidebar/sidebar.ts

index 9e6b6ec332ba30463ea360c5a7735dcd21602e2f..aaef61f2e41e80a06d4c35b0b99b7c6870117205 100644 (file)
@@ -16,7 +16,7 @@
   "license": "ISC",
   "dependencies": {
     "@reactivex/rxjs": "^5.0.0-alpha.10",
-    "angular2": "2.0.0-alpha.48",
+    "angular2": "2.0.0-alpha.44",
     "systemjs": "0.19.2"
   },
   "devDependencies": {
index f5ace350a28c398e1df75d4eec092bdcf5d228f9..c9c2e54962b2089b0da7bfd9c54e41f83112fc55 100644 (file)
@@ -2,7 +2,7 @@
 
 
     <div class="col-lg-9 col-md-8 col-xs-7"><mou-search (newsearch)="map.update($event)"></mou-search></div>
-    <div class="col-lg-3 col-md-4 col-xs-5 no-padding"><mou-sidebar (tempmarker)="map.tempMarker($event)" #sidebar></mou-sidebar></div>
+    <div class="col-lg-3 col-md-4 col-xs-5 no-padding"><mou-sidebar (tempmarker)="map.tempMarker($event)" (updateorg)="map.update($event)"#sidebar></mou-sidebar></div>
 
     <mou-map (newactive)="sidebar.update($event)" (neworg)="sidebar.add($event)"#map (toplevel)="showtoplevel()"></mou-map>
 </div>
index 649a246b5ce4a81b1ae300a98b44fcab4cffd306..9ca4bd003853f10f803f0b9a44b6c248c5856d7f 100644 (file)
@@ -6,7 +6,7 @@ declare var zone: Zone;
 @Component({
     selector: 'mou-sidebar',
     directives: [CORE_DIRECTIVES, FORM_DIRECTIVES, NgFor, NgModel, NgIf],
-    events: ['tempmarker'],
+    events: ['tempmarker','updateorg'],
     templateUrl: './components/sidebar/sidebar.html'
 })
 
@@ -71,6 +71,7 @@ export class Sidebar {
         this.active = false;
         this.coordinatePoint = false;
         this.tempmarker = new EventEmitter();
+        this.updateorg = new EventEmitter();
         this.exitButton = document.getElementById("slideout")
 
         let instance = this;
@@ -130,8 +131,8 @@ export class Sidebar {
             this.coordinatePoint = true;
             let coord = new Object();
             coord = JSON.parse(res["coordinates"]);
-            this.form.controls.lat.updateValue(coord[0]);
-            this.form.controls.lng.updateValue(coord[1]);
+            this.form.controls.lat.updateValue(coord[1]);
+            this.form.controls.lng.updateValue(coord[0]);
         }
         else{
             this.coordinatePoint = false;
@@ -169,11 +170,11 @@ export class Sidebar {
         });
 
         $.each(jsonObject.organisationUnitGroups, function(key, value){
-            if( value === "" || value === null){
+//            if( value === "" || value === null){
                 delete jsonObject.organisationUnitGroups[key];
-            } else {
-                jsonObject.organisationUnitGroups[key].id = value;
-            }
+  //          } else {
+  //              jsonObject.organisationUnitGroups[key].id = value;
+   //         }
         });
 
 
@@ -190,14 +191,14 @@ export class Sidebar {
             jsonObject.parent = {};
             jsonObject.parent.id = this.form.controls.parent.value;
             jsonObject.featureType="POINT";
-            jsonObject.coordinates="[" + this.form.controls.lat.value + ","+this.form.controls.lng.value+"]";
+            jsonObject.coordinates="[" + this.form.controls.lng.value + ","+this.form.controls.lat.value+"]";
             delete jsonObject["lat"];
             delete jsonObject["lng"];
             this.http.post(dhisAPI + "/api/organisationUnits/", JSON.stringify(jsonObject), {
                     headers: headers
                 })
                 .map(res => res.json())
-                .subscribe(res => console.log(res));
+                .subscribe(res => this.emitNewUpdatedObject(res));
         }else {
             this.http.put(dhisAPI + "/api/organisationUnits/" + this.form.controls.id.value, JSON.stringify(jsonObject), {
                     headers: headers
@@ -206,10 +207,19 @@ export class Sidebar {
                 .subscribe(res => console.log(res));
         }
 
+
+
+
+    }
+
+    emitNewUpdatedObject(obj){
+        console.log(obj);
+        this.updateorg.next(obj.response.lastImported);
     }
 
     cancel(){
         this.editmode = false;
+        this.tempmarker.next(null);
     }