| <div class="newstore-form" ng-controller="EditStoreController"> | |
| <form class="container-fluid"> | |
| <div class="row"> | |
| <div class="form-group col-md-6"> | |
| <label for="store">Store Name</label> | |
| <input type="text" class="form-control" ng-model="newData.store"> | |
| </div> | |
| <div class="form-group col-md-6"> | |
| <label for="groups">Groups</label> | |
| <div class="radio" ng-repeat="(group, role) in vm.allGroups"> | |
| <label><input type="checkbox" ng-click="vm.newData.addOrRemove(group)">{{label> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="row"> | |
| <div class="form-group col-md-4"> | |
| <select class="business_type" ng-model="newData.business_type"> | |
| <option>Clothing</option> | |
| </select> | |
| </div> | |
| <div class="form-group col-md-4"> | |
| <label for="phone_number">Phone Number</label> | |
| <input type="number" class="form-control" ng-model="newData.phone_number"> | |
| </div> | |
| <div class="form-group col-md-4"> | |
| <label for="country">Country</label> | |
| <input type="text" class="form-control" ng-model="newData.country" placeholder="USA"> | |
| </div> | |
| </div> | |
| <div class="row"> | |
| <div class="form-group col-md-4"> | |
| <label for="state">State</label> | |
| <input type="text" class="form-control" ng-model="newData.state" placeholder="California"> | |
| </div> | |
| <div class="form-group col-md-4"> | |
| <label for="city">City</label> | |
| <input type="text" class="form-control" ng-model="newData.city" placeholder="San Francisco"> | |
| </div> | |
| <div class="form-group col-md-4"> | |
| <label for="zip">Zip Code</label> | |
| <input type="number" class="form-control" ng-model="newData.zip" placeholder="94105"> | |
| </div> | |
| <div class="form-group col-md-4"> | |
| <label for="neighborhood">Neighborhood</label> | |
| <input type="text" class="form-control" ng-model="newData.neighborhood" placeholder="SoMa"> | |
| </div> | |
| </div> | |
| <button type="submit" class="btn btn-primary" ng-click="vm.submit()">Submit</button> | |
| </form> | |
| </div> |
| export default class EditStoreController { | |
| constructor($scope, $http, datastore, $stateParams){ | |
| 'ngInject'; | |
| this.scope = $scope; | |
| this.http = $http; | |
| this.config = {"withCredentials": true, "Access-Control-Allow-Origin": true}; | |
| this.account = datastore.retrieve("account"); | |
| this.storedata = JSON.parse(datastore.retrieve($stateParams.store)) | |
| this.scope.oldData = { | |
| store: this.storedata['store'], | |
| // groups: this.storedata['groups'], | |
| allGroups: {"westcoast": "admin", "eastcoast": "admin"}, | |
| neighborhood: this.storedata['neighborhood'], | |
| phone_number: parseInt(this.storedata['phone_number']), | |
| business_type: this.storedata['business_type'], | |
| country: this.storedata['country'], | |
| state: this.storedata['state'], | |
| city: this.storedata['city'], | |
| zip: parseInt(this.storedata['zip']) | |
| } | |
| this.scope.newData = { | |
| store: this.storedata['store'], | |
| // groups: this.storedata['groups'], | |
| allGroups: {"westcoast": "admin", "eastcoast": "admin"}, | |
| neighborhood: this.storedata['neighborhood'], | |
| phone_number: parseInt(this.storedata['phone_number']), | |
| business_type: this.storedata['business_type'], | |
| country: this.storedata['country'], | |
| state: this.storedata['state'], | |
| city: this.storedata['city'], | |
| zip: parseInt(this.storedata['zip']) | |
| } | |
| } | |
| submit(){ | |
| let changes = this.changes(); | |
| let body = JSON.stringify({ | |
| changes: changes | |
| }) | |
| this.http.put("http://192.168.99.100:3000" + `/accounts/v1/${this.account}/stores/${this.scope.store}`, body, this.config) | |
| .then(response => console.log(response)) | |
| .catch(err => console.log(err)) | |
| } | |
| changes(){ | |
| var o = this.scope.oldData; | |
| var n = this.scope.newData; | |
| var changes = {}; | |
| Object.keys(o).forEach((key) => { | |
| console.log([o[key], n[key]]) | |
| if (o[key] != n[key]){ | |
| changes[key] = n[key] | |
| } | |
| }) | |
| return changes | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment