[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 9e6b6ec..aaef61f 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 f5ace35..c9c2e54 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 649a246..9ca4bd0 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);
     }