units.jsp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
  3. <t:template>
  4. <jsp:attribute name="title">Unit Manager</jsp:attribute>
  5. <jsp:attribute name="head">
  6. <script type="text/javascript" src="static/units.js"></script>
  7. <script type="text/javascript" src="static/ndbDatabase.js"></script>
  8. <script type="text/javascript" src="static/paginatedTable.js"></script>
  9. <script type="text/javascript" src="static/unitEditor.js"></script>
  10. <script type="text/javascript">
  11. var app = angular.module('unitManager', [
  12. 'Units', 'ui.bootstrap', 'ieat.ui', 'ieat.ui.editors']);
  13. // TODO: Disable debug info in prod version
  14. app.controller('UnitController', [
  15. '$scope', '$uibModal', 'Unit',
  16. function($scope, $uibModal, Unit) {
  17. var loadUnitList = function(type) {
  18. type.list = Unit.query({"type": type.name.toLowerCase()});
  19. }
  20. var promptWindow = function(newUnit) {
  21. $uibModal.open({
  22. // TODO: Figure out what these are and how they work
  23. //ariaLabelledBy: 'modal-title',
  24. //ariaDescribedBy: 'modal-body',
  25. templateUrl: "addModal",
  26. controller: ['$scope', '$uibModalInstance',
  27. function($scope, $uibModalInstance) {
  28. $scope.addUnit = $uibModalInstance.close;
  29. $scope.dismiss = $uibModalInstance.dismiss;
  30. $scope.newUnit = newUnit;
  31. }],
  32. size: "md"
  33. }).result.then(function(unit) {
  34. unit.$save(function(resp) {
  35. loadUnitList(
  36. $scope.types.find(function(x) {
  37. return x.name == resp.type
  38. })
  39. );
  40. }, function(err) {
  41. // TODO: Error handling
  42. console.error(err);
  43. });
  44. }, function(reason) {
  45. console.debug(reason);
  46. });
  47. };
  48. $scope.table = [{
  49. name: "Name",
  50. col: "name"
  51. }, {
  52. name: "Abv.",
  53. col: "symbol",
  54. size: 1
  55. }, {
  56. name: "Conversion",
  57. col: "conversion"
  58. }, {
  59. defaultValue: "Edit",
  60. onClick: promptWindow,
  61. size: 1
  62. }, {
  63. name: "Add",
  64. onHeaderClick: function() {
  65. promptWindow(new Unit({
  66. type: $scope.types[$scope.activeType].name
  67. }));
  68. },
  69. defaultValue: "Delete",
  70. onClick: function(unit) {
  71. unit.$remove(function(resp) {
  72. loadUnitList(
  73. $scope.types.find(function(x) {
  74. return x.name == resp.type
  75. })
  76. );
  77. }, function(err) {
  78. // TODO: Error handling
  79. console.error(err);
  80. });
  81. },
  82. size: 1
  83. }];
  84. $scope.types = [
  85. {name: "Mass"},
  86. {name: "Volume"},
  87. {name: "Count"}
  88. ];
  89. angular.forEach($scope.types, function(type) {
  90. loadUnitList(type);
  91. });
  92. }]);
  93. </script>
  94. </jsp:attribute>
  95. <jsp:body>
  96. <div class="section container"
  97. data-ng-app="unitManager"
  98. data-ng-controller="UnitController">
  99. <h2>Unit Manager</h2>
  100. <uib-tabset data-active="activeType">
  101. <uib-tab data-ng-repeat="type in types"
  102. data-index="$index"
  103. data-heading="{{type.name}}">
  104. <paginated-table data-table-data="type.list"
  105. data-structure="table">
  106. </paginated-table>
  107. </uib-tab>
  108. </uib-tabset>
  109. <script type="text/ng-template" id="addModal">
  110. <unit-editor data-unit="newUnit">
  111. </unit-editor>
  112. <div style="width: 100%; text-align: right; padding: 0 1em 1em 0;">
  113. <button type="button"
  114. class="btn btn-success"
  115. data-ng-click="addUnit(newUnit);">Submit</button>
  116. <button type="button" class="btn" data-ng-click="dismiss();">
  117. Cancel
  118. </button>
  119. </div>
  120. </script>
  121. </div>
  122. </jsp:body>
  123. </t:template>