Guest User

Untitled

a guest
Dec 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. <historical-summary-table
  2. columns="::historicalSummaryCtrl.historicalColumns"
  3. lines-array="historicalSummaryCtrl.modifiedCustomerProperties"
  4. group-field="date",
  5. group-field-filter="date",
  6. group-field-filter-format="dd/MM/yyyy">
  7. </historical-summary-table>
  8.  
  9. <modal id="custom-modal-1">
  10. <div class="modal">
  11. <div class="modal-body">
  12. <h1>A Custom Modal!</h1>
  13. <p>
  14. Home page text: <input type="text" ng-model="vm.bodyText" />
  15. </p>
  16. <button ng-click="vm.closeModal('custom-modal-1');">Close</button>
  17. </div>
  18. </div>
  19. <div class="modal-background"></div>
  20. </modal>
  21.  
  22. (function() {
  23. 'use strict';
  24. angular
  25. .module('eciSubscription')
  26. .controller('historicalSummaryController', historicalSummaryController);
  27. historicalSummaryController.$inject = ['$scope', '$q', '$http', '$state', '$stateParams', '$filter', 'historicalService', 'customerFactory', 'historicalSummaryUtils', 'historicalUtils'];
  28. /* @ngInject */
  29. function historicalSummaryController($scope, $q, $http, $state, $stateParams, $filter, historicalService, customerFactory, historicalSummaryUtils, historicalUtils, ModalService) {
  30. var vm = this;
  31.  
  32. initController();
  33.  
  34.     function initController() {
  35.      vm.bodyText = 'This text can be updated in modal 1';
  36.     }
  37.          
  38.     function openModal(id){
  39.      ModalService.Open(id);
  40.     }
  41.  
  42.     function closeModal(id){
  43.      ModalService.Close(id);
  44.     }
  45.  
  46. ...
  47.  
  48. (function () {
  49. 'use strict';
  50.  
  51. angular
  52. .module('eciSubscription')
  53. .directive('modal', Directive);
  54.  
  55. function Directive(ModalService) {
  56. return {
  57. link: function (scope, element, attrs) {
  58. // ensure id attribute exists
  59. if (!attrs.id) {
  60. console.error('modal must have an id');
  61. return;
  62. }
  63.  
  64. // move element to bottom of page (just before </body>) so it can be displayed above everything else
  65. element.append('body');
  66.  
  67. // close modal on background click
  68. element.on('click', function (e) {
  69. var target = angular.element(e.target);
  70. if (!target.closest('.modal-body').length) {
  71. scope.$evalAsync(Close);
  72. }
  73. });
  74.  
  75. // add self (this modal instance) to the modal service so it's accessible from controllers
  76. var modal = {
  77. id: attrs.id,
  78. open: Open,
  79. close: Close
  80. };
  81. ModalService.Add(modal);
  82.  
  83. // remove self from modal service when directive is destroyed
  84. scope.$on('$destroy', function() {
  85. ModalService.Remove(attrs.id);
  86. element.remove();
  87. });
  88.  
  89. // open modal
  90. function Open() {
  91. element.show();
  92. angular.element('body').addClass('modal-open');
  93. }
  94.  
  95. // close modal
  96. function Close() {
  97. element.hide();
  98. angular.element('body').removeClass('modal-open');
  99. }
  100. }
  101. };
  102. }
  103. })();
  104.  
  105. function historicalSummaryTable($filter){
  106. return {
  107. restrict:'EA',
  108. link:link,
  109. templateUrl: 'jfrontalesru/app/components/historicalSummary/historicalSummaryTable.html',
  110. scope:{
  111. linesArray: "=",
  112. columns: "=",
  113. groupField:"@",
  114. groupFieldFilter:"@",
  115. groupFieldFilterFormat:"@"
  116. },
  117. };
  118.  
  119. function link(scope, element, attrs){
  120. var _groupField = 'groupField';
  121. var _subgroupField = 'subgroupField';
  122.  
  123. scope.$watch('linesArray',function(value){
  124. scope.linesArray.forEach(function(line){
  125. scope.columns.forEach(function(column, index){
  126. if(column.filter && column.filter.length > 0){
  127. console.log(line[column.key]);
  128. var date = new Date(line[column.key]);
  129. console.log(date);
  130. date = ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear();
  131. console.log(date);
  132.  
  133. line[column.key] = $filter(column.filter)(line[column.key], column.format);
  134. line[column.key] = date + ' ' + '(' + line[column.key] + ')';
  135. }
  136. });
  137. });
  138. });
  139. }
  140. }
Add Comment
Please, Sign In to add comment