|
|
@@ -8,29 +8,11 @@
|
|
|
<script type="text/javascript" src="static/searchBar.js"></script>
|
|
|
<script type="text/javascript" src="static/paginatedTable.js"></script>
|
|
|
<script type="text/javascript">
|
|
|
- var app = angular.module('ingredients', ['ndbDatabase', 'basicFoodEditor', 'ui.bootstrap', 'ieat.ui']);
|
|
|
+ var app = angular.module('ingredients', ['ndbDatabase', 'ui.bootstrap', 'ieat.ui', 'ieat.ui.editors']);
|
|
|
// TODO: Disable debug info in prod version
|
|
|
app.controller('SearchController', ['$scope', '$uibModal', 'NDBSearch', 'NDBFood', 'BasicFood',
|
|
|
- function($scope, $uibModal, NDBSearch, NDBFood, BasicFood) {
|
|
|
+ function($scope, $uibModal, NDBSearch, NDBFood, BasicFood) {
|
|
|
$scope.searchResults = [];
|
|
|
- $scope.table = [
|
|
|
- {
|
|
|
- name: "NDB #",
|
|
|
- col: "ndbno",
|
|
|
- size: 1
|
|
|
- }, {
|
|
|
- name: "Name",
|
|
|
- col: "name",
|
|
|
- size: 6
|
|
|
- }, {
|
|
|
- name: "Group",
|
|
|
- col: "group"
|
|
|
- }, {
|
|
|
- name: "Manufacturer",
|
|
|
- col: "manu"
|
|
|
- }
|
|
|
- ];
|
|
|
-
|
|
|
$scope.searchFn = function(searchTerm) {
|
|
|
NDBSearch.get({
|
|
|
"key": "${ndbKey}",
|
|
|
@@ -40,36 +22,65 @@
|
|
|
}, function (err) {
|
|
|
// TODO: Actual error handling
|
|
|
console.error(err);
|
|
|
- })
|
|
|
+ });
|
|
|
};
|
|
|
+
|
|
|
+ var modalCtrl = ['$scope', '$uibModalInstance', 'food', function($scope, $uibModalInstance, food) {
|
|
|
+ $scope.food = food;
|
|
|
+ $scope.submit = $uibModalInstance.close;
|
|
|
+ $scope.dismiss = $uibModalInstance.dismiss;
|
|
|
+ }];
|
|
|
|
|
|
- $scope.promptWindow = function(item) {
|
|
|
- var foodRequest = NDBFood.get(
|
|
|
- {
|
|
|
- "key": "${ndbKey}",
|
|
|
- "ndbno": item.ndbno,
|
|
|
- "type": "f"
|
|
|
- }).$promise.then(function(data) {
|
|
|
- return BasicFood.fromNdb(data);
|
|
|
- }, function (err) {
|
|
|
- // TODO: Proper error handling
|
|
|
- console.error(err);
|
|
|
- });
|
|
|
+ var promptWindow = function(item) {
|
|
|
+ var foodRequest = NDBFood.get({
|
|
|
+ "key": "${ndbKey}",
|
|
|
+ "ndbno": item.ndbno,
|
|
|
+ "type": "f"
|
|
|
+ }).$promise.then(function(data) {
|
|
|
+ return BasicFood.fromNdb(data);
|
|
|
+ }, function (err) {
|
|
|
+ // TODO: Proper error handling
|
|
|
+ console.error(err);
|
|
|
+ });
|
|
|
$uibModal.open({
|
|
|
// TODO: Figure out what these are and how they work
|
|
|
//ariaLabelledBy: 'modal-title',
|
|
|
//ariaDescribedBy: 'modal-body',
|
|
|
- templateUrl: '${url}/static/templates/editBasicFood.html',
|
|
|
- controller: 'BasicFoodEditorController',
|
|
|
- size: "md",
|
|
|
+ templateUrl: "modal",
|
|
|
resolve: {
|
|
|
- foodData: function() {return foodRequest;},
|
|
|
- ndbKey: function() {return "${ndbKey}";}
|
|
|
- }
|
|
|
- }).result.then(function() {
|
|
|
- // TODO: Push put response into array.
|
|
|
+ food: function() {return foodRequest;}
|
|
|
+ },
|
|
|
+ controller: modalCtrl,
|
|
|
+ size: "md"
|
|
|
+ }).result.then(function(food) {
|
|
|
+ food.$save(null, function(err) {
|
|
|
+ // TODO: Error handling
|
|
|
+ console.error(err);
|
|
|
+ });
|
|
|
+ }, function(reason) {
|
|
|
+ console.debug(reason);
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
+ $scope.table = [{
|
|
|
+ defaultValue: "Add",
|
|
|
+ onClick: promptWindow,
|
|
|
+ size: 1
|
|
|
+ }, {
|
|
|
+ name: "NDB #",
|
|
|
+ col: "ndbno",
|
|
|
+ size: 1
|
|
|
+ }, {
|
|
|
+ name: "Name",
|
|
|
+ col: "name",
|
|
|
+ size: 6
|
|
|
+ }, {
|
|
|
+ name: "Group",
|
|
|
+ col: "group"
|
|
|
+ }, {
|
|
|
+ name: "Manufacturer",
|
|
|
+ col: "manu"
|
|
|
+ }];
|
|
|
}]);
|
|
|
</script>
|
|
|
</jsp:attribute>
|
|
|
@@ -85,10 +96,18 @@
|
|
|
data-delay="100">
|
|
|
</search-bar>
|
|
|
</div>
|
|
|
- <paginated-table data-table-data="searchResults"
|
|
|
- data-structure="table"
|
|
|
- data-on-select="promptWindow(item)">
|
|
|
+ <paginated-table data-table-data="searchResults" data-structure="table">
|
|
|
</paginated-table>
|
|
|
+
|
|
|
+ <script type="text/ng-template" id="modal">
|
|
|
+ <basic-food-editor data-ndb-key="${ndbKey}" data-food="food"></basic-food-editor>
|
|
|
+ <div style="width: 100%; text-align: right; padding-right: 1em; padding-bottom: 1em;">
|
|
|
+ <button type="button"
|
|
|
+ class="btn btn-success"
|
|
|
+ data-ng-click="submit(food);">Submit</button>
|
|
|
+ <button type="button" class="btn" data-ng-click="dismiss();">Cancel</button>
|
|
|
+ </div>
|
|
|
+ </script>
|
|
|
</div>
|
|
|
</jsp:body>
|
|
|
</t:template>
|