[sidebar] Functionality to cancel editing
authorErik Haider Forsén <erikhf@ifi.uio.no>
Thu, 26 Nov 2015 12:10:44 +0000 (13:10 +0100)
committerErik Haider Forsén <erikhf@ifi.uio.no>
Thu, 26 Nov 2015 12:10:44 +0000 (13:10 +0100)
src/components/sidebar/sidebar.html
src/components/sidebar/sidebar.ts

index 8c7e39f..f5fd079 100644 (file)
@@ -1,6 +1,7 @@
 <div>
     <div *ng-if="activeOrgUnit">
         <form *ng-if="editmode" (ng-submit)="onSubmit()" #of="form">
+            <h3>{{activeOrgUnit.id?"Update Organizational Unit":"Add new Organizational Unit"}}</h3>
             <div class="form-group">
                 <label>Name</label>
                 <input class="form-control" type="text" [(ng-model)]="activeOrgUnit.name" required ng-control="name" #name="form">
@@ -45,7 +46,8 @@
                     <input class="form-control" type="text" [(ng-model)]="group.name">
                 </div>
             </fieldset>
-            <button type="submit" [disabled]="!of.form.valid" class="btn btn-default">Save</button>
+            <button type="button" (click)="cancel()" class="btn btn-default">Cancel</button>
+            <button type="submit" [disabled]="!of.form.valid" class="btn btn-default">{{activeOrgUnit.id? "Update" :"Add"}}</button>
 
         </form>
 
@@ -82,8 +84,9 @@
             <ul *ng-for="#group of activeOrgUnit.organisationUnitGroups">
                 <li>{{group.name}}</li>
             </ul>
+            <button class="btn btn-default" (click)="editmode = !editmode">Edit</button>
         </section>
-        <button class="btn btn-default" (click)="editmode = !editmode">{{editmode ? "Cancel" : "Edit"}}</button>
+
 
     </div>
 </div>
\ No newline at end of file
index f2e6142..b513341 100644 (file)
@@ -27,7 +27,6 @@ export class Sidebar {
     }
 
     update(orgunitId) {
-        console.log(orgunitId);
         this.http.get(dhisAPI + "/api/organisationUnits/" + orgunitId)
             .map(res => res.json())
             .subscribe(res => this.activeOrgUnit = res)
@@ -49,5 +48,14 @@ export class Sidebar {
         }
 
     }
+
+    cancel(){
+        this.editmode = false;
+        if(this.activeOrgUnit.id){
+            this.update(this.activeOrgUnit.id);
+        }else{
+            this.activeOrgUnit = null;
+        }
+    }
 }